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

Function grfont_LoadTemplate

grtext/grfont.cpp:455–525  ·  view source on GitHub ↗

loads a font template

Source from the content-addressed store, hash-verified

453
454// loads a font template
455bool grfont_LoadTemplate(const char *fname, tFontTemplate *ft) {
456 FONTFILE ff;
457 char fontname[32];
458 int16_t ft_width, ft_height, ft_flags, ft_minasc, ft_maxasc, num_char, i;
459 tFontFileInfo2 ffi2;
460
461 // open file.
462 ff = OPEN_FONT(fname);
463 if (!ff) {
464 Error("Unable to open font %s.\n", fname);
465 } else if (ff == (FONTFILE)0xffffffff) {
466 Error("Illegal font file: %s.\n", fname);
467 }
468
469 // read header information
470 ft_width = READ_FONT_SHORT(ff);
471 ft_height = READ_FONT_SHORT(ff);
472 ft_flags = READ_FONT_SHORT(ff);
473 READ_FONT_SHORT(ff); // skip baseline value (HACKED FOR BRIGHTNESS)
474 ft_minasc = READ_FONT_BYTE(ff);
475 ft_maxasc = READ_FONT_BYTE(ff);
476 READ_FONT_DATA(ff, fontname, 32, 1); // read namae
477
478 // read ffi2 font info
479 if (ft_flags & FT_FFI2) {
480 ffi2.tracking = READ_FONT_SHORT(ff);
481 READ_FONT_DATA(ff, &ffi2.reserved, sizeof(ffi2.reserved), 1);
482 }
483
484 num_char = ft_maxasc - ft_minasc + 1;
485
486 // Read in all widths
487 if (ft_flags & FT_PROPORTIONAL) {
488 ft->ch_widths = (uint8_t *)mem_malloc(num_char);
489 for (i = 0; i < num_char; i++)
490 ft->ch_widths[i] = (uint8_t)READ_FONT_SHORT(ff);
491 } else {
492 ft->ch_widths = nullptr;
493 }
494
495 if (ft_flags & FT_KERNED) {
496 int n_pairs = (int)READ_FONT_SHORT(ff);
497 ft->kern_data = (uint8_t *)mem_malloc(sizeof(uint8_t) * 3 * (n_pairs + 1));
498 for (i = 0; i < n_pairs; i++) {
499 ft->kern_data[i * 3] = READ_FONT_BYTE(ff);
500 ft->kern_data[i * 3 + 1] = READ_FONT_BYTE(ff);
501 ft->kern_data[i * 3 + 2] = READ_FONT_BYTE(ff);
502 }
503 ft->kern_data[i * 3] = 255;
504 ft->kern_data[i * 3 + 1] = 255;
505 ft->kern_data[i * 3 + 2] = 0;
506 } else {
507 ft->kern_data = NULL;
508 }
509
510 ft->ch_height = (uint8_t)ft_height;
511 ft->ch_maxwidth = (uint8_t)ft_width;
512 ft->max_ascii = ft_maxasc;

Callers 4

FontKernFunction · 0.85
FontKernDumpFunction · 0.85
FontViewFunction · 0.85
LoadAllFontsFunction · 0.85

Calls 6

ErrorFunction · 0.85
OPEN_FONTFunction · 0.70
READ_FONT_SHORTFunction · 0.70
READ_FONT_BYTEFunction · 0.70
READ_FONT_DATAFunction · 0.70
CLOSE_FONTFunction · 0.70

Tested by

no test coverage detected