updated version of the experimental Type 1 driver (this thing now works even better than the "regular" driver, but is much smaller). Provides no hinter !!
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 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057
diff --git a/src/type1z/rules.mk b/src/type1z/rules.mk
index d4bc25d..da2036c 100644
--- a/src/type1z/rules.mk
+++ b/src/type1z/rules.mk
@@ -108,16 +108,16 @@ T1Z_COMPILE := $(FT_COMPILE) $(T1Z_INCLUDE:%=$I%)
T1Z_DRV_SRC := $(T1Z_DIR_)t1parse.c \
$(T1Z_DIR_)t1load.c \
$(T1Z_DIR_)t1driver.c \
- $(T1Z_DIR_)t1encode.c \
+ $(T1Z_DIR_)t1afm.c \
$(T1Z_DIR_)t1gload.c
# Type1 driver headers
#
T1Z_DRV_H := $(T1Z_DIR_)t1errors.h \
- $(T1Z_DIR_)t1config.h \
- $(T1SHARED_H) \
- $(T1Z_DRV_SRC:%.c=%.h)
+ $(T1Z_DIR_)t1config.h \
+ $(T1SHARED_H) \
+ $(T1Z_DRV_SRC:%.c=%.h)
# driver object(s)
diff --git a/src/type1z/t1afm.c b/src/type1z/t1afm.c
new file mode 100644
index 0000000..abd19b8
--- /dev/null
+++ b/src/type1z/t1afm.c
@@ -0,0 +1,222 @@
+/***************************************************************************
+ *
+ * t1afm.c - support for reading Type 1 AFM files
+ *
+ *
+ ***************************************************************************/
+
+#include <t1afm.h>
+#include <ftstream.h>
+#include <t1types.h>
+#include <stdlib.h> /* for qsort */
+
+ LOCAL_FUNC
+ void T1_Done_AFM( FT_Memory memory, T1_AFM* afm )
+ {
+ FREE( afm->kern_pairs );
+ afm->num_pairs = 0;
+ }
+
+#undef IS_KERN_PAIR
+#define IS_KERN_PAIR(p) ( p[0] == 'K' && p[1] == 'P' )
+
+#define IS_ALPHANUM(c) ( (c >= 'A' && c <= 'Z') || \
+ (c >= 'a' && c <= 'z') || \
+ (c >= '0' && c <= '9') || \
+ (c == '_' && c == '.') )
+
+ /* read a glyph name and return the equivalent glyph index */
+ static
+ FT_UInt afm_atoindex( FT_Byte* *start, FT_Byte* limit, T1_Font* type1 )
+ {
+ FT_Byte* p = *start;
+ FT_Int len;
+ FT_UInt result = 0;
+ char temp[64];
+
+ /* skip whitespace */
+ while ( (*p == ' ' || *p == '\t' || *p == ':' || *p == ';') && p < limit )
+ p++;
+ *start = p;
+
+ /* now, read glyph name */
+ while ( IS_ALPHANUM(*p) && p < limit ) p++;
+ len = p - *start;
+ if (len > 0 && len < 64)
+ {
+ FT_Int n;
+
+ /* copy glyph name to intermediate array */
+ MEM_Copy( temp, start, len );
+ temp[len] = 0;
+
+ /* lookup glyph name in face array */
+ for ( n = 0; n < type1->num_glyphs; n++ )
+ {
+ char* gname = (char*)type1->glyph_names;
+
+ if ( gname && gname[0] == temp[0] && strcmp(gname,temp) == 0 )
+ {
+ result = n;
+ break;
+ }
+ }
+ }
+ *start = p;
+ return result;
+ }
+
+
+ /* read an integer */
+ static
+ int afm_atoi( FT_Byte** start, FT_Byte* limit )
+ {
+ FT_Byte* p = *start;
+ int sum = 0;
+
+ /* skip everything that is not a number */
+ while ( p < limit && (*p < '0' || *p > '9') )
+ p++;
+
+ while ( p < limit && (*p >= '0' || *p < '9') )
+ {
+ sum = sum*10 + (*p - '0');
+ p++;
+ }
+ *start = p;
+ return sum;
+ }
+
+
+#undef KERN_INDEX
+#define KERN_INDEX(g1,g2) (((T1_ULong)g1 << 16) | g2)
+
+ /* compare two kerning pairs */
+ static
+ int compare_kern_pairs( const void* a, const void* b )
+ {
+ T1_Kern_Pair* pair1 = (T1_Kern_Pair*)a;
+ T1_Kern_Pair* pair2 = (T1_Kern_Pair*)b;
+
+ T1_ULong index1 = KERN_INDEX(pair1->glyph1,pair1->glyph2);
+ T1_ULong index2 = KERN_INDEX(pair2->glyph1,pair2->glyph2);
+
+ return ( index1 < index2 ? -1 :
+ ( index1 > index2 ? 1 : 0 ));
+ }
+
+
+ /* parse an AFM file - for now, only read the kerning pairs */
+ LOCAL_FUNC
+ FT_Error T1_Read_AFM( FT_Stream stream,
+ FT_Face t1_face )
+ {
+ FT_Error error;
+ FT_Memory memory = stream->memory;
+ FT_Byte* start;
+ FT_Byte* limit;
+ FT_Byte* p;
+ FT_Int count = 0;
+ T1_Kern_Pair* pair;
+ T1_Font* type1 = &((T1_Face)t1_face)->type1;
+ T1_AFM* afm = 0;
+
+ if ( !ACCESS_Frame(stream->size) )
+ return error;
+
+ start = (FT_Byte*)stream->cursor;
+ limit = (FT_Byte*)stream->limit;
+ p = start;
+
+ /* we are now going to count the occurences of "KP" or "KPX" in */
+ /* the AFM file.. */
+ count = 0;
+ for ( p = start; p < limit-3; p++ )
+ {
+ if ( IS_KERN_PAIR(p) )
+ count++;
+ }
+
+ /* Actually, kerning pairs are simply optional !! */
+ if (count == 0)
+ goto Exit;
+
+ /* allocate the pairs */
+ if ( ALLOC( afm, sizeof(*afm ) ) ||
+ ALLOC_ARRAY( afm->kern_pairs, count, T1_Kern_Pair ) )
+ goto Exit;
+
+ /* now, read each kern pair */
+ pair = afm->kern_pairs;
+ afm->num_pairs = count;
+
+ /* save in face object */
+ ((T1_Face)t1_face)->afm_data = afm;
+
+ for ( p = start; p < limit-3; p++ )
+ {
+ if ( IS_KERN_PAIR(p) )
+ {
+ FT_Byte* q;
+
+ /* skip keyword (KP or KPX) */
+ q = p+2;
+ if (*q == 'X') q++;
+
+ pair->glyph1 = afm_atoindex( &q, limit, type1 );
+ pair->glyph2 = afm_atoindex( &q, limit, type1 );
+ pair->kerning.x = afm_atoi( &q, limit );
+
+ pair->kerning.y = 0;
+ if ( p[2] != 'X' )
+ pair->kerning.y = afm_atoi( &q, limit );
+
+ pair++;
+ }
+ }
+
+ /* now, sort the kern pairs according to their glyph indices */
+ qsort( afm->kern_pairs, count, sizeof(T1_Kern_Pair), compare_kern_pairs );
+
+ Exit:
+ if (error)
+ FREE( afm );
+
+ FORGET_Frame();
+ return error;
+ }
+
+
+ /* find the kerning for a given glyph pair */
+ LOCAL_FUNC
+ void T1_Get_Kerning( T1_AFM* afm,
+ FT_UInt glyph1,
+ FT_UInt glyph2,
+ FT_Vector* kerning )
+ {
+ T1_Kern_Pair *min, *mid, *max;
+ T1_ULong index = KERN_INDEX(glyph1,glyph2);
+
+ /* simple binary search */
+ min = afm->kern_pairs;
+ max = min + afm->num_pairs-1;
+
+ while (min <= max)
+ {
+ T1_ULong midi;
+
+ mid = min + (max-min)/2;
+ midi = KERN_INDEX(mid->glyph1,mid->glyph2);
+ if ( midi == index )
+ {
+ *kerning = mid->kerning;
+ return;
+ }
+
+ if ( midi < index ) min = mid+1;
+ else max = mid-1;
+ }
+ kerning->x = 0;
+ kerning->y = 0;
+ }
+
diff --git a/src/type1z/t1afm.h b/src/type1z/t1afm.h
new file mode 100644
index 0000000..39bbc4b
--- /dev/null
+++ b/src/type1z/t1afm.h
@@ -0,0 +1,47 @@
+/***************************************************************************
+ *
+ * t1afm.h - support for reading Type 1 AFM files
+ *
+ *
+ ***************************************************************************/
+
+#ifndef T1AFM_H
+#define T1AFM_H
+
+#include <ftobjs.h>
+
+/* In this version, we only read the kerning table from the */
+/* AFM file. We may add support for ligatures a bit later.. */
+
+typedef struct T1_Kern_Pair_
+{
+ FT_UInt glyph1;
+ FT_UInt glyph2;
+ FT_Vector kerning;
+
+} T1_Kern_Pair;
+
+
+typedef struct T1_AFM_
+{
+ FT_Int num_pairs;
+ T1_Kern_Pair* kern_pairs;
+
+} T1_AFM;
+
+
+LOCAL_DEF
+FT_Error T1_Read_AFM( FT_Stream stream,
+ FT_Face face );
+
+LOCAL_DEF
+void T1_Done_AFM( FT_Memory memory,
+ T1_AFM* afm );
+
+LOCAL_DEF
+void T1_Get_Kerning( T1_AFM* afm,
+ FT_UInt glyph1,
+ FT_UInt glyph2,
+ FT_Vector* kerning );
+
+#endif /* T1AFM_H */
diff --git a/src/type1z/t1config.h b/src/type1z/t1config.h
index a72b177..9767301 100644
--- a/src/type1z/t1config.h
+++ b/src/type1z/t1config.h
@@ -42,4 +42,11 @@
/* */
#undef T1_CONFIG_OPTION_DISABLE_HINTER
+/* Define this configuration macro if you want to prevent the */
+/* compilation of "t1afm", which is in charge of reading Type1 */
+/* AFM files into an existing face. Note that when set, the T1 */
+/* driver will be unable to produce kerning distances.. */
+/* */
+#undef T1_CONFIG_OPTION_NO_AFM
+
#endif /* T1CONFIG_H */
diff --git a/src/type1z/t1driver.c b/src/type1z/t1driver.c
index 039ecd1..9d2fdd9 100644
--- a/src/type1z/t1driver.c
+++ b/src/type1z/t1driver.c
@@ -17,13 +17,16 @@
#include <t1driver.h>
#include <t1gload.h>
+#include <t1afm.h>
#include <ftdebug.h>
#include <ftstream.h>
+#include <psnames.h>
#undef FT_COMPONENT
#define FT_COMPONENT trace_t1driver
+#ifndef T1_CONFIG_OPTION_NO_AFM
/*************************************************************************/
/* */
/* <Function> */
@@ -52,15 +55,68 @@
/* time). */
/* */
static
- void* Get_Interface( FT_Driver* driver,
- const FT_String* interface )
+ FTDriver_Interface Get_Interface( FT_Driver driver,
+ const FT_String* interface )
{
- UNUSED(driver);
- UNUSED(interface);
+ if ( strcmp( (const char*)interface, "attach_file" ) == 0 )
+ return (FTDriver_Interface)T1_Read_AFM;
+
return 0;
}
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* Get_Kerning */
+ /* */
+ /* <Description> */
+ /* A driver method used to return the kerning vector between two */
+ /* glyphs of the same face. */
+ /* */
+ /* <Input> */
+ /* face :: A handle to the source face object. */
+ /* */
+ /* left_glyph :: The index of the left glyph in the kern pair. */
+ /* */
+ /* right_glyph :: The index of the right glyph in the kern pair. */
+ /* */
+ /* <Output> */
+ /* kerning :: The kerning vector. This is in font units for */
+ /* scalable formats, and in pixels for fixed-sizes */
+ /* formats. */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0 means success. */
+ /* */
+ /* <Note> */
+ /* Only horizontal layouts (left-to-right & right-to-left) are */
+ /* supported by this function. Other layouts, or more sophisticated */
+ /* kernings are out of scope of this method (the basic driver */
+ /* interface is meant to be simple). */
+ /* */
+ /* They can be implemented by format-specific interfaces. */
+ /* */
+ static
+ T1_Error Get_Kerning( T1_Face face,
+ T1_UInt left_glyph,
+ T1_UInt right_glyph,
+ T1_Vector* kerning )
+ {
+ T1_AFM* afm;
+
+ kerning->x = 0;
+ kerning->y = 0;
+
+ afm = (T1_AFM*)face->afm_data;
+ if (afm)
+ T1_Get_Kerning( afm, left_glyph, right_glyph, kerning );
+
+ return T1_Err_Ok;
+ }
+#endif
+
/******************************************************************/
/* */
/* <Function> Set_Char_Sizes */
@@ -130,6 +186,171 @@
return T1_Reset_Size(size);
}
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* Get_Char_Index */
+ /* */
+ /* <Description> */
+ /* Uses a charmap to return a given character code's glyph index. */
+ /* */
+ /* <Input> */
+ /* charmap :: A handle to the source charmap object. */
+ /* charcode :: The character code. */
+ /* */
+ /* <Return> */
+ /* Glyph index. 0 means `undefined character code'. */
+ /* */
+ static
+ T1_UInt Get_Char_Index( FT_CharMap charmap,
+ T1_Long charcode )
+ {
+ T1_Face face;
+ T1_UInt result = 0;
+ PSNames_Interface* psnames;
+
+ face = (T1_Face)charmap->face;
+ psnames = (PSNames_Interface*)face->psnames;
+ if (psnames)
+ switch (charmap->encoding)
+ {
+ /********************************************************************/
+ /* */
+ /* Unicode encoding support */
+ /* */
+ case ft_encoding_unicode:
+ {
+ /* use the "psnames" module to synthetize the Unicode charmap */
+ result = psnames->lookup_unicode( &face->unicode_map,
+ (T1_ULong)charcode );
+
+ /* the function returns 0xFFFF when the Unicode charcode has */
+ /* no corresponding glyph.. */
+ if (result == 0xFFFF)
+ result = 0;
+ goto Exit;
+ }
+
+ /********************************************************************/
+ /* */
+ /* Custom Type 1 encoding */
+ /* */
+ case ft_encoding_adobe_custom:
+ {
+ T1_Encoding* encoding = &face->type1.encoding;
+ if (charcode >= encoding->code_first &&
+ charcode <= encoding->code_last)
+ {
+ result = encoding->char_index[charcode];
+ }
+ goto Exit;
+ }
+
+ /********************************************************************/
+ /* */
+ /* Adobe Standard & Expert encoding support */
+ /* */
+ default:
+ if (charcode < 256)
+ {
+ FT_UInt code;
+ FT_Int n;
+ const char* glyph_name;
+
+ code = psnames->adobe_std_encoding[charcode];
+ if (charmap->encoding == ft_encoding_adobe_expert)
+ code = psnames->adobe_expert_encoding[charcode];
+
+ glyph_name = psnames->adobe_std_strings(code);
+ if (!glyph_name) break;
+
+ for ( n = 0; n < face->type1.num_glyphs; n++ )
+ {
+ const char* gname = face->type1.glyph_names[n];
+
+ if ( gname && gname[0] == glyph_name[0] &&
+ strcmp( gname, glyph_name ) == 0 )
+ {
+ result = n;
+ break;
+ }
+ }
+ }
+ }
+ Exit:
+ return result;
+ }
+
+
+ static
+ T1_Error Init_Face( FT_Stream stream,
+ FT_Int face_index,
+ T1_Face face )
+ {
+ T1_Error error;
+
+ error = T1_Init_Face(stream, face_index, face);
+ if (!error)
+ {
+ FT_Face root = &face->root;
+ FT_CharMap charmap = face->charmaprecs;
+
+ /* synthetize a Unicode charmap if there is support in the "psnames" */
+ /* module.. */
+ if (face->psnames)
+ {
+ PSNames_Interface* psnames = (PSNames_Interface*)face->psnames;
+ if (psnames->unicode_value)
+ {
+ error = psnames->build_unicodes( root->memory,
+ face->type1.num_glyphs,
+ (const char**)face->type1.glyph_names,
+ &face->unicode_map );
+ if (!error)
+ {
+ root->charmap = charmap;
+ charmap->face = (FT_Face)face;
+ charmap->encoding = ft_encoding_unicode;
+ charmap->platform_id = 3;
+ charmap->encoding_id = 1;
+ charmap++;
+ }
+
+ /* simply clear the error in case of failure (which really) */
+ /* means that out of memory or no unicode glyph names */
+ error = 0;
+ }
+ }
+
+ /* now, support either the standard, expert, or custom encodings */
+ charmap->face = (FT_Face)face;
+ charmap->platform_id = 7; /* a new platform id for Adobe fonts ?? */
+
+ switch (face->type1.encoding_type)
+ {
+ case t1_encoding_standard:
+ charmap->encoding = ft_encoding_adobe_standard;
+ charmap->encoding_id = 0;
+ break;
+
+ case t1_encoding_expert:
+ charmap->encoding = ft_encoding_adobe_expert;
+ charmap->encoding_id = 1;
+ break;
+
+ default:
+ charmap->encoding = ft_encoding_adobe_custom;
+ charmap->encoding_id = 2;
+ break;
+ }
+
+ root->charmaps = face->charmaps;
+ root->num_charmaps = charmap - face->charmaprecs + 1;
+ face->charmaps[0] = &face->charmaprecs[0];
+ face->charmaps[1] = &face->charmaprecs[1];
+ }
+ return error;
+ }
/******************************************************************/
/* */
@@ -206,7 +427,7 @@
/* */
EXPORT_FUNC
- const FT_DriverInterface t1_driver_interface =
+ const FT_DriverInterface t1z_driver_interface =
{
sizeof( FT_DriverRec ),
sizeof( T1_FaceRec ),
@@ -214,18 +435,28 @@
sizeof( T1_GlyphSlotRec ),
"type1",
- 100, /* driver version == 1.0 */
- 200, /* requires FreeType 2.0 or above */
+ 100,
+ 200,
0, /* format interface */
(FTDriver_initDriver) T1_Init_Driver,
(FTDriver_doneDriver) T1_Done_Driver,
+
+#ifdef T1_CONFIG_OPTION_NO_AFM
+ (FTDriver_getInterface) 0,
+#else
(FTDriver_getInterface) Get_Interface,
+#endif
- (FTDriver_initFace) T1_Init_Face,
+ (FTDriver_initFace) Init_Face,
(FTDriver_doneFace) T1_Done_Face,
+
+#ifdef T1_CONFIG_OPTION_NO_AFM
(FTDriver_getKerning) 0,
+#else
+ (FTDriver_getKerning) Get_Kerning,
+#endif
(FTDriver_initSize) T1_Init_Size,
(FTDriver_doneSize) T1_Done_Size,
@@ -236,36 +467,38 @@
(FTDriver_doneGlyphSlot) T1_Done_GlyphSlot,
(FTDriver_loadGlyph) T1_Load_Glyph,
- (FTDriver_getCharIndex) 0,
+ (FTDriver_getCharIndex) Get_Char_Index,
};
- /*************************************************************************/
- /* */
- /* <Function> */
- /* getDriverInterface */
- /* */
- /* <Description> */
- /* This function is used when compiling the font driver as a */
- /* shared library (`.DLL' or `.so'). It will be used by the */
- /* high-level library of FreeType to retrieve the address of the */
- /* driver's generic interface. */
- /* */
- /* It shouldn't be implemented in a static build, as each driver must */
- /* have the same function as an exported entry point. */
- /* */
- /* <Return> */
- /* The address of the TrueType's driver generic interface. The */
- /* format-specific interface can then be retrieved through the method */
- /* interface->get_format_interface. */
- /* */
-#ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS
+ /******************************************************************/
+ /* */
+ /* <Function> Get_FreeType_Driver_Interface */
+ /* */
+ /* <Description> */
+ /* This function is used when compiling the TrueType driver */
+ /* as a shared library (.DLL or .so). It will be used by the */
+ /* high-level library of FreeType to retrieve the address of */
+ /* the driver's generic interface. */
+ /* */
+ /* It shouldn't be implemented in a static build, as each */
+ /* driver must have the same function as an exported entry */
+ /* point. */
+ /* */
+ /* <Return> */
+ /* address of TrueType's driver generic interface. The */
+ /* forma-specific interface can then be retrieved through */
+ /* the method interface->get_format_interface.. */
+ /* */
+
+#ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS
+
EXPORT_FUNC
FT_DriverInterface* getDriverInterface( void )
{
return &t1_driver_interface;
}
-
-#endif /* CONFIG_OPTION_DYNAMIC_DRIVERS */
+
+#endif /* FT_CONFIG_OPTION_DYNAMIC_DRIVERS */
diff --git a/src/type1z/t1driver.h b/src/type1z/t1driver.h
index a442035..801fc54 100644
--- a/src/type1z/t1driver.h
+++ b/src/type1z/t1driver.h
@@ -22,7 +22,7 @@
#include <t1errors.h>
EXPORT_DEF
- const FT_DriverInterface t1_driver_interface;
+ const FT_DriverInterface t1z_driver_interface;
#endif /* T1DRIVER_H */
diff --git a/src/type1z/t1gload.c b/src/type1z/t1gload.c
index 0b1d8f4..476b618 100644
--- a/src/type1z/t1gload.c
+++ b/src/type1z/t1gload.c
@@ -17,9 +17,75 @@
#include <t1gload.h>
#include <ftdebug.h>
-#include <t1encode.h>
#include <ftstream.h>
+#undef FT_COMPONENT
+#define FT_COMPONENT trace_t1gload
+
+ typedef enum T1_Operator_
+ {
+ op_none = 0,
+ op_endchar,
+ op_hsbw,
+ op_seac,
+ op_sbw,
+ op_closepath,
+ op_hlineto,
+ op_hmoveto,
+ op_hvcurveto,
+ op_rlineto,
+ op_rmoveto,
+ op_rrcurveto,
+ op_vhcurveto,
+ op_vlineto,
+ op_vmoveto,
+ op_dotsection,
+ op_hstem,
+ op_hstem3,
+ op_vstem,
+ op_vstem3,
+ op_div,
+ op_callothersubr,
+ op_callsubr,
+ op_pop,
+ op_return,
+ op_setcurrentpoint,
+
+ op_max /* never remove this one */
+
+ } T1_Operator;
+
+ static const T1_Int t1_args_count[ op_max ] =
+ {
+ 0, /* none */
+ 0, /* endchar */
+ 2, /* hsbw */
+ 5, /* seac */
+ 4, /* sbw */
+ 0, /* closepath */
+ 1, /* hlineto */
+ 1, /* hmoveto */
+ 4, /* hvcurveto */
+ 2, /* rlineto */
+ 2, /* rmoveto */
+ 6, /* rrcurveto */
+ 4, /* vhcurveto */
+ 1, /* vlineto */
+ 1, /* vmoveto */
+ 0, /* dotsection */
+ 2, /* hstem */
+ 6, /* hstem3 */
+ 2, /* vstem */
+ 6, /* vstem3 */
+ 2, /* div */
+ -1, /* callothersubr */
+ 1, /* callsubr */
+ 0, /* pop */
+ 0, /* return */
+ 2 /* setcurrentpoint */
+ };
+
+
/**********************************************************************/
/**********************************************************************/
/**********************************************************************/
@@ -264,17 +330,26 @@
if (outline->n_contours > 0)
outline->contours[ outline->n_contours-1 ] = outline->n_points-1;
+ outline->n_contours++;
return T1_Err_Ok;
}
-
/* if a path was begun, add its first on-curve point */
static
T1_Error start_point( T1_Builder* builder,
T1_Pos x,
T1_Pos y )
{
- return builder->path_begun && add_point1( builder, x, y );
+ /* test wether we're building a new contour */
+ if (!builder->path_begun)
+ {
+ T1_Error error;
+
+ builder->path_begun = 1;
+ error = add_contour( builder );
+ if (error) return error;
+ }
+ return add_point1( builder, x, y );
}
@@ -312,20 +387,22 @@
T1_Int lookup_glyph_by_stdcharcode( T1_Face face,
T1_Int charcode )
{
- T1_Int n;
- const T1_String* glyph_name;
+ T1_Int n;
+ const T1_String* glyph_name;
+ PSNames_Interface* psnames = (PSNames_Interface*)face->psnames;
/* check range of standard char code */
if (charcode < 0 || charcode > 255)
return -1;
- glyph_name = t1_standard_strings[t1_standard_encoding[charcode]];
+ glyph_name = psnames->adobe_std_strings(
+ psnames->adobe_std_encoding[charcode]);
for ( n = 0; n < face->type1.num_glyphs; n++ )
{
T1_String* name = (T1_String*)face->type1.glyph_names[n];
- if ( name && name[0] == glyph_name[0] && strcmp(name,glyph_name) == 0 )
+ if ( name && strcmp(name,glyph_name) == 0 )
return n;
}
@@ -506,62 +583,364 @@
while ( ip < limit )
{
T1_Int* top = decoder->top;
+ T1_Operator op = op_none;
+ T1_Long value = 0;
+
+ /********************************************************************/
+ /* */
+ /* Decode operator or operand */
+ /* */
+ /* */
/* First of all, decompress operator or value */
switch (*ip++)
{
- case 1: /* hstem */
- case 3: /* vstem */
+ case 1: op = op_hstem; break;
+
+ case 3: op = op_vstem; break;
+ case 4: op = op_vmoveto; break;
+ case 5: op = op_rlineto; break;
+ case 6: op = op_hlineto; break;
+ case 7: op = op_vlineto; break;
+ case 8: op = op_rrcurveto; break;
+ case 9: op = op_closepath; break;
+ case 10: op = op_callsubr; break;
+ case 11: op = op_return; break;
+
+ case 13: op = op_hsbw; break;
+ case 14: op = op_endchar; break;
+
+ case 21: op = op_rmoveto; break;
+ case 22: op = op_hmoveto; break;
+
+ case 30: op = op_vhcurveto; break;
+ case 31: op = op_hvcurveto; break;
+
+ case 12:
{
- Clear_Stack:
- top = decoder->stack;
- break;
+ if (ip > limit)
+ {
+ FT_ERROR(( "T1.Parse_CharStrings : invalid escape (12+EOF)\n" ));
+ goto Syntax_Error;
+ }
+
+ switch (*ip++)
+ {
+ case 0: op = op_dotsection; break;
+ case 1: op = op_vstem3; break;
+ case 2: op = op_hstem3; break;
+ case 6: op = op_seac; break;
+ case 7: op = op_sbw; break;
+ case 12: op = op_div; break;
+ case 16: op = op_callothersubr; break;
+ case 17: op = op_pop; break;
+ case 33: op = op_setcurrentpoint; break;
+
+ default:
+ FT_ERROR(( "T1.Parse_CharStrings : invalid escape (12+%d)\n",
+ ip[-1] ));
+ goto Syntax_Error;
+ }
}
+ break;
- case 4: /* vmoveto */
+ case 255: /* four bytes integer */
{
- USE_ARGS(1);
- y += top[0];
- builder->path_begun = 1;
- goto Clear_Stack;
+ if (ip+4 > limit)
+ {
+ FT_ERROR(( "T1.Parse_CharStrings : unexpected EOF in integer\n" ));
+ goto Syntax_Error;
+ }
+
+ value = ((long)ip[0] << 24) |
+ ((long)ip[1] << 16) |
+ ((long)ip[2] << 8) |
+ ip[3];
+ ip += 4;
}
+ break;
+
+ default:
+ if (ip[-1] >= 32)
+ {
+ if (ip[-1] < 247)
+ value = (long)ip[-1] - 139;
+ else
+ {
+ if (++ip > limit)
+ {
+ FT_ERROR(( "T1.Parse_CharStrings : unexpected EOF in integer\n" ));
+ goto Syntax_Error;
+ }
+
+ if (ip[-2] < 251)
+ value = ((long)(ip[-2]-247) << 8) + ip[-1] + 108;
+ else
+ value = -((((long)ip[-2]-251) << 8) + ip[-1] + 108 );
+ }
+ }
+ else
+ {
+ FT_ERROR(( "T1.Parse_CharStrings : invalid byte (%d)\n",
+ ip[-1] ));
+ goto Syntax_Error;
+ }
+ }
+
+ /********************************************************************/
+ /* */
+ /* Push value on stack, or process operator */
+ /* */
+ /* */
+ if ( op == op_none )
+ {
+ if ( top - decoder->stack >= T1_MAX_CHARSTRINGS_OPERANDS )
+ {
+ FT_ERROR(( "T1.Parse_CharStrings : Stack overflow !!\n" ));
+ goto Syntax_Error;
+ }
+
+ FT_TRACE4(( " %ld", value ));
+ *top++ = value;
+ decoder->top = top;
+ }
+ else if ( op == op_callothersubr ) /* callothersubr */
+ {
+ FT_TRACE4(( " callothersubr" ));
+ if ( top - decoder->stack < 2 )
+ goto Stack_Underflow;
- case 5: /* rlineto */
+ top -= 2;
+ switch ( top[1] )
+ {
+ case 1: /* start flex feature ---------------------- */
+ {
+ if ( top[0] != 0 ) goto Unexpected_OtherSubr;
+
+ decoder->flex_state = 1;
+ decoder->num_flex_vectors = 0;
+ if ( start_point(builder, x, y) ||
+ check_points(builder,6) ) goto Memory_Error;
+ }
+ break;
+
+ case 2: /* add flex vectors ------------------------ */
+ {
+ T1_Int index;
+
+ if ( top[0] != 0 ) goto Unexpected_OtherSubr;
+
+ /* note that we should not add a point for index 0 */
+ /* this will move our current position to the flex */
+ /* point without adding any point to the outline */
+ index = decoder->num_flex_vectors++;
+ if (index > 0 && index < 7)
+ add_point( builder,
+ x,
+ y,
+ (T1_Byte)( index==3 || index==6 ) );
+ }
+ break;
+
+ case 0: /* end flex feature ------------------------- */
+ {
+ if ( top[0] != 3 ) goto Unexpected_OtherSubr;
+
+ if ( decoder->flex_state == 0 ||
+ decoder->num_flex_vectors != 7 )
+ {
+ FT_ERROR(( "T1.Parse_CharStrings: unexpected flex end\n" ));
+ goto Syntax_Error;
+ }
+
+ /* now consume the remaining "pop pop setcurpoint" */
+ if ( ip+6 > limit ||
+ ip[0] != 12 || ip[1] != 17 || /* pop */
+ ip[2] != 12 || ip[3] != 17 || /* pop */
+ ip[4] != 12 || ip[5] != 33 ) /* setcurpoint */
+ {
+ FT_ERROR(( "T1.Parse_CharStrings: invalid flex charstring\n" ));
+ goto Syntax_Error;
+ }
+
+ ip += 6;
+ decoder->flex_state = 0;
+ break;
+ }
+
+ case 3: /* change hints ---------------------------- */
+ {
+ if ( top[0] != 1 ) goto Unexpected_OtherSubr;
+
+ /* eat the following "pop" */
+ if (ip+2 > limit)
+ {
+ FT_ERROR(( "T1.Parse_CharStrings: invalid escape (12+%d)\n",
+ ip[-1] ));
+ goto Syntax_Error;
+ }
+
+ if (ip[0] != 12 || ip[1] != 17)
+ {
+ FT_ERROR(( "T1.Parse_CharStrings: 'pop' expected, found (%d %d)\n",
+ ip[0], ip[1] ));
+ goto Syntax_Error;
+ }
+ ip += 2;
+ break;;
+ }
+
+ default:
+ Unexpected_OtherSubr:
+ FT_ERROR(( "T1.Parse_CharStrings: invalid othersubr [%d %d]!!\n",
+ top[0], top[1] ));
+ goto Syntax_Error;
+ }
+ decoder->top = top;
+ }
+ else /* general operator */
+ {
+ T1_Int num_args = t1_args_count[op];
+
+ if ( top - decoder->stack < num_args )
+ goto Stack_Underflow;
+
+ top -= num_args;
+
+ switch (op)
+ {
+ case op_endchar: /*************************************************/
{
- if ( start_point( builder, x, y ) ) goto Memory_Error;
+ FT_TRACE4(( " endchar" ));
+ close_contour( builder );
+
+ /* add current outline to the glyph slot */
+ builder->base.n_points += builder->current.n_points;
+ builder->base.n_contours += builder->current.n_contours;
+
+ /* return now !! */
+ FT_TRACE4(( "\n\n" ));
+ return T1_Err_Ok;
+ }
+
+
+ case op_hsbw: /****************************************************/
+ {
+ FT_TRACE4(( " hsbw" ));
+ builder->left_bearing.x += top[0];
+ builder->advance.x = top[1];
+ builder->advance.y = 0;
+
+ builder->last.x = x = top[0];
+ builder->last.y = y = 0;
+
+ /* the "metrics_only" indicates that we only want to compute */
+ /* the glyph's metrics (lsb + advance width), not load the */
+ /* rest of it.. so exit immediately */
+ if (builder->metrics_only)
+ return T1_Err_Ok;
- USE_ARGS(2);
- x += top[0];
- y += top[1];
- Add_Line:
- if (add_point1( builder, top[0], top[1] )) goto Memory_Error;
- goto Clear_Stack;
+ break;
}
-
- case 6: /* hlineto */
+
+
+ case op_seac: /****************************************************/
+ /* return immediately after the processing */
+ return t1operator_seac( decoder, top[0], top[1],
+ top[2], top[3], top[4] );
+
+ case op_sbw: /****************************************************/
+ {
+ FT_TRACE4(( " sbw" ));
+ builder->left_bearing.x += top[0];
+ builder->left_bearing.y += top[1];
+ builder->advance.x = top[2];
+ builder->advance.y = top[3];
+
+ builder->last.x = x = top[0];
+ builder->last.y = y = top[1];
+
+ /* the "metrics_only" indicates that we only want to compute */
+ /* the glyph's metrics (lsb + advance width), not load the */
+ /* rest of it.. so exit immediately */
+ if (builder->metrics_only)
+ return T1_Err_Ok;
+
+ break;
+ }
+
+
+ case op_closepath: /**********************************************/
+ {
+ FT_TRACE4(( " closepath" ));
+ close_contour( builder );
+ builder->path_begun = 0;
+ }
+ break;
+
+
+ case op_hlineto: /************************************************/
{
+ FT_TRACE4(( " hlineto" ));
if ( start_point( builder, x, y ) ) goto Memory_Error;
-
- USE_ARGS(1);
+
x += top[0];
goto Add_Line;
}
-
- case 7: /* vlineto */
+
+
+ case op_hmoveto: /************************************************/
+ {
+ FT_TRACE4(( " hmoveto" ));
+ x += top[0];
+ break;
+ }
+
+
+ case op_hvcurveto: /**********************************************/
+ {
+ FT_TRACE4(( " hvcurveto" ));
+ if ( start_point( builder, x, y ) ||
+ check_points( builder, 3 ) ) goto Memory_Error;
+
+ x += top[0];
+ add_point( builder, x, y, 0 );
+ x += top[1];
+ y += top[2];
+ add_point( builder, x, y, 0 );
+ y += top[3];
+ add_point( builder, x, y, 1 );
+ break;
+ }
+
+
+ case op_rlineto: /*************************************************/
{
+ FT_TRACE4(( " rlineto" ));
if ( start_point( builder, x, y ) ) goto Memory_Error;
- USE_ARGS(1);
- y += top[0];
- goto Add_Line;
+ x += top[0];
+ y += top[1];
+ Add_Line:
+ if (add_point1( builder, x, y )) goto Memory_Error;
+ break;
}
-
- case 8: /* rrcurveto */
+
+
+ case op_rmoveto: /*************************************************/
+ {
+ FT_TRACE4(( " rmoveto" ));
+ x += top[0];
+ y += top[1];
+ break;
+ }
+
+ case op_rrcurveto: /***********************************************/
{
+ FT_TRACE4(( " rcurveto" ));
if ( start_point( builder, x, y ) ||
check_points( builder, 3 ) ) goto Memory_Error;
- USE_ARGS(6);
x += top[0];
y += top[1];
add_point( builder, x, y, 0 );
@@ -573,22 +952,64 @@
x += top[4];
y += top[5];
add_point( builder, x, y, 1 );
- goto Clear_Stack;
+ break;
}
-
- case 9: /* closepath */
+
+
+ case op_vhcurveto: /**********************************************/
{
- close_contour( builder );
- builder->path_begun = 0;
+ FT_TRACE4(( " vhcurveto" ));
+ if ( start_point( builder, x, y ) ||
+ check_points( builder, 3 ) ) goto Memory_Error;
+
+ y += top[0];
+ add_point( builder, x, y, 0 );
+ x += top[1];
+ y += top[2];
+ add_point( builder, x, y, 0 );
+ x += top[3];
+ add_point( builder, x, y, 1 );
+ break;
}
- break;
-
- case 10: /* callsubr */
+
+
+ case op_vlineto: /************************************************/
+ {
+ FT_TRACE4(( " vlineto" ));
+ if ( start_point( builder, x, y ) ) goto Memory_Error;
+
+ y += top[0];
+ goto Add_Line;
+ }
+
+
+ case op_vmoveto: /************************************************/
+ {
+ FT_TRACE4(( " vmoveto" ));
+ y += top[0];
+ break;
+ }
+
+
+ case op_div: /****************************************************/
+ {
+ FT_TRACE4(( " div" ));
+ if (top[1])
+ *top++ = top[0] / top[1];
+ else
+ {
+ FT_ERROR(( "T1.Parse_CharStrings : division by 0\n" ));
+ goto Syntax_Error;
+ }
+ break;
+ }
+
+
+ case op_callsubr: /***********************************************/
{
T1_Int index;
- USE_ARGS(1);
-
+ FT_TRACE4(( " callsubr" ));
index = top[0];
if ( index < 0 || index >= num_subrs )
{
@@ -618,13 +1039,21 @@
decoder->zone = zone;
ip = zone->base;
limit = zone->limit;
-
- /* do not clear stack */
+ break;
}
- break;
-
- case 11: /* return */
+
+
+ case op_pop: /****************************************************/
{
+ FT_TRACE4(( " pop" ));
+ FT_ERROR(( "T1.Parse_CharStrings : unexpected POP\n" ));
+ goto Syntax_Error;
+ }
+
+
+ case op_return: /************************************************/
+ {
+ FT_TRACE4(( " return" ));
if ( zone <= decoder->zones )
{
FT_ERROR(( "T1.Parse_CharStrings : unexpected return\n" ));
@@ -635,306 +1064,58 @@
ip = zone->cursor;
limit = zone->limit;
decoder->zone = zone;
- }
- break;
-
- case 13: /* hsbw */
- {
- USE_ARGS(2);
- builder->left_bearing.x += top[0];
- builder->advance.x = top[1];
- builder->advance.y = 0;
-
- builder->last.x = x = top[0];
- builder->last.y = y = 0;
-
- /* the "metrics_only" indicates that we only want to compute */
- /* the glyph's metrics (lsb + advance width), not load the */
- /* rest of it.. so exit immediately */
- if (builder->metrics_only)
- return T1_Err_Ok;
-
- goto Clear_Stack;
+ break;
}
- case 14: /* endchar */
+ case op_dotsection: /*********************************************/
{
- close_contour( builder );
-
- /* add current outline to the glyph slot */
- builder->base.n_points += builder->current.n_points;
- builder->base.n_contours += builder->current.n_contours;
-
- /* return now !! */
- return T1_Err_Ok;
+ FT_TRACE4(( " dotsection" ));
+ break;
}
-
- case 21: /* rmoveto */
+
+ case op_hstem: /**************************************************/
{
- USE_ARGS(2);
- x += top[0];
- y += top[1];
- goto Clear_Stack;
+ FT_TRACE4(( " hstem" ));
+ break;
}
-
- case 22: /* hmoveto */
+
+ case op_hstem3: /*************************************************/
{
- USE_ARGS(1);
- x += top[0];
- goto Clear_Stack;
+ FT_TRACE4(( " hstem3" ));
+ break;
}
-
- case 30: /* vhcurveto */
+
+ case op_vstem: /**************************************************/
{
- if ( start_point( builder, x, y ) ||
- check_points( builder, 3 ) ) goto Memory_Error;
-
- USE_ARGS(4);
- y += top[0];
- add_point( builder, x, y, 0 );
- x += top[1];
- y += top[2];
- add_point( builder, x, y, 0 );
- x += top[3];
- add_point( builder, x, y, 1 );
- goto Clear_Stack;
+ FT_TRACE4(( " vstem" ));
+ break;
}
-
- case 31: /* hvcurveto */
+
+ case op_vstem3: /*************************************************/
{
- if ( start_point( builder, x, y ) ||
- check_points( builder, 3 ) ) goto Memory_Error;
-
- USE_ARGS(4);
- x += top[0];
- add_point( builder, x, y, 0 );
- x += top[1];
- y += top[2];
- add_point( builder, x, y, 0 );
- y += top[3];
- add_point( builder, x, y, 1 );
- goto Clear_Stack;
+ FT_TRACE4(( " vstem3" ));
+ break;
}
-
- case 12:
+ case op_setcurrentpoint: /*****************************************/
{
- if (ip > limit)
- {
- FT_ERROR(( "T1.Parse_CharStrings : invalid escape (12+EOF)\n" ));
- goto Syntax_Error;
- }
-
- switch (*ip++)
- {
- case 0: /* dotsection */
- case 1: /* vstem3 */
- case 2: /* hstem3 */
- goto Clear_Stack;
-
- case 6: /* seac */
- {
- USE_ARGS(5);
-
- /* return immediately to implement an accented character */
- return t1operator_seac( decoder,
- top[0], top[1], top[3],
- top[4], top[5] );
- }
-
- case 7: /* sbw */
- {
- USE_ARGS(4);
- builder->left_bearing.x += top[0];
- builder->left_bearing.y += top[1];
- builder->advance.x = top[2];
- builder->advance.y = top[3];
-
- builder->last.x = x = top[0];
- builder->last.y = y = top[1];
-
- /* the "metrics_only" indicates that we only want to compute */
- /* the glyph's metrics (lsb + advance width), not load the */
- /* rest of it.. so exit immediately */
- if (builder->metrics_only)
- return T1_Err_Ok;
-
- goto Clear_Stack;
- }
-
- case 12: /* div */
- {
- USE_ARGS(2);
- top[0] /= top[1];
- top++;
- }
- break;
-
- case 16: /* callothersubr */
- {
- USE_ARGS(1);
- switch (top[0])
- {
- case 1: /* start flex feature ---------------------- */
- {
- decoder->flex_state = 1;
- decoder->num_flex_vectors = 0;
- if ( start_point(builder, x, y) ||
- check_points(builder,6) ) goto Memory_Error;
- }
- break;
-
- case 2: /* add flex vectors ------------------------ */
- {
- T1_Int index;
-
- /* note that we should not add a point for index 0 */
- /* this will move our current position to the flex */
- /* point without adding any point to the outline */
- index = decoder->num_flex_vectors++;
- if (index > 0 && index < 7)
- add_point( builder,
- x,
- y,
- (T1_Byte)( index==3 || index==6 ) );
- }
- break;
-
- case 0: /* end flex feature ------------------------- */
- {
- USE_ARGS(3); /* ignore parameters */
-
- if ( decoder->flex_state == 0 ||
- decoder->num_flex_vectors != 7 )
- {
- FT_ERROR(( "T1.Parse_CharStrings: unexpected flex end\n" ));
- goto Syntax_Error;
- }
-
- /* now consume the remaining "pop pop setcurpoint" */
- if ( ip+6 > limit ||
- ip[0] != 12 || ip[1] != 17 || /* pop */
- ip[2] != 12 || ip[3] != 17 || /* pop */
- ip[4] != 12 || ip[5] != 33 ) /* setcurpoint */
- {
- FT_ERROR(( "T1.Parse_CharStrings: invalid flex charstring\n" ));
- goto Syntax_Error;
- }
-
- ip += 6;
- decoder->flex_state = 0;
- decoder->top = top;
-
- goto Clear_Stack;
- }
-
- case 3: /* change hints ---------------------------- */
- {
- /* eat the following "pop" */
- if (ip+2 > limit)
- {
- FT_ERROR(( "T1.Parse_CharStrings: invalid escape (12+%d)\n",
- ip[-1] ));
- goto Syntax_Error;
- }
-
- if (ip[0] != 12 || ip[1] != 17)
- {
- FT_ERROR(( "T1.Parse_CharStrings: 'pop' expected, found (%d %d)\n",
- ip[0], ip[1] ));
- goto Syntax_Error;
- }
- ip += 2;
- goto Clear_Stack;
- }
-
- default:
- FT_ERROR(( "T1.Parse_CharStrings: invalid othersubr %d !!\n",
- top[0] ));
- goto Syntax_Error;
- }
- }
-
- case 17: /* pop - should not happen !! */
- {
- FT_ERROR(( "T1.Parse_CharStrings : 'pop' should not happen !!\n" ));
- goto Syntax_Error;
- }
-
- case 33: /* setcurrentpoint */
- {
- FT_ERROR(( "T1.Parse_CharStrings : 'setcurrentpoint' should not happen !!\n" ));
- goto Syntax_Error;
- }
-
- default:
- FT_ERROR(( "T1.Parse_CharStrings : invalid escape (12+%d)\n",
- ip[-1] ));
- goto Syntax_Error;
- }
+ FT_TRACE4(( " setcurrentpoint" ));
+ FT_ERROR(( "T1.Parse_CharStrings : unexpected SETCURRENTPOINT\n" ));
+ goto Syntax_Error;
}
- break; /* escape - 12 */
- case 255: /* four bytes integer */
- {
- if (ip+4 > limit)
- {
- FT_ERROR(( "T1.Parse_CharStrings : unexpected EOF in integer\n" ));
- goto Syntax_Error;
- }
+ default:
+ FT_ERROR(( "T1.Parse_CharStrings : unhandled opcode %d\n", op ));
+ goto Syntax_Error;
+ }
- *top++ = ((long)ip[0] << 24) |
- ((long)ip[1] << 16) |
- ((long)ip[2] << 8) |
- ip[3];
- ip += 4;
- }
- break;
+ decoder->top = top;
+
+ } /* general operator processing */
- default:
- {
- T1_Long v, v2;
-
- v = ip[-1];
- if (v < 32)
- {
- FT_ERROR(( "T1.Parse_CharStrings : invalid byte (%d)\n",
- ip[-1] ));
- goto Syntax_Error;
- }
-
- /* compute value ---- */
- /* */
- if (v < 247) /* 1-byte value */
- v -= 139;
- else
- {
- if (++ip > limit) /* 2-bytes value, check limits */
- {
- FT_ERROR(( "T1.Parse_CharStrings : unexpected EOF in integer\n" ));
- goto Syntax_Error;
- }
-
- v2 = ip[-1] + 108;
- if (v < 251)
- v = ((v-247) << 8) + v2;
- else
- v = -(((v-251) << 8) + v2);
- }
-
- /* store value - is there enough room ?*/
- if ( top >= decoder->stack + T1_MAX_CHARSTRINGS_OPERANDS )
- {
- FT_ERROR(( "T1.Parse_CharStrings : Stack overflow !!\n" ));
- goto Syntax_Error;
- }
-
- *top++ = v;
- decoder->top = top;
- }
- } /* big switch */
} /* while ip < limit */
+ FT_TRACE4(( "..end..\n\n" ));
return error;
Syntax_Error:
diff --git a/src/type1z/t1load.c b/src/type1z/t1load.c
index 2bf4ec4..9795031 100644
--- a/src/type1z/t1load.c
+++ b/src/type1z/t1load.c
@@ -63,10 +63,8 @@
#include <t1types.h>
#include <t1errors.h>
-#include <t1encode.h>
#include <t1config.h>
#include <t1load.h>
-
#include <stdio.h>
#undef FT_COMPONENT
@@ -345,8 +343,12 @@
{
if ( cur[1] == 'e' &&
cur[2] == 'f' &&
+ is_space(cur[-1]) &&
is_space(cur[3]) )
- break;
+ {
+ FT_TRACE6(( "encoding end\n" ));
+ break;
+ }
}
/* otherwise, we must find a number before anything else */
@@ -382,6 +384,7 @@
}
face->type1.encoding_type = t1_encoding_array;
+ parser->cursor = cur;
}
/* Otherwise, we should have either "StandardEncoding" or */
/* "ExpertEncoding" */
@@ -433,6 +436,10 @@
index = T1_ToInt(parser);
if (!read_binary_data(parser,&size,&base)) return;
+ T1_Decrypt( base, size, 4330 );
+ size -= face->type1.lenIV;
+ base += face->type1.lenIV;
+
error = T1_Add_Table( table, index, base, size );
if (error) goto Fail;
}
@@ -481,13 +488,19 @@
cur = parser->cursor;
if (cur >= limit) break;
- /* we stop when we find a "def" */
+ /* we stop when we find a "def" or "end" keyword */
if (*cur == 'd' &&
cur+3 < limit &&
cur[1] == 'e' &&
cur[2] == 'f' )
break;
+ if (*cur == 'e' &&
+ cur+3 < limit &&
+ cur[1] == 'n' &&
+ cur[2] == 'd' )
+ break;
+
if (*cur != '/')
skip_blackspace(parser);
else
@@ -497,6 +510,7 @@
while (cur2 < limit && is_alpha(*cur2)) cur2++;
len = cur2-cur-1;
+
error = T1_Add_Table( name_table, n, cur+1, len+1 );
if (error) goto Fail;
@@ -505,7 +519,11 @@
parser->cursor = cur2;
if (!read_binary_data(parser,&size,&base)) return;
-
+
+ T1_Decrypt( base, size, 4330 );
+ size -= face->type1.lenIV;
+ base += face->type1.lenIV;
+
error = T1_Add_Table( code_table, n, base, size );
if (error) goto Fail;
@@ -514,6 +532,7 @@
break;
}
}
+ loader->num_glyphs = n;
return;
Fail:
@@ -562,7 +581,7 @@
T1_Error parse_dict( T1_Face face,
T1_Loader* loader,
T1_Byte* base,
- T1_Int size )
+ T1_Long size )
{
T1_Parser* parser = &loader->parser;
@@ -571,8 +590,8 @@
parser->error = 0;
{
- T1_Byte* cur = base;
- T1_Byte* limit = cur + size;
+ T1_Byte* cur = base;
+ T1_Byte* limit = cur + size;
for ( ;cur < limit; cur++ )
{
@@ -587,7 +606,7 @@
while (cur2 < limit && is_alpha(*cur2)) cur2++;
len = cur2-cur;
- if (len > 0)
+ if (len > 0 && len < 20)
{
/* now, compare the immediate name to the keyword table */
T1_KeyWord* keyword = (T1_KeyWord*)t1_keywords;
@@ -617,6 +636,7 @@
return parser->error;
cur = parser->cursor;
+ break;
}
}
keyword++;
@@ -631,9 +651,11 @@
static
void t1_init_loader( T1_Loader* loader, T1_Face face )
{
+ MEM_Set( loader, 0, sizeof(*loader) );
loader->num_glyphs = 0;
loader->num_chars = 0;
-
+
+ /* initialize the tables - simply set their 'init' field to 0 */
loader->encoding_table.init = 0;
loader->charstrings.init = 0;
loader->glyph_names.init = 0;
@@ -685,6 +707,18 @@
/* to the Type1 data */
type1->num_glyphs = loader.num_glyphs;
+ if ( !loader.subrs.init )
+ {
+ FT_ERROR(( "T1.Open_Face: no subrs array in face !!\n" ));
+ error = FT_Err_Invalid_File_Format;
+ }
+
+ if ( !loader.charstrings.init )
+ {
+ FT_ERROR(( "T1.Open_Face: no charstrings array in face !!\n" ));
+ error = FT_Err_Invalid_File_Format;
+ }
+
loader.subrs.init = 0;
type1->num_subrs = loader.num_subrs;
type1->subrs_block = loader.subrs.block;
diff --git a/src/type1z/t1objs.c b/src/type1z/t1objs.c
index f00e4ca..82b4108 100644
--- a/src/type1z/t1objs.c
+++ b/src/type1z/t1objs.c
@@ -20,6 +20,7 @@
#include <t1gload.h>
#include <t1load.h>
+#include <psnames.h>
/* Required by tracing mode */
#undef FT_COMPONENT
@@ -164,12 +165,25 @@
T1_Face face )
{
T1_Error error;
+ PSNames_Interface* psnames;
(void)face_index;
(void)face;
face->root.num_faces = 1;
+ psnames = (PSNames_Interface*)face->psnames;
+ if (!psnames)
+ {
+ /* look-up the PSNames driver */
+ FT_Driver psnames_driver;
+
+ psnames_driver = FT_Get_Driver( face->root.driver->library, "psnames" );
+ if (psnames_driver)
+ face->psnames = (PSNames_Interface*)
+ (psnames_driver->interface.format_interface);
+ }
+
/* open the tokenizer, this will also check the font format */
error = T1_Open_Face( face );
if (error) goto Exit;
diff --git a/src/type1z/t1parse.c b/src/type1z/t1parse.c
index a326d3c..ea86214 100644
--- a/src/type1z/t1parse.c
+++ b/src/type1z/t1parse.c
@@ -367,9 +367,18 @@
cur++;
/* now, read the coordinates */
- for ( ; cur < limit; cur++ )
+ for ( ; cur < limit; )
{
- c = *cur;
+ /* skip whitespace in front of data */
+ for (;;)
+ {
+ c = *cur;
+ if ( c != ' ' && c != '\t' ) break;
+
+ cur++;
+ if (cur >= limit) goto Exit;
+ }
+
if (count >= max_coords || c == ender)
break;
@@ -414,9 +423,18 @@
cur++;
/* now, read the values */
- for ( ; cur < limit; cur++ )
+ for ( ; cur < limit; )
{
- c = *cur;
+ /* skip whitespace in front of data */
+ for (;;)
+ {
+ c = *cur;
+ if ( c != ' ' && c != '\t' ) break;
+
+ cur++;
+ if (cur >= limit) goto Exit;
+ }
+
if (count >= max_values || c == ender)
break;
@@ -442,10 +460,19 @@
T1_String* result;
FT_Error error;
- /* first of all, skip everything until we encounter a string */
- while ( cur < limit && *cur != '(' ) cur++;
- cur++;
- if (cur >= limit) return 0;
+ /* XXX : some stupid fonts have a "Notice" or "Copyright" string */
+ /* that simply doesn't begin with an opening parenthesis, even */
+ /* though they have a closing one !!! E.g. "amuncial.pfb" */
+ /* */
+ /* We must deal with these ill-fated cases there. Note that */
+ /* these fonts didn't work with the old Type 1 driver as the */
+ /* notice/copyright was not recognized as a valid string token */
+ /* and made the old token parser commit errors.. */
+
+ while ( cur < limit && (*cur == ' ' || *cur == '\t')) cur++;
+ if (cur+1 >= limit) return 0;
+
+ if (*cur == '(') cur++; /* skip the opening parenthesis, if there is one */
*cursor = cur;
count = 0;
@@ -470,7 +497,7 @@
/* now copy the string */
MEM_Copy( result, *cursor, len );
result[len] = '\0';
-
+ *cursor = cur;
return result;
}
@@ -632,43 +659,44 @@
else
parser->in_pfb = 1;
- /* now, try to load the "size" bytes of the "base" dictionary we */
- /* found previously */
-
- /* if it's a memory-based resource, set up pointers */
- if ( !stream->read )
- {
- parser->base_dict = (T1_Byte*)stream->base + stream->pos;
- parser->base_len = size;
- parser->in_memory = 1;
-
- /* check that the "size" field is valid */
- if ( FILE_Skip(size) ) goto Exit;
- }
- else
- {
- /* read segment in memory */
- if ( ALLOC( parser->base_dict, size ) ||
- FILE_Read( parser->base_dict, size ) )
- goto Exit;
- }
-
- /* Now check font format, we must see a '%!PS-AdobeFont-1' */
- /* or a '%!FontType' */
- {
- if ( size <= 16 ||
- ( strncmp( (const char*)parser->base_dict, "%!PS-AdobeFont-1", 16 ) &&
- strncmp( (const char*)parser->base_dict, "%!FontType", 10 ) ) )
- {
- FT_TRACE2(( "Not a Type1 font\n" ));
- error = T1_Err_Invalid_File_Format;
- }
- else
- {
- parser->cursor = parser->base_dict;
- parser->limit = parser->cursor + parser->base_len;
- }
- }
+ /* now, try to load the "size" bytes of the "base" dictionary we */
+ /* found previously */
+
+ /* if it's a memory-based resource, set up pointers */
+ if ( !stream->read )
+ {
+ parser->base_dict = (T1_Byte*)stream->base + stream->pos;
+ parser->base_len = size;
+ parser->in_memory = 1;
+
+ /* check that the "size" field is valid */
+ if ( FILE_Skip(size) ) goto Exit;
+ }
+ else
+ {
+ /* read segment in memory */
+ if ( ALLOC( parser->base_dict, size ) ||
+ FILE_Read( parser->base_dict, size ) )
+ goto Exit;
+ parser->base_len = size;
+ }
+
+ /* Now check font format, we must see a '%!PS-AdobeFont-1' */
+ /* or a '%!FontType' */
+ {
+ if ( size <= 16 ||
+ ( strncmp( (const char*)parser->base_dict, "%!PS-AdobeFont-1", 16 ) &&
+ strncmp( (const char*)parser->base_dict, "%!FontType", 10 ) ) )
+ {
+ FT_TRACE2(( "Not a Type1 font\n" ));
+ error = T1_Err_Invalid_File_Format;
+ }
+ else
+ {
+ parser->cursor = parser->base_dict;
+ parser->limit = parser->cursor + parser->base_len;
+ }
+ }
Exit:
if (error && !parser->in_memory)
diff --git a/src/type1z/type1z.c b/src/type1z/type1z.c
index 5000a8a..422f200 100644
--- a/src/type1z/type1z.c
+++ b/src/type1z/type1z.c
@@ -34,5 +34,8 @@
#include <t1objs.c>
#include <t1driver.c>
#include <t1gload.c>
-#include <t1encode.c>
+
+#ifndef T1_CONFIG_OPTION_NO_AFM
+#include <t1afm.c>
+#endif