many new small, but important, changes there: - modified the interface of the "sfnt" module. There is now a function called "load_format_tag", and another called "load_directory". The first one is in charge of returning the 4-byte tag located at the beginning of a given font file. It understand TrueType collections and parses them automatically The second loads the table directory that is located just after the format tag. This is useful, because the "SFNT" storage scheme can be used by several distinct formats, each with its own format tag. The TrueType driver now checks the format tag in "src/truetype/ttobjs.c" - made some changes to "src/shared/t1types.h" to clearly separate the Type 1 font content from the rest of the T1_Face structure. This will be useful when adding the CFF/Type2 driver that will be able to reuse the "T1_Font" structure within a "TT_Font" one (which really describes a SFNT-based font file). Some changes in "src/type1" were thus performed to reflect this. Note that the current type1 driver will be discontinued in a distant future. More on this later..
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 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 21f495b..d46692f 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -1340,6 +1340,8 @@
FT_Driver driver;
FT_Memory memory;
FT_DriverInterface* interface;
+ FT_Size_Metrics* metrics = &face->size->metrics;
+ FT_Long dim_x, dim_y;
if ( !face || !face->size || !face->driver)
return FT_Err_Invalid_Face_Handle;
@@ -1360,6 +1362,25 @@
interface = &driver->interface;
memory = driver->memory;
+ /* default processing - this can be overriden by the driver */
+ if ( char_width < 1*64 ) char_width = 1*64;
+ if ( char_height < 1*64 ) char_height = 1*64;
+
+ /* Compute pixel sizes in 26.6 units */
+ dim_x = (((char_width * horz_resolution) / 72) + 32) & -64;
+ dim_y = (((char_height * vert_resolution) / 72) + 32) & -64;
+
+ metrics->x_ppem = (FT_UShort)(dim_x >> 6);
+ metrics->y_ppem = (FT_UShort)(dim_y >> 6);
+
+ metrics->x_scale = 0x10000;
+ metrics->y_scale = 0x10000;
+ if ( face->face_flags & FT_FACE_FLAG_SCALABLE)
+ {
+ metrics->x_scale = FT_DivFix( dim_x, face->units_per_EM );
+ metrics->y_scale = FT_DivFix( dim_y, face->units_per_EM );
+ }
+
error = interface->set_char_sizes( face->size,
char_width,
char_height,
@@ -1395,6 +1416,7 @@
FT_Driver driver;
FT_Memory memory;
FT_DriverInterface* interface;
+ FT_Size_Metrics* metrics = &face->size->metrics;
if ( !face || !face->size || !face->driver )
return FT_Err_Invalid_Face_Handle;
@@ -1403,8 +1425,25 @@
interface = &driver->interface;
memory = driver->memory;
- error = interface->set_pixel_sizes( face->size, pixel_width, pixel_height );
+ /* default processing - this can be overriden by the driver */
+ if ( pixel_width < 1 ) pixel_width = 1;
+ if ( pixel_height < 1 ) pixel_height = 1;
+
+ metrics->x_ppem = pixel_width;
+ metrics->y_ppem = pixel_height;
+
+ if ( face->face_flags & FT_FACE_FLAG_SCALABLE )
+ {
+ metrics->x_scale = FT_DivFix( metrics->x_ppem << 6,
+ face->units_per_EM );
+
+ metrics->y_scale = FT_DivFix( metrics->y_ppem << 6,
+ face->units_per_EM );
+ }
+ error = interface->set_pixel_sizes( face->size,
+ pixel_width,
+ pixel_height );
return error;
}
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index 0f173fa..0d187f3 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -11,6 +11,7 @@
TT_Goto_Table,
TT_Load_Any,
+ TT_Load_Format_Tag,
TT_Load_Directory,
TT_Load_Header,
diff --git a/src/sfnt/ttload.c b/src/sfnt/ttload.c
index 7bca84a..5eb2d74 100644
--- a/src/sfnt/ttload.c
+++ b/src/sfnt/ttload.c
@@ -115,39 +115,38 @@
/*************************************************************************/
/* */
- /* <Function> */
- /* TT_Load_Directory */
+ /* <FuncType> */
+ /* TT_Load_Format_Tag */
/* */
/* <Description> */
- /* Loads the table directory into a face object. */
+ /* Loads the first 4 bytes of the font file. This is a tag that */
+ /* identifies the font format used. */
/* */
/* <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 */
/* */
/* <Return> */
/* TrueType error code. 0 means success. */
/* */
/* <Note> */
/* The stream cursor must be at the font file's origin */
+ /* This function recognizes fonts embedded in a "TrueType collection" */
/* */
LOCAL_FUNC
- TT_Error TT_Load_Directory( TT_Face face,
- FT_Stream stream,
- TT_Long faceIndex )
+ TT_Error TT_Load_Format_Tag( TT_Face face,
+ FT_Stream stream,
+ TT_Long faceIndex,
+ TT_ULong *format_tag )
{
TT_Error error;
FT_Memory memory = stream->memory;
- TT_TableDir tableDir;
- TT_ULong tag;
-
- TT_Table *entry, *limit;
-
-
- FT_TRACE2(( "TT_Load_Directory( %08lx, %ld )\n",
+ FT_TRACE2(( "TT_Load_Format_Tag(%08lx, %ld )\n",
(TT_Long)face, faceIndex ));
face->ttc_header.Tag = 0;
@@ -157,26 +156,24 @@
face->num_tables = 0;
/* first of all, read the first 4 bytes. If it's `ttcf', then the */
- /* file is a TrueType collection, otherwise it must be a normal */
- /* TrueType file.. */
-
- if ( READ_ULong(tag) )
- goto Exit;
+ /* file is a TrueType collection, otherwise it can be any other */
+ /* kind of font.. */
+ if ( READ_ULong(*format_tag) ) goto Exit;
- if ( tag == TTAG_ttcf )
+ if ( *format_tag == TTAG_ttcf )
{
TT_Int n;
- FT_TRACE4(( "TT_Load_Directory: file is a collection\n" ));
+ FT_TRACE4(( "TT_Load_Format_Tag: file is a collection\n" ));
/* it's a TrueType collection, i.e. a file containing several */
/* font files. Read the font directory now */
/* */
if ( ACCESS_Frame( 8 ) ) goto Exit;
-
+
face->ttc_header.version = GET_Long();
face->ttc_header.DirCount = GET_Long();
-
+
FORGET_Frame();
/* now read the offsets of each font in the file */
@@ -205,28 +202,54 @@
/* seek to the appropriate TrueType file, then read tag */
if ( FILE_Skip( face->ttc_header.TableDirectory[faceIndex] - 12 ) ||
- READ_Long( tableDir.version ) )
+ READ_Long( *format_tag ) )
goto Exit;
}
- else
- {
- FT_TRACE6(( "TT_Load_Directory: file is not a collection\n" ));
- /* the file isn't a collection, exit if we're asking for a */
- /* collected font.. */
- if (faceIndex > 0)
- {
- error = TT_Err_File_Is_Not_Collection;
- goto Exit;
- }
-
- tableDir.version = tag;
- }
- if ( ACCESS_Frame( 8L ) )
- goto Exit;
+ Exit:
+ return error;
+ }
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* TT_Load_Directory */
+ /* */
+ /* <Description> */
+ /* Loads the table directory into a face object. */
+ /* */
+ /* <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. */
+ /* */
+ /* <Return> */
+ /* TrueType error code. 0 means success. */
+ /* */
+ /* <Note> */
+ /* 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 error;
+ FT_Memory memory = stream->memory;
+
+ TT_TableDir tableDir;
+
+ TT_Table *entry, *limit;
+
+
+ FT_TRACE2(( "TT_Load_Directory( %08lx, %ld )\n",
+ (TT_Long)face, faceIndex ));
- tableDir.numTables = GET_UShort();
+ if ( ACCESS_Frame( 8L ) ) goto Exit;
+ tableDir.numTables = GET_UShort();
tableDir.searchRange = GET_UShort();
tableDir.entrySelector = GET_UShort();
tableDir.rangeShift = GET_UShort();
@@ -236,23 +259,6 @@
FT_TRACE2(( "-- Tables count : %12u\n", tableDir.numTables ));
FT_TRACE2(( "-- Format version : %08lx\n", tableDir.version ));
- /* Check that we have a `sfnt' format there */
- /* We must also be able to accept Mac/GX fonts, as well as OT ones */
-
- if ( tableDir.version != 0x00010000 && /* MS fonts */
- tableDir.version != TTAG_true && /* Mac fonts */
- tableDir.version != TTAG_OTTO ) /* OT-Type2 fonts */
- {
- FT_TRACE2(( "[not a valid TTF or OTF font]" ));
- error = TT_Err_Invalid_File_Format;
- goto Exit;
- }
-
- /* if we're performing a font format check, exit immediately */
- /* with success */
- if ( faceIndex < 0 )
- goto Exit;
-
face->num_tables = tableDir.numTables;
if ( ALLOC_ARRAY( face->dir_tables,
@@ -267,7 +273,7 @@
limit = entry + face->num_tables;
for ( ; entry < limit; entry++ )
- { /* loop through the tables and get all entries */
+ { /* loop through the tables and get all entries */
entry->Tag = GET_Tag4();
entry->CheckSum = GET_ULong();
entry->Offset = GET_Long();
diff --git a/src/sfnt/ttload.h b/src/sfnt/ttload.h
index c9ea0a7..28902e7 100644
--- a/src/sfnt/ttload.h
+++ b/src/sfnt/ttload.h
@@ -32,116 +32,29 @@
#endif
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_LookUp_Table */
- /* */
- /* <Description> */
- /* Looks for a TrueType table by name. */
- /* */
- /* <Input> */
- /* face :: A face object handle. */
- /* tag :: The searched tag. */
- /* */
- /* <Return> */
- /* pointer to table directory entry. 0 if not found.. */
- /* */
EXPORT_DEF
TT_Table* TT_LookUp_Table( TT_Face face,
TT_ULong tag );
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Goto_Table */
- /* */
- /* <Description> */
- /* Looks for a TrueType table by name, then seek a stream to it. */
- /* */
- /* <Input> */
- /* face :: a face object handle. */
- /* tag :: the searched tag. */
- /* stream :: the stream to seek when the table is found */
- /* */
- /* <Return> */
- /* pointer to table directory entry. 0 if not found.. */
- /* */
- EXPORT_DEF
+ LOCAL_DEF
TT_Error TT_Goto_Table( TT_Face face,
TT_ULong tag,
FT_Stream stream,
TT_ULong *length );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Load_Directory */
- /* */
- /* <Description> */
- /* Loads the table directory into a face object. */
- /* */
- /* <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. */
- /* */
- /* <Return> */
- /* TrueType error code. 0 means success. */
- /* */
- /* <Note> */
- /* The stream cursor must be at the font file's origin */
- /* */
+ 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 );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Load_Any */
- /* */
- /* <Description> */
- /* Loads any font table into client memory. Used by the */
- /* TT_Get_Font_Data() API function. */
- /* */
- /* <Input> */
- /* face :: The face object to look for. */
- /* */
- /* tag :: The tag of table to load. Use the value 0 if you want */
- /* to access the whole font file, else set this parameter */
- /* to a valid TrueType table tag that you can forge with */
- /* the MAKE_TT_TAG macro. */
- /* */
- /* offset :: The starting offset in the table (or the file if */
- /* tag == 0). */
- /* */
- /* length :: The address of the decision variable: */
- /* */
- /* If length == NULL: */
- /* Loads the whole table. Returns an error if */
- /* `offset' == 0! */
- /* */
- /* If *length == 0: */
- /* Exits immediately; returning the length of the given */
- /* table or of the font file, depending on the value of */
- /* `tag'. */
- /* */
- /* If *length != 0: */
- /* Loads the next `length' bytes of table or font, */
- /* starting at offset `offset' (in table or font too). */
- /* */
- /* <Output> */
- /* buffer :: The address of target buffer. */
- /* */
- /* <Return> */
- /* TrueType error code. 0 means success. */
- /* */
LOCAL_DEF
TT_Error TT_Load_Any( TT_Face face,
TT_ULong tag,
@@ -150,42 +63,11 @@
TT_Long* length );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Load_Header */
- /* */
- /* <Description> */
- /* Loads the TrueType font header. */
- /* */
- /* <Input> */
- /* face :: A handle to the target face object. */
- /* stream :: The input stream. */
- /* */
- /* <Return> */
- /* TrueType error code. 0 means success. */
- /* */
LOCAL_DEF
TT_Error TT_Load_Header( TT_Face face,
FT_Stream stream );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Load_Metrics_Header */
- /* */
- /* <Description> */
- /* Loads the horizontal or vertical header in a face object. */
- /* */
- /* <Input> */
- /* face :: A handle to the target face object. */
- /* stream :: The input stream. */
- /* vertical :: A boolean flag. If set, load vertical metrics. */
- /* */
- /* <Return> */
- /* TrueType error code. 0 means success. */
- /* */
LOCAL_DEF
TT_Error TT_Load_Metrics_Header( TT_Face face,
FT_Stream stream,
@@ -197,180 +79,44 @@
FT_Stream stream );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Load_MaxProfile */
- /* */
- /* <Description> */
- /* Loads the maximum profile into a face object. */
- /* */
- /* <Input> */
- /* face :: A handle to the target face object. */
- /* stream :: The input stream. */
- /* */
- /* <Return> */
- /* TrueType error code. 0 means success. */
- /* */
LOCAL_DEF
TT_Error TT_Load_MaxProfile( TT_Face face,
FT_Stream stream );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Load_Names */
- /* */
- /* <Description> */
- /* Loads the name records. */
- /* */
- /* <Input> */
- /* face :: A handle to the target face object. */
- /* stream :: The input stream. */
- /* */
- /* <Return> */
- /* TrueType error code. 0 means success. */
- /* */
LOCAL_DEF
TT_Error TT_Load_Names( TT_Face face,
FT_Stream stream );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Load_OS2 */
- /* */
- /* <Description> */
- /* Loads the OS2 table. */
- /* */
- /* <Input> */
- /* face :: A handle to the target face object. */
- /* stream :: A handle to the input stream. */
- /* */
- /* <Return> */
- /* TrueType error code. 0 means success. */
- /* */
LOCAL_DEF
TT_Error TT_Load_OS2( TT_Face face,
FT_Stream stream );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Load_Postscript */
- /* */
- /* <Description> */
- /* Loads the Postscript table. */
- /* */
- /* <Input> */
- /* face :: A handle to the target face object. */
- /* stream :: A handle to the input stream. */
- /* */
- /* <Return> */
- /* TrueType error code. 0 means success. */
- /* */
LOCAL_DEF
TT_Error TT_Load_PostScript( TT_Face face,
FT_Stream stream );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Load_Hdmx */
- /* */
- /* <Description> */
- /* Loads the horizontal device metrics table. */
- /* */
- /* <Input> */
- /* face :: A handle to the target face object. */
- /* stream :: A handle to the input stream. */
- /* */
- /* <Return> */
- /* TrueType error code. 0 means success. */
- /* */
LOCAL_DEF
TT_Error TT_Load_Hdmx( TT_Face face,
FT_Stream stream );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Free_Names */
- /* */
- /* <Description> */
- /* Frees the name records. */
- /* */
- /* <Input> */
- /* face :: A handle to the target face object. */
- /* */
- /* <Return> */
- /* TrueType error code. 0 means success. */
- /* */
LOCAL_DEF
void TT_Free_Names( TT_Face face );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Free_Hdmx */
- /* */
- /* <Description> */
- /* Frees the horizontal device metrics table. */
- /* */
- /* <Input> */
- /* face :: A handle to the target face object. */
- /* */
- /* <Return> */
- /* TrueType error code. 0 means success. */
- /* */
LOCAL_DEF
void TT_Free_Hdmx ( TT_Face face );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Load_Kern */
- /* */
- /* <Description> */
- /* Loads the first kerning table with format 0 in the font. Only */
- /* accepts the first horizontal kerning table. Developers should use */
- /* the `ftxkern' extension to access other kerning tables in the font */
- /* file, if they really want to. */
- /* */
- /* <Input> */
- /* face :: A handle to the target face object. */
- /* stream :: The input stream. */
- /* */
- /* <Return> */
- /* TrueType error code. 0 means success. */
- /* */
LOCAL_DEF
TT_Error TT_Load_Kern( TT_Face face,
FT_Stream stream );
- /*************************************************************************/
- /* */
- /* <Function> */
- /* TT_Load_Gasp */
- /* */
- /* <Description> */
- /* Loads the `GASP' table into a face object. */
- /* */
- /* <Input> */
- /* face :: A handle to the target face object. */
- /* stream :: The input stream. */
- /* */
- /* <Return> */
- /* TrueType error code. 0 means success. */
- /* */
LOCAL_DEF
TT_Error TT_Load_Gasp( TT_Face face,
FT_Stream stream );
diff --git a/src/shared/sfnt.h b/src/shared/sfnt.h
index 4311ed5..d08f7f9 100644
--- a/src/shared/sfnt.h
+++ b/src/shared/sfnt.h
@@ -26,6 +26,36 @@
/*************************************************************************/
/* */
/* <FuncType> */
+ /* TT_Load_Format_Tag */
+ /* */
+ /* <Description> */
+ /* Loads the first 4 bytes of the font file. This is a tag that */
+ /* identifies the font format used. */
+ /* */
+ /* <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 */
+ /* */
+ /* <Return> */
+ /* TrueType error code. 0 means success. */
+ /* */
+ /* <Note> */
+ /* The stream cursor must be at the font file's origin */
+ /* This function recognizes fonts embedded in a "TrueType collection" */
+ /* */
+ typedef
+ TT_Error (*TT_Load_Format_Tag_Func)( TT_Face face,
+ FT_Stream stream,
+ TT_Long faceIndex,
+ TT_ULong *format_tag );
+
+ /*************************************************************************/
+ /* */
+ /* <FuncType> */
/* TT_Load_Directory_Func */
/* */
/* <Description> */
@@ -41,7 +71,9 @@
/* TrueType error code. 0 means success. */
/* */
/* <Note> */
- /* The stream cursor must be at the font file's origin */
+ /* The stream cursor must be on the first byte after the 4-byte */
+ /* font format tag. This is the case just after a call to */
+ /* TT_Load_Format_Tag */
/* */
typedef
TT_Error (*TT_Load_Directory_Func)( TT_Face face,
@@ -306,6 +338,7 @@
TT_Goto_Table_Func goto_table;
TT_Load_Any_Func load_any;
+ TT_Load_Format_Tag_Func load_format_tag;
TT_Load_Directory_Func load_directory;
TT_Load_Table_Func load_header;
diff --git a/src/shared/t1types.h b/src/shared/t1types.h
index 175482c..8bf5a5b 100644
--- a/src/shared/t1types.h
+++ b/src/shared/t1types.h
@@ -270,24 +270,47 @@
/***********************************************************************/
/* */
- /* <Struct> T1_FontInfo */
+ /* <Struct> T1_Encoding */
/* */
/* <Description> */
- /* The FontInfo dictionary structure. */
+ /* A structure modeling a custom encoding */
/* */
/* <Fields> */
- /* version :: */
- /* notice :: */
- /* full_name :: */
- /* family_name :: */
- /* weight :: */
- /* italic_angle :: */
- /* is_fixed_pitch :: */
- /* underline_position :: */
- /* underline_thickness :: */
+ /* num_chars :: number of char codes in encoding. Usually 256 */
+ /* code_first :: lower char code in encoding */
+ /* code_last :: higher char code in encoding */
/* */
- typedef struct T1_FontInfo_
+ /* char_code :: array of character codes */
+ /* char_index :: array of correpsonding glyph indices */
+ /* char_name :: array of correpsonding glyph names */
+ /* */
+ typedef struct T1_Encoding_
+ {
+ T1_Int num_chars;
+ T1_Int code_first;
+ T1_Int code_last;
+
+ T1_Short* char_index;
+ T1_String** char_name;
+
+ } T1_Encoding;
+
+
+ typedef enum T1_EncodingType_
+ {
+ t1_encoding_none = 0,
+ t1_encoding_array,
+ t1_encoding_standard,
+ t1_encoding_expert
+
+ } T1_EncodingType;
+
+
+ typedef struct T1_Font_
{
+
+ /* font info dictionary */
+
T1_String* version;
T1_String* notice;
T1_String* full_name;
@@ -298,53 +321,8 @@
T1_Short underline_position;
T1_UShort underline_thickness;
- } T1_FontInfo;
-
+ /* private dictionary */
- /***********************************************************************/
- /* */
- /* <Struct> T1_Private */
- /* */
- /* <Description> */
- /* The Private dictionary structure. */
- /* */
- /* <Fields> */
- /* unique_id :: the font's unique id */
- /* lenIV :: length of decrypt padding */
- /* */
- /* num_blues :: number of blue values */
- /* num_other_blues :: number of other blue values */
- /* num_family_blues :: number of family blue values */
- /* num_family_other_blues :: number of family other blue values */
- /* */
- /* blue_values :: array of blue values */
- /* other_blues :: array of other blue values */
- /* family_blues :: array of family blue values */
- /* family_other_blues :: array of family other blue values */
- /* */
- /* blue_scale :: */
- /* blue_shift :: */
- /* blue_scale :: */
- /* */
- /* standard_width :: */
- /* standard_height :: */
- /* */
- /* num_snap_widths :: */
- /* num_snap_heights :: */
- /* force_bold :: */
- /* round_stem_up :: */
- /* */
- /* stem_snap_widths :: */
- /* stem_snap_heights :: */
- /* */
- /* language_group :: */
- /* password :: */
- /* */
- /* min_feature :: */
- /* */
- /* */
- typedef struct T1_Private_
- {
T1_Int unique_id;
T1_Int lenIV;
@@ -379,37 +357,36 @@
T1_Short min_feature[2];
- } T1_Private;
+ /* top-level dictionary */
+
+ FT_String* font_name;
+ T1_EncodingType encoding_type;
+ T1_Encoding encoding;
+ T1_Byte* subrs_block;
+ T1_Byte* charstrings_block;
+ T1_Byte* glyph_names_block;
- /***********************************************************************/
- /* */
- /* <Struct> T1_Private */
- /* */
- /* <Description> */
- /* The Private dictionary structure. */
- /* */
- /* <Fields> */
- /* num_chars :: number of char codes in encoding. Usually 256 */
- /* code_first :: lower char code in encoding */
- /* code_last :: higher char code in encoding */
- /* */
- /* char_code :: array of character codes */
- /* char_index :: array of correpsonding glyph indices */
- /* char_name :: array of correpsonding glyph names */
- /* */
- typedef struct T1_Encoding_
- {
- T1_Int num_chars;
- T1_Int code_first;
- T1_Int code_last;
+ T1_Int num_subrs;
+ T1_Byte** subrs;
+ T1_Int* subrs_len;
- T1_Short* char_index;
- T1_String** char_name;
+ T1_Int num_glyphs;
+ T1_String** glyph_names; /* array of glyph names */
+ T1_Byte** charstrings; /* array of glyph charstrings */
+ T1_Int* charstrings_len;
- } T1_Encoding;
+ T1_Byte paint_type;
+ T1_Byte font_type;
+ T1_Matrix font_matrix;
+ T1_BBox font_bbox;
+ T1_Long font_id;
+ T1_Int stroke_width;
+
+ } T1_Font;
+
/*************************************************************************/
@@ -417,7 +394,7 @@
/*************************************************************************/
/*** ***/
/*** ***/
-/*** ORIGINAL TT_FACE CLASS DEFINITION ***/
+/*** ORIGINAL T1_FACE CLASS DEFINITION ***/
/*** ***/
/*** ***/
/*************************************************************************/
@@ -451,33 +428,7 @@
typedef struct T1_FaceRec_
{
FT_FaceRec root;
-
- T1_FontInfo font_info;
- FT_String* font_name;
-
- T1_Encoding encoding;
-
- T1_Byte* subrs_block;
- T1_Byte* charstrings_block;
-
- T1_Int num_subrs;
- T1_Byte** subrs;
- T1_Int* subrs_len;
-
- T1_Int num_glyphs;
- T1_String** glyph_names; /* array of glyph names */
- T1_Byte** charstrings; /* array of glyph charstrings */
- T1_Int* charstrings_len;
-
- T1_Byte paint_type;
- T1_Byte font_type;
- T1_Matrix font_matrix;
- T1_BBox font_bbox;
- T1_Long unique_id;
- T1_Long font_id;
-
- T1_Int stroke_width;
- T1_Private private_dict;
+ T1_Font type1;
} T1_FaceRec;
diff --git a/src/truetype/ttdriver.c b/src/truetype/ttdriver.c
index 7dafb88..fdf9dff 100644
--- a/src/truetype/ttdriver.c
+++ b/src/truetype/ttdriver.c
@@ -29,77 +29,6 @@
#define FT_COMPONENT trace_ttdriver
- static
- TT_Bool string_compare( const TT_String* s1,
- const TT_String* s2 )
- {
- int tries;
-
-
- for ( tries = 128; tries > 0; tries-- )
- {
- if ( !*s1 )
- return !*s2;
-
- if ( *s1 != *s2 )
- return 0;
-
- s1++;
- s2++;
- }
-
- return 0;
- }
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Get_Interface */
- /* */
- /* <Description> */
- /* Some drivers can be compiled with extensions, special code used */
- /* only for specific purposes (usually for system-specific uses). */
- /* Each extension is registered through a simple name (e.g. `sfnt', */
- /* `post_names', etc). */
- /* */
- /* This function is used to return an extension's interface (i.e., */
- /* a table of pointers) when it is present in the driver. */
- /* */
- /* If the driver wasn't compiled with the requested extension, it */
- /* should return NULL. */
- /* */
- /* <Input> */
- /* driver :: A handle to the driver object. */
- /* */
- /* interface :: The interface's name string. */
- /* */
- /* <Return> */
- /* A typeless pointer to the extension's interface (normally a table */
- /* of function pointers). Returns NULL when the requested extension */
- /* isn't available (i.e., wasn't compiled in the driver at build */
- /* time). */
- /* */
- /* <Note> */
- /* Note that unlike format-specific methods returned by */
- /* getFormatInterface(), extensions can be format-independent. */
- /* */
- static
- void* Get_Interface( TT_Driver driver,
- const TT_String* interface )
- {
- /* `sfnt' returns a vtable of functions used to access the tables */
- /* of a TrueType or OpenType font resource. */
- if ( string_compare( interface, "sfnt" ) )
- return (void*)NULL;
-
- /* XXXX : For now, there is no extension support there */
- UNUSED( driver );
- UNUSED( interface );
-
- return NULL;
- }
-
/*************************************************************************/
/*************************************************************************/
@@ -500,34 +429,27 @@
TT_Face face = (TT_Face)size->root.face;
TT_Long dim_x, dim_y;
-
- if ( char_width < 1*64 ) char_width = 1*64;
- if ( char_height < 1*64 ) char_height = 1*64;
-
- /* Compute pixel sizes in 26.6 units */
- dim_x = (char_width * horz_resolution) / 72;
- dim_y = (char_height * vert_resolution) / 72;
-
- /* Truncate to integer pixels if required by font - nearly all */
- /* TrueType fonts have this bit set, as hinting can really work */
- /* with integer pixel sizes. */
- if ( face->header.Flags & 8 )
+ /* This bit flag, when set, indicates that the pixel size must be */
+ /* truncated to an integer. Nearly all TrueType fonts have this */
+ /* bit set, as hinting won't work really well otherwise. */
+ /* */
+ /* However, for those rare fonts who do not set it, we override */
+ /* the default computations performed by the base layer. I really */
+ /* don't know if this is useful, but hey, that's the spec :-) */
+ /* */
+ if ( (face->header.Flags & 8) == 0 )
{
- dim_x = (dim_x + 32) & -64;
- dim_y = (dim_y + 32) & -64;
- }
-
- metrics->x_scale = FT_MulDiv( dim_x,
- 0x10000L,
- face->root.units_per_EM );
-
- metrics->y_scale = FT_MulDiv( dim_y,
- 0x10000L,
- face->root.units_per_EM );
+ /* Compute pixel sizes in 26.6 units */
+ dim_x = (char_width * horz_resolution) / 72;
+ dim_y = (char_height * vert_resolution) / 72;
- metrics->x_ppem = (TT_UShort)(dim_x >> 6);
- metrics->y_ppem = (TT_UShort)(dim_y >> 6);
+ metrics->x_scale = FT_DivFix( dim_x, face->root.units_per_EM );
+ metrics->y_scale = FT_DivFix( dim_y, face->root.units_per_EM );
+ metrics->x_ppem = (TT_UShort)(dim_x >> 6);
+ metrics->y_ppem = (TT_UShort)(dim_y >> 6);
+ }
+
size->ttmetrics.valid = FALSE;
return TT_Reset_Size( size );
@@ -559,23 +481,10 @@
TT_UInt pixel_width,
TT_UInt pixel_height )
{
- FT_Size_Metrics* metrics = &size->root.metrics;
- TT_Face face = (TT_Face)size->root.face;
-
-
- if ( pixel_width < 1 ) pixel_width = 1;
- if ( pixel_height < 1 ) pixel_height = 1;
-
- metrics->x_ppem = pixel_width;
- metrics->y_ppem = pixel_height;
-
- metrics->x_scale = FT_MulDiv( metrics->x_ppem << 6,
- 0x10000L,
- face->root.units_per_EM );
+ (void) pixel_width;
+ (void) pixel_height;
- metrics->y_scale = FT_MulDiv( metrics->y_ppem << 6,
- 0x10000L,
- face->root.units_per_EM );
+ /* many things were pre-computed by the base layer */
size->ttmetrics.valid = FALSE;
@@ -722,15 +631,15 @@
sizeof ( TT_SizeRec ),
sizeof ( FT_GlyphSlotRec ),
- "truetype", /* driver name */
- 1, /* driver version */
- 2, /* driver requires FreeType 2 or above */
+ "truetype", /* driver name */
+ 100, /* driver version == 1.0 */
+ 200, /* driver requires FreeType 2.0 or above */
(void*)0,
(FTDriver_initDriver) TT_Init_Driver,
(FTDriver_doneDriver) TT_Done_Driver,
- (FTDriver_getInterface) Get_Interface,
+ (FTDriver_getInterface) 0, /* now extra interface for now */
(FTDriver_initFace) Init_Face,
(FTDriver_doneFace) TT_Done_Face,
diff --git a/src/truetype/ttinterp.c b/src/truetype/ttinterp.c
index c9be4f2..b27de27 100644
--- a/src/truetype/ttinterp.c
+++ b/src/truetype/ttinterp.c
@@ -31,6 +31,8 @@
#undef FT_COMPONENT
#define FT_COMPONENT trace_ttinterp
+#undef NO_APPLE_PATENT
+#define APPLE_THRESHOLD 0x4000000
/*************************************************************************/
/* */
@@ -1432,10 +1434,14 @@
if ( v != 0 )
{
+#ifdef NO_APPLE_PATENT
+ if ( ABS(CUR.F_dot_P) > APPLE_THRESHOLD )
+ zone->cur[point].x += distance;
+#else
zone->cur[point].x += TT_MULDIV( distance,
v * 0x10000L,
CUR.F_dot_P );
-
+#endif
zone->touch[point] |= FT_Curve_Tag_Touch_X;
}
@@ -1443,10 +1449,14 @@
if ( v != 0 )
{
+#ifdef NO_APPLE_PATENT
+ if ( ABS(CUR.F_dot_P) > APPLE_THRESHOLD )
+ zone->cur[point].y += distance;
+#else
zone->cur[point].y += TT_MULDIV( distance,
v * 0x10000L,
CUR.F_dot_P );
-
+#endif
zone->touch[point] |= FT_Curve_Tag_Touch_Y;
}
}
@@ -4940,13 +4950,17 @@
d = CUR_Func_project( zp.cur + p, zp.org + p );
+#ifdef NO_APPLE_PATENT
+ *x = TT_MULDIV( d, CUR.GS.freeVector.x, 0x4000 );
+ *y = TT_MULDIV( d, CUR.GS.freeVector.y, 0x4000 );
+#else
*x = TT_MULDIV( d,
(TT_Long)CUR.GS.freeVector.x * 0x10000L,
CUR.F_dot_P );
*y = TT_MULDIV( d,
(TT_Long)CUR.GS.freeVector.y * 0x10000L,
CUR.F_dot_P );
-
+#endif
return SUCCESS;
}
diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c
index da1d494..262f3e1 100644
--- a/src/truetype/ttobjs.c
+++ b/src/truetype/ttobjs.c
@@ -222,6 +222,7 @@
TT_Face face )
{
TT_Error error;
+ TT_ULong format_tag;
SFNT_Interface* sfnt;
sfnt = (SFNT_Interface*)face->sfnt;
@@ -246,7 +247,20 @@
if ( FILE_Seek(0) )
goto Exit;
- /* Load collection directory if present, then font directory */
+ /* check that we have a valid TrueType file */
+ error = sfnt->load_format_tag( face, stream, face_index, &format_tag );
+ if (error) goto Exit;
+
+ /* We must also be able to accept Mac/GX fonts, as well as OT ones */
+ if ( format_tag != 0x00010000 && /* MS fonts */
+ format_tag != TTAG_true ) /* Mac fonts */
+ {
+ FT_TRACE2(( "[not a valid TTF font]" ));
+ error = TT_Err_Invalid_File_Format;
+ goto Exit;
+ }
+
+ /* Load font directory */
error = sfnt->load_directory( face, stream, face_index );
if ( error ) goto Exit;