new version of the CFF driver, this one works :-)
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 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297
diff --git a/include/freetype/internal/t2types.h b/include/freetype/internal/t2types.h
index f031a0b..fa6119d 100644
--- a/include/freetype/internal/t2types.h
+++ b/include/freetype/internal/t2types.h
@@ -167,6 +167,11 @@
CFF_Top_Dict top_dict;
CFF_Private private_dict;
+ FT_UInt num_global_subrs;
+ FT_UInt num_local_subrs;
+ FT_Byte** global_subrs;
+ FT_Byte** local_subrs;
+
} CFF_Font;
#ifdef __cplusplus
diff --git a/src/cff/cff.c b/src/cff/cff.c
index b2581e9..5e0e7f0 100644
--- a/src/cff/cff.c
+++ b/src/cff/cff.c
@@ -45,5 +45,6 @@
#include <t2parse.c> /* token parser */
#include <t2load.c> /* tables loader */
#include <t2objs.c> /* object management */
+#include <t2gload.c> /* glyph loader */
/* END */
diff --git a/src/cff/t2driver.c b/src/cff/t2driver.c
index cac43ca..f50582b 100644
--- a/src/cff/t2driver.c
+++ b/src/cff/t2driver.c
@@ -288,19 +288,15 @@
if ( size )
{
/* these two object must have the same parent */
- if ( size->face != slot->face )
+ if ( size->face != slot->root.face )
return FT_Err_Invalid_Face_Handle;
}
/* now load the glyph outline if necessary */
-#if 1 /* XXXX: TODO */
- error = FT_Err_Unimplemented_Feature;
-#else
- error = T2_Load_Glyph( size, slot, glyph_index, load_flags );
-#endif
+ error = T2_Load_Glyph( slot, size, glyph_index, load_flags );
+
/* force drop-out mode to 2 - irrelevant now */
/* slot->outline.dropout_mode = 2; */
-
return error;
}
@@ -382,7 +378,7 @@
sizeof ( T2_DriverRec ),
sizeof ( TT_FaceRec ),
sizeof ( FT_SizeRec ),
- sizeof ( FT_GlyphSlotRec ),
+ sizeof ( T2_GlyphSlotRec ),
"cff", /* driver name */
100, /* driver version == 1.0 */
diff --git a/src/cff/t2gload.c b/src/cff/t2gload.c
index a5caa75..d4d8413 100644
--- a/src/cff/t2gload.c
+++ b/src/cff/t2gload.c
@@ -22,1156 +22,1562 @@
#include <freetype/internal/sfnt.h>
#include <freetype/tttags.h>
+#undef FT_COMPONENT
+#define FT_COMPONENT trace_t1gload
#include <t2gload.h>
+ typedef enum T2_Operator_
+ {
+ t2_op_unknown = 0,
+ t2_op_rmoveto,
+ t2_op_hmoveto,
+ t2_op_vmoveto,
+ t2_op_rlineto,
+ t2_op_hlineto,
+ t2_op_vlineto,
+ t2_op_rrcurveto,
+ t2_op_hhcurveto,
+ t2_op_hvcurveto,
+ t2_op_rcurveline,
+ t2_op_rlinecurve,
+ t2_op_vhcurveto,
+ t2_op_vvcurveto,
+ t2_op_flex,
+ t2_op_hflex,
+ t2_op_hflex1,
+ t2_op_flex1,
+ t2_op_endchar,
+ t2_op_hstem,
+ t2_op_vstem,
+ t2_op_hstemhm,
+ t2_op_vstemhm,
+ t2_op_hintmask,
+ t2_op_cntrmask,
+ t2_op_abs,
+ t2_op_add,
+ t2_op_sub,
+ t2_op_div,
+ t2_op_neg,
+ t2_op_random,
+ t2_op_mul,
+ t2_op_sqrt,
+ t2_op_blend,
+ t2_op_drop,
+ t2_op_exch,
+ t2_op_index,
+ t2_op_roll,
+ t2_op_dup,
+ t2_op_put,
+ t2_op_get,
+ t2_op_store,
+ t2_op_load,
+ t2_op_and,
+ t2_op_or,
+ t2_op_not,
+ t2_op_eq,
+ t2_op_ifelse,
+ t2_op_callsubr,
+ t2_op_callgsubr,
+ t2_op_return,
+ /* do not remove */
+ t2_op_max
+
+ } T2_Operator;
+
+ #define T2_COUNT_CHECK_WIDTH 0x80
+ #define T2_COUNT_EXACT 0x40
+ #define T2_COUNT_CLEAR_STACK 0x20
+
+ static const FT_Byte t2_argument_counts[] =
+ {
+ 0, /* unknown */
+
+ 2 | T2_COUNT_CHECK_WIDTH | T2_COUNT_EXACT, /* rmoveto */
+ 1 | T2_COUNT_CHECK_WIDTH | T2_COUNT_EXACT,
+ 1 | T2_COUNT_CHECK_WIDTH | T2_COUNT_EXACT,
+
+ 0 | T2_COUNT_CLEAR_STACK, /* rlineto */
+ 0 | T2_COUNT_CLEAR_STACK,
+ 0 | T2_COUNT_CLEAR_STACK,
+
+ 0 | T2_COUNT_CLEAR_STACK, /* rrcurveto */
+ 0 | T2_COUNT_CLEAR_STACK,
+ 0 | T2_COUNT_CLEAR_STACK,
+ 0 | T2_COUNT_CLEAR_STACK,
+ 0 | T2_COUNT_CLEAR_STACK,
+ 0 | T2_COUNT_CLEAR_STACK,
+ 0 | T2_COUNT_CLEAR_STACK,
+
+ 13, /* flex */
+ 7,
+ 9,
+ 11,
+
+ 0, /* enchar */
+
+ 2 | T2_COUNT_CHECK_WIDTH, /* hstem */
+ 2 | T2_COUNT_CHECK_WIDTH,
+ 2 | T2_COUNT_CHECK_WIDTH,
+ 2 | T2_COUNT_CHECK_WIDTH,
+
+ 0, /* hintmask */
+ 0, /* cntrmask */
+
+ 1, /* abs */
+ 2,
+ 2,
+ 2,
+ 1,
+ 0,
+ 2,
+ 1,
+
+ 1, /* blend */
+
+ 1, /* drop */
+ 2,
+ 1,
+ 2,
+ 1,
+
+ 2, /* put */
+ 1,
+ 4,
+ 3,
+
+ 2, /* and */
+ 2,
+ 1,
+ 2,
+ 4,
+
+ 1, /* callsubr */
+ 1,
+ 0
+ };
+
/* required for the tracing mode */
#undef FT_COMPONENT
#define FT_COMPONENT trace_ttgload
- /*************************************************************************/
- /* */
- /* Composite font flags. */
- /* */
-#define ARGS_ARE_WORDS 0x001
-#define ARGS_ARE_XY_VALUES 0x002
-#define ROUND_XY_TO_GRID 0x004
-#define WE_HAVE_A_SCALE 0x008
-/* reserved 0x010 */
-#define MORE_COMPONENTS 0x020
-#define WE_HAVE_AN_XY_SCALE 0x040
-#define WE_HAVE_A_2X2 0x080
-#define WE_HAVE_INSTR 0x100
-#define USE_MY_METRICS 0x200
-
-
-
- /*************************************************************************/
- /* Returns the horizontal or vertical metrics in font units for a */
- /* given glyph. The metrics are the left side bearing (resp. top */
- /* side bearing) and advance width (resp. advance height). */
- /* */
- LOCAL_FUNC
- void T2_Get_Metrics( TT_HoriHeader* header,
- FT_UInt index,
- FT_Short* bearing,
- FT_UShort* advance )
+ /**********************************************************************/
+ /**********************************************************************/
+ /**********************************************************************/
+ /********** *********/
+ /********** *********/
+ /********** GENERIC CHARSTRINGS PARSING *********/
+ /********** *********/
+ /********** *********/
+ /**********************************************************************/
+ /**********************************************************************/
+ /**********************************************************************/
+
+/*********************************************************************
+ *
+ * <Function>
+ * T2_Init_Builder
+ *
+ * <Description>
+ * Initialise a given glyph builder.
+ *
+ * <Input>
+ * builder :: glyph builder to initialise
+ * face :: current face object
+ * size :: current size object
+ * glyph :: current glyph object
+ *
+ *********************************************************************/
+
+ static
+ void T2_Init_Builder( T2_Builder* builder,
+ TT_Face face,
+ T2_Size size,
+ T2_GlyphSlot glyph )
{
- TT_LongMetrics* longs_m;
- TT_UShort k = header->number_Of_HMetrics;
+ builder->path_begun = 0;
+ builder->load_points = 1;
+ builder->face = face;
+ builder->glyph = glyph;
+ builder->memory = face->root.memory;
- if ( index < k )
+ if (glyph)
{
- longs_m = (TT_LongMetrics*)header->long_metrics + index;
- *bearing = longs_m->bearing;
- *advance = longs_m->advance;
+ builder->base = glyph->root.outline;
+ builder->max_points = glyph->max_points;
+ builder->max_contours = glyph->max_contours;
}
- else
+
+ if (size)
{
- *bearing = ((TT_ShortMetrics*)header->short_metrics)[index - k];
- *advance = ((TT_LongMetrics*)header->long_metrics)[k - 1].advance;
+ builder->scale_x = size->metrics.x_scale;
+ builder->scale_y = size->metrics.y_scale;
}
- }
+ builder->pos_x = 0;
+ builder->pos_y = 0;
- /*************************************************************************/
- /* Returns the horizontal metrics in font units for a given glyph. */
- /* If `check' is true, take care of monospaced fonts by returning the */
- /* advance width maximum. */
- /* */
- static
- void Get_HMetrics( T2_Face face,
- FT_UInt index,
- FT_Bool check,
- FT_Short* lsb,
- FT_UShort* aw )
- {
- T2_Get_Metrics( &face->horizontal, index, lsb, aw );
+ builder->left_bearing.x = 0;
+ builder->left_bearing.y = 0;
+ builder->advance.x = 0;
+ builder->advance.y = 0;
- if ( check && face->postscript.isFixedPitch )
- *aw = face->horizontal.advance_Width_Max;
+ builder->base.n_points = 0;
+ builder->base.n_contours = 0;
+ builder->current = builder->base;
}
- /*************************************************************************/
- /* Returns the advance width table for a given pixel size if it is */
- /* found in the font's `hdmx' table (if any). */
- /* */
+/*********************************************************************
+ *
+ * <Function>
+ * T2_Done_Builder
+ *
+ * <Description>
+ * Finalise a given glyph builder. Its content can still be
+ * used after the call, but the function saves important information
+ * within the corresponding glyph slot.
+ *
+ * <Input>
+ * builder :: glyph builder to initialise
+ *
+ *********************************************************************/
+
static
- FT_Byte* Get_Advance_Widths( T2_Face face,
- FT_UShort ppem )
+ void T2_Done_Builder( T2_Builder* builder )
{
- FT_UShort n;
-
- for ( n = 0; n < face->hdmx.num_records; n++ )
- if ( face->hdmx.records[n].ppem == ppem )
- return face->hdmx.records[n].widths;
+ T2_GlyphSlot glyph = builder->glyph;
- return NULL;
+ if (glyph)
+ {
+ glyph->root.outline = builder->base;
+ glyph->max_points = builder->max_points;
+ glyph->max_contours = builder->max_contours;
+ }
}
-#define cur_to_org( n, zone ) \
- MEM_Copy( (zone)->org, (zone)->cur, n * sizeof ( TT_Vector ) )
-
-#define org_to_cur( n, zone ) \
- MEM_Copy( (zone)->cur, (zone)->org, n * sizeof ( TT_Vector ) )
+/*********************************************************************
+ *
+ * <Function>
+ * T2_Init_Decoder
+ *
+ * <Description>
+ * Initialise a given Type 2 decoder for parsing
+ *
+ * <Input>
+ * decoder :: Type 1 decoder to initialise
+ * funcs :: hinter functions interface
+ *
+ *********************************************************************/
- /*************************************************************************/
- /* Translates an array of coordinates. */
- /* */
- static
- void translate_array( FT_UInt n,
- FT_Vector* coords,
- FT_Pos delta_x,
- FT_Pos delta_y )
+ static FT_Int t2_compute_bias( FT_UInt num_subrs )
{
- FT_UInt k;
-
- if ( delta_x )
- for ( k = 0; k < n; k++ )
- coords[k].x += delta_x;
-
- if ( delta_y )
- for ( k = 0; k < n; k++ )
- coords[k].y += delta_y;
+ FT_Int result;
+
+ if (num_subrs < 1240)
+ result = 107;
+ else if (num_subrs < 33900)
+ result = 1131;
+ else
+ result = 32768;
+
+ return result;
}
-
- /*************************************************************************/
- /* Mounts one glyph zone on top of another. This is needed to */
- /* assemble composite glyphs. */
- /* */
- static
- void mount_zone( FT_GlyphZone* source,
- FT_GlyphZone* target )
+ LOCAL_FUNC
+ void T2_Init_Decoder( T2_Decoder* decoder,
+ TT_Face face,
+ T2_Size size,
+ T2_GlyphSlot slot )
{
- FT_UInt np;
- FT_Int nc;
-
- np = source->n_points;
- nc = source->n_contours;
-
- target->org = source->org + np;
- target->cur = source->cur + np;
- target->tags = source->tags + np;
-
- target->contours = source->contours + nc;
-
- target->n_points = 0;
- target->n_contours = 0;
+ CFF_Font* cff = (CFF_Font*)face->other;
+
+ /* clear everything */
+ MEM_Set( decoder, 0, sizeof(*decoder) );
+
+ /* initialise builder */
+ T2_Init_Builder( &decoder->builder, face, size, slot );
+
+ /* initialise Type2 decoder */
+ decoder->num_locals = cff->num_local_subrs;
+ decoder->num_globals = cff->num_global_subrs;
+ decoder->locals = cff->local_subrs;
+ decoder->globals = cff->global_subrs;
+ decoder->locals_bias = t2_compute_bias( decoder->num_locals );
+ decoder->globals_bias = t2_compute_bias( decoder->num_globals );
+
+ decoder->glyph_width = cff->private_dict.default_width;
+ decoder->nominal_width = cff->private_dict.nominal_width;
}
-#undef IS_HINTED
-#define IS_HINTED(flags) ((flags & FT_LOAD_NO_HINTING) == 0)
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* Load_Simple_Glyph */
- /* */
- /* <Description> */
- /* Loads a simple (i.e, non-composite) glyph. This function is used */
- /* for the `Load_Simple' state of TT_Load_Glyph(). All composite */
- /* glyphs elements will be loaded with routine. */
- /* */
+ /* check that there is enough room for "count" more points */
static
- FT_Error Load_Simple( T2_Loader* load,
- FT_UInt byte_count,
- FT_Int n_contours,
- FT_Bool debug )
+ FT_Error check_points( T2_Builder* builder,
+ FT_Int count )
{
- FT_Error error;
- FT_Stream stream = load->stream;
- FT_GlyphZone* zone = &load->zone;
- T2_Face face = load->face;
-
- FT_UShort n_ins;
- FT_Int n, n_points;
-
- /*********************************************************************/
- /* simple check */
-
- if ( n_contours > load->left_contours )
- {
- FT_TRACE0(( "ERROR: Glyph index %ld has %d contours > left %d\n",
- load->glyph_index,
- n_contours,
- load->left_contours ));
- return TT_Err_Too_Many_Contours;
- }
-
- /* preparing the execution context */
- mount_zone( &load->base, zone );
-
- /*********************************************************************/
- /* reading the contours endpoints */
-
- if ( ACCESS_Frame( byte_count ) )
- return error;
-
- for ( n = 0; n < n_contours; n++ )
- zone->contours[n] = GET_UShort();
-
- n_points = 0;
- if ( n_contours > 0 )
- n_points = zone->contours[n_contours - 1] + 1;
+ FT_Outline* base = &builder->base;
+ FT_Outline* outline = &builder->current;
+ if (!builder->load_points)
+ return FT_Err_Ok;
- /*********************************************************************/
- /* reading the bytecode instructions */
+ count += base->n_points + outline->n_points;
- n_ins = GET_UShort();
- load->face->root.glyph->control_len = n_ins;
-
- if ( n_points > load->left_points )
+ /* realloc points table if necessary */
+ if ( count >= builder->max_points )
{
- FT_TRACE0(( "ERROR: Too many points in glyph %ld\n", load->glyph_index ));
- error = TT_Err_Too_Many_Points;
- goto Fail;
- }
+ FT_Error error;
+ FT_Memory memory = builder->memory;
+ FT_Int increment = outline->points - base->points;
+ FT_Int current = builder->max_points;
- FT_TRACE4(( "Instructions size : %d\n", n_ins ));
+ while ( builder->max_points < count )
+ builder->max_points += 8;
- if ( n_ins > face->max_profile.maxSizeOfInstructions )
- {
- FT_TRACE0(( "ERROR: Too many instructions!\n" ));
- error = TT_Err_Too_Many_Ins;
- goto Fail;
- }
+ if ( REALLOC_ARRAY( base->points, current,
+ builder->max_points, FT_Vector ) ||
- if (stream->cursor + n_ins > stream->limit)
- {
- FT_TRACE0(( "ERROR: Instruction count mismatch!\n" ));
- error = TT_Err_Too_Many_Ins;
- goto Fail;
- }
-
- stream->cursor += n_ins;
-
- /*********************************************************************/
- /* reading the point tags */
-
- {
- FT_Byte* flag = load->zone.tags;
- FT_Byte* limit = flag + n_points;
- FT_Byte c, count;
-
- for (; flag < limit; flag++)
+ REALLOC_ARRAY( base->tags, current,
+ builder->max_points, FT_Byte ) )
{
- *flag = c = GET_Byte();
- if ( c & 8 )
- {
- for ( count = GET_Byte(); count > 0; count-- )
- *++flag = c;
- }
+ builder->error = error;
+ return error;
}
- }
-
- /*********************************************************************/
- /* reading the X coordinates */
- {
- FT_Vector* vec = zone->org;
- FT_Vector* limit = vec + n_points;
- FT_Byte* flag = zone->tags;
- FT_Pos x = 0;
-
- for ( ; vec < limit; vec++, flag++ )
- {
- FT_Pos y = 0;
-
- if ( *flag & 2 )
- {
- y = GET_Byte();
- if ((*flag & 16) == 0) y = -y;
- }
- else if ((*flag & 16) == 0)
- y = GET_Short();
-
- x += y;
- vec->x = x;
- }
+ outline->points = base->points + increment;
+ outline->tags = base->tags + increment;
}
+ return FT_Err_Ok;
+ }
- /*********************************************************************/
- /* reading the Y coordinates */
-
- {
- FT_Vector* vec = zone->org;
- FT_Vector* limit = vec + n_points;
- FT_Byte* flag = zone->tags;
- FT_Pos x = 0;
-
- for ( ; vec < limit; vec++, flag++ )
- {
- FT_Pos y = 0;
-
- if ( *flag & 4 )
- {
- y = GET_Byte();
- if ((*flag & 32) == 0) y = -y;
- }
- else if ((*flag & 32) == 0)
- y = GET_Short();
-
- x += y;
- vec->y = x;
- }
- }
-
- FORGET_Frame();
-
- /*********************************************************************/
- /* Add shadow points */
- /* Now add the two shadow points at n and n + 1. */
- /* We need the left side bearing and advance width. */
+ /* add a new point, do not check room */
+ static
+ void add_point( T2_Builder* builder,
+ FT_Pos x,
+ FT_Pos y,
+ FT_Byte flag )
+ {
+ FT_Outline* outline = &builder->current;
+ if (builder->load_points)
{
- FT_Vector* pp1;
- FT_Vector* pp2;
-
- /* pp1 = xMin - lsb */
- pp1 = zone->org + n_points;
- pp1->x = load->bbox.xMin - load->left_bearing;
- pp1->y = 0;
+ FT_Vector* point = outline->points + outline->n_points;
+ FT_Byte* control = (FT_Byte*)outline->tags + outline->n_points;
- /* pp2 = pp1 + aw */
- pp2 = pp1 + 1;
- pp2->x = pp1->x + load->advance;
- pp2->y = 0;
+ point->x = x >> 16;
+ point->y = y >> 16;
+ *control = ( flag ? FT_Curve_Tag_On : FT_Curve_Tag_Cubic );
- /* clear the touch tags */
- for ( n = 0; n < n_points; n++ )
- zone->tags[n] &= FT_Curve_Tag_On;
-
- zone->tags[n_points ] = 0;
- zone->tags[n_points + 1] = 0;
+ builder->last = *point;
}
- /* Note that we return two more points that are not */
- /* part of the glyph outline. */
-
- zone->n_points = n_points;
- zone->n_contours = n_contours;
- n_points += 2;
- /*******************************************/
- /* now eventually scale and hint the glyph */
-
- if (load->load_flags & FT_LOAD_NO_SCALE)
- {
- /* no scaling, just copy the orig arrays into the cur ones */
- org_to_cur( n_points, zone );
- }
- else
- {
- FT_Vector* vec = zone->org;
- FT_Vector* limit = vec + n_points;
- FT_Fixed x_scale = load->size->root.metrics.x_scale;
- FT_Fixed y_scale = load->size->root.metrics.y_scale;
-
- /* first scale the glyph points */
- for (; vec < limit; vec++)
- {
- vec->x = FT_MulFix( vec->x, x_scale );
- vec->y = FT_MulFix( vec->y, y_scale );
- }
-
- /* if hinting, round pp1, and shift the glyph accordingly */
- if ( !IS_HINTED(load->load_flags) )
- {
- org_to_cur( n_points, zone );
- }
- else
- {
- FT_Pos x = zone->org[n_points-2].x;
- x = ((x + 32) & -64) - x;
- translate_array( n_points, zone->org, x, 0 );
-
- org_to_cur( n_points, zone );
-
- zone->cur[n_points-1].x = (zone->cur[n_points-1].x + 32) & -64;
+ outline->n_points++;
+ }
- }
- }
- /* save glyph phantom points */
- if ( !load->preserve_pps )
- {
- load->pp1 = zone->cur[n_points - 2];
- load->pp2 = zone->cur[n_points - 1];
- }
+ /* check room for a new on-curve point, then add it */
+ static
+ FT_Error add_point1( T2_Builder* builder,
+ FT_Pos x,
+ FT_Pos y )
+ {
+ FT_Error error;
- return FT_Err_Ok;
+ error = check_points(builder,1);
+ if (!error)
+ add_point( builder, x, y, 1 );
- Fail:
- FORGET_Frame();
return error;
}
-
-
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* load_opentype_glyph */
- /* */
- /* <Description> */
- /* Loads a given truetype glyph. Handles composites and uses a */
- /* T2_Loader object.. */
- /* */
+ /* check room for a new contour, then add it */
static
- FT_Error load_opentype_glyph( T2_Loader* loader,
- FT_UInt glyph_index )
+ FT_Error add_contour( T2_Builder* builder )
{
- FT_Stream stream = loader->stream;
- FT_Error error;
- T2_Face face = loader->face;
- FT_ULong offset;
- FT_Int num_subglyphs = 0, contours_count;
- FT_UInt index, num_points, num_contours, count;
- FT_Fixed x_scale, y_scale;
- FT_ULong ins_offset;
-
- /* check glyph index */
- index = glyph_index;
- if ( index >= (TT_UInt)face->root.num_glyphs )
- {
- error = TT_Err_Invalid_Glyph_Index;
- goto Fail;
- }
+ FT_Outline* base = &builder->base;
+ FT_Outline* outline = &builder->current;
- loader->glyph_index = glyph_index;
- num_contours = 0;
- num_points = 0;
- ins_offset = 0;
-
- x_scale = 0x10000;
- y_scale = 0x10000;
- if ( (loader->load_flags & FT_LOAD_NO_SCALE)==0 )
+ if (!builder->load_points)
{
- x_scale = loader->size->root.metrics.x_scale;
- y_scale = loader->size->root.metrics.y_scale;
+ outline->n_contours++;
+ return FT_Err_Ok;
}
- /* get horizontal metrics */
- {
- FT_Short left_bearing;
- FT_UShort advance_width;
-
- Get_HMetrics( face, index,
- (FT_Bool)!(loader->load_flags &
- FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH),
- &left_bearing,
- &advance_width );
-
- loader->left_bearing = left_bearing;
- loader->advance = advance_width;
- }
-
- /* load glyph header */
- offset = face->glyph_locations[index];
- count = 0;
- if (index < (TT_UInt)face->num_locations-1)
- count = face->glyph_locations[index+1] - offset;
-
-
- if (count == 0)
+ /* realloc contours array if necessary */
+ if ( base->n_contours + outline->n_contours >= builder->max_contours &&
+ builder->load_points )
{
- /* as described by Frederic Loyer, these are spaces, and */
- /* not the unknown glyph. */
- loader->bbox.xMin = 0;
- loader->bbox.xMax = 0;
- loader->bbox.yMin = 0;
- loader->bbox.yMax = 0;
+ FT_Error error;
+ FT_Memory memory = builder->memory;
+ FT_Int increment = outline->contours - base->contours;
+ FT_Int current = builder->max_contours;
- loader->pp1.x = 0;
- loader->pp2.x = loader->advance;
+ builder->max_contours += 4;
- if ( (loader->load_flags & FT_LOAD_NO_SCALE)==0 )
- loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale );
+ if ( REALLOC_ARRAY( base->contours,
+ current, builder->max_contours, FT_Short ) )
+ {
+ builder->error = error;
+ return error;
+ }
- goto Load_End;
+ outline->contours = base->contours + increment;
}
- offset = loader->glyf_offset + offset;
-
- /* read first glyph header */
- if ( FILE_Seek( offset ) || ACCESS_Frame( 10L ) )
- goto Fail;
-
- contours_count = GET_Short();
+ if (outline->n_contours > 0)
+ outline->contours[ outline->n_contours-1 ] = outline->n_points-1;
- loader->bbox.xMin = GET_Short();
- loader->bbox.yMin = GET_Short();
- loader->bbox.xMax = GET_Short();
- loader->bbox.yMax = GET_Short();
-
- FORGET_Frame();
-
- FT_TRACE6(( "Glyph %ld\n", index ));
- FT_TRACE6(( " # of contours : %d\n", num_contours ));
- FT_TRACE6(( " xMin: %4d xMax: %4d\n", loader->bbox.xMin,
- loader->bbox.xMax ));
- FT_TRACE6(( " yMin: %4d yMax: %4d\n", loader->bbox.yMin,
- loader->bbox.yMax ));
- FT_TRACE6(( "-" ));
-
- count -= 10;
+ outline->n_contours++;
+ return FT_Err_Ok;
+ }
- if ( contours_count > loader->left_contours )
+ /* if a path was begun, add its first on-curve point */
+ static
+ FT_Error start_point( T2_Builder* builder,
+ FT_Pos x,
+ FT_Pos y )
+ {
+ /* test wether we're building a new contour */
+ if (!builder->path_begun)
{
- FT_TRACE0(( "ERROR: Too many contours for glyph %ld\n", index ));
- error = TT_Err_Too_Many_Contours;
- goto Fail;
- }
+ FT_Error error;
- loader->pp1.x = loader->bbox.xMin - loader->left_bearing;
- loader->pp1.y = 0;
- loader->pp2.x = loader->pp1.x + loader->advance;
- loader->pp2.y = 0;
-
- if ((loader->load_flags & FT_LOAD_NO_SCALE)==0)
- {
- loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale );
- loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale );
+ builder->path_begun = 1;
+ error = add_contour( builder );
+ if (error) return error;
}
+ return add_point1( builder, x, y );
+ }
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
-
- /**********************************************************************/
- /* if it is a simple glyph, load it */
- if (contours_count >= 0)
- {
- FT_UInt num_base_points;
-
- error = Load_Simple( loader, count, contours_count, 0 );
- if ( error ) goto Fail;
- /* Note: We could have put the simple loader source there */
- /* but the code is fat enough already :-) */
- num_points = loader->zone.n_points;
- num_contours = loader->zone.n_contours;
+ /* close the current contour */
+ static
+ void close_contour( T2_Builder* builder )
+ {
+ FT_Outline* outline = &builder->current;
- num_base_points = loader->base.n_points;
- {
- FT_UInt k;
- for ( k = 0; k < num_contours; k++ )
- loader->zone.contours[k] += num_base_points;
- }
+ if ( outline->n_contours > 0 )
+ outline->contours[outline->n_contours-1] = outline->n_points-1;
+ }
- loader->base.n_points += num_points;
- loader->base.n_contours += num_contours;
- loader->zone.n_points = 0;
- loader->zone.n_contours = 0;
+/*********************************************************************
+ *
+ * <Function>
+ * T2_Parse_CharStrings
+ *
+ * <Description>
+ * Parses a given Type 1 charstrings program
+ *
+ * <Input>
+ * decoder :: current Type 1 decoder
+ * charstring_base :: base of the charstring stream
+ * charstring_len :: length in bytes of the charstring stream
+ * num_subrs :: number of sub-routines
+ * subrs_base :: array of sub-routines addresses
+ * subrs_len :: array of sub-routines lengths
+ *
+ * <Return>
+ * Error code. 0 means success.
+ *
+ *********************************************************************/
+
+#define USE_ARGS(n) top -= n; if (top < decoder->stack) goto Stack_Underflow
- loader->left_points -= num_points;
- loader->left_contours -= num_contours;
- }
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /************************************************************************/
- else /* otherwise, load a composite !! */
+ LOCAL_FUNC
+ FT_Error T2_Parse_CharStrings( T2_Decoder* decoder,
+ FT_Byte* charstring_base,
+ FT_Int charstring_len )
+ {
+ FT_Error error;
+ T2_Decoder_Zone* zone;
+ FT_Byte* ip;
+ FT_Byte* limit;
+ T2_Builder* builder = &decoder->builder;
+ FT_Outline* outline;
+ FT_Pos x, y;
+ FT_Fixed seed;
+ FT_Fixed* stack;
+
+ /* set default width */
+ decoder->num_hints = 0;
+ decoder->read_width = 1;
+
+ /* compute random seed from stack address of parameter */
+ seed = (FT_Fixed)(char*)&seed ^
+ (FT_Fixed)(char*)&decoder ^
+ (FT_Fixed)(char*)&charstring_base;
+ seed = (seed ^ (seed >> 10) ^ (seed >> 20)) & 0xFFFF;
+ if (seed == 0)
+ seed = 0x7384;
+
+ /* First of all, initialise the decoder */
+ decoder->top = decoder->stack;
+ decoder->zone = decoder->zones;
+ zone = decoder->zones;
+ stack = decoder->top;
+
+ builder->path_begun = 0;
+
+ zone->base = charstring_base;
+ limit = zone->limit = charstring_base + charstring_len;
+ ip = zone->cursor = zone->base;
+
+ error = FT_Err_Ok;
+ outline = &builder->current;
+
+ x = builder->pos_x;
+ y = builder->pos_y;
+
+ /* now, execute loop */
+ while ( ip < limit )
{
- /* for each subglyph, read composite header */
- T2_GlyphSlot glyph = loader->glyph;
- FT_SubGlyph* subglyph = glyph->subglyphs + glyph->num_subglyphs;
+ T2_Operator op;
+ FT_Byte v;
+ FT_Byte count;
- if (ACCESS_Frame(count)) goto Fail;
-
- num_subglyphs = 0;
- do
+ /********************************************************************/
+ /* */
+ /* Decode operator or operand */
+ /* */
+ /* */
+ v = *ip++;
+ if (v >= 32 || v == 28)
{
- TT_Fixed xx, xy, yy, yx;
- FT_UInt total_subglyphs;
-
- /* grow the 'glyph->subglyphs' table if necessary */
- total_subglyphs = glyph->num_subglyphs + num_subglyphs;
- if ( total_subglyphs >= glyph->max_subglyphs )
- {
- FT_UInt new_max = glyph->max_subglyphs;
- FT_Memory memory = loader->face->root.memory;
-
- while (new_max <= total_subglyphs)
- new_max += 4;
-
- if ( REALLOC_ARRAY( glyph->subglyphs, glyph->max_subglyphs,
- new_max, FT_SubGlyph ) )
- goto Fail;
-
- glyph->max_subglyphs = new_max;
- subglyph = glyph->subglyphs + glyph->num_subglyphs + num_subglyphs;
- }
-
- subglyph->arg1 = subglyph->arg2 = 0;
-
- subglyph->flags = GET_UShort();
- subglyph->index = GET_UShort();
-
- /* read arguments */
- if (subglyph->flags & ARGS_ARE_WORDS)
+ FT_Int shift = 16;
+ FT_Long val;
+
+ /* this is an operand, push it on the stack */
+ if ( v == 28)
{
- subglyph->arg1 = GET_Short();
- subglyph->arg2 = GET_Short();
+ if ( ip+1 >= limit ) goto Syntax_Error;
+ val = (FT_Short)(((FT_Int)ip[0] << 8) + ip[1]);
+ ip += 2;
}
- else
+ else if ( v < 247 )
+ val = v - 139;
+ else if ( v < 251 )
{
- subglyph->arg1 = GET_Char();
- subglyph->arg2 = GET_Char();
+ if ( ip >= limit ) goto Syntax_Error;
+ val = (v-247)*256 + *ip++ + 108;
}
-
- /* read transform */
- xx = yy = 0x10000;
- xy = yx = 0;
-
- if (subglyph->flags & WE_HAVE_A_SCALE)
- {
- xx = (TT_Fixed)GET_Short() << 2;
- yy = xx;
- }
- else if (subglyph->flags & WE_HAVE_AN_XY_SCALE)
+ else if ( v < 255 )
{
- xx = (TT_Fixed)GET_Short() << 2;
- yy = (TT_Fixed)GET_Short() << 2;
+ if ( ip >= limit ) goto Syntax_Error;
+ val = -((v-251)*256) - *ip++ - 108;
}
- else if (subglyph->flags & WE_HAVE_A_2X2)
+ else
{
- xx = (TT_Fixed)GET_Short() << 2;
- xy = (TT_Fixed)GET_Short() << 2;
- yx = (TT_Fixed)GET_Short() << 2;
- yy = (TT_Fixed)GET_Short() << 2;
+ if ( ip + 3 >= limit ) goto Syntax_Error;
+ val = ((FT_Long)ip[0] << 24) |
+ ((FT_Long)ip[1] << 16) |
+ ((FT_Long)ip[2] << 8) | ip[3];
+ ip += 4;
+ shift = 0;
}
-
- subglyph->transform.xx = xx;
- subglyph->transform.xy = xy;
- subglyph->transform.yx = yx;
- subglyph->transform.yy = yy;
-
- subglyph++;
- num_subglyphs++;
- }
- while (subglyph[-1].flags & MORE_COMPONENTS);
-
- FORGET_Frame();
-
- /* if the flag FT_LOAD_NO_RECURSE is set, we return the subglyph */
- /* "as is" in the glyph slot (the client application will be */
- /* responsible for interpreting this data..) */
- if ( loader->load_flags & FT_LOAD_NO_RECURSE )
- {
- /* set up remaining glyph fields */
- glyph->num_subglyphs += num_subglyphs;
- glyph->format = ft_glyph_format_composite;
- goto Load_End;
+ if (decoder->top - stack >= T2_MAX_OPERANDS)
+ goto Stack_Overflow;
+
+ val <<= shift;
+ *decoder->top ++ = val;
+
+ #ifdef FT_DEBUG_LEVEL_TRACE
+ if (!(val & 0xFFFF))
+ FT_TRACE4(( " %d", (FT_Int)(val >> 16) ));
+ else
+ FT_TRACE4(( " %.2f", val/65536.0 ));
+ #endif
}
-
-
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
-
- /*********************************************************************/
- /* Now, read each subglyph independently.. */
+ else
{
- FT_Int n, num_base_points, num_new_points;
-
- subglyph = glyph->subglyphs + glyph->num_subglyphs;
- glyph->num_subglyphs += num_subglyphs;
-
- for ( n = 0; n < num_subglyphs; n++, subglyph++ )
+ FT_Fixed* args = decoder->top;
+ FT_Int num_args = args - decoder->stack;
+ FT_Int req_args;
+
+ /* find operator */
+ op = t2_op_unknown;
+ switch (v)
{
- FT_Vector pp1, pp2;
- FT_Pos x, y;
-
- pp1 = loader->pp1;
- pp2 = loader->pp2;
-
- num_base_points = loader->base.n_points;
-
- error = load_truetype_glyph( loader, subglyph->index );
- if (error) goto Fail;
+ case 1: op = t2_op_hstem; break;
+ case 3: op = t2_op_vstem; break;
+ case 4: op = t2_op_vmoveto; break;
+ case 5: op = t2_op_rlineto; break;
+ case 6: op = t2_op_hlineto; break;
+ case 7: op = t2_op_vlineto; break;
+ case 8: op = t2_op_rrcurveto; break;
+ case 10: op = t2_op_callsubr; break;
+ case 11: op = t2_op_return; break;
+ case 12:
+ {
+ if (ip >= limit) goto Syntax_Error;
+ v = *ip++;
+ switch (v)
+ {
+ case 3: op = t2_op_and; break;
+ case 4: op = t2_op_or; break;
+ case 5: op = t2_op_not; break;
+ case 8: op = t2_op_store; break;
+ case 9: op = t2_op_abs; break;
+ case 10: op = t2_op_add; break;
+ case 11: op = t2_op_sub; break;
+ case 12: op = t2_op_div; break;
+ case 13: op = t2_op_load; break;
+ case 14: op = t2_op_neg; break;
+ case 15: op = t2_op_eq; break;
+ case 18: op = t2_op_drop; break;
+ case 20: op = t2_op_put; break;
+ case 21: op = t2_op_get; break;
+ case 22: op = t2_op_ifelse; break;
+ case 23: op = t2_op_random; break;
+ case 24: op = t2_op_mul; break;
+ case 26: op = t2_op_sqrt; break;
+ case 27: op = t2_op_dup; break;
+ case 28: op = t2_op_exch; break;
+ case 29: op = t2_op_index; break;
+ case 30: op = t2_op_roll; break;
+ case 34: op = t2_op_hflex; break;
+ case 35: op = t2_op_flex; break;
+ case 36: op = t2_op_hflex1; break;
+ case 37: op = t2_op_flex1; break;
+ default:
+ /* decrement ip for syntax error message */
+ ip--;
+ }
+ }
+ break;
+
+ case 14: op = t2_op_endchar; break;
+ case 16: op = t2_op_blend; break;
+ case 18: op = t2_op_hstemhm; break;
+ case 19: op = t2_op_hintmask; break;
+ case 20: op = t2_op_cntrmask; break;
+ case 21: op = t2_op_rmoveto; break;
+ case 22: op = t2_op_hmoveto; break;
+ case 23: op = t2_op_vstemhm; break;
+ case 24: op = t2_op_rcurveline; break;
+ case 25: op = t2_op_rlinecurve; break;
+ case 26: op = t2_op_vvcurveto; break;
+ case 27: op = t2_op_hhcurveto; break;
+ case 29: op = t2_op_callgsubr; break;
+ case 30: op = t2_op_vhcurveto; break;
+ case 31: op = t2_op_hvcurveto; break;
+ default:
+ ;
+ }
+ if ( op == t2_op_unknown )
+ goto Syntax_Error;
- if ( subglyph->flags & USE_MY_METRICS )
- {
- pp1 = loader->pp1;
- pp2 = loader->pp2;
- }
- else
+ /* check arguments */
+ req_args = count = t2_argument_counts[op];
+ if (req_args & T2_COUNT_CHECK_WIDTH)
+ {
+ args = stack;
+ if ( decoder->read_width )
{
- loader->pp1 = pp1;
- loader->pp2 = pp2;
+ decoder->glyph_width = decoder->nominal_width + (stack[0] >> 16);
+ decoder->read_width = 0;
+ num_args--;
+ args++;
}
-
- num_points = loader->base.n_points;
- num_contours = loader->base.n_contours;
-
- num_new_points = num_points - num_base_points;
-
- /********************************************************/
- /* now perform the transform required for this subglyph */
-
- if ( subglyph->flags & ( WE_HAVE_A_SCALE |
- WE_HAVE_AN_XY_SCALE |
- WE_HAVE_A_2X2 ) )
- {
- FT_Vector* cur = loader->zone.cur;
- FT_Vector* org = loader->zone.org;
- FT_Vector* limit = cur + num_new_points;
-
- for ( ; cur < limit; cur++, org++ )
+ req_args = 0;
+ }
+
+ req_args &= 15;
+ if (num_args < req_args) goto Stack_Underflow;
+ args -= req_args;
+ num_args -= req_args;
+
+ switch (op)
+ {
+ case t2_op_hstem:
+ case t2_op_vstem:
+ case t2_op_hstemhm:
+ case t2_op_vstemhm:
{
- TT_Pos nx, ny;
-
- nx = FT_MulFix( cur->x, subglyph->transform.xx ) +
- FT_MulFix( cur->y, subglyph->transform.yx );
-
- ny = FT_MulFix( cur->x, subglyph->transform.xy ) +
- FT_MulFix( cur->y, subglyph->transform.yy );
-
- cur->x = nx;
- cur->y = ny;
-
- nx = FT_MulFix( org->x, subglyph->transform.xx ) +
- FT_MulFix( org->y, subglyph->transform.yx );
-
- ny = FT_MulFix( org->x, subglyph->transform.xy ) +
- FT_MulFix( org->y, subglyph->transform.yy );
-
- org->x = nx;
- org->y = ny;
+ /* if the number of arguments is no even, the first one */
+ /* is simply the glyph width.. encoded as the difference */
+ /* to nominalWidthX */
+ FT_TRACE4(( op == t2_op_hstem ? " hstem" :
+ op == t2_op_vstem ? " vstem" :
+ op == t2_op_hstemhm ? " hstemhm" :
+ " vstemhm" ));
+ decoder->num_hints += num_args/2;
+ args = stack;
}
- }
-
- /* apply offset */
-
- if ( !(subglyph->flags & ARGS_ARE_XY_VALUES) )
- {
- FT_Int k = subglyph->arg1;
- FT_UInt l = subglyph->arg2;
+ break;
+
+ case t2_op_hintmask:
+ case t2_op_cntrmask:
+ {
+ FT_TRACE4(( op == t2_op_hintmask ? " hintmask" : " cntrmask" ));
+ decoder->num_hints += num_args/2;
+ ip += (decoder->num_hints+7) >> 3;
+ if (ip >= limit) goto Syntax_Error;
+ args = stack;
+ }
+ break;
+
+ case t2_op_rmoveto:
+ {
+ FT_TRACE4(( " rmoveto" ));
+ close_contour( builder );
+ builder->path_begun = 0;
+ x += args[0];
+ y += args[1];
+ args = stack;
+ }
+ break;
+
+ case t2_op_vmoveto:
+ {
+ FT_TRACE4(( " vmoveto" ));
+ close_contour( builder );
+ builder->path_begun = 0;
+ y += args[0];
+ args = stack;
+ }
+ break;
+
+ case t2_op_hmoveto:
+ {
+ FT_TRACE4(( " vmoveto" ));
+ close_contour( builder );
+ builder->path_begun = 0;
+ x += args[0];
+ args = stack;
+ }
+ break;
+
+ case t2_op_rlineto:
+ {
+ FT_TRACE4(( " rlineto" ));
+
+ if ( start_point ( builder, x, y ) ||
+ check_points( builder, num_args/2 ) ) goto Memory_Error;
+
+ if ( num_args < 2 || num_args & 1 ) goto Stack_Underflow;
+ args = stack;
+ while ( args < decoder->top )
+ {
+ x += args[0];
+ y += args[1];
+ add_point( builder, x, y, 1 );
+ args += 2;
+ }
+ args = stack;
+ }
+ break;
- if ( k >= num_base_points ||
- l >= (TT_UInt)num_new_points )
+ case t2_op_hlineto:
+ case t2_op_vlineto:
{
- error = TT_Err_Invalid_Composite;
- goto Fail;
+ FT_Int phase = ( op == t2_op_hlineto );
+
+ FT_TRACE4(( op == t2_op_hlineto ? " hlineto" : " vlineto" ));
+
+ if ( start_point ( builder, x, y ) ||
+ check_points( builder, num_args ) ) goto Memory_Error;
+
+ args = stack;
+ while (args < decoder->top )
+ {
+ if (phase) x += args[0];
+ else y += args[0];
+
+ if (add_point1( builder, x, y )) goto Memory_Error;
+ args++;
+ phase ^= 1;
+ }
+ args = stack;
}
+ break;
- l += num_base_points;
+ case t2_op_rrcurveto:
+ {
+ FT_TRACE4(( " rrcurveto" ));
+
+ /* check number of arguments, must be a multiple of 6 */
+ if (num_args % 6 != 0) goto Stack_Underflow;
+
+ if ( start_point ( builder, x, y ) ||
+ check_points( builder, num_args/2 ) ) goto Memory_Error;
+
+ args = stack;
+ while (args < decoder->top)
+ {
+ x += args[0];
+ y += args[1];
+ add_point( builder, x, y, 0 );
+ x += args[2];
+ y += args[3];
+ add_point( builder, x, y, 0 );
+ x += args[4];
+ y += args[5];
+ add_point( builder, x, y, 1 );
+ args += 6;
+ }
+ args = stack;
+ }
+ break;
+
+ case t2_op_vvcurveto:
+ {
+ FT_TRACE4(( " vvcurveto" ));
+
+ if ( start_point ( builder, x, y ) ) goto Memory_Error;
+
+ args = stack;
+ if (num_args & 1)
+ {
+ x += args[0];
+ args++;
+ num_args--;
+ }
+ if (num_args % 4 != 0) goto Stack_Underflow;
+ if (check_points( builder, 3*(num_args/4) )) goto Memory_Error;
+
+ while (args < decoder->top)
+ {
+ y += args[0];
+ add_point( builder, x, y, 0 );
+ x += args[1];
+ y += args[2];
+ add_point( builder, x, y, 0 );
+ y += args[3];
+ add_point( builder, x, y, 1 );
+ args += 4;
+ }
+ args = stack;
+ }
+ break;
- x = loader->base.cur[k].x - loader->base.cur[l].x;
- y = loader->base.cur[k].y - loader->base.cur[l].y;
- }
- else
- {
- x = subglyph->arg1;
- y = subglyph->arg2;
+ case t2_op_hhcurveto:
+ {
+ FT_TRACE4(( " hhcurveto" ));
+
+ if ( start_point ( builder, x, y ) ) goto Memory_Error;
+ args = stack;
+ if (num_args & 1)
+ {
+ y += args[0];
+ args++;
+ num_args--;
+ }
+ if (num_args % 4 != 0) goto Stack_Underflow;
+ if (check_points( builder, 3*(num_args/4) )) goto Memory_Error;
+
+ while (args < decoder->top)
+ {
+ x += args[0];
+ add_point( builder, x, y, 0 );
+ x += args[1];
+ y += args[2];
+ add_point( builder, x, y, 0 );
+ x += args[3];
+ add_point( builder, x, y, 1 );
+ args += 4;
+ }
+ args = stack;
+ }
+ break;
- if (!(loader->load_flags & FT_LOAD_NO_SCALE))
+ case t2_op_vhcurveto:
+ case t2_op_hvcurveto:
{
- x = FT_MulFix( x, x_scale );
- y = FT_MulFix( y, y_scale );
-
- if ( subglyph->flags & ROUND_XY_TO_GRID )
- {
- x = (x + 32) & -64;
- y = (y + 32) & -64;
- }
+ FT_Int phase;
+
+ FT_TRACE4(( op == t2_op_vhcurveto ? " vhcurveto" : " hvcurveto" ));
+
+ if ( start_point ( builder, x, y ) ) goto Memory_Error;
+ args = stack;
+ if (num_args < 4 || (num_args % 4) > 1 ) goto Stack_Underflow;
+ if (check_points( builder, (num_args/4)*3 )) goto Stack_Underflow;
+ phase = ( op == t2_op_hvcurveto );
+ while (num_args >= 4)
+ {
+ num_args -= 4;
+ if (phase)
+ {
+ x += args[0];
+ add_point( builder, x, y, 0 );
+ x += args[1];
+ y += args[2];
+ add_point( builder, x, y, 0 );
+ y += args[3];
+ if (num_args == 1)
+ x += args[4];
+ add_point( builder, x, y, 1 );
+ }
+ else
+ {
+ y += args[0];
+ add_point( builder, x, y, 0 );
+ x += args[1];
+ y += args[2];
+ add_point( builder, x, y, 0 );
+ x += args[3];
+ if (num_args == 1)
+ y += args[4];
+ add_point( builder, x, y, 1 );
+ }
+ args += 4;
+ phase ^= 1;
+ }
+ args = stack;
}
- }
+ break;
- translate_array( num_new_points, loader->zone.cur, x, y );
- cur_to_org( num_new_points, &loader->zone );
+ case t2_op_rlinecurve:
+ case t2_op_rcurveline:
+ {
+ FT_Int mod6 = num_args % 6;
+
+ FT_TRACE4(( op == t2_op_rcurveline ? " rcurveline" :
+ " rlinecurve" ));
+
+ if ( num_args < 8 || (mod6 != 0 && mod6 != 2) )
+ goto Stack_Underflow;
+
+ if ( start_point ( builder, x, y ) ||
+ check_points( builder, (num_args/6)*3 + mod6/2 ) )
+ goto Memory_Error;
+
+ args = stack;
+ if (op == t2_op_rlinecurve && mod6)
+ {
+ x += args[0];
+ y += args[1];
+ add_point( builder, x, y, 1 );
+ args += 2;
+ num_args -= 2;
+ }
+ while (num_args >= 6)
+ {
+ x += args[0];
+ y += args[1];
+ add_point( builder, x, y, 0 );
+ x += args[2];
+ y += args[3];
+ add_point( builder, x, y, 0 );
+ x += args[4];
+ y += args[5];
+ add_point( builder, x, y, 1 );
+ args += 6;
+ num_args -= 6;
+ }
+ if ( op == t2_op_rcurveline && num_args)
+ {
+ x += args[0];
+ y += args[1];
+ add_point( builder, x, y, 1 );
+ }
+ args = stack;
+ }
+ break;
+
+ case t2_op_endchar:
+ {
+ 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 FT_Err_Ok;
+ }
+
+ case t2_op_abs:
+ {
+ FT_TRACE4(( " abs" ));
+ if (args[0] < 0)
+ args[0] = -args[0];
+ args++;
+ }
+ break;
+
+ case t2_op_add:
+ {
+ FT_TRACE4(( " add" ));
+ args[0] += args[1];
+ args++;
+ }
+ break;
+
+ case t2_op_sub:
+ {
+ FT_TRACE4(( " sub" ));
+ args[0] -= args[1];
+ args++;
+ }
+ break;
+
+ case t2_op_div:
+ {
+ FT_TRACE4(( " div" ));
+ args[0] = FT_DivFix( args[0], args[1] );
+ args++;
+ }
+ break;
+
+ case t2_op_neg:
+ {
+ FT_TRACE4(( " neg" ));
+ args[0] = -args[0];
+ args++;
+ }
+ break;
+
+ case t2_op_random:
+ {
+ FT_Fixed rand;
+
+ FT_TRACE4(( " rand" ));
+ rand = seed;
+ if (rand >= 0x8000)
+ rand++;
+
+ args[0] = rand;
+ seed = FT_MulFix( seed, 0x10000 - seed );
+ if (seed == 0) seed += 0x2873;
+ args++;
+ }
+ break;
+
+ case t2_op_mul:
+ {
+ FT_TRACE4(( " mul" ));
+ args[0] = FT_MulFix( args[0], args[1] );
+ args++;
+ }
+ break;
+
+ case t2_op_sqrt:
+ {
+ FT_TRACE4(( " sqrt" ));
+ if (args[0] > 0)
+ {
+ FT_Int count = 9;
+ FT_Fixed root = args[0];
+ FT_Fixed new_root;
+
+ for (;;)
+ {
+ new_root = ( root + FT_DivFix(args[0],root) + 1 ) >> 1;
+ if (new_root == root || count <= 0)
+ break;
+ root = new_root;
+ }
+ args[0] = new_root;
+ }
+ else
+ args[0] = 0;
+ args++;
+ }
+ break;
+
+ case t2_op_drop:
+ {
+ /* nothing */
+ FT_TRACE4(( " drop" ));
+ }
+ break;
+
+ case t2_op_exch:
+ {
+ FT_Fixed tmp;
+ FT_TRACE4(( " exch" ));
+ tmp = args[0];
+ args[0] = args[1];
+ args[1] = tmp;
+ args += 2;
+ }
+ break;
+
+ case t2_op_index:
+ {
+ FT_Int index = args[0] >> 16;
+ FT_TRACE4(( " index" ));
+ if (index < 0)
+ index = 0;
+ else if (index > num_args-2)
+ index = num_args-2;
+ args[0] = args[-(index+1)];
+ args++;
+ }
+ break;
+
+ case t2_op_roll:
+ {
+ FT_Int count = (FT_Int)(args[0] >> 16);
+ FT_Int index = (FT_Int)(args[1] >> 16);
+
+ FT_TRACE4(( " roll" ));
+
+ if (count <= 0)
+ count = 1;
+
+ args -= count;
+ if (args < stack) goto Stack_Underflow;
+ if (index >= 0)
+ {
+ while (index > 0)
+ {
+ FT_Fixed tmp = args[count-1];
+ FT_Int i;
+ for ( i = count-2; i >= 0; i-- )
+ args[i+1] = args[i];
+ args[0] = tmp;
+ index--;
+ }
+ }
+ else
+ {
+ while (index < 0)
+ {
+ FT_Fixed tmp = args[0];
+ FT_Int i;
+ for ( i = 0; i < count-1; i++ )
+ args[i] = args[i+1];
+ args[count-1] = tmp;
+ index++;
+ }
+ }
+ args += count;
+ }
+ break;
+
+ case t2_op_dup:
+ {
+ FT_TRACE4(( " dup" ));
+ args[1] = args[0];
+ args++;
+ }
+ break;
+
+ case t2_op_put:
+ {
+ FT_Fixed val = args[0];
+ FT_Int index = (FT_Int)(args[1] >> 16);
+
+ FT_TRACE4(( " put" ));
+ if (index >= 0 && index < decoder->len_buildchar)
+ decoder->buildchar[index] = val;
+ }
+ break;
+
+ case t2_op_get:
+ {
+ FT_Int index = (FT_Int)(args[0] >> 16);
+ FT_Fixed val = 0;
+ FT_TRACE4(( " get" ));
+
+ if (index >= 0 && index < decoder->len_buildchar)
+ val = decoder->buildchar[index];
+
+ args[0] = val;
+ args++;
+ }
+ break;
+
+ case t2_op_store:
+ FT_TRACE4(( " store "));
+ goto Unimplemented;
+
+ case t2_op_load:
+ FT_TRACE4(( " load" ));
+ goto Unimplemented;
+
+ case t2_op_and:
+ {
+ FT_Fixed cond = args[0] && args[1];
+ FT_TRACE4(( " and" ));
+ args[0] = cond ? 0x10000 : 0;
+ args++;
+ }
+ break;
+
+ case t2_op_or:
+ {
+ FT_Fixed cond = args[0] || args[1];
+ FT_TRACE4(( " or" ));
+ args[0] = cond ? 0x10000 : 0;
+ args++;
+ }
+ break;
+
+ case t2_op_eq:
+ {
+ FT_Fixed cond = !args[0];
+ FT_TRACE4(( " eq" ));
+ args[0] = cond ? 0x10000 : 0;
+ args++;
+ }
+ break;
+
+ case t2_op_ifelse:
+ {
+ FT_Fixed cond = args[2] <= args[3];
+ FT_TRACE4(( " ifelse" ));
+ if (!cond)
+ args[0] = args[1];
+ args++;
+ }
+ break;
+
+ case t2_op_callsubr:
+ {
+ FT_UInt index = (FT_UInt)((args[0] >> 16) + decoder->locals_bias);
+
+ FT_TRACE4(( " callsubr(%d)", index ));
+ if (index >= decoder->num_locals)
+ {
+ FT_ERROR(( "T2.Parse_Charstrings: invalid local subr index\n" ));
+ goto Syntax_Error;
+ }
+
+ if ( zone - decoder->zones >= T2_MAX_SUBRS_CALLS )
+ {
+ FT_ERROR(( "T2.Parse_CharStrings : too many nested subrs\n" ));
+ goto Syntax_Error;
+ }
+
+ zone->cursor = ip; /* save current instruction pointer */
+
+ zone++;
+ zone->base = decoder->locals[index];
+ zone->limit = decoder->locals[index+1];
+ zone->cursor = zone->base;
+
+ if (!zone->base)
+ {
+ FT_ERROR(( "T2.Parse_CharStrings : invoking empty subrs !!\n" ));
+ goto Syntax_Error;
+ }
+
+ decoder->zone = zone;
+ ip = zone->base;
+ limit = zone->limit;
+ }
+ break;
+
+ case t2_op_callgsubr:
+ {
+ FT_UInt index = (FT_UInt)((args[0] >> 16) + decoder->globals_bias);
+
+ FT_TRACE4(( " callgsubr(%d)", index ));
+ if (index >= decoder->num_globals)
+ {
+ FT_ERROR(( "T2.Parse_Charstrings: invalid global subr index\n" ));
+ goto Syntax_Error;
+ }
+
+ if ( zone - decoder->zones >= T2_MAX_SUBRS_CALLS )
+ {
+ FT_ERROR(( "T2.Parse_CharStrings : too many nested subrs\n" ));
+ goto Syntax_Error;
+ }
+
+ zone->cursor = ip; /* save current instruction pointer */
+
+ zone++;
+ zone->base = decoder->globals[index];
+ zone->limit = decoder->globals[index+1];
+ zone->cursor = zone->base;
+
+ if (!zone->base)
+ {
+ FT_ERROR(( "T2.Parse_CharStrings : invoking empty subrs !!\n" ));
+ goto Syntax_Error;
+ }
+
+ decoder->zone = zone;
+ ip = zone->base;
+ limit = zone->limit;
+ }
+ break;
+
+ case t2_op_return:
+ {
+ FT_TRACE4(( " return" ));
+ if ( decoder->zone <= decoder->zones )
+ {
+ FT_ERROR(( "T2.Parse_CharStrings : unexpected return\n" ));
+ goto Syntax_Error;
+ }
+
+ decoder->zone--;
+ zone = decoder->zone;
+ ip = zone->cursor;
+ limit = zone->limit;
+ }
+ break;
+
+ default:
+
+ Unimplemented:
+ FT_ERROR(( "Unimplemented opcode: %d", ip[-1] ));
+ if (ip[-1] == 12)
+ {
+ FT_ERROR(( " %d", ip[0] ));
+ }
+ FT_ERROR(( "\n" ));
+ return FT_Err_Unimplemented_Feature;
}
+ decoder->top = args;
+
+ } /* general operator processing */
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
-
- /* we have finished loading all sub-glyphs, now, look for */
- /* instructions for this composite !! */
-
- }
- /* end of composite loading */
- }
+ } /* while ip < limit */
+ FT_TRACE4(( "..end..\n\n" ));
+ return error;
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
+ Syntax_Error:
+ return FT_Err_Invalid_File_Format;
- Load_End:
- error = FT_Err_Ok;
+ Stack_Underflow:
+ return T2_Err_Too_Few_Arguments;
- Fail:
- return error;
+ Stack_Overflow:
+ return T2_Err_Stack_Overflow;
+
+ Memory_Error:
+ return builder->error;
}
+ /**********************************************************************/
+ /**********************************************************************/
+ /**********************************************************************/
+ /********** *********/
+ /********** *********/
+ /********** COMPUTE THE MAXIMUM ADVANCE WIDTH *********/
+ /********** *********/
+ /********** The following code is in charge of computing *********/
+ /********** the maximum advance width of the font. It *********/
+ /********** quickly process each glyph charstring to *********/
+ /********** extract the value from either a "sbw" or "seac" *********/
+ /********** operator. *********/
+ /********** *********/
+ /**********************************************************************/
+ /**********************************************************************/
+ /**********************************************************************/
+
+#if 0 /* unused until we support pure CFF fonts */
+ LOCAL_FUNC
+ FT_Error T2_Compute_Max_Advance( TT_Face face,
+ FT_Int *max_advance )
+ {
+ FT_Error error = 0;
+ T2_Decoder decoder;
+ FT_Int glyph_index;
+ CFF_Font* cff = (CFF_Font*)face->other;
+ *max_advance = 0;
- static
- void compute_glyph_metrics( T2_Loader* loader,
- FT_UInt glyph_index )
- {
- FT_UInt num_points = loader->base.n_points;
- FT_UInt num_contours = loader->base.n_contours;
- FT_BBox bbox;
- T2_Face face = loader->face;
- FT_Fixed x_scale, y_scale;
- T2_GlyphSlot glyph = loader->glyph;
- T2_Size size = loader->size;
-
- /* when a simple glyph was loaded, the value of */
- /* "base.n_points" and "base.n_contours" is 0, we must */
- /* take those in the "zone" instead.. */
- if ( num_points == 0 && num_contours == 0 )
- {
- num_points = loader->zone.n_points;
- num_contours = loader->zone.n_contours;
- }
+ /* Initialise load decoder */
+ T2_Init_Decoder( &decoder, face, 0, 0 );
- x_scale = 0x10000;
- y_scale = 0x10000;
- if ( (loader->load_flags & FT_LOAD_NO_SCALE) == 0)
- {
- x_scale = size->root.metrics.x_scale;
- y_scale = size->root.metrics.y_scale;
- }
+ decoder.builder.metrics_only = 1;
+ decoder.builder.load_points = 0;
- if ( glyph->format != ft_glyph_format_composite )
+ /* For each glyph, parse the glyph charstring and extract */
+ /* the advance width.. */
+ for ( glyph_index = 0; glyph_index < face->root.num_glyphs; glyph_index++ )
{
- FT_UInt u;
- for ( u = 0; u < num_points + 2; u++ )
+ FT_Byte* charstring;
+ FT_ULong charstring_len;
+
+ /* now get load the unscaled outline */
+ error = T2_Access_Element( &cff->charstrings_index, glyph_index,
+ &charstring, &charstring_len );
+ if (!error)
{
- glyph->outline.points[u] = loader->base.cur[u];
- glyph->outline.tags [u] = loader->base.tags[u];
+ error = T2_Parse_CharStrings( &decoder, charstring, charstring_len );
+
+ T2_Forget_Element( &cff->charstrings_index, &charstring );
}
+ /* ignore the error if one occured - skip to next glyph */
+ error = 0;
+ }
- for ( u = 0; u < num_contours; u++ )
- glyph->outline.contours[u] = loader->base.contours[u];
-
- /* glyph->outline.second_pass = TRUE; */
- glyph->outline.flags &= ~ft_outline_single_pass;
- glyph->outline.n_points = num_points;
- glyph->outline.n_contours = num_contours;
+ *max_advance = decoder.builder.advance.x;
+ return FT_Err_Ok;
+ }
+#endif
+
+ /**********************************************************************/
+ /**********************************************************************/
+ /**********************************************************************/
+ /********** *********/
+ /********** *********/
+ /********** UNHINTED GLYPH LOADER *********/
+ /********** *********/
+ /********** The following code is in charge of loading a *********/
+ /********** single outline. It completely ignores hinting *********/
+ /********** and is used when FT_LOAD_NO_HINTING is set. *********/
+ /********** *********/
+ /**********************************************************************/
+ /**********************************************************************/
+ /**********************************************************************/
- /* translate array so that (0,0) is the glyph's origin */
- translate_array( (TT_UShort)(num_points + 2),
- glyph->outline.points,
- -loader->pp1.x,
- 0 );
- FT_Outline_Get_CBox( &glyph->outline, &bbox );
+ LOCAL_FUNC
+ FT_Error T2_Load_Glyph( T2_GlyphSlot glyph,
+ T2_Size size,
+ FT_Int glyph_index,
+ FT_Int load_flags )
+ {
+ FT_Error error;
+ T2_Decoder decoder;
+ TT_Face face = (TT_Face)glyph->root.face;
+ FT_Bool hinting;
+ CFF_Font* cff = (CFF_Font*)face->other;
- if ( IS_HINTED(loader->load_flags) )
- {
- /* grid-fit the bounding box */
- bbox.xMin &= -64;
- bbox.yMin &= -64;
- bbox.xMax = (bbox.xMax + 63) & -64;
- bbox.yMax = (bbox.yMax + 63) & -64;
- }
- }
- else
- bbox = loader->bbox;
+ if (load_flags & FT_LOAD_NO_RECURSE)
+ load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
- /* get the device-independent scaled horizontal metrics */
- /* take care of fixed-pitch fonts... */
- {
- FT_Pos left_bearing;
- FT_Pos advance;
-
- left_bearing = loader->left_bearing;
- advance = loader->advance;
-
- /* the flag FT_LOAD_NO_ADVANCE_CHECK was introduced to */
- /* correctly support DynaLab fonts, who have an incorrect */
- /* "advance_Width_Max" field !! It is used, to my knowledge */
- /* exclusively in the X-TrueType font server.. */
- /* */
- if ( face->postscript.isFixedPitch &&
- (loader->load_flags & FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH) == 0 )
- advance = face->horizontal.advance_Width_Max;
-
- if ( !(loader->load_flags & FT_LOAD_NO_SCALE) )
- {
- left_bearing = FT_MulFix( left_bearing, x_scale );
- advance = FT_MulFix( advance, x_scale );
- }
+ glyph->x_scale = size->metrics.x_scale;
+ glyph->y_scale = size->metrics.y_scale;
- glyph->metrics2.horiBearingX = left_bearing;
- glyph->metrics2.horiAdvance = advance;
- }
+ glyph->root.outline.n_points = 0;
+ glyph->root.outline.n_contours = 0;
- glyph->metrics.horiBearingX = bbox.xMin;
- glyph->metrics.horiBearingY = bbox.yMax;
- glyph->metrics.horiAdvance = loader->pp2.x - loader->pp1.x;
+ hinting = ( load_flags & FT_LOAD_NO_SCALE ) == 0 &&
+ ( load_flags & FT_LOAD_NO_HINTING ) == 0;
- /* Now take care of vertical metrics. In the case where there is */
- /* no vertical information within the font (relatively common), make */
- /* up some metrics by `hand'... */
+ glyph->root.format = ft_glyph_format_none;
{
- FT_Short top_bearing; /* vertical top side bearing (EM units) */
- FT_UShort advance_height; /* vertical advance height (EM units) */
+ FT_Byte* charstring;
+ FT_ULong charstring_len;
+
+ T2_Init_Decoder( &decoder, face, size, glyph );
- FT_Pos left; /* scaled vertical left side bearing */
- FT_Pos Top; /* scaled original vertical top side bearing */
- FT_Pos top; /* scaled vertical top side bearing */
- FT_Pos advance; /* scaled vertical advance height */
+ decoder.builder.no_recurse = (FT_Bool)!!(load_flags & FT_LOAD_NO_RECURSE);
-
- /* Get the unscaled `tsb' and `ah' */
- if ( face->vertical_info &&
- face->vertical.number_Of_VMetrics > 0 )
+ /* now load the unscaled outline */
+ error = T2_Access_Element( &cff->charstrings_index, glyph_index,
+ &charstring, &charstring_len );
+ if (!error)
{
- /* Don't assume that both the vertical header and vertical */
- /* metrics are present in the same font :-) */
-
- T2_Get_Metrics( (TT_HoriHeader*)&face->vertical,
- glyph_index,
- &top_bearing,
- &advance_height );
- }
- else
- {
- /* Make up the distances from the horizontal header.. */
-
- /* NOTE: The OS/2 values are the only `portable' ones, */
- /* which is why we use them, when there is an */
- /* OS/2 table in the font. Otherwise, we use the */
- /* values defined in the horizontal header.. */
- /* */
- /* NOTE2: The sTypoDescender is negative, which is why */
- /* we compute the baseline-to-baseline distance */
- /* here with: */
- /* ascender - descender + linegap */
- /* */
- if ( face->os2.version != 0xFFFF )
- {
- top_bearing = face->os2.sTypoLineGap / 2;
- advance_height = (TT_UShort)(face->os2.sTypoAscender -
- face->os2.sTypoDescender +
- face->os2.sTypoLineGap);
- }
- else
- {
- top_bearing = face->horizontal.Line_Gap / 2;
- advance_height = (TT_UShort)(face->horizontal.Ascender +
- face->horizontal.Descender +
- face->horizontal.Line_Gap);
- }
+ error = T2_Parse_CharStrings( &decoder, charstring, charstring_len );
+
+ T2_Forget_Element( &cff->charstrings_index, &charstring );
}
- /* We must adjust the top_bearing value from the bounding box given
- in the glyph header to te bounding box calculated with
- TT_Get_Outline_BBox() */
+ /* save new glyph tables */
+ T2_Done_Builder( &decoder.builder );
+ }
- /* scale the metrics */
- if ( !(loader->load_flags & FT_LOAD_NO_SCALE) )
+ /* Now, set the metrics.. - this is rather simple, as : */
+ /* the left side bearing is the xMin, and the top side */
+ /* bearing the yMax.. */
+ if (!error)
+ {
+ /* for composite glyphs, return only the left side bearing and the */
+ /* advance width.. */
+ if ( load_flags & FT_LOAD_NO_RECURSE )
{
- Top = FT_MulFix( top_bearing, y_scale );
- top = FT_MulFix( top_bearing + loader->bbox.yMax, y_scale )
- - bbox.yMax;
- advance = FT_MulFix( advance_height, y_scale );
+#if 0
+ glyph->root.metrics.horiBearingX = decoder.builder.left_bearing.x;
+ glyph->root.metrics.horiAdvance = decoder.builder.advance.x;
+#else
+ glyph->root.metrics.horiBearingX = decoder.builder.left_bearing.x;
+ glyph->root.metrics.horiAdvance = decoder.glyph_width;
+#endif
}
else
{
- Top = top_bearing;
- top = top_bearing + loader->bbox.yMax - bbox.yMax;
- advance = advance_height;
- }
-
- glyph->metrics2.vertBearingY = Top;
- glyph->metrics2.vertAdvance = advance;
-
- /* XXX: for now, we have no better algorithm for the lsb, but it */
- /* should work fine. */
- /* */
- left = ( bbox.xMin - bbox.xMax ) / 2;
-
- /* grid-fit them if necessary */
- if ( IS_HINTED(loader->load_flags) )
- {
- left &= -64;
- top = (top + 63) & -64;
- advance = (advance + 32) & -64;
- }
-
- glyph->metrics.vertBearingX = left;
- glyph->metrics.vertBearingY = top;
- glyph->metrics.vertAdvance = advance;
- }
-
- /* Adjust advance width to the value contained in the hdmx table. */
- if ( !face->postscript.isFixedPitch && size &&
- IS_HINTED(loader->load_flags) )
- {
- FT_Byte* widths = Get_Advance_Widths( face,
- size->root.metrics.x_ppem );
- if ( widths )
- glyph->metrics.horiAdvance = widths[glyph_index] << 6;
- }
-
- /* set glyph dimensions */
- glyph->metrics.width = bbox.xMax - bbox.xMin;
- glyph->metrics.height = bbox.yMax - bbox.yMin;
- }
-
-
-
-
-
-
-
-
-
-
+ FT_BBox cbox;
+ FT_Glyph_Metrics* metrics = &glyph->root.metrics;
+
+ /* copy the _unscaled_ advance width */
+#if 0
+ metrics->horiAdvance = decoder.builder.advance.x;
+#else
+ metrics->horiAdvance = decoder.glyph_width;
+#endif
+ /* make up vertical metrics */
+ metrics->vertBearingX = 0;
+ metrics->vertBearingY = 0;
+ metrics->vertAdvance = 0;
+
+ glyph->root.format = ft_glyph_format_outline;
+
+ glyph->root.outline.flags &= ft_outline_owner;
+ if ( size && size->metrics.y_ppem < 24 )
+ glyph->root.outline.flags |= ft_outline_high_precision;
+
+ glyph->root.outline.flags |= ft_outline_reverse_fill;
+
+ /*
+ glyph->root.outline.second_pass = TRUE;
+ glyph->root.outline.high_precision = ( size->root.metrics.y_ppem < 24 );
+ glyph->root.outline.dropout_mode = 2;
+ */
+
+ if ( (load_flags & FT_LOAD_NO_SCALE) == 0 )
+ {
+ /* scale the outline and the metrics */
+ FT_Int n;
+ FT_Outline* cur = &decoder.builder.base;
+ FT_Vector* vec = cur->points;
+ FT_Fixed x_scale = glyph->x_scale;
+ FT_Fixed y_scale = glyph->y_scale;
+
+ /* First of all, scale the points */
+ for ( n = cur->n_points; n > 0; n--, vec++ )
+ {
+ vec->x = FT_MulFix( vec->x, x_scale );
+ vec->y = FT_MulFix( vec->y, y_scale );
+ }
+ FT_Outline_Get_CBox( &glyph->root.outline, &cbox );
- LOCAL_FUNC
- FT_Error TT_Load_Glyph( T2_Size size,
- T2_GlyphSlot glyph,
- FT_UShort glyph_index,
- FT_UInt load_flags )
- {
- SFNT_Interface* sfnt;
- T2_Face face;
- FT_Stream stream;
- FT_Memory memory;
- FT_Error error;
- T2_Loader loader;
- FT_GlyphZone* zone;
-
- face = (TT_Face)glyph->face;
- sfnt = (SFNT_Interface*)face->sfnt;
- stream = face->root.stream;
- memory = face->root.memory;
- error = 0;
-
- if ( !size || (load_flags & FT_LOAD_NO_SCALE) ||
- (load_flags & FT_LOAD_NO_RECURSE ))
- {
- size = NULL;
- load_flags |= FT_LOAD_NO_SCALE |
- FT_LOAD_NO_HINTING |
- FT_LOAD_NO_BITMAP;
- }
+ /* Then scale the metrics */
+ metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, x_scale );
- glyph->num_subglyphs = 0;
+ metrics->vertBearingX = FT_MulFix( metrics->vertBearingX, x_scale );
+ metrics->vertBearingY = FT_MulFix( metrics->vertBearingY, y_scale );
+ metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, x_scale );
+ }
-#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
- /*********************************************************************/
- /* Try to load embedded bitmap if any */
- if ( size && (load_flags & FT_LOAD_NO_BITMAP) == 0 && sfnt->load_sbits )
- {
- TT_SBit_Metrics metrics;
-
- error = sfnt->load_sbit_image( face,
- size->root.metrics.x_ppem,
- size->root.metrics.y_ppem,
- glyph_index,
- load_flags,
- stream,
- &glyph->bitmap,
- &metrics );
- if ( !error )
- {
- glyph->outline.n_points = 0;
- glyph->outline.n_contours = 0;
+ /* apply the font matrix */
+ /* FT_Outline_Transform( &glyph->root.outline, cff->font_matrix ); */
- glyph->metrics.width = (FT_Pos)metrics.width << 6;
- glyph->metrics.height = (FT_Pos)metrics.height << 6;
+ /* compute the other metrics */
+ FT_Outline_Get_CBox( &glyph->root.outline, &cbox );
- glyph->metrics.horiBearingX = (FT_Pos)metrics.horiBearingX << 6;
- glyph->metrics.horiBearingY = (FT_Pos)metrics.horiBearingY << 6;
- glyph->metrics.horiAdvance = (FT_Pos)metrics.horiAdvance << 6;
+ /* grid fit the bounding box if necessary */
+ if (hinting)
+ {
+ cbox.xMin &= -64;
+ cbox.yMin &= -64;
+ cbox.xMax = ( cbox.xMax+63 ) & -64;
+ cbox.yMax = ( cbox.yMax+63 ) & -64;
+ }
- glyph->metrics.vertBearingX = (FT_Pos)metrics.vertBearingX << 6;
- glyph->metrics.vertBearingY = (FT_Pos)metrics.vertBearingY << 6;
- glyph->metrics.vertAdvance = (FT_Pos)metrics.vertAdvance << 6;
+ metrics->width = cbox.xMax - cbox.xMin;
+ metrics->height = cbox.yMax - cbox.yMin;
- glyph->format = ft_glyph_format_bitmap;
- return error;
+ metrics->horiBearingX = cbox.xMin;
+ metrics->horiBearingY = cbox.yMax;
}
}
-#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
-
- if ( load_flags & FT_LOAD_NO_OUTLINE )
- return ( error ? error : TT_Err_Unavailable_Bitmap );
-
- /* seek to the beginning of the glyph table. For Type 43 fonts */
- /* the table might be accessed from a Postscript stream or something */
- /* else... */
- error = face->goto_table( face, TTAG_glyf, stream, 0 );
- if (error)
- {
- FT_ERROR(( "TT.GLoad: could not access glyph table\n" ));
- goto Exit;
- }
-
- MEM_Set( &loader, 0, sizeof(loader) );
-
- /* update the glyph zone bounds */
- zone = &((TT_Driver)face->root.driver)->zone;
- error = FT_Update_GlyphZone( zone,
- face->root.max_points,
- face->root.max_contours );
- if (error)
- {
- FT_ERROR(( "TT.GLoad: could not update loader glyph zone\n" ));
- goto Exit;
- }
- loader.base = *zone;
-
- loader.zone.n_points = 0;
- loader.zone.n_contours = 0;
-
- /* clear all outline flags, except the "owner" one */
- glyph->outline.flags &= ft_outline_owner;
-
- if (size && size->root.metrics.y_ppem < 24 )
- glyph->outline.flags |= ft_outline_high_precision;
-
- /************************************************************************/
- /* let's initialise the rest of our loader now */
- loader.left_points = face->root.max_points;
- loader.left_contours = face->root.max_contours;
- loader.load_flags = load_flags;
-
- loader.face = face;
- loader.size = size;
- loader.glyph = glyph;
- loader.stream = stream;
-
- loader.glyf_offset = FILE_Pos();
-
- /* Main loading loop */
- glyph->format = ft_glyph_format_outline;
- glyph->num_subglyphs = 0;
- error = load_truetype_glyph( &loader, glyph_index );
- if (!error)
- compute_glyph_metrics( &loader, glyph_index );
-
- Exit:
return error;
}
-
-
/* END */
diff --git a/src/cff/t2gload.h b/src/cff/t2gload.h
index 012b7ac..aa1c9a3 100644
--- a/src/cff/t2gload.h
+++ b/src/cff/t2gload.h
@@ -25,110 +25,160 @@
extern "C" {
#endif
- typedef struct T2_Loader_
+ #define T2_MAX_OPERANDS 48
+ #define T2_MAX_SUBRS_CALLS 32
+
+/*************************************************************************/
+/* */
+/* <Structure> T2_Builder */
+/* */
+/* <Description> */
+/* a structure used during glyph loading to store its outline. */
+/* */
+/* <Fields> */
+/* system :: current system object */
+/* face :: current face object */
+/* glyph :: current glyph slot */
+/* */
+/* current :: current glyph outline */
+/* base :: base glyph outline */
+/* */
+/* max_points :: maximum points in builder outline */
+/* max_contours :: maximum contours in builder outline */
+/* */
+/* last :: last point position */
+/* */
+/* scale_x :: horizontal scale ( FUnits to sub-pixels ) */
+/* scale_y :: vertical scale ( FUnits to sub-pixels ) */
+/* pos_x :: horizontal translation (composite glyphs) */
+/* pos_y :: vertical translation (composite glyph) */
+/* */
+/* left_bearing :: left side bearing point */
+/* advance :: horizontal advance vector */
+/* */
+/* path_begun :: flag, indicates that a new path has begun */
+/* load_points :: flag, if not set, no points are loaded */
+/* */
+/* error :: an error code that is only used to report */
+/* memory allocation problems.. */
+/* */
+/* metrics_only :: a boolean indicating that we only want to */
+/* compute the metrics of a given glyph, not load */
+/* all of its points.. */
+/* */
+
+ typedef struct T2_Builder_
{
- T2_Face face;
- T2_Size size;
- T2_GlyphSlot glyph;
-
- FT_ULong load_flags;
- FT_UInt glyph_index;
-
- FT_Stream stream;
- FT_Int byte_len;
- FT_Int left_points;
- FT_Int left_contours;
-
- FT_BBox bbox;
- FT_Int left_bearing;
- FT_Int advance;
- FT_Bool preserve_pps;
- FT_Vector pp1;
- FT_Vector pp2;
-
- FT_ULong glyf_offset;
-
- /* the zone where we load our glyphs */
- FT_GlyphZone base;
- FT_GlyphZone zone;
-
- } T2_Loader;
-
-
-#if 0
- /*************************************************************************/
- /* */
- /* <Function> */
- /* T2_Get_Metrics */
- /* */
- /* <Description> */
- /* Returns the horizontal or vertical metrics in font units for a */
- /* given glyph. The metrics are the left side bearing (resp. top */
- /* side bearing) and advance width (resp. advance height). */
- /* */
- /* <Input> */
- /* header :: A pointer to either the horizontal or vertical metrics */
- /* structure. */
- /* */
- /* index :: The glyph index. */
- /* */
- /* <Output> */
- /* bearing :: The bearing, either left side or top side. */
- /* */
- /* advance :: The advance width resp. advance height. */
- /* */
- /* <Note> */
- /* This function will much probably move to another component in the */
- /* near future, but I haven't decided which yet. */
- /* */
+ FT_Memory memory;
+ TT_Face face;
+ T2_GlyphSlot glyph;
+
+ FT_Outline current; /* the current glyph outline */
+ FT_Outline base; /* the composite glyph outline */
+
+ FT_Int max_points; /* capacity of base outline in points */
+ FT_Int max_contours; /* capacity of base outline in contours */
+
+ FT_Vector last;
+
+ FT_Fixed scale_x;
+ FT_Fixed scale_y;
+
+ FT_Pos pos_x;
+ FT_Pos pos_y;
+
+ FT_Vector left_bearing;
+ FT_Vector advance;
+
+ FT_BBox bbox; /* bounding box */
+ FT_Bool path_begun;
+ FT_Bool load_points;
+ FT_Bool no_recurse;
+
+ FT_Error error; /* only used for memory errors */
+ FT_Bool metrics_only;
+
+ } T2_Builder;
+
+
+ /* execution context charstring zone */
+ typedef struct T2_Decoder_Zone_
+ {
+ FT_Byte* base;
+ FT_Byte* limit;
+ FT_Byte* cursor;
+
+ } T2_Decoder_Zone;
+
+
+ typedef struct T2_Decoder_
+ {
+ T2_Builder builder;
+ CFF_Font* cff;
+
+ FT_Fixed stack[ T2_MAX_OPERANDS+1 ];
+ FT_Fixed* top;
+
+ T2_Decoder_Zone zones[ T2_MAX_SUBRS_CALLS+1 ];
+ T2_Decoder_Zone* zone;
+
+ FT_Int flex_state;
+ FT_Int num_flex_vectors;
+ FT_Vector flex_vectors[7];
+
+ FT_Pos glyph_width;
+ FT_Pos nominal_width;
+
+ FT_Bool read_width;
+ FT_Int num_hints;
+ FT_Fixed* buildchar;
+ FT_Int len_buildchar;
+
+ FT_UInt num_locals;
+ FT_UInt num_globals;
+
+ FT_Int locals_bias;
+ FT_Int globals_bias;
+
+ FT_Byte** locals;
+ FT_Byte** globals;
+
+
+ } T2_Decoder;
+
+
+
LOCAL_DEF
- void T2_Get_Metrics( TT_HoriHeader* header,
- FT_UInt index,
- FT_Short* bearing,
- FT_UShort* advance );
-
-
- /*************************************************************************/
- /* */
- /* <Function> */
- /* T2_Load_Glyph */
- /* */
- /* <Description> */
- /* A function used to load a single glyph within a given glyph slot, */
- /* for a given size. */
- /* */
- /* <Input> */
- /* glyph :: A handle to a target slot object where the glyph */
- /* will be loaded. */
- /* */
- /* size :: A handle to the source face size at which the glyph */
- /* must be scaled/loaded. */
- /* */
- /* glyph_index :: The index of the glyph in the font file. */
- /* */
- /* load_flags :: A flag indicating what to load for this glyph. The */
- /* FT_LOAD_XXX constants can be used to control the */
- /* glyph loading process (e.g., whether the outline */
- /* should be scaled, whether to load bitmaps or not, */
- /* whether to hint the outline, etc). */
- /* <Output> */
- /* result :: A set of bit flags indicating the type of data that */
- /* was loaded in the glyph slot (outline or bitmap, */
- /* etc). */
- /* */
- /* You can set this field to 0 if you don't want this */
- /* information. */
- /* */
- /* <Return> */
- /* FreeType error code. 0 means success. */
- /* */
+ void T2_Init_Decoder( T2_Decoder* decoder,
+ TT_Face face,
+ T2_Size size,
+ T2_GlyphSlot slot );
+
+
+#if 0 /* unused until we support pure CFF fonts */
+ /* Compute the maximum advance width of a font through quick parsing */
LOCAL_DEF
- FT_Error T2_Load_Glyph( T2_Size size,
- T2_GlyphSlot glyph,
- FT_UShort glyph_index,
- FT_UInt load_flags );
+ FT_Error T2_Compute_Max_Advance( TT_Face face,
+ FT_Int *max_advance );
#endif
+ /* This function is exported, because it is used by the T1Dump utility */
+ LOCAL_DEF
+ FT_Error T2_Parse_CharStrings( T2_Decoder* decoder,
+ FT_Byte* charstring_base,
+ FT_Int charstring_len );
+
+
+
+ LOCAL_DEF
+ FT_Error T2_Load_Glyph( T2_GlyphSlot glyph,
+ T2_Size size,
+ FT_Int glyph_index,
+ FT_Int load_flags );
+
+
+
+
#ifdef __cplusplus
}
#endif
diff --git a/src/cff/t2load.c b/src/cff/t2load.c
index bc411f0..6544a61 100644
--- a/src/cff/t2load.c
+++ b/src/cff/t2load.c
@@ -25,7 +25,7 @@
#include <freetype/tttags.h>
#include <t2load.h>
#include <t2parse.h>
-#include <freetype/internal/t2errors.h>
+#include <t2errors.h>
#undef FT_COMPONENT
#define FT_COMPONENT trace_ttload
@@ -53,6 +53,7 @@
FT_UShort count;
MEM_Set( index, 0, sizeof(*index) );
+ index->stream = stream;
if ( !READ_UShort( count ) &&
count > 0 )
{
@@ -127,7 +128,36 @@
static
- FT_Error t2_access_element( CFF_Index* index,
+ FT_Error t2_explicit_cff_index( CFF_Index* index,
+ FT_Byte** *table )
+ {
+ FT_Error error = 0;
+ FT_Memory memory = index->stream->memory;
+ FT_UInt n, offset, old_offset;
+ FT_Byte** t;
+
+ *table = 0;
+ if ( index->count > 0 && !ALLOC_ARRAY( t, index->count+1, FT_Byte* ) )
+ {
+ old_offset = 1;
+ for ( n = 0; n <= index->count; n++ )
+ {
+ offset = index->offsets[n];
+ if (!offset)
+ offset = old_offset;
+
+ t[n] = index->bytes + offset - 1;
+
+ old_offset = offset;
+ }
+ *table = t;
+ }
+ return error;
+ }
+
+
+ LOCAL_FUNC
+ FT_Error T2_Access_Element( CFF_Index* index,
FT_UInt element,
FT_Byte* *pbytes,
FT_ULong *pbyte_len )
@@ -187,8 +217,8 @@
}
- static
- void t2_forget_element( CFF_Index* index,
+ LOCAL_FUNC
+ void T2_Forget_Element( CFF_Index* index,
FT_Byte* *pbytes )
{
if (index->bytes == 0)
@@ -199,8 +229,8 @@
}
- static
- FT_String* t2_get_name( CFF_Index* index,
+ LOCAL_FUNC
+ FT_String* T2_Get_Name( CFF_Index* index,
FT_UInt element )
{
FT_Memory memory = index->stream->memory;
@@ -209,7 +239,7 @@
FT_Error error;
FT_String* name = 0;
- error = t2_access_element( index, element, &bytes, &byte_len );
+ error = T2_Access_Element( index, element, &bytes, &byte_len );
if (error) goto Exit;
if ( !ALLOC( name, byte_len+1 ) )
@@ -217,14 +247,14 @@
MEM_Copy( name, bytes, byte_len );
name[byte_len] = 0;
}
- t2_forget_element( index, &bytes );
-
+ T2_Forget_Element( index, &bytes );
+
Exit:
return name;
}
-#if 0
+#if 0 /* unused until we fully support pure-CFF fonts */
LOCAL_FUNC
FT_String* T2_Get_String( CFF_Index* index,
FT_UInt sid,
@@ -232,7 +262,7 @@
{
/* if it's not a standard string, return it */
if ( sid > 390 )
- return t2_get_name( index, sid - 390 );
+ return T2_Get_Name( index, sid - 390 );
/* that's a standard string, fetch a copy from the psnamed module */
{
@@ -318,20 +348,39 @@
FT_Byte* dict;
FT_ULong dict_len;
CFF_Index* index = &font->top_dict_index;
+ CFF_Top_Dict* top = &font->top_dict;
/* parse the top-level font dictionary */
T2_Parser_Init( &parser, T2CODE_TOPDICT, &font->top_dict );
+
+ /* set defaults */
+ memset( top, 0, sizeof(*top) );
+ top->underline_position = -100;
+ top->underline_thickness = 50;
+ top->charstring_type = 2;
+ top->font_matrix.xx = 0x10000;
+ top->font_matrix.yy = 0x10000;
+ top->cid_count = 8720;
- error = t2_access_element( index, face_index, &dict, &dict_len ) ||
+ error = T2_Access_Element( index, face_index, &dict, &dict_len ) ||
T2_Parser_Run( &parser, dict, dict + dict_len );
- t2_forget_element( &font->top_dict_index, &dict );
+ T2_Forget_Element( &font->top_dict_index, &dict );
if (error) goto Exit;
/* parse the private dictionary, if any */
if (font->top_dict.private_offset && font->top_dict.private_size)
{
- T2_Parser_Init( &parser, T2CODE_PRIVATE, &font->private_dict );
+ CFF_Private* priv = &font->private_dict;
+
+ /* set defaults */
+ priv->blue_shift = 7;
+ priv->blue_fuzz = 1;
+ priv->lenIV = -1;
+ priv->expansion_factor = (FT_Fixed)0.06*0x10000;
+ priv->blue_scale = (FT_Fixed)0.039625*0x10000;
+
+ T2_Parser_Init( &parser, T2CODE_PRIVATE, priv );
if ( FILE_Seek( base_offset + font->top_dict.private_offset ) ||
ACCESS_Frame( font->top_dict.private_size ) )
@@ -357,10 +406,28 @@
error = t2_new_cff_index( &font->charstrings_index, stream, 0 );
if (error) goto Exit;
+
+ /* read the local subrs */
+ if ( FILE_Seek( base_offset + font->top_dict.private_offset +
+ font->private_dict.local_subrs_offset ) )
+ goto Exit;
+
+ error = t2_new_cff_index( &font->local_subrs_index, stream, 1 );
+ if (error) goto Exit;
+
+ /* explicit the global and local subrs */
+ font->num_local_subrs = font->local_subrs_index.count;
+ font->num_global_subrs = font->global_subrs_index.count;
+
+ error = t2_explicit_cff_index( &font->global_subrs_index,
+ &font->global_subrs ) ||
+ t2_explicit_cff_index( &font->local_subrs_index,
+ &font->local_subrs );
+ if (error) goto Exit;
}
/* get the font name */
- font->font_name = t2_get_name( &font->name_index, face_index );
+ font->font_name = T2_Get_Name( &font->name_index, face_index );
Exit:
return error;
@@ -369,11 +436,17 @@
LOCAL_FUNC
void T2_Done_CFF_Font( CFF_Font* font )
{
+ FT_Memory memory = font->memory;
+
t2_done_cff_index( &font->global_subrs_index );
t2_done_cff_index( &font->string_index );
t2_done_cff_index( &font->top_dict_index );
t2_done_cff_index( &font->name_index );
t2_done_cff_index( &font->charstrings_index );
+
+ FREE( font->local_subrs );
+ FREE( font->global_subrs );
+ FREE( font->font_name );
}
diff --git a/src/cff/t2load.h b/src/cff/t2load.h
index 720f05f..7a7d3b2 100644
--- a/src/cff/t2load.h
+++ b/src/cff/t2load.h
@@ -25,6 +25,28 @@
extern "C" {
#endif
+ LOCAL_FUNC
+ FT_String* T2_Get_Name( CFF_Index* index,
+ FT_UInt element );
+
+#if 0 /* will be used later for pure-CFF font support */
+ LOCAL_DEF
+ FT_String* T2_Get_String( CFF_Index* index,
+ FT_UInt sid,
+ PSNames_Interface* interface );
+#endif
+
+ LOCAL_DEF
+ FT_Error T2_Access_Element( CFF_Index* index,
+ FT_UInt element,
+ FT_Byte* *pbytes,
+ FT_ULong *pbyte_len );
+
+ LOCAL_DEF
+ void T2_Forget_Element( CFF_Index* index,
+ FT_Byte* *pbytes );
+
+
#ifdef __cplusplus
}
#endif
diff --git a/src/cff/t2objs.c b/src/cff/t2objs.c
index 5a99f5f..9dff0a4 100644
--- a/src/cff/t2objs.c
+++ b/src/cff/t2objs.c
@@ -104,12 +104,19 @@
{
CFF_Font* cff;
FT_Memory memory = face->root.memory;
+ FT_Face root;
if ( ALLOC( cff, sizeof(*cff) ) )
goto Exit;
face->other = cff;
error = T2_Load_CFF_Font( stream, face_index, cff );
+ if (error) goto Exit;
+
+ /* complement the root flags with some interesting information */
+ /* note that for OpenType/CFF, there is no need to do this, but */
+ /* this will be necessary for pure CFF fonts through.. */
+ root = &face->root;
}
Exit:
@@ -258,17 +265,13 @@
LOCAL_FUNC
FT_Error T2_Init_GlyphSlot( T2_GlyphSlot slot )
{
- /* allocate the outline space */
- FT_Face face = slot->face;
- FT_Library library = face->driver->library;
+ FT_Library library = slot->root.face->driver->library;
- FT_TRACE4(( "TT.Init_GlyphSlot: Creating outline maxp = %d, maxc = %d\n",
- face->max_points, face->max_contours ));
+ slot->max_points = 0;
+ slot->max_contours = 0;
+ slot->root.bitmap.buffer = 0;
- return FT_Outline_New( library,
- face->max_points + 2,
- face->max_contours,
- &slot->outline );
+ return FT_Outline_New( library, 0, 0, &slot->root.outline );
}
@@ -286,13 +289,13 @@
LOCAL_FUNC
void T2_Done_GlyphSlot( T2_GlyphSlot slot )
{
- FT_Library library = slot->face->driver->library;
+ FT_Library library = slot->root.face->driver->library;
FT_Memory memory = library->memory;
- if (slot->flags & ft_glyph_own_bitmap)
- FREE( slot->bitmap.buffer );
+ if (slot->root.flags & ft_glyph_own_bitmap)
+ FREE( slot->root.bitmap.buffer );
- FT_Outline_Done( library, &slot->outline );
+ FT_Outline_Done( library, &slot->root.outline );
return;
}
diff --git a/src/cff/t2objs.h b/src/cff/t2objs.h
index 73a212f..b3aaab0 100644
--- a/src/cff/t2objs.h
+++ b/src/cff/t2objs.h
@@ -65,7 +65,21 @@
/* This is a direct typedef of FT_GlyphSlot, as there is nothing */
/* specific about the OpenType glyph slot. */
/* */
- typedef FT_GlyphSlot T2_GlyphSlot;
+
+ typedef struct T2_GlyphSlotRec_
+ {
+ FT_GlyphSlotRec root;
+
+ FT_Bool hint;
+ FT_Bool scaled;
+
+ FT_Int max_points;
+ FT_Int max_contours;
+
+ FT_Fixed x_scale;
+ FT_Fixed y_scale;
+
+ } T2_GlyphSlotRec, *T2_GlyphSlot;
diff --git a/src/cff/t2parse.c b/src/cff/t2parse.c
index ea5b884..29d89bd 100644
--- a/src/cff/t2parse.c
+++ b/src/cff/t2parse.c
@@ -64,7 +64,7 @@
if (v == 28)
{
if ( p+2 > limit ) goto Bad;
- val = ((FT_Long)p[0] << 8) | p[1];
+ val = (FT_Short)(((FT_Int)p[0] << 8) | p[1]);
p += 2;
}
else if (v == 29)
@@ -261,10 +261,10 @@
error = T2_Err_Stack_Underflow;
if (parser->top >= parser->stack + 4)
{
- bbox->xMin = t2_parse_fixed( data++ );
- bbox->yMin = t2_parse_fixed( data++ );
- bbox->xMax = t2_parse_fixed( data++ );
- bbox->yMax = t2_parse_fixed( data );
+ bbox->xMin = t2_parse_num( data++ );
+ bbox->yMin = t2_parse_num( data++ );
+ bbox->xMax = t2_parse_num( data++ );
+ bbox->yMax = t2_parse_num( data );
error = 0;
}
return error;
@@ -281,8 +281,8 @@
error = T2_Err_Stack_Underflow;
if (parser->top >= parser->stack + 2)
{
- dict->private_offset = t2_parse_num( data++ );
- dict->private_size = t2_parse_num( data );
+ dict->private_size = t2_parse_num( data++ );
+ dict->private_offset = t2_parse_num( data );
error = 0;
}
return error;
@@ -319,7 +319,7 @@
#define T2_REF(s,f) (((s*)0)->f)
#define T2_FIELD_CALLBACK( code, name ) \
- { t2_kind_callback, code, 0, 0, parse_ ## name, 0, 0 },
+ { t2_kind_callback, code | T2CODE, 0, 0, parse_ ## name, 0, 0 },
#undef T2_FIELD
#define T2_FIELD( code, name, kind ) \
@@ -363,7 +363,7 @@
while (p < limit)
{
FT_Byte v = *p;
- if ( v >= 27 || v != 31 )
+ if ( v >= 27 && v != 31 )
{
/* its a number, we'll push its position on the stack */
if (parser->top - parser->stack >= T2_MAX_STACK_DEPTH)
@@ -404,6 +404,7 @@
/* first of all, a trivial check */
if ( num_args < 1 ) goto Stack_Underflow;
+ *parser->top = p;
code = v;
if (v == 12)
{
@@ -476,16 +477,14 @@
error = field->reader( parser );
if (error) goto Exit;
}
- /* clear stack */
- parser->top = parser->stack;
+ goto Found;
}
- goto Found; /* exit loop */
}
/* this is an unknown operator, or it is unsupported, we will ignore */
/* it for now... */
-
- Found:
+
+ Found:
/* clear stack */
parser->top = parser->stack;
}