MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / grfont_SetTemplate

Function grfont_SetTemplate

grtext/grfont.cpp:541–689  ·  view source on GitHub ↗

MTS: unused? sets a template to a font, be careful.

Source from the content-addressed store, hash-verified

539// MTS: unused?
540// sets a template to a font, be careful.
541bool grfont_SetTemplate(const char *pathname, const tFontTemplate *ft) {
542 // okay, load the font manually, set the template members, then save it out.
543 tFontFileInfo fnt;
544 char tempstr[32];
545 FONTFILE ffin;
546 FONTFILE2 ffout;
547 int num_char, i;
548
549 tFontFileInfo2 ffi2;
550
551 ffin = OPEN_FONT(pathname);
552 if (!ffin) {
553 return false;
554 } else if (ffin == (FONTFILE)0xffffffff) {
555 mprintf(0, "Illegal font file %s\n", pathname);
556 return false;
557 }
558
559 // read header information
560 fnt.width = READ_FONT_SHORT(ffin);
561 fnt.height = READ_FONT_SHORT(ffin);
562 fnt.flags = READ_FONT_SHORT(ffin);
563 fnt.baseline = READ_FONT_SHORT(ffin);
564 fnt.min_ascii = READ_FONT_BYTE(ffin);
565 fnt.max_ascii = READ_FONT_BYTE(ffin);
566 READ_FONT_DATA(ffin, tempstr, 32, 1);
567
568 // read ffi2 font info
569 if (fnt.flags & FT_FFI2) {
570 ffi2.tracking = READ_FONT_SHORT(ffin);
571 READ_FONT_DATA(ffin, &ffi2.reserved, sizeof(ffi2.reserved), 1);
572 }
573
574 fnt.brightness = ((fnt.baseline >> 8) / 10.0f);
575
576 num_char = fnt.max_ascii - fnt.min_ascii + 1;
577
578 // Read in all widths
579 if (fnt.flags & FT_PROPORTIONAL) {
580 fnt.char_widths = (uint8_t *)mem_malloc(sizeof(uint8_t) * num_char);
581 for (i = 0; i < num_char; i++)
582 fnt.char_widths[i] = (uint8_t)READ_FONT_SHORT(ffin);
583 } else {
584 fnt.char_widths = nullptr;
585 }
586
587 // Read in kerning data
588 if (fnt.flags & FT_KERNED) {
589 int n_pairs = (int)READ_FONT_SHORT(ffin);
590 fnt.kern_data = (uint8_t *)mem_malloc(sizeof(uint8_t) * 3 * (n_pairs + 1));
591 for (i = 0; i < n_pairs; i++) {
592 fnt.kern_data[i * 3] = READ_FONT_BYTE(ffin);
593 fnt.kern_data[i * 3 + 1] = READ_FONT_BYTE(ffin);
594 fnt.kern_data[i * 3 + 2] = READ_FONT_BYTE(ffin);
595 }
596 fnt.kern_data[i * 3] = 255;
597 fnt.kern_data[i * 3 + 1] = 255;
598 fnt.kern_data[i * 3 + 2] = 0;

Callers 1

FontKernFunction · 0.85

Calls 12

OPEN_FONT2Function · 0.85
CLOSE_FONT2Function · 0.85
OPEN_FONTFunction · 0.70
READ_FONT_SHORTFunction · 0.70
READ_FONT_BYTEFunction · 0.70
READ_FONT_DATAFunction · 0.70
READ_FONT_INTFunction · 0.70
CLOSE_FONTFunction · 0.70
WRITE_FONT_INTFunction · 0.70
WRITE_FONT_SHORTFunction · 0.70
WRITE_FONT_BYTEFunction · 0.70
WRITE_FONT_DATAFunction · 0.70

Tested by

no test coverage detected