changed the SFNT driver slightly to add more robust checking based on the "search_rang", etc.., fields of the sfnt header.. This avoids problems (like certain Type 1 multiple masters incorrectly recognized as trueType files)..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
diff --git a/demos/src/ftmulti.c b/demos/src/ftmulti.c
index 77e3e1d..5628439 100644
--- a/demos/src/ftmulti.c
+++ b/demos/src/ftmulti.c
@@ -408,10 +408,10 @@ $\243^\250*\265\371%!\247:/;.,?<>";
grLn();
grWriteln(" F3 : decrement first axis position by 20" );
grWriteln(" F4 : increment first axis position by 20" );
- grWriteln(" F3 : decrement second axis position by 20" );
- grWriteln(" F4 : increment second axis position by 20" );
- grWriteln(" F3 : decrement third axis position by 20" );
- grWriteln(" F4 : increment third axis position by 20" );
+ grWriteln(" F5 : decrement second axis position by 20" );
+ grWriteln(" F6 : increment second axis position by 20" );
+ grWriteln(" F7 : decrement third axis position by 20" );
+ grWriteln(" F8 : increment third axis position by 20" );
grLn();
grWriteln("press any key to exit this help screen");
diff --git a/include/freetype/config/ftmodule.h b/include/freetype/config/ftmodule.h
index e9c06cd..d5e4d07 100644
--- a/include/freetype/config/ftmodule.h
+++ b/include/freetype/config/ftmodule.h
@@ -1,3 +1,4 @@
+FT_DRIVER(cff_driver_interface)
FT_DRIVER(psnames_driver_interface)
FT_DRIVER(sfnt_driver_interface)
FT_DRIVER(tt_driver_interface)
diff --git a/include/freetype/internal/sfnt.h b/include/freetype/internal/sfnt.h
index 8c85a1a..656be04 100644
--- a/include/freetype/internal/sfnt.h
+++ b/include/freetype/internal/sfnt.h
@@ -116,19 +116,17 @@
/*************************************************************************/
/* */
/* <FuncType> */
- /* TT_Load_Format_Tag */
+ /* TT_Load_SFNT_Header */
/* */
/* <Description> */
- /* Loads the first 4 bytes of the font file. This is a tag that */
- /* identifies the font format used. */
+ /* Loads the header of a SFNT font file. Supports collections.. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* stream :: The input stream. */
- /* faceIndex :: The index of the TrueType font, if we're opening a */
- /* collection. */
+ /* */
/* <Output> */
- /* format_tag :: a 4-byte tag */
+ /* sfnt :: the sfnt header */
/* */
/* <Return> */
/* TrueType error code. 0 means success. */
@@ -137,11 +135,14 @@
/* The stream cursor must be at the font file's origin */
/* This function recognizes fonts embedded in a "TrueType collection" */
/* */
+ /* This function checks that the header is valid by looking at the */
+ /* values of "search_range", "entry_selector" and "range_shift".. */
+ /* */
typedef
- TT_Error (*TT_Load_Format_Tag_Func)( TT_Face face,
- FT_Stream stream,
- TT_Long faceIndex,
- TT_ULong *format_tag );
+ TT_Error (*TT_Load_SFNT_Header_Func)( TT_Face face,
+ FT_Stream stream,
+ TT_Long faceIndex,
+ SFNT_Header* sfnt );
/*************************************************************************/
/* */
@@ -154,8 +155,7 @@
/* <Input> */
/* face :: A handle to the target face object. */
/* stream :: The input stream. */
- /* faceIndex :: The index of the TrueType font, if we're opening a */
- /* collection. */
+ /* sfnt :: sfnt header */
/* */
/* <Return> */
/* TrueType error code. 0 means success. */
@@ -166,9 +166,9 @@
/* TT_Load_Format_Tag */
/* */
typedef
- TT_Error (*TT_Load_Directory_Func)( TT_Face face,
- FT_Stream stream,
- TT_Long faceIndex );
+ TT_Error (*TT_Load_Directory_Func)( TT_Face face,
+ FT_Stream stream,
+ SFNT_Header* sfnt );
/*************************************************************************/
@@ -426,49 +426,49 @@
/* */
typedef struct SFNT_Interface_
{
- TT_Goto_Table_Func goto_table;
+ TT_Goto_Table_Func goto_table;
- TT_Init_Face_Func init_face;
- TT_Load_Face_Func load_face;
- TT_Done_Face_Func done_face;
- SFNT_Get_Interface_Func get_interface;
+ TT_Init_Face_Func init_face;
+ TT_Load_Face_Func load_face;
+ TT_Done_Face_Func done_face;
+ SFNT_Get_Interface_Func get_interface;
- TT_Load_Any_Func load_any;
- TT_Load_Format_Tag_Func load_format_tag;
- TT_Load_Directory_Func load_directory;
+ TT_Load_Any_Func load_any;
+ TT_Load_SFNT_Header_Func load_sfnt_header;
+ TT_Load_Directory_Func load_directory;
/* these functions are called by "load_face" but they can also */
/* be called from external modules, if there is a need to */
- TT_Load_Table_Func load_header;
- TT_Load_Metrics_Func load_metrics;
- TT_Load_Table_Func load_charmaps;
- TT_Load_Table_Func load_max_profile;
- TT_Load_Table_Func load_os2;
- TT_Load_Table_Func load_psnames;
+ TT_Load_Table_Func load_header;
+ TT_Load_Metrics_Func load_metrics;
+ TT_Load_Table_Func load_charmaps;
+ TT_Load_Table_Func load_max_profile;
+ TT_Load_Table_Func load_os2;
+ TT_Load_Table_Func load_psnames;
- TT_Load_Table_Func load_names;
- TT_Free_Table_Func free_names;
+ TT_Load_Table_Func load_names;
+ TT_Free_Table_Func free_names;
/* optional tables */
- TT_Load_Table_Func load_hdmx;
- TT_Free_Table_Func free_hdmx;
+ TT_Load_Table_Func load_hdmx;
+ TT_Free_Table_Func free_hdmx;
- TT_Load_Table_Func load_kerning;
- TT_Load_Table_Func load_gasp;
- TT_Load_Table_Func load_pclt;
+ TT_Load_Table_Func load_kerning;
+ TT_Load_Table_Func load_gasp;
+ TT_Load_Table_Func load_pclt;
/* see `ttsbit.h' */
- TT_Load_Table_Func load_sbits;
- TT_Load_SBit_Image_Func load_sbit_image;
- TT_Free_Table_Func free_sbits;
+ TT_Load_Table_Func load_sbits;
+ TT_Load_SBit_Image_Func load_sbit_image;
+ TT_Free_Table_Func free_sbits;
/* see `ttpost.h' */
- TT_Get_PS_Name_Func get_psname;
- TT_Free_Table_Func free_psnames;
+ TT_Get_PS_Name_Func get_psname;
+ TT_Free_Table_Func free_psnames;
/* see `ttcmap.h' */
- TT_CharMap_Load_Func load_charmap;
- TT_CharMap_Free_Func free_charmap;
+ TT_CharMap_Load_Func load_charmap;
+ TT_CharMap_Free_Func free_charmap;
} SFNT_Interface;
diff --git a/include/freetype/internal/tttypes.h b/include/freetype/internal/tttypes.h
index 0510d1d..7383b48 100644
--- a/include/freetype/internal/tttypes.h
+++ b/include/freetype/internal/tttypes.h
@@ -369,6 +369,31 @@
/*************************************************************************/
/* */
/* <Struct> */
+ /* SFNT_Header */
+ /* */
+ /* <Description> */
+ /* SFNT file format header. */
+ /* */
+ /* <Fields> */
+ /* format_tag :: font format tag.. */
+ /* num_tables :: number of tables in file */
+ /* search_range :: must be 16*(max power of 2 <= num_tables) */
+ /* entry_selector :: log2 of search_range/16 */
+ /* range_shift :: must be num_tables*16 - search_range */
+ /* */
+ typedef struct SFNT_Header_
+ {
+ TT_ULong format_tag;
+ TT_UShort num_tables;
+ TT_UShort search_range;
+ TT_UShort entry_selector;
+ TT_UShort range_shift;
+
+ } SFNT_Header;
+
+ /*************************************************************************/
+ /* */
+ /* <Struct> */
/* TT_TableDir */
/* */
/* <Description> */
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index c76a8db..abdc645 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -52,7 +52,7 @@
SFNT_Get_Interface,
TT_Load_Any,
- TT_Load_Format_Tag,
+ TT_Load_SFNT_Header,
TT_Load_Directory,
TT_Load_Header,
diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c
index e0c833e..d85d022 100644
--- a/src/sfnt/sfobjs.c
+++ b/src/sfnt/sfobjs.c
@@ -145,6 +145,7 @@
FT_Error error;
SFNT_Interface* sfnt;
PSNames_Interface* psnames;
+ SFNT_Header sfnt_header;
/* for now, parameters are unused */
UNUSED(num_params);
@@ -187,12 +188,14 @@
}
/* check that we have a valid TrueType file */
- error = sfnt->load_format_tag( face, stream, face_index,
- &face->format_tag );
+ error = sfnt->load_sfnt_header( face, stream, face_index, &sfnt_header );
if (error) goto Exit;
+ face->format_tag = sfnt_header.format_tag;
+ face->num_tables = sfnt_header.num_tables;
+
/* Load font directory */
- error = sfnt->load_directory( face, stream, face_index );
+ error = sfnt->load_directory( face, stream, &sfnt_header );
if ( error ) goto Exit;
face->root.num_faces = face->ttc_header.DirCount;
diff --git a/src/sfnt/ttcmap.c b/src/sfnt/ttcmap.c
index 83cb2bd..daeaccf 100644
--- a/src/sfnt/ttcmap.c
+++ b/src/sfnt/ttcmap.c
@@ -451,7 +451,7 @@
/* the ranges are sorted in increasing order, if we're out of */
/* the range here, the char code isn't in the charmap, so exit */
if ( charCode > seg4->endCount )
- break;
+ continue;
if ( charCode >= seg4->startCount )
goto Found;
diff --git a/src/sfnt/ttload.c b/src/sfnt/ttload.c
index 20811fd..72e9b54 100644
--- a/src/sfnt/ttload.c
+++ b/src/sfnt/ttload.c
@@ -118,19 +118,17 @@
/*************************************************************************/
/* */
/* <FuncType> */
- /* TT_Load_Format_Tag */
+ /* TT_Load_SFNT_Header */
/* */
/* <Description> */
- /* Loads the first 4 bytes of the font file. This is a tag that */
- /* identifies the font format used. */
+ /* Loads the header of a SFNT font file. Supports collections.. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* stream :: The input stream. */
- /* faceIndex :: The index of the TrueType font, if we're opening a */
- /* collection. */
+ /* */
/* <Output> */
- /* format_tag :: a 4-byte font format tag */
+ /* sfnt :: the sfnt header */
/* */
/* <Return> */
/* TrueType error code. 0 means success. */
@@ -139,24 +137,34 @@
/* The stream cursor must be at the font file's origin */
/* This function recognizes fonts embedded in a "TrueType collection" */
/* */
+ /* This function checks that the header is valid by looking at the */
+ /* values of "search_range", "entry_selector" and "range_shift".. */
+ /* */
LOCAL_FUNC
- TT_Error TT_Load_Format_Tag( TT_Face face,
- FT_Stream stream,
- TT_Long faceIndex,
- TT_ULong *format_tag )
+ TT_Error TT_Load_SFNT_Header( TT_Face face,
+ FT_Stream stream,
+ TT_Long face_index,
+ SFNT_Header* sfnt )
{
- TT_Error error;
- FT_Memory memory = stream->memory;
-
-#ifdef READ_FIELDS
+ TT_Error error;
+ TT_ULong format_tag;
+ FT_Memory memory = stream->memory;
+
+ const FT_Frame_Field sfnt_header_fields[] = {
+ FT_FRAME_START(8),
+ FT_FRAME_USHORT( SFNT_Header, num_tables ),
+ FT_FRAME_USHORT( SFNT_Header, search_range ),
+ FT_FRAME_USHORT( SFNT_Header, entry_selector ),
+ FT_FRAME_USHORT( SFNT_Header, range_shift ),
+ FT_FRAME_END };
+
const FT_Frame_Field ttc_header_fields[] = {
FT_FRAME_START(8), /* frame of 8 bytes */
FT_FRAME_LONG( TTC_Header, version ),
FT_FRAME_LONG( TTC_Header, DirCount ),
FT_FRAME_END };
-#endif
- FT_TRACE2(( "TT_Load_Format_Tag(%08p, %ld )\n",
+ FT_TRACE2(( "TT_Load_SFNT_Header(%08p, %ld )\n",
face, faceIndex ));
face->ttc_header.Tag = 0;
@@ -168,28 +176,19 @@
/* first of all, read the first 4 bytes. If it's `ttcf', then the */
/* file is a TrueType collection, otherwise it can be any other */
/* kind of font.. */
- if ( READ_ULong(*format_tag) ) goto Exit;
+ if ( READ_ULong(format_tag) ) goto Exit;
- if ( *format_tag == TTAG_ttcf )
+ if ( format_tag == TTAG_ttcf )
{
TT_Int n;
- FT_TRACE4(( "TT_Load_Format_Tag: file is a collection\n" ));
+ FT_TRACE4(( "TT_Load_SFNT_Header: file is a collection\n" ));
/* it's a TrueType collection, i.e. a file containing several */
/* font files. Read the font directory now */
/* */
- #ifdef READ_FIELDS
if ( READ_Fields( ttc_header_fields, &face->ttc_header ) )
goto Exit;
- #else
- if ( ACCESS_Frame( 8 ) ) goto Exit;
-
- face->ttc_header.version = GET_Long();
- face->ttc_header.DirCount = GET_Long();
-
- FORGET_Frame();
- #endif
/* now read the offsets of each font in the file */
/* */
@@ -205,25 +204,42 @@
FORGET_Frame();
/* check face index */
- if (faceIndex >= face->ttc_header.DirCount)
+ if (face_index >= face->ttc_header.DirCount)
{
error = TT_Err_Bad_Argument;
goto Exit;
}
- /* if we're checking the font format, exit immediately */
- if (faceIndex < 0)
- goto Exit;
-
/* seek to the appropriate TrueType file, then read tag */
- if ( FILE_Seek( face->ttc_header.TableDirectory[faceIndex] ) ||
- READ_Long( *format_tag ) )
+ if ( FILE_Seek( face->ttc_header.TableDirectory[face_index] ) ||
+ READ_Long( format_tag ) )
goto Exit;
}
+ /* the format tag was read, now check the rest of the header */
+ sfnt->format_tag = format_tag;
+ if ( READ_Fields( sfnt_header_fields, sfnt ) )
+ goto Exit;
+
+ /* now, check the values of "num_tables", "seach_range", etc.. */
+ {
+ TT_UInt num_tables = sfnt->num_tables;
+ TT_UInt search_range = sfnt->search_range;
+ TT_ULong entry_selector = 1L << sfnt->entry_selector;
+
+ if ( entry_selector > num_tables || entry_selector*2 <= num_tables ||
+ search_range != 16*entry_selector ||
+ num_tables*16 != search_range + sfnt->range_shift )
+ {
+ FT_TRACE2(( "TT_Load_SFNT_Header: file is not SFNT !\n" ));
+ error = FT_Err_Unknown_File_Format;
+ }
+ }
+
Exit:
return error;
- }
+ }
+
/*************************************************************************/
@@ -237,8 +253,7 @@
/* <Input> */
/* face :: A handle to the target face object. */
/* stream :: The input stream. */
- /* faceIndex :: The index of the TrueType font, if we're opening a */
- /* collection. */
+ /* sfnt :: sfnt directory header */
/* */
/* <Return> */
/* TrueType error code. 0 means success. */
@@ -247,49 +262,22 @@
/* The stream cursor must be at the font file's origin */
/* */
LOCAL_FUNC
- TT_Error TT_Load_Directory( TT_Face face,
- FT_Stream stream,
- TT_Long faceIndex )
+ TT_Error TT_Load_Directory( TT_Face face,
+ FT_Stream stream,
+ SFNT_Header* sfnt )
{
TT_Error error;
FT_Memory memory = stream->memory;
-#ifdef READ_FIELDS
- const FT_Frame_Field table_dir_fields[] = {
- FT_FRAME_START(8),
- FT_FRAME_USHORT( TT_TableDir, numTables ),
- FT_FRAME_USHORT( TT_TableDir, searchRange ),
- FT_FRAME_USHORT( TT_TableDir, entrySelector ),
- FT_FRAME_USHORT( TT_TableDir, rangeShift ),
- FT_FRAME_END };
-#endif
-
- TT_TableDir tableDir;
TT_Table *entry, *limit;
- UNUSED(faceIndex);
-
FT_TRACE2(( "TT_Load_Directory( %08p, %ld )\n",
face, faceIndex ));
-#ifdef READ_FIELDS
- if ( READ_Fields( table_dir_fields, &tableDir ) )
- goto Exit;
-#else
- if ( ACCESS_Frame( 8L ) ) goto Exit;
+ FT_TRACE2(( "-- Tables count : %12u\n", sfnt->num_tables ));
+ FT_TRACE2(( "-- Format version : %08lx\n", sfnt->format_tag ));
- tableDir.numTables = GET_UShort();
- tableDir.searchRange = GET_UShort();
- tableDir.entrySelector = GET_UShort();
- tableDir.rangeShift = GET_UShort();
-
- FORGET_Frame();
-#endif
-
- FT_TRACE2(( "-- Tables count : %12u\n", tableDir.numTables ));
- FT_TRACE2(( "-- Format version : %08lx\n", tableDir.version ));
-
- face->num_tables = tableDir.numTables;
+ face->num_tables = sfnt->num_tables;
if ( ALLOC_ARRAY( face->dir_tables,
face->num_tables,
@@ -437,7 +425,7 @@
{
TT_Error error;
TT_Header* header;
-#ifdef READ_FIELDS
+
static const FT_Frame_Field header_fields[] = {
FT_FRAME_START(54),
FT_FRAME_ULONG( TT_Header, Table_Version ),
@@ -460,7 +448,6 @@
FT_FRAME_SHORT( TT_Header, Index_To_Loc_Format ),
FT_FRAME_SHORT( TT_Header, Glyph_Data_Format ),
FT_FRAME_END };
-#endif
FT_TRACE2(( "Load_TT_Header( %08p )\n", face ));
@@ -473,40 +460,9 @@
header = &face->header;
-#ifdef READ_FIELDS
- if ( READ_Fields( header_fields, header ) ) goto Exit;
-#else
- if ( ACCESS_Frame( 54L ) )
+ if ( READ_Fields( header_fields, header ) )
goto Exit;
- header->Table_Version = GET_ULong();
- header->Font_Revision = GET_ULong();
-
- header->CheckSum_Adjust = GET_Long();
- header->Magic_Number = GET_Long();
-
- header->Flags = GET_UShort();
- header->Units_Per_EM = GET_UShort();
-
- header->Created [0] = GET_Long();
- header->Created [1] = GET_Long();
- header->Modified[0] = GET_Long();
- header->Modified[1] = GET_Long();
-
- header->xMin = GET_Short();
- header->yMin = GET_Short();
- header->xMax = GET_Short();
- header->yMax = GET_Short();
-
- header->Mac_Style = GET_UShort();
- header->Lowest_Rec_PPEM = GET_UShort();
-
- header->Font_Direction = GET_Short();
- header->Index_To_Loc_Format = GET_Short();
- header->Glyph_Data_Format = GET_Short();
-
- FORGET_Frame();
-#endif
FT_TRACE2(( " Units per EM : %8u\n", header->Units_Per_EM ));
FT_TRACE2(( " IndexToLoc : %8d\n", header->Index_To_Loc_Format ));
FT_TRACE2(( "Font Header Loaded.\n" ));
@@ -537,7 +493,7 @@
{
TT_Error error;
TT_MaxProfile* maxProfile = &face->max_profile;
-#ifdef READ_FIELDS
+
const FT_Frame_Field maxp_fields[] = {
FT_FRAME_START(32),
FT_FRAME_ULONG( TT_MaxProfile, version ),
@@ -556,41 +512,13 @@
FT_FRAME_USHORT( TT_MaxProfile, maxComponentElements ),
FT_FRAME_USHORT( TT_MaxProfile, maxComponentDepth ),
FT_FRAME_END };
-#endif
FT_TRACE2(( "Load_TT_MaxProfile( %08p )\n", face ));
error = face->goto_table( face, TTAG_maxp, stream, 0 );
if (error) goto Exit;
-#ifdef READ_FIELDS
if ( READ_Fields( maxp_fields, maxProfile ) ) goto Exit;
-#else
- if ( ACCESS_Frame( 32L ) )
- goto Exit;
-
- /* read frame data into face table */
- maxProfile->version = GET_ULong();
- maxProfile->numGlyphs = GET_UShort();
-
- maxProfile->maxPoints = GET_UShort();
- maxProfile->maxContours = GET_UShort();
- maxProfile->maxCompositePoints = GET_UShort();
- maxProfile->maxCompositeContours = GET_UShort();
-
- maxProfile->maxZones = GET_UShort();
- maxProfile->maxTwilightPoints = GET_UShort();
-
- maxProfile->maxStorage = GET_UShort();
- maxProfile->maxFunctionDefs = GET_UShort();
- maxProfile->maxInstructionDefs = GET_UShort();
- maxProfile->maxStackElements = GET_UShort();
- maxProfile->maxSizeOfInstructions = GET_UShort();
- maxProfile->maxComponentElements = GET_UShort();
- maxProfile->maxComponentDepth = GET_UShort();
-
- FORGET_Frame();
-#endif
/* XXX: an adjustment that is necessary to load certain */
/* broken fonts like `Keystrokes MT' :-( */
@@ -783,7 +711,7 @@
{
TT_Error error;
TT_HoriHeader* header;
-#ifdef READ_FIELDS
+
const FT_Frame_Field metrics_header_fields[] = {
FT_FRAME_START(36),
FT_FRAME_ULONG( TT_HoriHeader, Version ),
@@ -804,7 +732,7 @@
FT_FRAME_SHORT( TT_HoriHeader, metric_Data_Format ),
FT_FRAME_USHORT( TT_HoriHeader, number_Of_HMetrics ),
FT_FRAME_END };
-#endif
+
FT_TRACE2(( vertical ? "Vertical header " : "Horizontal header " ));
if ( vertical )
@@ -837,37 +765,7 @@
header = &face->horizontal;
}
-#ifdef READ_FIELDS
if ( READ_Fields( metrics_header_fields, header ) ) goto Exit;
-#else
- if ( ACCESS_Frame( 36L ) )
- goto Exit;
-
- header->Version = GET_ULong();
- header->Ascender = GET_Short();
- header->Descender = GET_Short();
- header->Line_Gap = GET_Short();
-
- header->advance_Width_Max = GET_UShort();
-
- header->min_Left_Side_Bearing = GET_Short();
- header->min_Right_Side_Bearing = GET_Short();
- header->xMax_Extent = GET_Short();
- header->caret_Slope_Rise = GET_Short();
- header->caret_Slope_Run = GET_Short();
-
- header->Reserved[0] = GET_Short(); /* this is caret_Offset for
- vertical headers */
- header->Reserved[1] = GET_Short();
- header->Reserved[2] = GET_Short();
- header->Reserved[3] = GET_Short();
- header->Reserved[4] = GET_Short();
-
- header->metric_Data_Format = GET_Short();
- header->number_Of_HMetrics = GET_UShort();
-
- FORGET_Frame();
-#endif
header->long_metrics = NULL;
header->short_metrics = NULL;
@@ -907,7 +805,7 @@
TT_ULong storageSize;
TT_NameTable* names;
-#ifdef READ_FIELDS
+
const FT_Frame_Field name_table_fields[] = {
FT_FRAME_START(6),
FT_FRAME_USHORT( TT_NameTable, format ),
@@ -923,7 +821,6 @@
FT_FRAME_USHORT( TT_NameRec, stringLength ),
FT_FRAME_USHORT( TT_NameRec, stringOffset ),
FT_FRAME_END };
-#endif
FT_TRACE2(( "Names " ));
@@ -941,19 +838,7 @@
names = &face->name_table;
-#ifdef READ_FIELDS
if ( READ_Fields( name_table_fields, names ) ) goto Exit;
-#else
- if ( ACCESS_Frame( 6L ) )
- goto Exit;
-
- /* Load the initial names data. */
- names->format = GET_UShort();
- names->numNameRecords = GET_UShort();
- names->storageOffset = GET_UShort();
-
- FORGET_Frame();
-#endif
/* Allocate the array of name records. */
if ( ALLOC_ARRAY( names->names,
@@ -974,16 +859,8 @@
{
TT_ULong upper;
-#ifdef READ_FIELDS
(void)READ_Fields( name_record_fields, cur );
-#else
- cur->platformID = GET_UShort();
- cur->encodingID = GET_UShort();
- cur->languageID = GET_UShort();
- cur->nameID = GET_UShort();
- cur->stringLength = GET_UShort();
- cur->stringOffset = GET_UShort();
-#endif
+
upper = (TT_ULong)(cur->stringOffset + cur->stringLength);
if ( upper > storageSize ) storageSize = upper;
}
@@ -1101,7 +978,6 @@
TT_Long table_start;
TT_CMapDir cmap_dir;
-#ifdef READ_FIELDS
const FT_Frame_Field cmap_fields[] = {
FT_FRAME_START(4),
FT_FRAME_USHORT( TT_CMapDir, tableVersionNumber ),
@@ -1114,7 +990,6 @@
FT_FRAME_USHORT( TT_CMapTable, length ),
FT_FRAME_USHORT( TT_CMapTable, version ),
FT_FRAME_END };
-#endif
FT_TRACE2(( "CMaps " ));
@@ -1127,17 +1002,7 @@
table_start = FILE_Pos();
-#ifdef READ_FIELDS
if ( READ_Fields( cmap_fields, &cmap_dir ) ) goto Exit;
-#else
- if ( ACCESS_Frame( 4L ) ) /* 4 bytes cmap header */
- goto Exit;
-
- cmap_dir.tableVersionNumber = GET_UShort();
- cmap_dir.numCMaps = GET_UShort();
-
- FORGET_Frame();
-#endif
/* save space in face table for cmap tables */
if ( ALLOC_ARRAY( face->charmaps,
@@ -1171,21 +1036,10 @@
{
TT_CMapTable* cmap = &charmap->cmap;
-#ifdef READ_FIELDS
if ( FILE_Seek( table_start + (TT_Long)cmap->offset ) ||
READ_Fields( cmap_rec_fields, cmap ) )
goto Exit;
-#else
- if ( FILE_Seek( table_start + (TT_Long)cmap->offset ) ||
- ACCESS_Frame(6L) )
- goto Exit;
-
- cmap->format = GET_UShort();
- cmap->length = GET_UShort();
- cmap->version = GET_UShort();
- FORGET_Frame();
-#endif
cmap->offset = FILE_Pos();
}
}
@@ -1217,7 +1071,7 @@
{
TT_Error error;
TT_OS2* os2;
-#ifdef READ_FIELDS
+
const FT_Frame_Field os2_fields[] = {
FT_FRAME_START(78),
FT_FRAME_USHORT( TT_OS2, version ),
@@ -1279,10 +1133,6 @@
FT_FRAME_USHORT( TT_OS2, usBreakChar ),
FT_FRAME_USHORT( TT_OS2, usMaxContext ),
FT_FRAME_END };
-#else
- TT_Int j;
-#endif
-
FT_TRACE2(( "OS/2 Table " ));
@@ -1300,51 +1150,7 @@
os2 = &face->os2;
-#ifdef READ_FIELDS
if ( READ_Fields( os2_fields, os2 ) ) goto Exit;
-#else
- if ( ACCESS_Frame( 78L ) )
- goto Exit;
-
- os2->version = GET_UShort();
- os2->xAvgCharWidth = GET_Short();
- os2->usWeightClass = GET_UShort();
- os2->usWidthClass = GET_UShort();
- os2->fsType = GET_Short();
- os2->ySubscriptXSize = GET_Short();
- os2->ySubscriptYSize = GET_Short();
- os2->ySubscriptXOffset = GET_Short();
- os2->ySubscriptYOffset = GET_Short();
- os2->ySuperscriptXSize = GET_Short();
- os2->ySuperscriptYSize = GET_Short();
- os2->ySuperscriptXOffset = GET_Short();
- os2->ySuperscriptYOffset = GET_Short();
- os2->yStrikeoutSize = GET_Short();
- os2->yStrikeoutPosition = GET_Short();
- os2->sFamilyClass = GET_Short();
-
- for ( j = 0; j < 10; j++ )
- os2->panose[j] = GET_Byte();
-
- os2->ulUnicodeRange1 = GET_ULong();
- os2->ulUnicodeRange2 = GET_ULong();
- os2->ulUnicodeRange3 = GET_ULong();
- os2->ulUnicodeRange4 = GET_ULong();
-
- for ( j = 0; j < 4; j++ )
- os2->achVendID[j] = GET_Byte();
-
- os2->fsSelection = GET_UShort();
- os2->usFirstCharIndex = GET_UShort();
- os2->usLastCharIndex = GET_UShort();
- os2->sTypoAscender = GET_Short();
- os2->sTypoDescender = GET_Short();
- os2->sTypoLineGap = GET_Short();
- os2->usWinAscent = GET_UShort();
- os2->usWinDescent = GET_UShort();
-
- FORGET_Frame();
-#endif
os2->ulCodePageRange1 = 0;
os2->ulCodePageRange2 = 0;
@@ -1352,35 +1158,12 @@
if ( os2->version >= 0x0001 )
{
/* only version 1 tables */
-#ifdef READ_FIELDS
if ( READ_Fields( os2_fields_extra, os2 ) ) goto Exit;
-#else
- if ( ACCESS_Frame( 8L ) ) /* read into frame */
- goto Exit;
-
- os2->ulCodePageRange1 = GET_ULong();
- os2->ulCodePageRange2 = GET_ULong();
-
- FORGET_Frame();
-#endif
if ( os2->version >= 0x0002 )
{
/* only version 2 tables */
-#ifdef READ_FIELDS
if ( READ_Fields( os2_fields_extra2, os2 ) ) goto Exit;
-#else
- if ( ACCESS_Frame( 10L ) ) /* read into frame */
- goto Exit;
-
- os2->sxHeight = GET_Short();
- os2->sCapHeight = GET_Short();
- os2->usDefaultChar = GET_UShort();
- os2->usBreakChar = GET_UShort();
- os2->usMaxContext = GET_UShort();
-
- FORGET_Frame();
-#endif
}
}
@@ -1412,7 +1195,7 @@
{
TT_Error error;
TT_Postscript* post = &face->postscript;
-#ifdef READ_FIELDS
+
static const FT_Frame_Field post_fields[] = {
FT_FRAME_START(32),
FT_FRAME_ULONG( TT_Postscript, FormatType ),
@@ -1425,7 +1208,6 @@
FT_FRAME_ULONG( TT_Postscript, minMemType1 ),
FT_FRAME_ULONG( TT_Postscript, maxMemType1 ),
FT_FRAME_END };
-#endif
FT_TRACE2(( "PostScript " ));
@@ -1433,26 +1215,8 @@
if (error)
return TT_Err_Post_Table_Missing;
-#ifdef READ_FIELDS
if ( READ_Fields( post_fields, post ) ) return error;
-#else
- if ( ACCESS_Frame( 32L ) )
- return error;
-
- /* read frame data into face table */
-
- post->FormatType = GET_ULong();
- post->italicAngle = GET_ULong();
- post->underlinePosition = GET_Short();
- post->underlineThickness = GET_Short();
- post->isFixedPitch = GET_ULong();
- post->minMemType42 = GET_ULong();
- post->maxMemType42 = GET_ULong();
- post->minMemType1 = GET_ULong();
- post->maxMemType1 = GET_ULong();
- FORGET_Frame();
-#endif
/* we don't load the glyph names, we do that in another */
/* module (ttpost). */
FT_TRACE2(( "loaded\n" ));
diff --git a/src/sfnt/ttload.h b/src/sfnt/ttload.h
index cde8401..37efb41 100644
--- a/src/sfnt/ttload.h
+++ b/src/sfnt/ttload.h
@@ -44,16 +44,14 @@
LOCAL_DEF
- TT_Error TT_Load_Format_Tag( TT_Face face,
- FT_Stream stream,
- TT_Long faceIndex,
- TT_ULong *format_tag );
-
- LOCAL_DEF
- TT_Error TT_Load_Directory( TT_Face face,
- FT_Stream stream,
- TT_Long faceIndex );
-
+ TT_Error TT_Load_SFNT_Header( TT_Face face,
+ FT_Stream stream,
+ TT_Long face_index,
+ SFNT_Header* sfnt );
+ LOCAL_DEF
+ TT_Error TT_Load_Directory( TT_Face face,
+ FT_Stream stream,
+ SFNT_Header* sfnt );
LOCAL_DEF
TT_Error TT_Load_Any( TT_Face face,