MTS: unused? sets a template to a font, be careful.
| 539 | // MTS: unused? |
| 540 | // sets a template to a font, be careful. |
| 541 | bool 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; |
no test coverage detected