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

Method load

2dlib/font.cpp:375–462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

373}
374
375void grFont::load(char *filename, int slot) {
376 FONTFILE ff;
377 gr_font_file_record fnt, *ft;
378 char fontname[32];
379 int num_char;
380 int i;
381
382 ft = &fnt;
383
384 bool success;
385 ff = OPEN_FONT(filename, success);
386 if (!ff) {
387 Error("Unable to open font in file %s.\n", filename);
388 } else if (!success) {
389 Error("Illegal font file: %s.\n", filename);
390 }
391
392 mprintf(0, "%s font.\n", grFont::m_FontList[slot].name);
393
394 ft->width = READ_FONT_SHORT(ff);
395 ft->height = READ_FONT_SHORT(ff);
396 ft->flags = READ_FONT_SHORT(ff);
397 ft->baseline = READ_FONT_SHORT(ff);
398 ft->min_ascii = READ_FONT_BYTE(ff);
399 ft->max_ascii = READ_FONT_BYTE(ff);
400 READ_FONT_DATA(ff, fontname, 32, 1);
401
402 mprintf(0, " <ht %d>::<min %d>::<max %d>::<base %d>", ft->height, ft->min_ascii, ft->max_ascii, ft->baseline);
403
404 num_char = ft->max_ascii - ft->min_ascii + 1;
405
406 // Read in all widths
407 if (ft->flags & FT_PROPORTIONAL) {
408 ft->char_widths = new int16_t[num_char];
409 for (i = 0; i < num_char; i++)
410 ft->char_widths[i] = READ_FONT_SHORT(ff);
411 mprintf(0, "::proportional");
412 } else {
413 ft->char_widths = NULL;
414 }
415
416 // Read in pixel data.
417 // for color fonts, read in byte count and then the data,
418 // generate character data pointer table
419 // for mono fonts, read in byte count, then the data, convert to bits and store
420 // generate character data pointer table
421 int bytesize = READ_FONT_INT(ff);
422
423 ft->raw_data = (uint8_t *)mem_malloc(bytesize);
424 ft->char_data = (uint8_t **)mem_malloc(num_char * sizeof(uint8_t *));
425
426 READ_FONT_DATA(ff, ft->raw_data, bytesize, 1);
427
428 if (ft->flags & FT_COLOR) {
429 int off = 0;
430 mprintf(0, "::color");
431 for (i = 0; i < num_char; i++) {
432 ft->char_data[i] = ft->raw_data + off;

Callers 13

UpdateDialogMethod · 0.45
UpdateProcViewMethod · 0.45
UpdateTextureViewsMethod · 0.45
UpdateProcViewMethod · 0.45
UpdateTextureViewMethod · 0.45
UpdateMegacellViewMethod · 0.45
UpdateViewMethod · 0.45
UpdateWeaponViewMethod · 0.45
OnPaintMethod · 0.45
UpdateMegaSetViewMethod · 0.45
DrawItemMethod · 0.45
UpdateViewMethod · 0.45

Calls 7

ErrorFunction · 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

Tested by

no test coverage detected