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 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830
|
#if 0
#include "../inc/basics.h"
#else
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef unsigned int uint32;
typedef int int32;
typedef short int16;
typedef signed char int8;
typedef unsigned short uint16;
typedef unsigned char uint8;
#define true 1
#define false 0
#endif
#include <string.h>
static int verbose = false;
static int max_lig_nest = 10000;
static int just_headers = false;
struct dup {
int glyph;
int enc;
struct dup *prev;
};
struct features {
int feature;
int nsettings;
struct settings { uint16 setting; int16 nameid; char *name; } *settings;
int featureflags;
char *name;
int nameIndex;
};
struct ttfinfo {
int emsize; /* ascent + descent? from the head table */
int ascent, descent; /* from the hhea table */
/* not the usWinAscent from the OS/2 table */
int width_cnt; /* from the hhea table, in the hmtx table */
int glyph_cnt; /* from maxp table */
unsigned int index_to_loc_is_long:1; /* in head table */
/* Mac fonts platform=0/1, platform specific enc id, roman=0, english is lang code 0 */
/* iso platform=2, platform specific enc id, latin1=0/2, no language */
/* microsoft platform=3, platform specific enc id, 1, english is lang code 0x??09 */
char *copyright; /* from the name table, nameid=0 */
char *familyname; /* nameid=1 */
char *fullname; /* nameid=4 */
char *version; /* nameid=5 */
char *fontname; /* postscript font name, nameid=6 */
double italicAngle; /* from post table */
int upos, uwidth; /* underline pos, width from post table */
int ttccnt; /* if a ttc file, number of fonts */
int *ttcoffsets; /* Offsets to font headers */
int numtables;
/* BASE */
int base_start;
int base_length;
/* CFF */
int cff_start;
int cff_length;
/* cmap */
int encoding_start; /* Offset from sof to start of encoding table */
/* cvt */
int cvt_start;
int cvt_length;
/* glyf */
int glyph_start; /* Offset from sof to start of glyph table */
/* bdat */
/* EBDT */
int bitmapdata_start; /* Offset to start of bitmap data */
/* bloc */
/* EBLT */
int bitmaploc_start; /* Offset to start of bitmap locator data */
int bitmaploc_length;
/* EBSC */
int bitmapscale_start; /* Offset to start of bitmap scaling data */
/* feat */
int feat_start;
/* fdsc */
int fdsc_start;
/* gasp */
int gasp_start;
/* GDEF */
int gdef_start; /* OpenType glyph definitions */
/* GPOS */
int gpos_start; /* OpenType glyph positioning, kerning etc. */
/* GSUB */
int gsub_start; /* OpenType glyph substitution, ligatures etc. */
/* hdmx */
int hdmx_start;
/* head */
int head_start;
/* hhea */
int hhea_start;
/* hmtx */
int hmetrics_start;
/* JSFT */
int JSTF_start;
/* kern */
int kern_start;
int lcar_start;
/* loca */
int glyphlocations_start; /* there are glyph_cnt of these, from maxp tab */
int loca_length; /* actually glypn_cnt is wrong. Use the table length (divided by size) instead */
/* MATH */
int math_start;
/* maxp */
int maxp_start; /* maximum number of glyphs */
int maxp_length;
/* mort */
int mort_start; /* Apple metamorph tab, ligs, etc. */
int mort_length;
/* morx */
int morx_start; /* Apple extended metamorph tab, ligs, etc. */
int morx_length;
/* name */
int copyright_start; /* copyright and fontname */
int opbd_start;
/* post */
int postscript_start; /* names for the glyphs, italic angle, etc. */
int postscript_len; /* names for the glyphs, italic angle, etc. */
/* OS/2 */
int os2_start;
int os2_len;
/* fvar */
int fvar_start;
int fvar_length;
/* gvar */
int gvar_start;
int gvar_length;
int fpgm_start;
int fpgm_length;
int prep_start;
int prep_length;
int prop_start;
/* head */
int fftm_start;
unsigned int *glyph_unicode;
char **glyph_names;
struct dup *dups;
struct features *features;
uint16 *morx_classes;
int fvar_axiscount;
};
static int getushort(FILE *ttf) {
int ch1 = getc(ttf);
int ch2 = getc(ttf);
if ( ch2==EOF )
return( EOF );
return( (ch1<<8)|ch2 );
}
static int32 getlong(FILE *ttf) {
int ch1 = getc(ttf);
int ch2 = getc(ttf);
int ch3 = getc(ttf);
int ch4 = getc(ttf);
if ( ch4==EOF )
return( EOF );
return( (ch1<<24)|(ch2<<16)|(ch3<<8)|ch4 );
}
static int32 get3byte(FILE *ttf) {
int ch1 = getc(ttf);
int ch2 = getc(ttf);
int ch3 = getc(ttf);
if ( ch3==EOF )
return( EOF );
return( (ch1<<16)|(ch2<<8)|ch3 );
}
static int32 getoffset(FILE *ttf, int offsize) {
int ch1, ch2, ch3, ch4;
ch1 = getc(ttf);
if ( offsize==1 )
return( ch1 );
ch2 = getc(ttf);
if ( offsize==2 ) {
if ( ch2==EOF )
return( EOF );
return( (ch1<<8)|ch2);
}
ch3 = getc(ttf);
if ( offsize==3 ) {
if ( ch3==EOF )
return( EOF );
return( (ch1<<16)|(ch2<<8)|ch3 );
}
ch4 = getc(ttf);
if ( ch4==EOF )
return( EOF );
return( (ch1<<24)|(ch2<<16)|(ch3<<8)|ch4 );
}
static double getfixed(FILE *ttf) {
int32 val = getlong(ttf);
int mant = val&0xffff;
/* This oddity may be needed to deal with the first 16 bits being signed */
/* and the low-order bits unsigned */
return( (double) (val>>16) + (mant/65536.0) );
}
static double long2fixed(int32 val) {
int mant = val&0xffff;
/* This oddity may be needed to deal with the first 16 bits being signed */
/* and the low-order bits unsigned */
return( (double) (val>>16) + (mant/65536.0) );
}
#if 0
static double get2dot14(FILE *ttf) {
int32 val = getushort(ttf);
int mant = val&0x3fff;
/* This oddity may be needed to deal with the first 2 bits being signed */
/* and the low-order bits unsigned */
return( (double) ((val<<16)>>(16+14)) + (mant/16384.0) );
}
#endif
static int32 filecheck(FILE *file, int start, int len) {
uint32 sum = 0, chunk;
fseek(file,start,SEEK_SET);
if ( len!=-1 ) len=(len+3)>>2;
while ( len==-1 || --len>=0 ) {
chunk = getlong(file);
if ( feof(file))
break;
sum += chunk;
}
return( sum );
}
#define CHR(ch1,ch2,ch3,ch4) (((ch1)<<24)|((ch2)<<16)|((ch3)<<8)|(ch4))
static int readcff(FILE *ttf,FILE *util, struct ttfinfo *info);
static int readttfheader(FILE *ttf, FILE *util, struct ttfinfo *info) {
int i;
int tag, checksum, offset, length, sr, es, rs, cs; uint32 v;
int e_sr, e_es, e_rs;
double version;
v = getlong(ttf);
if ( v==CHR('t','t','c','f')) {
v = getlong(ttf);
info->ttccnt = getlong(ttf);
printf( "This is a TrueType Font Collection file (version=%x), with %d fonts\n", v, info->ttccnt );
info->ttcoffsets = calloc(info->ttccnt,sizeof(int));
for ( i = 0; i<info->ttccnt; ++i ) {
info->ttcoffsets[i] = getlong(ttf);
printf( " Offset to font %d header: %d\n", i, info->ttcoffsets[i]);
}
return(true);
}
version = long2fixed(v);
info->numtables = getushort(ttf);
sr = getushort(ttf),
es = getushort(ttf),
rs = getushort(ttf);
if ( v==CHR('O','T','T','O'))
printf( "version='OTTO', " );
else if ( v==CHR('t','r','u','e'))
printf( "version='true', " );
else if ( v==CHR('S','p','l','i')) {
fprintf(stderr, "This looks like one of fontforge's spline font databases, and not a truetype font.\n" );
exit ( 1 );
} else if ( v==CHR('%','!','P','S')) {
fprintf(stderr, "This looks like a postscript (pfa) file, and not a truetype font.\n" );
exit ( 1 );
} else if ( v>=0x80000000 && info->numtables==0 ) {
fprintf(stderr, "This looks like a postscript (pfb) file, and not a truetype font.\n" );
exit ( 1 );
} else if ( (v>>24)==1 && ((v>>16)&0xff)==0 && ((v>>8)&0xff)==4 ) {
fprintf( stderr, "This looks like a bare CFF file. Proceding under that assumption.\n");
info->cff_start = 0;
fseek(ttf,0,SEEK_END);
info->cff_length = ftell(ttf);
rewind(ttf);
readcff(ttf,util,info);
exit(0);
} else if ( v==CHR('t','y','p','1')) {
printf( "version='typ1', " );
/* This is apple's embedding of a type1 font in a truetype file. I don't know how to parse it. I'd like a copy to look at if you don't mind sending me one... gww@silcom.com */
} else
printf( "version=%g, ", version );
printf( "numtables=%d, searchRange=%d entrySel=%d rangeshift=%d\n",
info->numtables, sr, es, rs);
e_sr = (info->numtables<8?4:info->numtables<16?8:info->numtables<32?16:info->numtables<64?32:64)*16;
e_es = (info->numtables<8?2:info->numtables<16?3:info->numtables<32?4:info->numtables<64?5:6);
e_rs = info->numtables*16-e_sr;
if ( e_sr!=sr || e_es!=es || e_rs!=rs )
printf( "!!!! Unexpected values for binsearch header. Based on the number of tables I\n!!!!! expect searchRange=%d (not %d), entrySel=%d (not %d) rangeShift=%d (not %d)\n",
e_sr, sr, e_es, es, e_rs, rs );
/* The one example I have of a ttc file has the file checksum set to: 0xdcd07d3e */
/* I don't know if that's magic or not (docs don't say), but it vaguely follows */
/* the same pattern as 0xb1b0afba so it might be */
/* All the fonts used the same head table so one difficulty was eased */
printf( "File Checksum =%x (should be 0xb1b0afba), diff=%x\n",
filecheck(util,0,-1), 0xb1b0afba-filecheck(util,0,-1));
for ( i=0; i<info->numtables; ++i ) {
tag = getlong(ttf);
checksum = getlong(ttf);
offset = getlong(ttf);
length = getlong(ttf);
cs = filecheck(util,offset,length);
printf( "%c%c%c%c checksum=%08x actual=%08x diff=%x offset=%d len=%d\n",
tag>>24, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff,
checksum, cs, checksum^cs,
offset, length );
switch ( tag ) {
case CHR('B','A','S','E'):
info->base_start = offset;
info->base_length = length;
break;
case CHR('C','F','F',' '):
info->cff_start = offset;
info->cff_length = length;
break;
case CHR('c','m','a','p'):
info->encoding_start = offset;
break;
case CHR('c','v','t',' '):
info->cvt_start = offset;
info->cvt_length = length;
break;
case CHR('F','F','T','M'):
info->fftm_start = offset;
break;
case CHR('f','p','g','m'):
info->fpgm_start = offset;
info->fpgm_length = length;
break;
case CHR('f','v','a','r'):
info->fvar_start = offset;
info->fvar_length = length;
break;
case CHR('f','e','a','t'):
info->feat_start = offset;
break;
case CHR('f','d','s','c'):
info->fdsc_start = offset;
break;
case CHR('g','a','s','p'):
info->gasp_start = offset;
break;
case CHR('g','l','y','f'):
info->glyph_start = offset;
break;
case CHR('G','D','E','F'):
info->gdef_start = offset;
break;
case CHR('G','P','O','S'):
info->gpos_start = offset;
break;
case CHR('G','S','U','B'):
info->gsub_start = offset;
break;
case CHR('g','v','a','r'):
info->gvar_start = offset;
info->gvar_length = length;
break;
case CHR('m','o','r','t'):
info->mort_start = offset;
info->mort_length = length;
break;
case CHR('m','o','r','x'):
info->morx_start = offset;
info->morx_length = length;
break;
case CHR('b','d','a','t'):
case CHR('E','B','D','T'):
info->bitmapdata_start = offset;
break;
case CHR('b','l','o','c'):
case CHR('E','B','L','C'):
info->bitmaploc_start = offset;
info->bitmaploc_length = length;
break;
case CHR('E','B','S','C'): /* Apple uses the same as MS on this one */
info->bitmapscale_start = offset;
break;
case CHR('h','d','m','x'):
info->hdmx_start = offset;
break;
case CHR('b','h','e','d'): /* Fonts with bitmaps but no outlines get bhea */
case CHR('h','e','a','d'):
info->head_start = offset;
if ( length!=54 ) fprintf( stderr, "> ! Unexpected length for head table, was %d expected 54 ! <\n", length );
break;
case CHR('h','h','e','a'):
info->hhea_start = offset;
if ( length!=36 ) fprintf( stderr, "> ! Unexpected length for hhea table, was %d expected 36 ! <\n", length );
break;
case CHR('h','m','t','x'):
info->hmetrics_start = offset;
break;
case CHR('k','e','r','n'):
info->kern_start = offset;
break;
case CHR('J','S','T','F'):
info->JSTF_start = offset;
break;
case CHR('l','o','c','a'):
info->glyphlocations_start = offset;
info->loca_length = length;
info->glyph_cnt = length/2-1;
break;
case CHR('M','A','T','H'):
info->math_start = offset;
break;
case CHR('m','a','x','p'):
info->maxp_start = offset;
if ( length!=32 && length!=6 ) fprintf( stderr, "> ! Unexpected length for maxp table, was %d expected 32 ! <\n", length );
info->maxp_length = length;
break;
case CHR('n','a','m','e'):
info->copyright_start = offset;
break;
case CHR('o','p','b','d'):
info->opbd_start = offset;
break;
case CHR('p','o','s','t'):
info->postscript_start = offset;
info->postscript_len = length;
break;
case CHR('O','S','/','2'):
info->os2_start = offset;
info->os2_len = length;
if ( length!=78 && length!=86 && length!=96 )
fprintf( stderr, "> ! Unexpected length for OS/2 table, was %d expected either 78 or 86 ! <\n", length );
break;
case CHR('p','r','e','p'):
info->prep_start = offset;
info->prep_length = length;
break;
case CHR('p','r','o','p'):
info->prop_start = offset;
break;
}
}
if ( (info->encoding_start!=0 && info->glyph_start==0 && info->head_start!=0 &&
info->hhea_start!=0 && info->hmetrics_start!=0 && info->glyphlocations_start == 0 &&
info->maxp_start!=0 && info->copyright_start!=0 && info->postscript_start!=0 &&
info->os2_start!=0 ) && info->cff_start!=0 ) {
fprintf( stderr, "Required tables: glyf and loca have been replaced by CFF => OpenType\n" );
} else if ( info->encoding_start==0 || info->glyph_start==0 || info->head_start==0 ||
info->hhea_start==0 || info->hmetrics_start==0 || info->glyphlocations_start == 0 ||
info->maxp_start==0 || info->copyright_start==0 || info->postscript_start==0 ||
info->os2_start==0 ) {
fprintf( stderr, "Required table(s) missing: " );
if ( info->encoding_start==0 ) fprintf(stderr,"cmap ");
if ( info->glyph_start==0 ) fprintf(stderr,"glyf ");
if ( info->head_start==0 ) fprintf(stderr,"head ");
if ( info->hhea_start==0 ) fprintf(stderr,"hhea ");
if ( info->hmetrics_start==0 ) fprintf(stderr,"hmtx ");
if ( info->glyphlocations_start==0 ) fprintf(stderr,"loca ");
if ( info->maxp_start==0 ) fprintf(stderr,"maxp ");
if ( info->copyright_start==0 ) fprintf(stderr,"name ");
if ( info->postscript_start==0 ) fprintf(stderr,"post ");
if ( info->os2_start==0 ) fprintf(stderr,"OS/2");
fprintf(stderr,"\n");
}
return( true );
}
static time_t readdate(FILE *ttf) {
int date[4], date1970[4], year[2];
int i;
/* Dates in sfnt files are seconds since 1904. I adjust to unix time */
/* seconds since 1970 by figuring out how many seconds were in between */
date[3] = getushort(ttf);
date[2] = getushort(ttf);
date[1] = getushort(ttf);
date[0] = getushort(ttf);
memset(date1970,0,sizeof(date1970));
year[0] = (60*60*24*365L)&0xffff;
year[1] = (60*60*24*365L)>>16;
for ( i=1904; i<1970; ++i ) {
date1970[0] += year[0];
date1970[1] += year[1];
if ( (i&3)==0 && (i%100!=0 || i%400==0))
date1970[0] += 24*60*60L; /* Leap year */
date1970[1] += (date1970[0]>>16);
date1970[0] &= 0xffff;
date1970[2] += date1970[1]>>16;
date1970[1] &= 0xffff;
date1970[3] += date1970[2]>>16;
date1970[2] &= 0xffff;
}
for ( i=0; i<3; ++i ) {
date[i] -= date1970[i];
date[i+1] += date[i]>>16;
date[i] &= 0xffff;
}
date[3] -= date1970[3];
return( (date[1]<<16) | date[0] );
}
static void readttfFFTM(FILE *ttf, FILE *util, struct ttfinfo *info) {
time_t unix_date;
struct tm *tm;
static const char *months[] = { "Jan", "Feb", "March", "April", "May",
"June", "July", "August", "Sept", "Oct", "Nov", "Dec", NULL };
fseek(ttf,info->fftm_start,SEEK_SET);
printf( "\n\nCreated by FontForge " );
if ( getlong(ttf)!=0x00000001 ) {
fprintf( stderr, "Unknown version for 'FFTM' table\n" );
} else {
unix_date = readdate(ttf);
tm = localtime(&unix_date);
printf( "%d:%02d %02d-%s-%d\n",
tm->tm_hour, tm->tm_min, tm->tm_mday, months[tm->tm_mon],
tm->tm_year+1900 );
unix_date = readdate(ttf);
printf( "\tFont created: %s", ctime(&unix_date));
unix_date = readdate(ttf);
printf( "\tFont modified: %s", ctime(&unix_date));
}
printf( "\n" );
}
static void readttfhead(FILE *ttf, FILE *util, struct ttfinfo *info) {
int mn, flags, fd;
time_t unix_date;
fseek(ttf,info->head_start,SEEK_SET);
printf( "\nHEAD table (at %d)\n", info->head_start );
printf( "\tVersion=%g\n", getfixed(ttf));
printf( "\tfontRevision=%g\n", getfixed(ttf));
printf( "\tchecksumAdj=%x\n", getlong(ttf));
mn = getlong(ttf);
printf( "\tmagicNumber=%x (0x5f0f3cf5, diff=%x)\n", mn, mn-0x5f0f3cf5);
printf( "\tflags=%x ", flags=getushort(ttf));
if ( flags&1 ) printf( "baseline_at_0 " );
if ( flags&2 ) printf( "lsb_at_0 " );
if ( flags&4 ) printf( "instrs_depend_on_size " );
if ( flags&8 ) printf( "ppem_to_int " );
if ( flags&16 ) printf( "instr_set_width " );
printf( "\n" );
printf( "\tunitsPerEm=%d\n", getushort(ttf));
printf( "\tcreate[0]=%x\n", getlong(ttf));
printf( "\t create[1]=%x\n", getlong(ttf));
fseek(ttf,-8,SEEK_CUR);
unix_date = readdate(ttf);
printf( "\tFile created: %s", ctime(&unix_date));
printf( "\tmodtime[0]=%x\n", getlong(ttf));
printf( "\t modtime[1]=%x\n", getlong(ttf));
fseek(ttf,-8,SEEK_CUR);
unix_date = readdate(ttf);
printf( "\tFile modified: %s", ctime(&unix_date));
printf( "\txmin=%d\n", (short) getushort(ttf));
printf( "\tymin=%d\n", (short) getushort(ttf));
printf( "\txmax=%d\n", (short) getushort(ttf));
printf( "\tymax=%d\n", (short) getushort(ttf));
printf( "\tmacstyle=%x\n", getushort(ttf));
printf( "\tlowestppem=%d\n", getushort(ttf));
printf( "\tfontdirhint=%d ", fd = getushort(ttf));
switch ( fd ) {
case 0: printf("mixed directional glyphs\n" ); break;
case 1: printf("strongly left to right glyphs\n" ); break;
case 2: printf("left to right and neutrals\n" ); break;
case -1: printf("strongly right to left glyphs\n" ); break;
case -2: printf("right to left and neutrals\n" ); break;
default: printf("???\n" ); break;
}
printf( "\tloca_is_32=%d\n", info->index_to_loc_is_long = getushort(ttf));
if ( info->index_to_loc_is_long )
info->glyph_cnt = info->loca_length/4-1;
printf( "\tglyphdataformat=%d\n", getushort(ttf));
}
static void readttfhhead(FILE *ttf, FILE *util, struct ttfinfo *info) {
fseek(ttf,info->hhea_start,SEEK_SET);
printf( "\nHHEAD table (at %d)\n", info->hhea_start );
printf( "\tVersion=%g\n", getfixed(ttf));
printf( "\tascender=%d\n", (short) getushort(ttf));
printf( "\tdescender=%d\n", (short) getushort(ttf));
printf( "\tlinegap=%d\n", (short) getushort(ttf));
printf( "\tadvanceWidthMax=%d\n", getushort(ttf));
printf( "\tminlsb=%d\n", (short) getushort(ttf));
printf( "\tminrsb=%d\n", (short) getushort(ttf));
printf( "\tmaxextent=%d\n", (short) getushort(ttf));
printf( "\tcaretsloperise=%d\n", (short) getushort(ttf));
printf( "\tcaretsloperun=%d\n", (short) getushort(ttf));
printf( "\tmbz=%d\n", (short) getushort(ttf));
printf( "\tmbz=%d\n", (short) getushort(ttf));
printf( "\tmbz=%d\n", (short) getushort(ttf));
printf( "\tmbz=%d\n", (short) getushort(ttf));
printf( "\tmbz=%d\n", (short) getushort(ttf));
printf( "\tmetricdataformat=%d\n", (short) getushort(ttf));
printf( "\tnumberOfHMetrics=%d\n", getushort(ttf));
}
static char *getttfname(FILE *util, struct ttfinfo *info, int nameid) {
int nrec, taboff, stroff, strlen, platform;
int i,j,id;
fseek(util,info->copyright_start,SEEK_SET);
/* format */ getushort(util);
nrec=getushort(util);
taboff=getushort(util);
for ( i=0; i<nrec; ++i ) {
platform = getushort(util);
/* plat spec encoding */ getushort(util);
/* language */ getushort(util);
id=getushort(util);
strlen=getushort(util);
stroff=getushort(util);
if ( platform==1 && id==nameid ) {
char *ret = malloc(strlen+2); /* In case it's unicode */
fseek(util,info->copyright_start+taboff+stroff,SEEK_SET);
for ( j=0; j<strlen; ++j )
ret[j] = getc(util);
ret[strlen] = '\0';
ret[strlen+1] = '\0';
return( ret );
}
}
return( NULL );
}
static void readttfname(FILE *ttf, FILE *util, struct ttfinfo *info) {
int nrec, taboff, stroff, strlen;
int i,j,id;
fseek(ttf,info->copyright_start,SEEK_SET);
printf( "\nNAME table (at %d)\n", info->copyright_start );
printf( "\tformat=%d\n", getushort(ttf));
printf( "\tnrecords=%d\n", nrec=getushort(ttf));
printf( "\ttaboff=%d\n", taboff=getushort(ttf));
for ( i=0; i<nrec; ++i ) {
printf( "\t platform=%d", getushort(ttf));
printf( " plat spec encoding=%d", getushort(ttf));
printf( " language=%x", getushort(ttf));
printf( " name=%d ", id=getushort(ttf));
/* Name IDs defined in original TTF docs */
printf( id==0?"Copyright\n":id==1?"Family\n":id==2?"Subfamily\n":id==3?
"UniqueID\n":id==4?"FullName\n":id==5?"Version\n":id==6?"Postscript\n":
id==7?"Trademark\n":
/* OpenType extensions. documented: http://partners.adobe.com/asn/developer/opentype/recom.html */
id==8?"Manufacturer\n":
id==9?"Designer\n":
id==10?"Descriptor\n":
id==11?"Vender URL\n":
id==12?"Designer URL\n":
/* Guesse based on ARIAL.TTF usage. Not documented that I've seen */
id==13?"License\n":
/* Guesses based on OpenType usage. Not documented that I've seen */
id==14?"License URL\n":
/* 15 is reserved */
id==16?"Preferred Family Name\n":
id==17?"Preferred Subfamily\n":
id==18?"Compatible full\n":
id==19?"Sample Text\n":
/* End guesses */
"???????\n");
printf( "\t strlen=%d ", strlen=getushort(ttf));
printf( " stroff=%d\t ", stroff=getushort(ttf));
fseek(util,info->copyright_start+taboff+stroff,SEEK_SET);
for ( j=0; j<strlen; ++j ) {
int ch = getc(util);
if ( ch<' ' ) {
putchar('^');
putchar(ch+'@');
} else if ( ch=='\177' ) {
putchar('^');
putchar('?');
} else if ( ch>=0x80 && ch<0xa0 ) {
printf("<%2X>", ch );
} else
putchar(ch);
}
putchar('\n');
}
}
static void readttfmaxp(FILE *ttf, FILE *util, struct ttfinfo *info) {
int ng;
fseek(ttf,info->maxp_start,SEEK_SET);
printf( "\nMAXP table (at %d)\n", info->maxp_start );
printf( "\tVersion=%g\n", getfixed(ttf));
printf( "\t numGlyphs=%d\n", ng = getushort(ttf));
info->glyph_cnt = ng; /* Open type doesn't have a loca table */
if ( info->maxp_length==6 ) /* Open Type */
return;
printf( "\t maxPoints=%d\n", getushort(ttf));
printf( "\t maxContours=%d\n", getushort(ttf));
printf( "\t maxCompositPoints=%d\n", getushort(ttf));
printf( "\t maxCompositContours=%d\n", getushort(ttf));
printf( "\t maxZones=%d\n", getushort(ttf));
printf( "\t maxTwilightPoints=%d\n", getushort(ttf));
printf( "\t maxStorage=%d\n", getushort(ttf));
printf( "\t maxFunctionDefs=%d\n", getushort(ttf));
printf( "\t maxInstructionDefs=%d\n", getushort(ttf));
printf( "\t maxStackElements=%d\n", getushort(ttf));
printf( "\t maxSizeOfInstructions=%d\n", getushort(ttf));
printf( "\t maxComponentElements=%d\n", getushort(ttf));
printf( "\t maxComponentDepth=%d\n", getushort(ttf));
}
static void readttfcvt(FILE *ttf, FILE *util, struct ttfinfo *info) {
int i;
if ( info->cvt_start==0 )
return;
fseek(ttf,info->cvt_start,SEEK_SET);
printf( "\nCVT table (at %d, len=%d)\n", info->cvt_start, info->cvt_length );
for ( i=0; i<info->cvt_length/2; ++i )
printf( " CVT[%d] = %d\n", i, (short) getushort(ttf));
}
static void readttfos2(FILE *ttf, FILE *util, struct ttfinfo *info) {
int i, val;
static char *weights[] = { "Unspecified", "Thin", "Extra-Light", "Light", "Normal", "Medium", "Semi-Bold", "Bold", "Extra-Bold", "Black", "???" };
static char *widths[] = { "Unspecified", "Ultra-Condensed", "Extra-Condensed", "Condensed", "Semi-Condensed", "Medium", "Semi-Expanded", "Expanded", "Extra-Expanded", "Ultra-Expanded", "???" };
static char *class[16] = { "No classification", "Old Style Serifs", "Transitional Serifs", "Modern Serifs", "Clarendon Serifs", "Slab Serifs", "???", "Freeform Serifs", "Sans Serif", "Ornamentals", "Scripts", "???", "Symbolic", "???", "???", "???" };
static char *subclass0[16] = { "", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "Misc" };
static char *subclass1[16] = { "", "ibm rounded", "garalde", "venetian", "modified venetian", "dutch modern", "dutch traditional", "contemporary", "caligraphic", "???", "???", "???", "???", "???", "???", "Misc" };
static char *subclass2[16] = { "", "direct line", "script", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "Misc" };
static char *subclass3[16] = { "", "italian", "script", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "Misc" };
static char *subclass4[16] = { "", "clarendon", "modern", "traditional", "newspaper", "stub", "monotone", "typewriter", "???", "???", "???", "???", "???", "???", "???", "Misc" };
static char *subclass5[16] = { "", "monotone", "humanist", "geometric", "swiss", "typewriter", "???", "???", "???", "???", "???", "???", "???", "???", "???", "Misc" };
static char *subclass7[16] = { "", "modern", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "Misc" };
static char *subclass8[16] = { "", "ibm neogrotesque", "humanist", "low-x rounded", "high-x rounded", "neo-grotesque", "modified neo-grotesque", "???", "???", "typewriter", "matrix", "???", "???", "???", "???", "Misc" };
static char *subclass9[16] = { "", "engraver", "black letter", "decorative", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "???", "Misc" };
static char *subclass10[16] = { "", "???", "uncial", "brush joined", "formal joined", "monotone joined", "calligraphic", "brush unjoined", "formal unjoined", "monotone unjoined", "???", "???", "???", "???", "???", "Misc" };
static char *subclass12[16] = { "", "???", "???", "mixed serif", "???", "???", "old style serif", "neo-grotesque sans", "???", "???", "???", "???", "???", "???", "???", "Misc" };
static char **subclasses[16] = { subclass0, subclass1, subclass2, subclass3,
subclass4, subclass5, subclass0, subclass7, subclass8, subclass9,
subclass10, subclass0, subclass12, subclass0, subclass0, subclass0 };
static char *panose0[] = { "Any", "No Fit", "Text & Display", "Script", "Decorative", "Pictoral" };
static char *panose1[] = { "Any", "No Fit", "Cove", "Obtuse Cove", "Square Cove", "Obtuse Square Cove", "Square", "Thin", "Bone", "Exaggerated", "Triangle", "Normal Sans", "Obtuse Sans", "Perp Sans", "Flared", "Rounded" };
static char *panose2[] = { "Any", "No Fit", "Very Light", "Light", "Thin", "Book", "Medium", "Demi", "Bold", "Heavy", "Black", "Nord" };
static char *panose3[] = { "Any", "No Fit", "Old Style", "Modern", "Even Width", "Expanded", "Condensed", "Very Expanded", "Very Condensed", "Monospaced" };
static char *panose4[] = { "Any", "No Fit", "None", "Very Low", "Low", "Medium Low", "Medium", "Medium High", "High", "Very High" };
static char *panose5[] = { "Any", "No Fit", "Gradual/Diagonal", "Gradual/Transitional", "Gradual/Vertical", "Gradual/Horizontal", "Rapid/Vertical", "Rapid/Horizontal", "Instant/Vertical" };
static char *panose6[] = { "Any", "No Fit", "Straight Arms/Horizontal", "Straight Arms/Wedge", "Straight Arms/Vertical", "Straight Arms/Single Serif", "Straight Arms/Double Serif", "Non-Straight Arms/Horizontal", "Non-Straight Arms/Wedge", "Non-Straight Arms/Vertical", "Non-Straight Arms/Single Serif", "Non-Straight Arms/Double Serif" };
static char *panose7[] = { "Any", "No Fit", "Normal/Contact", "Normal/Weighted", "Normal/Boxed", "Normal/Flattened", "Normal/Rounded", "Normal/Off-Center", "Normal/Square", "Oblique/Contact", "Oblique/Weighted", "Oblique/Boxed", "Oblique/Flattened", "Oblique/Rounded", "Oblique/Off-Center", "Oblique/Square" };
static char *panose8[] = { "Any", "No Fit", "Standard/Trimmed", "Standard/Pointed", "Standard/Serifed", "High/Trimmed", "High/Pointed", "High/Serifed", "Constant/Trimmed", "Constant/Pointed", "Constant/Serifed", "Low/Trimmed", "Low/Pointed", "Low/Serifed" };
static char *panose9[] = { "Any", "No Fit", "Constant/Small", "Constant/Standard", "Constant/Large", "Ducking/Small", "Ducking/Standard", "Ducking/Large" };
static struct { char *name; char **choices; int cnt; } panose[10] = {
{ "Family", panose0, sizeof(panose0) },
{ "Serif Type", panose1, sizeof(panose1) },
{ "Weight", panose2, sizeof(panose2) },
{ "Proportion", panose3, sizeof(panose3) },
{ "Contrast", panose4, sizeof(panose4) },
{ "Stroke Variation", panose5, sizeof(panose5) },
{ "Arm Style", panose6, sizeof(panose6) },
{ "Letterform", panose7, sizeof(panose7) },
{ "Midline", panose8, sizeof(panose8) },
{ "X-Height", panose9, sizeof(panose9) } };
fseek(ttf,info->os2_start,SEEK_SET);
printf( "\nOS/2 table (at %d for %d bytes)\n", info->os2_start, info->os2_len );
printf( "\tVersion=%d\n", getushort(ttf));
printf( "\t avgWidth=%d\n", (short)getushort(ttf));
printf( "\t weightClass=%d ", val = getushort(ttf));
if ( val>=0 && val<=999 ) printf( "%s\n", weights[val/100] ); else printf( "???\n");
printf( "\t widthClass=%d ", val = getushort(ttf));
if ( val>=0 && val<=9 ) printf( "%s\n", widths[val] ); else printf( "???\n");
printf( "\t fstype=0x%x ", val = (short) getushort(ttf));
if ( val&0x8 ) printf( "Editable embedding\n");
else if ( val&0x4 ) printf( "Preview & Print embedding\n");
else if ( val&0x2 ) printf( "Restricted license embedding\n");
else printf( "\n");
printf( "\t ySubscript XSize=%d\n", (short) getushort(ttf));
printf( "\t ySubscript YSize=%d\n", (short) getushort(ttf));
printf( "\t ySubscript XOffset=%d\n", (short) getushort(ttf));
printf( "\t ySubscript YOffset=%d\n", (short) getushort(ttf));
printf( "\t ySupscript XSize=%d\n", (short) getushort(ttf));
printf( "\t ySupscript YSize=%d\n", (short) getushort(ttf));
printf( "\t ySupscript XOffset=%d\n", (short) getushort(ttf));
printf( "\t ySupscript YOffset=%d\n", (short) getushort(ttf));
printf( "\t yStrikeoutSize=%d\n", (short) getushort(ttf));
printf( "\t yStrikeoutPos=%d\n", (short) getushort(ttf));
printf( "\t sFamilyClass=%04x ", val = getushort(ttf));
if ( (val>>8)>=0 && (val>>8)<16 ) {
printf( "%s ", class[val>>8]);
if ( (val&0xff)<16 )
printf( "%s\n", subclasses[val>>8][val&0xff]);
else
printf( "???\n" );
} else printf ( "??? ???\n" );
printf( "\t Panose\n" );
for ( i=0; i<10; ++i ) {
printf( "\t\t%s: %02x ", panose[i].name, val= getc(ttf));
if ( val>0 && val<panose[i].cnt ) printf( "%s\n", panose[i].choices[val]);
else printf( "???\n" );
}
printf( "\n");
printf( "\t UnicodeRange=%08x ", getlong(ttf));
printf( "%08x ", getlong(ttf));
printf( "%08x ", getlong(ttf));
printf( "%08x\n", getlong(ttf));
printf( "\t achVendId " );
for ( i=0; i<4; ++i )
printf( "%02x ", getc(ttf));
printf( "\n");
printf( "\t fsSelection=%d\n", getushort(ttf));
printf( "\t firstcharindex=%d\n", getushort(ttf));
printf( "\t lastcharindex=%d\n", getushort(ttf));
printf( "\t stypeascender=%d\n", getushort(ttf));
printf( "\t stypedescender=%d\n", (short) getushort(ttf));
printf( "\t stypelinegap=%d\n", getushort(ttf));
printf( "\t usWinAscent=%d\n", getushort(ttf));
printf( "\t usWinDescent=%d\n", (short) getushort(ttf));
if ( info->os2_len==78 ) {
printf( "\t (no CodePageRange)\n" );
} else {
printf( "\t CodePageRange=%08x ", getlong(ttf));
printf( "%08x\n", getlong(ttf));
if ( info->os2_len==96 ) {
/* Open type additions */
printf( "\txHeight=%d\n", (short) getushort(ttf));
printf( "\tCapHeight=%d\n", (short) getushort(ttf));
printf( "\tDefaultChar=%d\n", getushort(ttf)); /* 0, or space I guess */
printf( "\tBreakChar=%d\n", getushort(ttf)); /* space */
printf( "\tMaxContext=%d\n", getushort(ttf)); /* Maximum look-ahead needed for processing. kerning=>2. 3letter ligature=>3, 4letter=>4 */
}
}
}
const unsigned short unicode_from_mac[] = {
0x0000, 0x00d0, 0x00f0, 0x0141, 0x0142, 0x0160, 0x0161, 0x00dd,
0x00fd, 0x0009, 0x000a, 0x00de, 0x00fe, 0x000d, 0x017d, 0x017e,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x00bd, 0x00bc, 0x00b9,
0x00be, 0x00b3, 0x00b2, 0x00a6, 0x00ad, 0x00d7, 0x001e, 0x001f,
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f,
0x00c4, 0x00c5, 0x00c7, 0x00c9, 0x00d1, 0x00d6, 0x00dc, 0x00e1,
0x00e0, 0x00e2, 0x00e4, 0x00e3, 0x00e5, 0x00e7, 0x00e9, 0x00e8,
0x00ea, 0x00eb, 0x00ed, 0x00ec, 0x00ee, 0x00ef, 0x00f1, 0x00f3,
0x00f2, 0x00f4, 0x00f6, 0x00f5, 0x00fa, 0x00f9, 0x00fb, 0x00fc,
0x2020, 0x00b0, 0x00a2, 0x00a3, 0x00a7, 0x2022, 0x00b6, 0x00df,
0x00ae, 0x00a9, 0x2122, 0x00b4, 0x00a8, 0x2260, 0x00c6, 0x00d8,
0x221e, 0x00b1, 0x2264, 0x2265, 0x00a5, 0x00b5, 0x2202, 0x2211,
0x220f, 0x03c0, 0x222b, 0x00aa, 0x00ba, 0x2126, 0x00e6, 0x00f8,
0x00bf, 0x00a1, 0x00ac, 0x221a, 0x0192, 0x2248, 0x2206, 0x00ab,
0x00bb, 0x2026, 0x00a0, 0x00c0, 0x00c3, 0x00d5, 0x0152, 0x0153,
0x2013, 0x2014, 0x201c, 0x201d, 0x2018, 0x2019, 0x00f7, 0x25ca,
0x00ff, 0x0178, 0x2044, 0x00a4, 0x2039, 0x203a, 0xfb01, 0xfb02,
0x2021, 0x00b7, 0x201a, 0x201e, 0x2030, 0x00c2, 0x00ca, 0x00c1,
0x00cb, 0x00c8, 0x00cd, 0x00ce, 0x00cf, 0x00cc, 0x00d3, 0x00d4,
0xf8ff, 0x00d2, 0x00da, 0x00db, 0x00d9, 0x0131, 0x02c6, 0x02dc,
0x00af, 0x02d8, 0x02d9, 0x02da, 0x00b8, 0x02dd, 0x02db, 0x02c7
};
static const char *standardnames[258] = {
".notdef",
".null",
"nonmarkingreturn",
"space",
"exclam",
"quotedbl",
"numbersign",
"dollar",
"percent",
"ampersand",
"quotesingle",
"parenleft",
"parenright",
"asterisk",
"plus",
"comma",
"hyphen",
"period",
"slash",
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"colon",
"semicolon",
"less",
"equal",
"greater",
"question",
"at",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
"bracketleft",
"backslash",
"bracketright",
"asciicircum",
"underscore",
"grave",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
"braceleft",
"bar",
"braceright",
"asciitilde",
"Adieresis",
"Aring",
"Ccedilla",
"Eacute",
"Ntilde",
"Odieresis",
"Udieresis",
"aacute",
"agrave",
"acircumflex",
"adieresis",
"atilde",
"aring",
"ccedilla",
"eacute",
"egrave",
"ecircumflex",
"edieresis",
"iacute",
"igrave",
"icircumflex",
"idieresis",
"ntilde",
"oacute",
"ograve",
"ocircumflex",
"odieresis",
"otilde",
"uacute",
"ugrave",
"ucircumflex",
"udieresis",
"dagger",
"degree",
"cent",
"sterling",
"section",
"bullet",
"paragraph",
"germandbls",
"registered",
"copyright",
"trademark",
"acute",
"dieresis",
"notequal",
"AE",
"Oslash",
"infinity",
"plusminus",
"lessequal",
"greaterequal",
"yen",
"mu",
"partialdiff",
"summation",
"product",
"pi",
"integral",
"ordfeminine",
"ordmasculine",
"Omega",
"ae",
"oslash",
"questiondown",
"exclamdown",
"logicalnot",
"radical",
"florin",
"approxequal",
"Delta",
"guillemotleft",
"guillemotright",
"ellipsis",
"nonbreakingspace",
"Agrave",
"Atilde",
"Otilde",
"OE",
"oe",
"endash",
"emdash",
"quotedblleft",
"quotedblright",
"quoteleft",
"quoteright",
"divide",
"lozenge",
"ydieresis",
"Ydieresis",
"fraction",
"currency",
"guilsinglleft",
"guilsinglright",
"fi",
"fl",
"daggerdbl",
"periodcentered",
"quotesinglbase",
"quotedblbase",
"perthousand",
"Acircumflex",
"Ecircumflex",
"Aacute",
"Edieresis",
"Egrave",
"Iacute",
"Icircumflex",
"Idieresis",
"Igrave",
"Oacute",
"Ocircumflex",
"apple",
"Ograve",
"Uacute",
"Ucircumflex",
"Ugrave",
"dotlessi",
"circumflex",
"tilde",
"macron",
"breve",
"dotaccent",
"ring",
"cedilla",
"hungarumlaut",
"ogonek",
"caron",
"Lslash",
"lslash",
"Scaron",
"scaron",
"Zcaron",
"zcaron",
"brokenbar",
"Eth",
"eth",
"Yacute",
"yacute",
"Thorn",
"thorn",
"minus",
"multiply",
"onesuperior",
"twosuperior",
"threesuperior",
"onehalf",
"onequarter",
"threequarters",
"franc",
"Gbreve",
"gbreve",
"Idotaccent",
"Scedilla",
"scedilla",
"Cacute",
"cacute",
"Ccaron",
"ccaron",
"dcroat"
};
/* Standard names for cff */
const char *cffnames[] = {
".notdef",
"space",
"exclam",
"quotedbl",
"numbersign",
"dollar",
"percent",
"ampersand",
"quoteright",
"parenleft",
"parenright",
"asterisk",
"plus",
"comma",
"hyphen",
"period",
"slash",
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"colon",
"semicolon",
"less",
"equal",
"greater",
"question",
"at",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
"bracketleft",
"backslash",
"bracketright",
"asciicircum",
"underscore",
"quoteleft",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
"braceleft",
"bar",
"braceright",
"asciitilde",
"exclamdown",
"cent",
"sterling",
"fraction",
"yen",
"florin",
"section",
"currency",
"quotesingle",
"quotedblleft",
"guillemotleft",
"guilsinglleft",
"guilsinglright",
"fi",
"fl",
"endash",
"dagger",
"daggerdbl",
"periodcentered",
"paragraph",
"bullet",
"quotesinglbase",
"quotedblbase",
"quotedblright",
"guillemotright",
"ellipsis",
"perthousand",
"questiondown",
"grave",
"acute",
"circumflex",
"tilde",
"macron",
"breve",
"dotaccent",
"dieresis",
"ring",
"cedilla",
"hungarumlaut",
"ogonek",
"caron",
"emdash",
"AE",
"ordfeminine",
"Lslash",
"Oslash",
"OE",
"ordmasculine",
"ae",
"dotlessi",
"lslash",
"oslash",
"oe",
"germandbls",
"onesuperior",
"logicalnot",
"mu",
"trademark",
"Eth",
"onehalf",
"plusminus",
"Thorn",
"onequarter",
"divide",
"brokenbar",
"degree",
"thorn",
"threequarters",
"twosuperior",
"registered",
"minus",
"eth",
"multiply",
"threesuperior",
"copyright",
"Aacute",
"Acircumflex",
"Adieresis",
"Agrave",
"Aring",
"Atilde",
"Ccedilla",
"Eacute",
"Ecircumflex",
"Edieresis",
"Egrave",
"Iacute",
"Icircumflex",
"Idieresis",
"Igrave",
"Ntilde",
"Oacute",
"Ocircumflex",
"Odieresis",
"Ograve",
"Otilde",
"Scaron",
"Uacute",
"Ucircumflex",
"Udieresis",
"Ugrave",
"Yacute",
"Ydieresis",
"Zcaron",
"aacute",
"acircumflex",
"adieresis",
"agrave",
"aring",
"atilde",
"ccedilla",
"eacute",
"ecircumflex",
"edieresis",
"egrave",
"iacute",
"icircumflex",
"idieresis",
"igrave",
"ntilde",
"oacute",
"ocircumflex",
"odieresis",
"ograve",
"otilde",
"scaron",
"uacute",
"ucircumflex",
"udieresis",
"ugrave",
"yacute",
"ydieresis",
"zcaron",
"exclamsmall",
"Hungarumlautsmall",
"dollaroldstyle",
"dollarsuperior",
"ampersandsmall",
"Acutesmall",
"parenleftsuperior",
"parenrightsuperior",
"twodotenleader",
"onedotenleader",
"zerooldstyle",
"oneoldstyle",
"twooldstyle",
"threeoldstyle",
"fouroldstyle",
"fiveoldstyle",
"sixoldstyle",
"sevenoldstyle",
"eightoldstyle",
"nineoldstyle",
"commasuperior",
"threequartersemdash",
"periodsuperior",
"questionsmall",
"asuperior",
"bsuperior",
"centsuperior",
"dsuperior",
"esuperior",
"isuperior",
"lsuperior",
"msuperior",
"nsuperior",
"osuperior",
"rsuperior",
"ssuperior",
"tsuperior",
"ff",
"ffi",
"ffl",
"parenleftinferior",
"parenrightinferior",
"Circumflexsmall",
"hyphensuperior",
"Gravesmall",
"Asmall",
"Bsmall",
"Csmall",
"Dsmall",
"Esmall",
"Fsmall",
"Gsmall",
"Hsmall",
"Ismall",
"Jsmall",
"Ksmall",
"Lsmall",
"Msmall",
"Nsmall",
"Osmall",
"Psmall",
"Qsmall",
"Rsmall",
"Ssmall",
"Tsmall",
"Usmall",
"Vsmall",
"Wsmall",
"Xsmall",
"Ysmall",
"Zsmall",
"colonmonetary",
"onefitted",
"rupiah",
"Tildesmall",
"exclamdownsmall",
"centoldstyle",
"Lslashsmall",
"Scaronsmall",
"Zcaronsmall",
"Dieresissmall",
"Brevesmall",
"Caronsmall",
"Dotaccentsmall",
"Macronsmall",
"figuredash",
"hypheninferior",
"Ogoneksmall",
"Ringsmall",
"Cedillasmall",
"questiondownsmall",
"oneeighth",
"threeeighths",
"fiveeighths",
"seveneighths",
"onethird",
"twothirds",
"zerosuperior",
"foursuperior",
"fivesuperior",
"sixsuperior",
"sevensuperior",
"eightsuperior",
"ninesuperior",
"zeroinferior",
"oneinferior",
"twoinferior",
"threeinferior",
"fourinferior",
"fiveinferior",
"sixinferior",
"seveninferior",
"eightinferior",
"nineinferior",
"centinferior",
"dollarinferior",
"periodinferior",
"commainferior",
"Agravesmall",
"Aacutesmall",
"Acircumflexsmall",
"Atildesmall",
"Adieresissmall",
"Aringsmall",
"AEsmall",
"Ccedillasmall",
"Egravesmall",
"Eacutesmall",
"Ecircumflexsmall",
"Edieresissmall",
"Igravesmall",
"Iacutesmall",
"Icircumflexsmall",
"Idieresissmall",
"Ethsmall",
"Ntildesmall",
"Ogravesmall",
"Oacutesmall",
"Ocircumflexsmall",
"Otildesmall",
"Odieresissmall",
"OEsmall",
"Oslashsmall",
"Ugravesmall",
"Uacutesmall",
"Ucircumflexsmall",
"Udieresissmall",
"Yacutesmall",
"Thornsmall",
"Ydieresissmall",
"001.000",
"001.001",
"001.002",
"001.003",
"Black",
"Bold",
"Book",
"Light",
"Medium",
"Regular",
"Roman",
"Semibold",
NULL
};
static const int nStdStrings = sizeof(cffnames)/sizeof(cffnames[0])-1;
static const char *instrs[] = {
"SVTCA[y-axis]",
"SVTCA[x-axis]",
"SPVTCA[y-axis]",
"SPVTCA[x-axis]",
"SFVTCA[y-axis]",
"SFVTCA[x-axis]",
"SPVTL[parallel]",
"SPVTL[orthog]",
"SFVTL[parallel]",
"SFVTL[orthog]",
"SPVFS",
"SFVFS",
"GPV",
"GFV",
"SFVTPV",
"ISECT",
"SRP0",
"SRP1",
"SRP2",
"SZP0",
"SZP1",
"SZP2",
"SZPS",
"SLOOP",
"RTG",
"RTHG",
"SMD",
"ELSE",
"JMPR",
"SCVTCI",
"SSWCI",
"SSW",
"DUP",
"POP",
"CLEAR",
"SWAP",
"DEPTH",
"CINDEX",
"MINDEX",
"ALIGNPTS",
"Unknown28",
"UTP",
"LOOPCALL",
"CALL",
"FDEF",
"ENDF",
"MDAP[no round]",
"MDAP[round]",
"IUP[y]",
"IUP[x]",
"SHP[rp2]",
"SHP[rp1]",
"SHC[rp2]",
"SHC[rp1]",
"SHZ[rp2]",
"SHZ[rp1]",
"SHPIX",
"IP",
"MSIRP[no set rp0]",
"MSIRP[set rp0]",
"ALIGNRP",
"RTDG",
"MIAP[no round]",
"MIAP[round]",
"NPUSHB",
"NPUSHW",
"WS",
"RS",
"WCVTP",
"RCVT",
"GC[cur]",
"GC[orig]",
"SCFS",
"MD[grid]",
"MD[orig]",
"MPPEM",
"MPS",
"FLIPON",
"FLIPOFF",
"DEBUG",
"LT",
"LTEQ",
"GT",
"GTEQ",
"EQ",
"NEQ",
"ODD",
"EVEN",
"IF",
"EIF",
"AND",
"OR",
"NOT",
"DELTAP1",
"SDB",
"SDS",
"ADD",
"SUB",
"DIV",
"MUL",
"ABS",
"NEG",
"FLOOR",
"CEILING",
"ROUND[Grey]",
"ROUND[Black]",
"ROUND[White]",
"ROUND[Undef4]",
"NROUND[Grey]",
"NROUND[Black]",
"NROUND[White]",
"NROUND[Undef4]",
"WCVTF",
"DELTAP2",
"DELTAP3",
"DELTAC1",
"DELTAC2",
"DELTAC3",
"SROUND",
"S45ROUND",
"JROT",
"JROF",
"ROFF",
"Unknown7B",
"RUTG",
"RDTG",
"SANGW",
"AA",
"FLIPPT",
"FLIPRGON",
"FLIPRGOFF",
"Unknown83",
"Unknown84",
"SCANCTRL",
"SDPVTL0",
"SDPVTL1",
"GETINFO",
"IDEF",
"ROLL",
"MAX",
"MIN",
"SCANTYPE",
"INSTCTRL",
"Unknown8F",
"Unknown90",
"Unknown91",
"Unknown92",
"Unknown93",
"Unknown94",
"Unknown95",
"Unknown96",
"Unknown97",
"Unknown98",
"Unknown99",
"Unknown9A",
"Unknown9B",
"Unknown9C",
"Unknown9D",
"Unknown9E",
"Unknown9F",
"UnknownA0",
"UnknownA1",
"UnknownA2",
"UnknownA3",
"UnknownA4",
"UnknownA5",
"UnknownA6",
"UnknownA7",
"UnknownA8",
"UnknownA9",
"UnknownAA",
"UnknownAB",
"UnknownAC",
"UnknownAD",
"UnknownAE",
"UnknownAF",
"PUSHB [1]",
"PUSHB [2]",
"PUSHB [3]",
"PUSHB [4]",
"PUSHB [5]",
"PUSHB [6]",
"PUSHB [7]",
"PUSHB [8]",
"PUSHW [1]",
"PUSHW [2]",
"PUSHW [3]",
"PUSHW [4]",
"PUSHW [5]",
"PUSHW [6]",
"PUSHW [7]",
"PUSHW [8]",
"MDRP[grey]",
"MDRP[black]",
"MDRP[white]",
"MDRP03",
"MDRP[round, grey]",
"MDRP[round, black]",
"MDRP[round, white]",
"MDRP07",
"MDRP[minimum, grey]",
"MDRP[minimum, black]",
"MDRP[minimum, white]",
"MDRP0b",
"MDRP[minimum, round, grey]",
"MDRP[minimum, round, black]",
"MDRP[minimum, round, white]",
"MDRP0f",
"MDRP[rp0, grey]",
"MDRP[rp0, black]",
"MDRP[rp0, white]",
"MDRP13",
"MDRP[rp0, round, grey]",
"MDRP[rp0, round, black]",
"MDRP[rp0, round, white]",
"MDRP17",
"MDRP[rp0, minimum, grey]",
"MDRP[rp0, minimum, black]",
"MDRP[rp0, minimum, white]",
"MDRP1b",
"MDRP[rp0, minimum, round, grey]",
"MDRP[rp0, minimum, round, black]",
"MDRP[rp0, minimum, round, white]",
"MDRP1f",
"MIRP[grey]",
"MIRP[black]",
"MIRP[white]",
"MIRP03",
"MIRP[round, grey]",
"MIRP[round, black]",
"MIRP[round, white]",
"MIRP07",
"MIRP[minimum, grey]",
"MIRP[minimum, black]",
"MIRP[minimum, white]",
"MIRP0b",
"MIRP[minimum, round, grey]",
"MIRP[minimum, round, black]",
"MIRP[minimum, round, white]",
"MIRP0f",
"MIRP[rp0, grey]",
"MIRP[rp0, black]",
"MIRP[rp0, white]",
"MIRP13",
"MIRP[rp0, round, grey]",
"MIRP[rp0, round, black]",
"MIRP[rp0, round, white]",
"MIRP17",
"MIRP[rp0, minimum, grey]",
"MIRP[rp0, minimum, black]",
"MIRP[rp0, minimum, white]",
"MIRP1b",
"MIRP[rp0, minimum, round, grey]",
"MIRP[rp0, minimum, round, black]",
"MIRP[rp0, minimum, round, white]",
"MIRP1f"
};
static struct dup *makedup(int glyph, int uni, struct dup *prev) {
struct dup *d = calloc(1,sizeof(struct dup));
d->glyph = glyph;
d->enc = uni;
d->prev = prev;
return( d );
}
static void readttfencodings(FILE *ttf,FILE *util, struct ttfinfo *info) {
int i,j;
int nencs, version;
int enc = 0;
int platform, specific;
int offset, encoff;
int format, len;
uint16 table[256];
int segCount;
unsigned short *endchars, *startchars, *delta, *rangeOffset, *glyphs;
int index;
struct dup *dup;
int vs_map = -1;
fseek(ttf,info->encoding_start,SEEK_SET);
printf( "\nEncoding (cmap) table (at %d)\n", info->encoding_start );
version = getushort(ttf);
nencs = getushort(ttf);
if ( version!=0 && nencs==0 )
nencs = version; /* Sometimes they are backwards */
for ( i=0; i<nencs; ++i ) {
platform = getushort(ttf);
specific = getushort(ttf);
offset = getlong(ttf);
if ( platform==3 /*&& (specific==1 || specific==5)*/) {
enc = 1;
encoff = offset;
} else if ( platform==1 && specific==0 && enc!=1 ) {
enc = 2;
encoff = offset;
} else if ( platform==1 && specific==1 ) {
enc = 1;
encoff = offset;
} else if ( platform==0 && specific!=5 ) {
enc = 1;
encoff = offset;
}
printf( "platform=%d specific=%d offset=%d ", platform, specific, offset );
if ( platform==3 ) {
if ( specific==0 ) printf( "MS Symbol\n" );
else if ( specific==1 ) printf( "MS Unicode\n" );
else if ( specific==2 ) printf( "MS Shift JIS\n" );
else if ( specific==3 ) printf( "MS PRC\n" );
else if ( specific==4 ) printf( "MS Big5\n" );
else if ( specific==5 ) printf( "MS Wansung\n" );
else if ( specific==6 ) printf( "MS Johab\n" );
else if ( specific==10 ) printf( "MS UCS4\n" );
else printf( "???\n" );
} else if ( platform==1 ) {
if ( specific==0 ) printf( "Mac Roman\n" );
else if ( specific==1 ) printf( "Japanese\n" );
else if ( specific==2 ) printf( "Traditional Chinese\n" );
else if ( specific==25 ) printf( "Simplified Chinese\n" );
else if ( specific==3 ) printf( "Korean\n" );
} else if ( platform==0 ) {
if ( specific==0 ) printf( "Unicode Default\n" );
else if ( specific==1 ) printf( "Unicode 1.0\n" );
else if ( specific==2 ) printf( "Unicode 1.1\n" );
else if ( specific==3 ) printf( "Unicode 2.0+\n" );
else if ( specific==4 ) printf( "Unicode UCS4\n" );
else if ( specific==5 ) printf( "Unicode Variations\n" );
else printf( "???\n" );
if ( specific==5 )
vs_map = offset;
} else printf( "???\n" );
}
if ( enc!=0 ) {
info->glyph_unicode = calloc(info->glyph_cnt,sizeof(unsigned int));
fseek(ttf,info->encoding_start+encoff,SEEK_SET);
format = getushort(ttf);
if ( format!=12 && format!=10 && format!=8 ) {
len = getushort(ttf);
printf( " Format=%d len=%d Language=%x\n", format, len, getushort(ttf) );
} else {
/* padding */ getushort(ttf);
len = getlong(ttf);
printf( " Format=%d len=%d Language=%x\n", format, len, getlong(ttf) );
}
if ( format==0 ) {
printf( " Table: " );
for ( i=0; i<len-6; ++i )
printf( "%d ", table[i] = getc(ttf));
putchar('\n');
for ( i=0; i<256 && i<info->glyph_cnt && i<len-6; ++i )
info->glyph_unicode[table[i]] = i;
} else if ( format==4 ) {
segCount = getushort(ttf)/2;
/* searchRange = */ getushort(ttf);
/* entrySelector = */ getushort(ttf);
/* rangeShift = */ getushort(ttf);
endchars = malloc(segCount*sizeof(unsigned short));
for ( i=0; i<segCount; ++i )
endchars[i] = getushort(ttf);
if ( getushort(ttf)!=0 )
fprintf(stderr,"Expected 0 in true type font");
startchars = malloc(segCount*sizeof(unsigned short));
for ( i=0; i<segCount; ++i )
startchars[i] = getushort(ttf);
delta = malloc(segCount*sizeof(unsigned short));
for ( i=0; i<segCount; ++i )
delta[i] = getushort(ttf);
rangeOffset = malloc(segCount*sizeof(unsigned short));
for ( i=0; i<segCount; ++i )
rangeOffset[i] = getushort(ttf);
len -= 8*sizeof(unsigned short) +
4*segCount*sizeof(unsigned short);
if ( len<0 ) {
fprintf( stderr, "This font has an illegal format 4 subtable with too little space for all the segments.\n" );
return;
}
/* that's the amount of space left in the subtable and it must */
/* be filled with glyphIDs */
glyphs = malloc(len);
for ( i=0; i<len/2; ++i )
glyphs[i] = getushort(ttf);
printf( "Format 4 (Windows unicode), %d segments\n", segCount );
for ( i=0; i<segCount; ++i ) {
printf( " Segment=%d unicode-start=%04x end=%04x range-offset=%d delta=%d",
i, startchars[i], endchars[i], rangeOffset[i], delta[i]);
if ( rangeOffset[i]==0 )
printf( " glyph-start=%d gend=%d\n", startchars[i]+delta[i], endchars[i]+delta[i]);
else if ( rangeOffset[i]!=0xffff ) {
index = glyphs[ (i-segCount+rangeOffset[i]/2)];
if ( index!=0 ) index += delta[i];
printf( " glyph-start=%d", index );
index = glyphs[ (i-segCount+rangeOffset[i]/2) + endchars[i]-startchars[i]];
if ( index!=0 ) index += delta[i];
printf( " end=%d\n", index);
} else
printf ( " End\n" );
if ( rangeOffset[i]==0 ) {
for ( j=startchars[i]; j<=endchars[i]; ++j ) {
if ( ((unsigned short) (j+delta[i]))>=info->glyph_cnt )
printf( "!!! Glyph index out of bounds! %d\n", (unsigned short) (j+delta[i]) );
else if ( info->glyph_unicode[(unsigned short) (j+delta[i])] )
info->dups = makedup((unsigned short) (j+delta[i]),j,info->dups);
else
info->glyph_unicode[(unsigned short) (j+delta[i])] = j;
}
} else if ( rangeOffset[i]!=0xffff ) {
/* It isn't explicitly mentioned by a rangeOffset of 0xffff*/
/* means no glyph */
for ( j=startchars[i]; j<=endchars[i]; ++j ) {
index = glyphs[ (i-segCount+rangeOffset[i]/2) +
j-startchars[i] ];
if ( index!=0 ) {
index = (unsigned short) (index+delta[i]);
if ( index>=info->glyph_cnt || index<0 )
printf( "!!! Glyph index out of bounds! %d\n", index );
else if ( info->glyph_unicode[index]!=0 )
info->dups = makedup(index,j,info->dups);
else
info->glyph_unicode[index] = j;
}
}
}
}
free(glyphs);
free(rangeOffset);
free(delta);
free(startchars);
free(endchars);
} else if ( format==6 ) {
/* Apple's unicode format */
/* Well, the docs say it's for 2byte encodings, but Apple actually*/
/* uses it for 1 byte encodings which don't fit into the require-*/
/* ments for a format 0 sub-table. See Zapfino.dfont */
int first, count;
first = getushort(ttf);
count = getushort(ttf);
for ( i=0; i<count; ++i )
info->glyph_unicode[getushort(ttf)] = first+i;
} else if ( format==2 ) {
int max_sub_head_key = 0, cnt, last;
struct subhead { uint16 first, cnt, delta, rangeoff; } *subheads;
for ( i=0; i<256; ++i ) {
table[i] = getushort(ttf)/8; /* Sub-header keys */
if ( table[i]>max_sub_head_key )
max_sub_head_key = table[i]; /* The entry is a byte pointer, I want a pointer in units of struct subheader */
}
subheads = malloc((max_sub_head_key+1)*sizeof(struct subhead));
for ( i=0; i<=max_sub_head_key; ++i ) {
subheads[i].first = getushort(ttf);
subheads[i].cnt = getushort(ttf);
subheads[i].delta = getushort(ttf);
subheads[i].rangeoff = (getushort(ttf)-
(max_sub_head_key-i)*sizeof(struct subhead)-
sizeof(short))/sizeof(short);
}
cnt = (len-(ftell(ttf)-(info->encoding_start+encoff)))/sizeof(short);
/* The count is the number of glyph indexes to read. it is the */
/* length of the entire subtable minus that bit we've read so far */
glyphs = malloc(cnt*sizeof(short));
for ( i=0; i<cnt; ++i )
glyphs[i] = getushort(ttf);
last = -1;
for ( i=0; i<256; ++i ) {
if ( table[i]==0 ) {
/* Special case, single byte encoding entry, look i up in */
/* subhead */
/* In the one example I've got of this encoding (wcl-02.ttf) the chars */
/* 0xfd, 0xfe, 0xff are said to exist but there is no mapping */
/* for them. */
if ( last!=-1 )
index = 0; /* the subhead says there are 256 entries, but in fact there are only 193, so attempting to find these guys should give an error */
else if ( i<subheads[0].first || i>=subheads[0].first+subheads[0].cnt ||
subheads[0].rangeoff+(i-subheads[0].first)>=cnt )
index = 0;
else if ( (index = glyphs[subheads[0].rangeoff+(i-subheads[0].first)])!= 0 )
index = (uint32) (index+subheads[0].delta);
/* I assume the single byte codes are just ascii or latin1*/
if ( index!=0 && index<info->glyph_cnt ) {
if ( info->glyph_unicode[index]==0 )
info->glyph_unicode[index] = i;
else
info->dups = makedup(index,i,info->dups);
}
} else {
int k = table[i];
for ( j=0; j<subheads[k].cnt; ++j ) {
int enc;
if ( subheads[k].rangeoff+j>=cnt )
index = 0;
else if ( (index = glyphs[subheads[k].rangeoff+j])!= 0 )
index = (uint16) (index+subheads[k].delta);
if ( index!=0 && index<info->glyph_cnt ) {
enc = (i<<8)|(j+subheads[k].first);
if ( info->glyph_unicode[index]==0 )
info->glyph_unicode[index] = enc;
else
info->dups = makedup(index,enc,info->dups);
}
}
if ( last==-1 ) last = i;
}
}
free(subheads);
free(glyphs);
} else if ( format==12 ) {
uint32 ngroups, start, end, startglyph;
ngroups = getlong(ttf);
for ( j=0; j<ngroups; ++j ) {
start = getlong(ttf);
end = getlong(ttf);
startglyph = getlong(ttf);
for ( i=start; i<=end; ++i ) {
info->glyph_unicode[startglyph+i-start] = i;
}
}
} else if ( format==8 ) {
fprintf(stderr,"I don't support mixed 16/32 bit characters (no unicode surogates), format=%d", format);
} else if ( format==10 ) {
fprintf(stderr,"I don't support 32 bit characters format=%d", format);
} else {
fprintf(stderr,"Eh? Unknown encoding format=%d", format);
}
}
if ( info->glyph_unicode!=NULL ) {
for ( i=0; i<info->glyph_cnt && (format!=0 || i<256); ++i )
printf( " Glyph %d -> U+%04X\n", i, info->glyph_unicode[i]);
for ( i=0; i<info->glyph_cnt; ++i ) if ( info->glyph_unicode[i]!=0 ) {
for ( j=i+1; j<info->glyph_cnt; ++j )
if ( info->glyph_unicode[i]==info->glyph_unicode[j] )
printf( "!!!Two glyphs %d and %d have the same encoding U+%04X",
i, j, info->glyph_unicode[i]);
}
if ( info->dups!=NULL ) {
printf("Some glyphs have multiple encodings:\n" );
for ( dup = info->dups; dup!=NULL ; dup=dup->prev )
printf( " Glyph %d -> U+%04X (primary=U+%04X)\n",
dup->glyph, dup->enc, info->glyph_unicode[dup->glyph] );
}
} else
printf( "Could not understand encoding table\n" );
if ( vs_map!=-1 ) {
struct vs_data { int vs; uint32 defoff, nondefoff; } *vs_data;
int cnt, rcnt;
fseek(ttf,info->encoding_start+vs_map,SEEK_SET);
if ( getushort(ttf)!=14 ) {
fprintf( stderr, "A unicode variation subtable (platform=0,specific=5) must have format=14\n" );
return;
}
len = getlong(ttf);
cnt = getlong(ttf);
printf( " Format=14 len=%d\n numVarSelRec=%d\n", len, cnt );
vs_data = malloc( cnt*sizeof(struct vs_data));
for ( i=0; i<cnt; ++i ) {
vs_data[i].vs = get3byte(ttf);
vs_data[i].defoff = getlong(ttf);
vs_data[i].nondefoff = getlong(ttf);
printf( " varSelector=%04x, defaultUVSOffset=%d nonDefaultOffset=%d\n",
vs_data[i].vs, vs_data[i].defoff, vs_data[i].nondefoff);
}
for ( i=0; i<cnt; ++i ) {
printf( " Variation Selector=%04x\n", vs_data[i].vs );
if ( vs_data[i].defoff!=0 ) {
fseek(ttf,info->encoding_start+vs_map+vs_data[i].defoff,SEEK_SET);
rcnt = getlong(ttf);
printf( " Default glyphs\n %d ranges\n", rcnt );
for ( j=0; j<rcnt; ++j ) {
int uni = get3byte(ttf);
printf( " U+%04x and %d code points following that\n",
uni, getc(ttf));
}
}
if ( vs_data[i].nondefoff!=0 ) {
fseek(ttf,info->encoding_start+vs_map+vs_data[i].nondefoff,SEEK_SET);
rcnt = getlong(ttf);
printf( " non Default glyphs\n %d mappings\n", rcnt );
for ( j=0; j<rcnt; ++j ) {
int uni = get3byte(ttf);
printf( " U+%04x.U+%04x -> GID %d\n",
uni, vs_data[i].vs, getushort(ttf));
}
}
}
}
}
static void readttfpost(FILE *ttf, FILE *util, struct ttfinfo *info) {
int i,j,ind, extras;
int format, gc, len;
uint16 *indexes, *glyphs;
char **names, *name;
fseek(ttf,info->postscript_start,SEEK_SET);
printf( "\npost table (at %d)\n", info->postscript_start );
printf( "\t format=%08x\n", format = getlong(ttf));
printf( "\t italicAngle=%g\n", getfixed(ttf));
printf( "\t underlinePos=%d\n", (short) getushort(ttf));
printf( "\t underlineWidth=%d\n", getushort(ttf));
printf( "\t fixedpitch=%d\n", getlong(ttf));
printf( "\t mem1=%d\n", getlong(ttf));
printf( "\t mem2=%d\n", getlong(ttf));
printf( "\t mem3=%d\n", getlong(ttf));
printf( "\t mem4=%d\n", getlong(ttf));
if ( format==0x00030000 ) {
/* Used in Open Type, seems only to contain the above stuff */
/* (no names, they're in the cff section) */
} else if ( format==0x00020000 ) {
gc = getushort(ttf);
if ( gc!=info->glyph_cnt )
fprintf( stderr, "!!!! Post table glyph count does not match that in 'maxp'\n" );
indexes = calloc(65536,sizeof(uint16));
glyphs = calloc(gc,sizeof(uint16));
names = calloc(gc<info->glyph_cnt?info->glyph_cnt:gc,sizeof(char *));
/* the index table is backwards from the way I want to use it */
extras = 0;
for ( i=0; i<gc; ++i ) {
ind = getushort(ttf);
if ( ind>=258 ) ++extras;
indexes[ind] = i;
glyphs[i] = ind;
}
for ( i=258; i<258+extras; ++i ) {
if ( indexes[i]==0 )
break;
len = getc(ttf);
name = malloc(len+1);
for ( j=0; j<len; ++j )
name[j] = getc(ttf);
name[j] = '\0';
names[indexes[i]] = name;
}
for ( i=0; i<gc; ++i ) {
printf( "Glyph %d (name index=%d) -> \"", i, glyphs[i] );
if ( names[i]!=NULL )
printf( "%s", names[i]);
else if ( glyphs[i]<258 ) {
printf( "%s", standardnames[glyphs[i]]);
names[i] = strdup(standardnames[glyphs[i]]);
} else
printf( "Gleep!!!!! %d", glyphs[i]);
if ( info->glyph_unicode!=NULL )
printf("\"\t U+%04X\n", info->glyph_unicode[i]);
else
printf( "\"\n" );
}
free(indexes);
free(glyphs);
#if 1
info->glyph_names = names;
#else
for ( i=0; i<gc; ++i )
free(names[i]);
free(names);
#endif
}
if ( info->glyph_unicode!=NULL ) {
if ( info->glyph_names==NULL )
info->glyph_names = calloc(info->glyph_cnt,sizeof(char *));
for ( i=0; i<info->glyph_cnt ; ++i ) {
if ( info->glyph_names[i]!=NULL )
/* Keep it */;
else if ( info->glyph_unicode[i]!=0 && info->glyph_unicode[i]!=0xffff ) {
char buffer[40];
sprintf(buffer,">U+%04X<", info->glyph_unicode[i]);
info->glyph_names[i] = strdup(buffer);
}
}
}
}
static void showlangsys(FILE *ttf,int script_start, uint16 ls_off, uint32 ls_name ) {
int i,cnt;
if ( ls_name==0 )
printf( "\t Language System table for default language\n" );
else
printf( "\t Language System table for '%c%c%c%c'\n",
(ls_name>>24)&0xff,
(ls_name>>16)&0xff,
(ls_name>>8)&0xff,
ls_name&0xff);
fseek(ttf,script_start+ls_off,SEEK_SET);
printf( "\t LookupOrder=%d\n", getushort(ttf));
printf( "\t Required Feature Index=%d\n", (short) getushort(ttf));
printf( "\t Feature Count=%d\n", cnt = getushort(ttf));
for ( i=0; i<cnt; ++i )
printf( "\t Feature %d Offset=%d\n", i, getushort(ttf));
}
static void showscriptlist(FILE *ttf,int script_start ) {
int cnt,i, j;
uint16 *script_table_offsets;
uint32 *script_table_names;
int dlo, ls_cnt;
uint32 *ls_names;
uint16 *ls_offsets;
fseek(ttf,script_start,SEEK_SET);
printf( "\tScript List\n" );
printf( "\t script count=%d\n", cnt=getushort(ttf));
script_table_offsets = malloc(cnt*sizeof(uint16));
script_table_names = malloc(cnt*sizeof(uint32));
for ( i=0; i<cnt; ++i ) {
script_table_names[i] = getlong(ttf);
script_table_offsets[i] = getushort(ttf);
printf( "\t Script[%d] '%c%c%c%c' Offset=%d\n", i,
(script_table_names[i]>>24)&0xff,
(script_table_names[i]>>16)&0xff,
(script_table_names[i]>>8)&0xff,
script_table_names[i]&0xff,
script_table_offsets[i]);
}
printf( "\t--\n" );
for ( i=0; i<cnt; ++i ) {
fseek(ttf,script_start+script_table_offsets[i],SEEK_SET);
printf( "\t Script table for '%c%c%c%c'\n",
(script_table_names[i]>>24)&0xff,
(script_table_names[i]>>16)&0xff,
(script_table_names[i]>>8)&0xff,
script_table_names[i]&0xff);
printf( "\t default language offset=%d\n", dlo=getushort(ttf));
printf( "\t language systems count=%d\n", ls_cnt = getushort(ttf));
ls_names = malloc(ls_cnt*sizeof(uint32));
ls_offsets = malloc(ls_cnt*sizeof(uint16));
for ( j=0; j<ls_cnt; ++j ) {
ls_names[j] = getlong(ttf);
ls_offsets[j] = getushort(ttf);
printf( "\t Language System '%c%c%c%c' Offset=%d\n",
(ls_names[j]>>24)&0xff,
(ls_names[j]>>16)&0xff,
(ls_names[j]>>8)&0xff,
ls_names[j]&0xff,
ls_offsets[j]);
}
if ( dlo!=0 )
showlangsys(ttf,script_start+script_table_offsets[i],dlo,0);
for ( j=0; j<ls_cnt; ++j )
showlangsys(ttf,script_start+script_table_offsets[i],ls_offsets[j],ls_names[j]);
free(ls_names); free(ls_offsets);
}
free(script_table_offsets);
free(script_table_names);
}
static void showfeaturelist(FILE *ttf,int feature_start ) {
int cnt,i, j, lu_cnt;
uint32 *feature_record_names;
uint16 *feature_record_offsets;
uint16 *lu_offsets;
fseek(ttf,feature_start,SEEK_SET);
printf( "\tFeature List\n" );
printf( "\t feature count=%d\n", cnt=getushort(ttf));
feature_record_offsets = malloc(cnt*sizeof(uint16));
feature_record_names = malloc(cnt*sizeof(uint32));
for ( i=0; i<cnt; ++i ) {
feature_record_names[i] = getlong(ttf);
feature_record_offsets[i] = getushort(ttf);
printf( "\t Feature[%d] '%c%c%c%c' Offset=%d\n", i,
(feature_record_names[i]>>24)&0xff,
(feature_record_names[i]>>16)&0xff,
(feature_record_names[i]>>8)&0xff,
feature_record_names[i]&0xff,
feature_record_offsets[i]);
}
printf( "\t--\n" );
for ( i=0; i<cnt; ++i ) {
fseek(ttf,feature_start+feature_record_offsets[i],SEEK_SET);
printf( "\t Feature Table[%d] '%c%c%c%c'\n", i,
(feature_record_names[i]>>24)&0xff,
(feature_record_names[i]>>16)&0xff,
(feature_record_names[i]>>8)&0xff,
feature_record_names[i]&0xff);
printf( "\t Feature Parameters Offset=%d\n", getushort(ttf));
printf( "\t Lookup Count = %d\n", lu_cnt = getushort(ttf));
if ( i+1<cnt && feature_record_offsets[i]<feature_record_offsets[i+1] &&
feature_record_offsets[i]+4+2*lu_cnt>feature_record_offsets[i+1] )
printf( "!!!! Bad lookup count. More lookups than there is space for!!!!\n" );
lu_offsets = malloc(lu_cnt*sizeof(uint16));
for ( j=0; j<lu_cnt; ++j ) {
printf( "\t Lookup List Offset[%d] = %d\n", j,
lu_offsets[j] = getushort(ttf));
}
free(lu_offsets);
}
free( feature_record_offsets );
free( feature_record_names );
}
static uint16 *showCoverageTable(FILE *ttf, int coverage_offset, int specified_cnt) {
int format, cnt, i,j, rcnt;
uint16 *glyphs=NULL;
int start, end, ind, max;
fseek(ttf,coverage_offset,SEEK_SET);
printf( "\t Coverage Table\n" );
printf( "\t Format=%d\n", format = getushort(ttf));
if ( format==1 ) {
printf("\t Glyph Count=%d\n\t ", cnt = getushort(ttf));
glyphs = malloc((cnt+1)*sizeof(uint16));
for ( i=0; i<cnt; ++i )
printf( "%d ", glyphs[i] = getushort(ttf));
glyphs[i] = 0xffff;
putchar('\n');
} else if ( format==2 ) {
glyphs = malloc((max=256)*sizeof(uint16));
printf("\t Range Count=%d\n\t ", rcnt = getushort(ttf));
cnt = 0;
for ( i=0; i<rcnt; ++i ) {
printf( "\t Range [%d] Start=%d ", i, start = getushort(ttf));
printf( "End=%d ", end = getushort(ttf));
printf( "Index=%d\n", ind = getushort(ttf));
if ( ind+end-start+2 >= max ) {
max = ind+end-start+2;
glyphs = realloc(glyphs,max*sizeof(uint16));
}
for ( j=start; j<=end; ++j )
glyphs[j-start+ind] = j;
if ( end-start+1+ind>cnt ) {
glyphs[end-start+1+ind] = 0xffff;
cnt = end-start+1+ind;
}
}
}
if ( specified_cnt>=0 && cnt!=specified_cnt )
fprintf(stderr, "! > Bad coverage table: Calculated Count(%d) does not match specified (%d)\n",
cnt, specified_cnt );
return( glyphs );
}
static uint16 *getClassDefTable(FILE *ttf, int classdef_offset, int cnt) {
int format, i, j;
uint16 start, glyphcnt, rangecnt, end, class;
uint16 *glist=NULL;
fseek(ttf, classdef_offset, SEEK_SET);
glist = malloc(cnt*sizeof(uint16));
for ( i=0; i<cnt; ++i )
glist[i] = 0; /* Class 0 is default */
format = getushort(ttf);
if ( format==1 ) {
start = getushort(ttf);
glyphcnt = getushort(ttf);
if ( start+glyphcnt>cnt ) {
fprintf( stderr, "Bad class def table. start=%d cnt=%d, max glyph=%d\n", start, glyphcnt, cnt );
glyphcnt = cnt-start;
}
for ( i=0; i<glyphcnt; ++i )
glist[start+i] = getushort(ttf);
} else if ( format==2 ) {
rangecnt = getushort(ttf);
for ( i=0; i<rangecnt; ++i ) {
start = getushort(ttf);
end = getushort(ttf);
if ( start>end || end>=cnt )
fprintf( stderr, "Bad class def table. Glyph range %d-%d out of range [0,%d)\n", start, end, cnt );
class = getushort(ttf);
for ( j=start; j<=end; ++j )
glist[j] = class;
}
}
return glist;
}
static void readvaluerecord(int vf,FILE *ttf,char *label) {
printf( "\t\t %s: ", label );
if ( vf&1 )
printf( "XPlacement: %d ", (short) getushort(ttf));
if ( vf&2 )
printf( "YPlacement: %d ", (short) getushort(ttf));
if ( vf&4 )
printf( "XAdvance: %d ", (short) getushort(ttf));
if ( vf&8 )
printf( "YAdvance: %d ", (short) getushort(ttf));
if ( vf&0x10 )
printf( "XPlacementDevOff: %d ", getushort(ttf));
if ( vf&0x20 )
printf( "YPlacementDevOff: %d ", getushort(ttf));
if ( vf&0x40 )
printf( "XAdvanceDevOff: %d ", getushort(ttf));
if ( vf&0x80 )
printf( "YAdvanceDevOff: %d ", getushort(ttf));
printf( "\n" );
}
static void PrintGlyphs(uint16 *glyphs, struct ttfinfo *info) {
if ( glyphs==NULL )
printf( "<Empty>\n" );
else if ( info->glyph_names!=NULL ) {
int i;
printf( " " );
for ( i=0; glyphs[i]!=0xffff; ++i ) {
printf( "%s ", info->glyph_names[glyphs[i]]);
}
printf("\n" );
}
}
static void gposPairSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) {
int coverage, cnt, i, subformat, vf1, vf2, j, pair_cnt;
uint16 *glyphs;
uint16 *ps_offsets;
printf( "\t Pair Sub Table[%d]\n", which );
printf( "\t SubFormat=%d\n", subformat = getushort(ttf));
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf));
printf( "\t ValueFormat1=0x%x ", vf1 = getushort(ttf));
printf( "%s%s%s%s%s%s%s%s\n",
(vf1&1) ? "XPlacement|":"",
(vf1&2) ? "YPlacement|":"",
(vf1&4) ? "XAdvance|":"",
(vf1&8) ? "YAdvance|":"",
(vf1&0x10) ? "XDevPlacement|":"",
(vf1&0x20) ? "YDevPlacement|":"",
(vf1&0x40) ? "XDevAdvance|":"",
(vf1&0x80) ? "YDevAdvance|":"" );
printf( "\t ValueFormat2=0x%x ", vf2 = getushort(ttf));
printf( "%s%s%s%s%s%s%s%s\n",
(vf2&1) ? "XPlacement|":"",
(vf2&2) ? "YPlacement|":"",
(vf2&4) ? "XAdvance|":"",
(vf2&8) ? "YAdvance|":"",
(vf2&0x10) ? "XDevPlacement|":"",
(vf2&0x20) ? "YDevPlacement|":"",
(vf2&0x40) ? "XDevAdvance|":"",
(vf2&0x80) ? "YDevAdvance|":"" );
if ( subformat==1 ) {
printf( "\t PairSetCnt=%d\n", cnt = getushort(ttf));
ps_offsets = calloc(cnt,sizeof(short));
for ( i=0; i<cnt; ++i )
ps_offsets[i] = getushort(ttf);
glyphs = showCoverageTable(ttf,stoffset+coverage, cnt);
for ( i=0; i<cnt; ++i ) {
fseek(ttf,stoffset+ps_offsets[i],SEEK_SET);
printf( "\t PairCnt=%d\n", pair_cnt = getushort(ttf));
for ( j=0; j<pair_cnt; ++j ) {
int glyph2 = getushort(ttf);
printf( "\t\tGlyph %d (%s) -> %d (%s)\n", glyphs[i],
glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names==NULL? "" : info->glyph_names[glyphs[i]],
glyph2,
glyph2>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyph2]);
readvaluerecord(vf1,ttf,"First");
readvaluerecord(vf2,ttf,"Second");
}
}
free(ps_offsets);
} else if ( subformat==2 ) {
printf( "\t Class based kerning (not displayed)\n" );
PrintGlyphs( showCoverageTable(ttf,stoffset+coverage,-1),info);
} else {
printf( "\t !!! unknown sub-table format !!!!\n" );
}
}
static void ShowAttach(FILE *ttf) {
int format = getushort(ttf);
int x = getushort(ttf);
int y = getushort(ttf);
if ( format==1 )
printf( "Attach at (%d,%d)\n", x, y );
else if ( format==2 )
printf( "Attach at (%d,%d pt=%d)\n", x, y, getushort(ttf) );
else if ( format==3 ) {
printf( "Attach at (%d,%d XDeviceOff=%d", x, y, getushort(ttf) );
printf( " YDeviceOff=%d)\n", getushort(ttf) );
} else
printf( "Unknown attachment format %d\n", format );
}
static void gposMarkToBaseSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info, int m2b) {
int mcoverage, bcoverage, classcnt, markoff, baseoff;
uint16 *mglyphs, *bglyphs;
int i, j;
uint16 *offsets;
uint32 pos;
printf( m2b ? "\t Mark To Base Sub Table[%d]\n" : "\t Mark To Mark Sub Table[%d]\n", which );
printf( "\t SubFormat=%d\n", getushort(ttf));
printf( "\t Mark Coverage Offset=%d\n", mcoverage = getushort(ttf));
printf( "\t Base Coverage Offset=%d\n", bcoverage = getushort(ttf));
printf( "\t Class Count=%d\n", classcnt = getushort(ttf));
printf( "\t Mark Offset=%d\n", markoff = getushort(ttf));
printf( "\t Base Offset=%d\n", baseoff = getushort(ttf));
printf( "\t Mark Glyphs\n" );
mglyphs = showCoverageTable(ttf,stoffset+mcoverage, -1); /* Class cnt is not the count of marks */
printf( "\t Base Glyphs\n" );
bglyphs = showCoverageTable(ttf,stoffset+bcoverage, -1);
fseek(ttf,stoffset+baseoff,SEEK_SET);
printf( "\t Base Glyph Count=%d\n", getushort(ttf));
offsets = malloc(classcnt*sizeof(uint16));
for ( i=0; bglyphs[i]!=0xffff; ++i ) {
printf( "\t\tBase Glyph %d (%s)\n", bglyphs[i],
bglyphs[i]>=info->glyph_cnt ? "!!! Bad glyph !!!" :
info->glyph_names == NULL ? "" : info->glyph_names[bglyphs[i]]);
for ( j=0; j<classcnt; ++j )
offsets[j] = getushort(ttf);
pos = ftell(ttf);
for ( j=0; j<classcnt; ++j ) {
if ( offsets[j]!=0 ) {
printf( "\t\t\tClass=%d Offset=%d ", j, offsets[j]);
fseek(ttf,stoffset+baseoff+offsets[j],SEEK_SET);
ShowAttach(ttf);
}
}
fseek(ttf,pos,SEEK_SET);
}
fseek(ttf,stoffset+markoff,SEEK_SET);
printf( "\t Mark Glyph Count=%d\n", getushort(ttf));
for ( i=0; mglyphs[i]!=0xffff; ++i ) {
printf( "\t\tMark Glyph %d (%s)\n", mglyphs[i],
mglyphs[i]>=info->glyph_cnt ? "!!! Bad glyph !!!" :
info->glyph_names == NULL ? "" : info->glyph_names[mglyphs[i]]);
printf( "\t\t\tClass=%d ", getushort(ttf));
offsets[0] = getushort(ttf);
pos = ftell(ttf);
if ( offsets[0]!=0 ) {
printf( "Offset=%d ", offsets[0]);
fseek(ttf,stoffset+markoff+offsets[0],SEEK_SET);
ShowAttach(ttf);
}
fseek(ttf,pos,SEEK_SET);
}
free(offsets);
free(mglyphs);
free(bglyphs);
}
static void gsubSingleSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) {
int coverage, cnt, i, type;
uint16 *glyphs;
printf( "\t Single Sub Table[%d] (varient forms)\n", which );
printf( "\t Type=%d\n", type = getushort(ttf));
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf));
if ( type==1 ) {
uint16 delta = getushort(ttf);
printf( "\t Delta=%d\n", delta);
glyphs = showCoverageTable(ttf,stoffset+coverage, -1);
printf( "\t Which means ...\n" );
for ( i=0; glyphs[i]!=0xffff; ++i )
printf( "\t\tGlyph %d (%s) -> %d (%s)\n", glyphs[i],
glyphs[i]>=info->glyph_cnt ? "!!! Bad glyph !!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]],
(uint16) (glyphs[i]+delta),
(uint16) (glyphs[i]+delta)>=info->glyph_cnt ? "!!! Bad glyph !!!" : info->glyph_names == NULL ? "" : info->glyph_names[(uint16) (glyphs[i]+delta)]);
} else {
int here;
printf( "\t Count=%d\n", cnt = getushort(ttf));
here = ftell(ttf);
glyphs = showCoverageTable(ttf,stoffset+coverage, cnt);
fseek(ttf,here,SEEK_SET);
for ( i=0; i<cnt; ++i ) {
int val = getushort(ttf);
printf( "\t\tGlyph %d (%s) -> %d (%s)\n", glyphs[i],
glyphs[i]>=info->glyph_cnt ? "!!! Bad glyph !!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]],
val,
val >= info->glyph_cnt ? "!!! Bad glyph !!!" : info->glyph_names == NULL ? "" : info->glyph_names[val]);
}
}
}
static void gsubMultipleSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) {
int coverage, cnt, i, j, glyph_cnt;
uint16 *seq_offsets;
uint16 *glyphs;
printf( "\t Multiple Sub Table[%d] (ligature decomposition)\n", which );
printf( "\t Type=%d\n", getushort(ttf));
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf));
printf( "\t Count=%d\n", cnt = getushort(ttf));
seq_offsets = malloc(cnt*sizeof(uint16));
for ( i=0; i<cnt; ++i )
printf( "\t Sequence Offsets[%d]=%d\n", i, seq_offsets[i]=getushort(ttf));
glyphs = showCoverageTable(ttf,stoffset+coverage, cnt);
for ( i=0; i<cnt; ++i ) {
fseek(ttf,stoffset+seq_offsets[i],SEEK_SET);
printf( "\t Glyph sequence[%d] for glyph %d (%s)\n", i, glyphs[i], glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]]);
printf( "\t Count=%d\n", glyph_cnt = getushort(ttf));
printf( "\t Glyph %d (%s) -> ", glyphs[i], glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]] );
for ( j=0; j<glyph_cnt; ++j ) {
int de = getushort(ttf);
printf( "%d (%s) ", de, de>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[de]);
}
putchar('\n');
}
free(seq_offsets);
}
static void gsubAlternateSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) {
int coverage, cnt, i, j, glyph_cnt;
uint16 *seq_offsets;
uint16 *glyphs;
printf( "\t Alternate Sub Table[%d] (varient forms)\n", which );
printf( "\t Type=%d\n", getushort(ttf));
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf));
printf( "\t Count=%d\n", cnt = getushort(ttf));
seq_offsets = malloc(cnt*sizeof(uint16));
for ( i=0; i<cnt; ++i )
printf( "\t Alternate Set Offsets[%d]=%d\n", i, seq_offsets[i]=getushort(ttf));
glyphs = showCoverageTable(ttf,stoffset+coverage, cnt);
for ( i=0; i<cnt; ++i ) {
fseek(ttf,stoffset+seq_offsets[i],SEEK_SET);
printf( "\t Glyph alternates[%d] for glyph %d (%s)\n", i, glyphs[i], glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]]);
printf( "\t Count=%d\n", glyph_cnt = getushort(ttf));
printf( "\t Glyph %d (%s) -> ", glyphs[i], glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]] );
for ( j=0; j<glyph_cnt; ++j ) {
int de = getushort(ttf);
printf( "%d (%s) | ", de, de>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[de]);
}
putchar('\n');
}
free(seq_offsets);
}
static void gsubLigatureSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) {
int coverage, cnt, i, j, k, lig_cnt, cc, gl;
uint16 *ls_offsets, *lig_offsets;
uint16 *glyphs;
printf( "\t Ligature Sub Table[%d]\n", which );
printf( "\t Type=%d\n", getushort(ttf));
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf));
printf( "\t Lig Set Count=%d\n", cnt = getushort(ttf));
ls_offsets = malloc(cnt*sizeof(uint16));
for ( i=0; i<cnt; ++i )
printf( "\t Lig Set Offsets[%d]=%d\n", i, ls_offsets[i]=getushort(ttf));
glyphs = showCoverageTable(ttf,stoffset+coverage,cnt);
for ( i=0; i<cnt; ++i ) {
fseek(ttf,stoffset+ls_offsets[i],SEEK_SET);
printf( "\t Ligature Set[%d] for glyph %d %s\n", i, glyphs[i], glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]]);
printf( "\t Count=%d\n", lig_cnt = getushort(ttf));
lig_offsets = malloc(lig_cnt*sizeof(uint16));
for ( j=0; j<lig_cnt; ++j )
printf("\t Offsets[%d]=%d\n", j, lig_offsets[j] = getushort(ttf));
for ( j=0; j<lig_cnt; ++j ) {
fseek(ttf,stoffset+ls_offsets[i]+lig_offsets[j],SEEK_SET);
gl = getushort(ttf);
printf( "\t Ligature glyph %d (%s) <- %d (%s) ",
gl, gl>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[gl], glyphs[i], glyphs[i]>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[glyphs[i]]);
cc = getushort(ttf);
for ( k=1; k<cc; ++k ) {
gl = getushort(ttf);
printf( "%d (%s) ", gl, gl>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names == NULL ? "" : info->glyph_names[gl]);
}
putchar('\n');
}
free(lig_offsets);
}
free(ls_offsets); free(glyphs);
}
static void gsubContextSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) {
}
static void gsubChainingContextSubTable(FILE *ttf, int which, int stoffset, struct ttfinfo *info) {
}
static void showgpossublookup(FILE *ttf,int base, int lkoffset,
struct ttfinfo *info, int gpos ) {
int lu_type, flags, cnt, j, st, is_exten_lu;
uint16 *st_offsets;
fseek(ttf,base+lkoffset,SEEK_SET);
lu_type = getushort(ttf);
flags = getushort(ttf);
cnt = getushort(ttf);
if ( gpos ) {
printf( "\t Type=%d %s\n", lu_type,
lu_type==1?"Single adjustment":
lu_type==2?"Pair adjustment":
lu_type==3?"Cursive attachment":
lu_type==4?"MarkToBase attachment":
lu_type==5?"MarkToLigature attachment":
lu_type==6?"MarkToMark attachment":
lu_type==7?"Context positioning":
lu_type==8?"Chained Context positioning":
lu_type==9?"Extension positioning":
"Reserved");
is_exten_lu = lu_type==9;
} else {
printf( "\t Type=%d %s\n", lu_type,
lu_type==1?"Single":
lu_type==2?"Multiple":
lu_type==3?"Alternate":
lu_type==4?"Ligature":
lu_type==5?"Context":
lu_type==6?"Chaining Context":
lu_type==7?"Extension":
lu_type==8?"Reverse chaining":
"Reserved");
is_exten_lu = lu_type==7;
}
printf( "\t Flags=0x%x %s|%s|%s|%s\n", flags,
(flags&0x1)?"RightToLeft":"LeftToRight",
(flags&0x2)?"IgnoreBaseGlyphs":"",
(flags&0x4)?"IgnoreLigatures":"",
(flags&0x8)?"IgnoreCombiningMarks":"");
printf( "\t Sub Table Count=%d\n", cnt);
st_offsets = malloc(cnt*sizeof(uint16));
for ( j=0; j<cnt; ++j )
printf( "\t Sub Table Offsets[%d]=%d\n", j, st_offsets[j] = getushort(ttf));
for ( j=0; j<cnt; ++j ) {
fseek(ttf,st = base+lkoffset+st_offsets[j],SEEK_SET);
if ( gpos ) {
if ( is_exten_lu ) { /* Extension lookup */
int format = getushort(ttf);
int subtype = getushort(ttf);
int offset = getlong(ttf);
printf( "\t (extension format)=%d\n", format );
lu_type = subtype;
printf( "\t (extension type)=%d %s\n", lu_type,
lu_type==1?"Single adjustment":
lu_type==2?"Pair adjustment":
lu_type==3?"Cursive attachment":
lu_type==4?"MarkToBase attachment":
lu_type==5?"MarkToLigature attachment":
lu_type==6?"MarkToMark attachment":
lu_type==7?"Context positioning":
lu_type==8?"Chained Context positioning":
lu_type==9?"Extension !!! Illegal here !!!":
"Reserved");
printf( "\t (extension offset)=%d\n", offset );
st += offset;
fseek(ttf,st,SEEK_SET);
}
switch ( lu_type ) {
case 2: gposPairSubTable(ttf,j,st,info); break;
case 4: gposMarkToBaseSubTable(ttf,j,st,info,true); break;
case 6: gposMarkToBaseSubTable(ttf,j,st,info,false); break;
}
} else {
if ( is_exten_lu ) { /* Extension lookup */
int format = getushort(ttf);
int subtype = getushort(ttf);
int offset = getlong(ttf);
printf( "\t (extension format)=%d\n", format );
lu_type = subtype;
printf( "\t (extension type)=%d %s\n", lu_type,
lu_type==1?"Single":
lu_type==2?"Multiple":
lu_type==3?"Alternate":
lu_type==4?"Ligature":
lu_type==5?"Context":
lu_type==6?"Chaining Context":
lu_type==7?"Extension !!! Illegal here !!!":
lu_type==8?"Reverse chaining":
"Reserved");
st += offset;
fseek(ttf,st,SEEK_SET);
}
switch ( lu_type ) {
case 1: gsubSingleSubTable(ttf,j,st,info); break;
case 2: gsubMultipleSubTable(ttf,j,st,info); break;
case 3: gsubAlternateSubTable(ttf,j,st,info); break;
case 4: gsubLigatureSubTable(ttf,j,st,info); break;
case 5: gsubContextSubTable(ttf,j,st,info); break;
case 6: gsubChainingContextSubTable(ttf,j,st,info); break;
}
}
}
free(st_offsets);
}
static void showgpossublookups(FILE *ttf,int lookup_start, struct ttfinfo *info, int gpos ) {
int i, lu_cnt;
uint16 *lu_offsets;
fseek(ttf,lookup_start,SEEK_SET);
printf( "\t%s Lookup List Table\n", gpos?"GPOS":"GSUB" );
printf( "\t Lookup Count=%d\n", lu_cnt = getushort(ttf));
lu_offsets = malloc(lu_cnt*sizeof(uint16));
for ( i=0; i<lu_cnt; ++i )
printf( "\t Lookup Offset[%d]=%d\n", i, lu_offsets[i] = getushort(ttf));
printf( "\t--\n");
for ( i=0; i<lu_cnt; ++i ) {
printf( "\t Lookup Table[%d]\n", i );
showgpossublookup(ttf,lookup_start, lu_offsets[i], info, gpos);
}
free(lu_offsets);
}
static void readttfgsub(FILE *ttf, FILE *util, struct ttfinfo *info) {
int slo, flo, llo;
fseek(ttf,info->gsub_start,SEEK_SET);
printf( "\nGSUB table (at %d) (Glyph substitution)\n", info->gsub_start );
printf( "\t version=%g\n", getfixed(ttf));
printf( "\t Script List Offset=%d\n", slo = getushort(ttf));
printf( "\t Feature List Offset=%d\n", flo = getushort(ttf));
printf( "\t Lookup List Offset=%d\n", llo = getushort(ttf));
showscriptlist(ttf,info->gsub_start+slo );
showfeaturelist(ttf,info->gsub_start+flo );
showgpossublookups(ttf,info->gsub_start+llo,info,false );
}
static void readttfgpos(FILE *ttf, FILE *util, struct ttfinfo *info) {
int slo, flo, llo;
fseek(ttf,info->gpos_start,SEEK_SET);
printf( "\nGPOS table (at %d) (Glyph positioning)\n", info->gpos_start );
printf( "\t version=%g\n", getfixed(ttf));
printf( "\t Script List Offset=%d\n", slo = getushort(ttf));
printf( "\t Feature List Offset=%d\n", flo = getushort(ttf));
printf( "\t Lookup List Offset=%d\n", llo = getushort(ttf));
showscriptlist(ttf,info->gpos_start+slo );
showfeaturelist(ttf,info->gpos_start+flo );
showgpossublookups(ttf,info->gpos_start+llo,info,true );
}
static void gdefshowglyphclassdef(FILE *ttf,int offset,struct ttfinfo *info) {
uint16 *glist=NULL;
int i;
static const char * const classes[] = { "Unspecified", "Base", "Ligature", "Mark", "Component" };
const int max_class = sizeof(classes)/sizeof(classes[0]);
printf( " Glyph Class Definitions\n" );
glist = getClassDefTable(ttf,offset,info->glyph_cnt);
for ( i=0; i<info->glyph_cnt; ++i ) if ( glist[i]>0 && glist[i]<max_class ) {
printf( "\t Glyph %d (%s) is a %s\n", i,
i>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ? info->glyph_names[i] : "",
classes[glist[i]]);
}
free(glist);
}
static void gdefshowligcaretlist(FILE *ttf,int offset,struct ttfinfo *info) {
int coverage, cnt, i, j, cc, format;
uint16 *lc_offsets, *glyphs, *offsets;
uint32 caret_base;
fseek(ttf,offset,SEEK_SET);
printf( " Ligature Caret List\n" );
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf));
printf( "\t Ligature Count=%d\n", cnt = getushort(ttf));
lc_offsets = malloc(cnt*sizeof(uint16));
for ( i=0; i<cnt; ++i )
printf( "\t Lig Caret Offsets[%d]=%d\n", i, lc_offsets[i]=getushort(ttf));
glyphs = showCoverageTable(ttf,offset+coverage,cnt);
for ( i=0; i<cnt; ++i ) {
fseek(ttf,offset+lc_offsets[i],SEEK_SET);
printf("\t Carets for glyph %d (%s)\n", glyphs[i],
glyphs[i]>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[glyphs[i]]);
caret_base = ftell(ttf);
printf("\t Count = %d\n", cc = getushort(ttf));
offsets = malloc(cc*sizeof(uint16));
for ( j=0; j<cc; ++j )
offsets[j] = getushort(ttf);
for ( j=0; j<cc; ++j ) {
fseek(ttf,caret_base+offsets[j],SEEK_SET);
format=getushort(ttf);
if ( format==1 ) {
printf("\t\tCaret[%d] at %d\n", j, (short) getushort(ttf));
} else if ( format==2 ) {
printf("\t\tCaret[%d] at point #%d\n", j, getushort(ttf));
} else if ( format==3 ) {
printf("\t\tCaret[%d] at %d ", j, (short) getushort(ttf));
printf(" in device table at offset %d\n", getushort(ttf));
} else {
printf( "!!!! Unknown caret format %d !!!!\n", format );
}
}
}
free(lc_offsets);
free(glyphs);
}
static void readttfgdef(FILE *ttf, FILE *util, struct ttfinfo *info) {
int gco, alo, lco, maco;
fseek(ttf,info->gdef_start,SEEK_SET);
printf( "\nGDEF table (at %d) (Glyph definitions)\n", info->gdef_start );
printf( "\t version=%g\n", getfixed(ttf));
printf( "\t Glyph class Def Offset=%d\n", gco = getushort(ttf));
printf( "\t Attach List Offset=%d\n", alo = getushort(ttf));
printf( "\t Ligature Caret List Offset=%d\n", lco = getushort(ttf));
printf( "\t Mark Attach Class Def Offset=%d\n", maco = getushort(ttf));
if ( gco!=0 ) gdefshowglyphclassdef(ttf,info->gdef_start+gco,info);
if ( lco!=0 ) gdefshowligcaretlist(ttf,info->gdef_start+lco,info);
}
static void readttfkern_context(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len);
static void readttfkern(FILE *ttf, FILE *util, struct ttfinfo *info) {
int version, ntables;
int header_size, len, coverage, i, j;
uint32 begin;
int left, right, array, n;
fseek(ttf,info->kern_start,SEEK_SET);
printf( "\nkern table (at %d)\n", info->kern_start );
version = getushort(ttf);
if ( version!=0 ) {
fseek(ttf,info->kern_start,SEEK_SET);
version = getlong(ttf);
ntables = getlong(ttf);
printf( "\t version=%g (Apple format)\n\t num_tables=%d\n", ((double) version)/65536., ntables);
header_size = 8;
} else {
ntables = getushort(ttf);
printf( "\t version=%d (Old style)\n\t num_tables=%d\n", version, ntables);
header_size = 6;
}
for ( i=0; i<ntables; ++i ) {
begin = ftell(ttf);
if ( version==0 ) {
printf( "\t Sub-table %d, version=%d\n", i, getushort(ttf));
len = getushort(ttf);
coverage = getushort(ttf);
printf( "\t len=%d coverage=%x %s%s%s%s sub table format=%d\n", len, coverage,
( coverage&1 ) ? "Horizontal": "Vertical",
( coverage&2 ) ? " Minimum" : "",
( coverage&4 ) ? " cross-stream" : "",
( coverage&8 ) ? " override" : "",
( coverage>>8 ));
if ( (coverage>>8)==0 ) {
/* Kern pairs */
int n = getushort(ttf);
int sr = getushort(ttf);
int es = getushort(ttf);
int rs = getushort(ttf);
printf( "\t npairs=%d searchRange=%d entrySelector=%d rangeShift=%d\n",
n, sr, es, rs );
for ( i=0; i<n; ++i ) {
int left, right, val;
left = getushort(ttf);
right = getushort(ttf);
val = (short) getushort(ttf);
if ( info->glyph_names!=NULL && left<info->glyph_cnt && right<info->glyph_cnt ) {
printf( "\t\t%s %s %d\n", info->glyph_names[left],
info->glyph_names[right], val );
} else {
printf( "\t\t%d %d %d\n", left, right, val );
}
}
}
fseek(ttf,begin+header_size,SEEK_SET);
} else {
len = getlong(ttf);
coverage = getushort(ttf);
printf( "\t len=%d coverage=%x %s%s%s sub table format=%d\n", len, coverage,
( coverage&0x8000 ) ? "Vertical": "Horizontal",
( coverage&0x4000 ) ? " cross-stream" : "",
( coverage&0x2000 ) ? " kern-variation" : "",
( coverage&0xff ));
printf( "\t tuple index=%d\n", getushort(ttf));
switch ( (coverage&0xff) ) {
case 1:
readttfkern_context(ttf,util, info, len-6);
break;
case 2:
printf( "\t row Width=%d\n", getushort(ttf));
printf( "\t left class offset=%d\n", left =getushort(ttf));
printf( "\t right class offset=%d\n", right = getushort(ttf));
printf( "\t array offset=%d\n", array = getushort(ttf));
fseek(ttf,begin+left,SEEK_SET);
printf( "\t left class table\n" );
printf( "\t first Glyph=%d\n", getushort(ttf) );
printf( "\t number of glyphs=%d\n", n = getushort(ttf) );
printf( "\t " );
for ( j=0; j<n; ++j )
printf( " %d", getushort(ttf));
printf( "\n" );
fseek(ttf,begin+right,SEEK_SET);
printf( "\t right class table\n" );
printf( "\t first Glyph=%d\n", getushort(ttf) );
printf( "\t number of glyphs=%d\n", n = getushort(ttf) );
printf( "\t " );
for ( j=0; j<n; ++j )
printf( " %d", getushort(ttf));
printf( "\n" );
break;
}
fseek(ttf,begin+header_size,SEEK_SET);
}
fseek(ttf,len-header_size,SEEK_CUR);
}
}
static void readttffontdescription(FILE *ttf, FILE *util, struct ttfinfo *info) {
int n, i;
uint32 tag, lval;
double val;
fseek(ttf,info->fdsc_start,SEEK_SET);
printf( "\nfdsc table (at %d) (font description)\n", info->fdsc_start );
printf( "\t version=%g\n", getfixed(ttf));
n = getushort(ttf);
printf( "\t number of descriptions=%d\n", n);
for ( i=0; i<n; ++i ) {
tag = getlong(ttf);
val = getfixed(ttf);
fseek(ttf,-4,SEEK_CUR);
lval = getlong(ttf);
printf("\t %c%c%c%c %s %08lx ",
tag>>24, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff,
tag==CHR('w','g','h','t')? "Weight" :
tag==CHR('w','d','t','h')? "Width" :
tag==CHR('s','l','n','t')? "Slant" :
tag==CHR('o','p','s','z')? "Optical Size" :
tag==CHR('n','a','l','f')? "Non-alphabetic" :
"Unknown",
lval );
switch ( tag ) {
case CHR('w','g','h','t'):
case CHR('w','d','t','h'):
case CHR('s','l','n','t'):
case CHR('o','p','s','z'):
default:
printf( "%g\n", val );
break;
case CHR('n','a','l','f'):
printf( lval==0 ? "Alphabetic\n" :
lval==1 ? "Dingbats\n" :
lval==2 ? "Pi characters\n" :
lval==3 ? "Fleurons\n" :
lval==4 ? "Decorative borders\n" :
lval==5 ? "International symbols\n" :
lval==6 ? "Math symbols\n" :
"Unknown" );
break;
}
}
}
static void readttffeatures(FILE *ttf, FILE *util, struct ttfinfo *info) {
int n, i, j, nameid;
uint32 setting_offset;
fseek(ttf,info->feat_start,SEEK_SET);
printf( "\nfeat table (at %d) (feature names)\n", info->feat_start );
printf( "\t version=%g\n", getfixed(ttf));
n = getushort(ttf);
printf( "\t number of features=%d\n", n);
printf( "\t must be zero: %x\n", getushort(ttf));
printf( "\t must be zero: %x\n", getlong(ttf));
info->features = calloc(n+1,sizeof(struct features));
info->features[n].feature = -1;
for ( i=0; i<n; ++i ) {
info->features[i].feature = getushort(ttf);
info->features[i].nsettings = getushort(ttf);
info->features[i].settings = calloc(info->features[i].nsettings,sizeof(struct settings));
setting_offset = getlong(ttf);
info->features[i].featureflags = getushort(ttf);
nameid = getushort(ttf);
info->features[i].name = getttfname(util,info,nameid);
printf( "\t Feature %d\n", i );
printf( "\t Feature Id %d\n", info->features[i].feature );
printf( "\t number Settings %d\n", info->features[i].nsettings );
printf( "\t setting offset %ld\n", setting_offset );
printf( "\t feature flags %d ", info->features[i].featureflags );
if ( !(info->features[i].featureflags&0x8000) )
printf( "Non-Exclusive settings\n" );
else if ( !(info->features[i].featureflags&0x4000) )
printf( "Exclusive Settings, Default=0\n" );
else
printf( "Exclusive Settings, Default=%d\n", info->features[i].featureflags&0xff);
printf( "\t name index %d (%s)\n", nameid, info->features[i].name==NULL?"Not found":info->features[i].name );
fseek(util,info->feat_start+setting_offset,SEEK_SET);
for ( j=0; j<info->features[i].nsettings; ++j ) {
info->features[i].settings[j].setting = getushort(util);
info->features[i].settings[j].nameid = getushort(util);
}
for ( j=0; j<info->features[i].nsettings; ++j )
info->features[i].settings[j].name = getttfname(util,info,info->features[i].settings[j].nameid);
for ( j=0; j<info->features[i].nsettings; ++j )
printf( "\t Setting %d nameid=%d name=%s\n",
info->features[i].settings[j].setting,
info->features[i].settings[j].nameid,
info->features[i].settings[j].name==NULL ? "Not found" :
info->features[i].settings[j].name );
}
}
static char *getfeaturename(struct ttfinfo *info, int type) {
int k;
char *name;
name = NULL;
if ( info->features!=NULL ) {
for ( k=0; info->features[k].feature!=-1 && info->features[k].feature!=type; ++k );
name = info->features[k].name; /* will be null at end of list */
}
if ( name!=NULL )
return( name );
/* This list is taken from http://developer.apple.com/fonts/Registry/index.html*/
return( type==0 ? "All typographic features" :
type==1 ? "Ligature" :
type==2 ? "Cursive connection" :
type==3 ? "Letter case" :
type==4 ? "Vertical substitution" :
type==5 ? "Linguistic rearrangement" :
type==6 ? "Number spacing" :
type==7 ? "apple, reserved" :
type==8 ? "Smart swashes" :
type==9 ? "Diacritics" :
type==10 ? "Vertical Position" :
type==11 ? "Fractions" :
type==13 ? "Overlapping characters" :
type==14 ? "Typographic extras" :
type==15 ? "Mathematical extras" :
type==16 ? "Ornament sets" :
type==17 ? "Character alternatives" :
type==18 ? "Design complexity" :
type==19 ? "Style options" :
type==20 ? "Character shape" :
type==21 ? "Number case" :
type==22 ? "Text/Letter spacing" :
type==23 ? "Transliteration" :
type==24 ? "Annotation" :
type==25 ? "Kana Spacing" :
type==26 ? "Ideographic Spacing" :
type==27 ? "?Accented leters (undocumented)?" :
type==103 ? "CJK Roman spacing" :
/* Compatability (depreciated) ... */
type==100 ? "(adobe) Character Spacing" :
type==101 ? "(adobe) Kana Spacing" :
type==102 ? "(adobe) Kanji Spacing" :
type==104 ? "(adobe) Square Ligatures" :
/* End */
type==16000 ? "?Decompose Unicode (undocumented)?" :
type==16001 ? "?Combining character (undocumented)?" :
"Unknown feature type" );
}
static char *getsettingname(struct ttfinfo *info, int type, int setting) {
int k,l;
char *name;
name = NULL;
if ( info->features!=NULL ) {
for ( k=0; info->features[k].feature!=-1 && info->features[k].feature!=type; ++k );
if ( info->features[k].feature!=-1 ) {
/*name = info->features[k].name; /* will be null at end of list */
for ( l=0 ; l<info->features[k].nsettings && info->features[k].settings[l].setting!=setting; ++l );
if ( l<info->features[k].nsettings )
name = info->features[k].settings[l].name;
}
}
if ( name )
return( name );
/* These lists are taken from http://developer.apple.com/fonts/Registry/index.html*/
/* the numeric values are at the bottom of the page */
else switch ( type ) {
case 0:
return( setting==0 ? "On" :
setting==1 ? "Off" :
"Unknown" );
break;
case 1: /* Ligatures */
return( setting==0 ? "Required ligatures On" :
setting==1 ? "Required ligatures Off" :
setting==2 ? "Common Ligatures On" :
setting==3 ? "Common Ligatures Off" :
setting==4 ? "Rare Ligatures On" :
setting==5 ? "Rare Ligatures Off" :
setting==6 ? "Logos On" :
setting==7 ? "Logos Off" :
setting==8 ? "Rebus pictures On" :
setting==9 ? "Rebus pictures Off" :
setting==10 ? "Dipthong ligatures On" :
setting==11 ? "Dipthong ligatures Off" :
setting==12 ? "Squared ligatures On" :
setting==13 ? "Squared ligatures Off" :
setting==14 ? "Squared ligatures, abbreviated On" :
setting==15 ? "Squared ligatures, abbreviated Off" :
"Unknown" );
break;
case 2: /* cursive */
return( setting==0 ? "Unconnected" :
setting==1 ? "Partially connected" :
setting==2 ? "Cursive" :
"Unknown" );
break;
case 3: /* Letter case */
return( setting==0 ? "Upper & Lower case" :
setting==1 ? "All Caps" :
setting==2 ? "All Lower Case" :
setting==3 ? "Small Caps" :
setting==4 ? "Initial Caps" :
setting==5 ? "Initial Caps & Small Caps" :
"Unknown" );
break;
case 4: /* Vertical Substitution */
return( setting==0 ? "On" :
setting==1 ? "Off" :
"Unknown" );
break;
case 5: /* Linguistic Rearrangement */
return( setting==0 ? "On" :
setting==1 ? "Off" :
"Unknown" );
break;
case 6: /* Number spacing */
return( setting==0 ? "On" :
setting==1 ? "Off" :
"Unknown" );
break;
case 8: /* Smart swash */
return( setting==0 ? "Initial swashes On" :
setting==1 ? "Initial swashes Off" :
setting==2 ? "Final swashes On" :
setting==3 ? "Final swashes Off" :
setting==4 ? "line initial swashes On" :
setting==5 ? "line initial swashes Off" :
setting==6 ? "line final swashes On" :
setting==7 ? "line final swashes Off" :
setting==8 ? "non-final swashes On" :
setting==9 ? "non-final swashes Off" :
"Unknown" );
break;
case 9: /* diacritics */
return( setting==0 ? "show Diacritics" :
setting==1 ? "hide Diacritics" :
setting==2 ? "decompose Diacritics" :
"Unknown" );
break;
case 10: /* vertical positioning */
return( setting==0 ? "normal position" :
setting==1 ? "superiors" :
setting==2 ? "inferiors" :
setting==3 ? "ordinals" :
"Unknown" );
break;
case 11: /* fractions */
return( setting==0 ? "no fractions" :
setting==1 ? "vertical fractions" :
setting==2 ? "diagonal fractions" :
"Unknown" );
break;
case 13: /* overlapping chars */
return( setting==0 ? "prevent Overlap On" :
setting==1 ? "prevent Overlap Off" :
"Unknown" );
break;
case 14: /* typographic extras */
return( setting==0 ? "hyphens to Em dashes On" :
setting==1 ? "hyphens to Em dashes Off" :
setting==2 ? "hyphens to En dashes On" :
setting==3 ? "hyphens to En dashes Off" :
setting==4 ? "unslashed Zero On" :
setting==5 ? "unslashed Zero Off" :
setting==6 ? "form Interrobang On" :
setting==7 ? "form Interrobang Off" :
setting==8 ? "smart Quotes On" :
setting==9 ? "smart Quotes Off" :
setting==10 ? "periods to ellipsis On" :
setting==11 ? "periods to ellipsis Off" :
"Unknown" );
break;
case 15: /* mathmatical extras */
return( setting==0 ? "hyphen to minus On" :
setting==1 ? "hyphen to minus Off" :
setting==2 ? "asterisk to multiply On" :
setting==3 ? "asterisk to multiply Off" :
setting==4 ? "slash to divide On" :
setting==5 ? "slash to divide Off" :
setting==6 ? "inequality ligatures On" :
setting==7 ? "inequality ligatures Off" :
setting==8 ? "exponents On" :
setting==9 ? "exponents Off" :
"Unknown" );
break;
case 16: /* ornament sets */
return( setting==0 ? "no ornaments" :
setting==1 ? "dingbats" :
setting==2 ? "pi Characters" :
setting==3 ? "fleurons" :
setting==4 ? "decorative borders" :
setting==5 ? "international symbols" :
setting==6 ? "math symbols" :
"Unknown" );
break;
case 17: /* character alternates */
return( setting==0 ? "no alternates" :
"Unknown" );
break;
case 18: /* design complexity */
return( setting==0 ? "design level 1" :
setting==1 ? "design level 2" :
setting==2 ? "design level 3" :
setting==3 ? "design level 4" :
setting==4 ? "design level 5" :
"Unknown" );
break;
case 19: /* style options */
return( setting==0 ? "no style options" :
setting==1 ? "display text" :
setting==2 ? "engraved text" :
setting==3 ? "illuminated Caps" :
setting==4 ? "titling caps" :
setting==5 ? "tall caps" :
"Unknown" );
break;
case 20: /* character shape */
return( setting==0 ? "traditional characters" :
setting==1 ? "simplified characters" :
setting==2 ? "jis1978 characters" :
setting==3 ? "jis1983 characters" :
setting==4 ? "jis1990 characters" :
setting==5 ? "traditional alt 1" :
setting==6 ? "traditional alt 2" :
setting==7 ? "traditional alt 3" :
setting==8 ? "traditional alt 4" :
setting==9 ? "traditional alt 5" :
setting==10 ? "expert characters" :
"Unknown" );
break;
case 21: /* number case */
return( setting==0 ? "lower case numbers" :
setting==1 ? "upper case numbers" :
"Unknown" );
break;
case 22: /* text spacing */
return( setting==0 ? "proportional" :
setting==1 ? "monospace" :
setting==2 ? "halfwidth" :
setting==3 ? "normally spaced" :
"Unknown" );
break;
case 23: /* transliteration */
return( setting==0 ? "no transliteration" :
setting==1 ? "hanja to hangul" :
setting==2 ? "hiragana to katakana" :
setting==3 ? "katakana to hiragana" :
setting==4 ? "kana to Romanization" :
setting==5 ? "romanization to Hiragana" :
setting==6 ? "romanization to Katakana" :
setting==7 ? "hanja to hangul alt 1" :
setting==8 ? "hanja to hangul alt 2" :
setting==9 ? "hanja to hangul alt 3" :
setting==10 ? "expert characters" :
"Unknown" );
break;
case 24: /* anotation */
return( setting==0 ? "no annotation" :
setting==1 ? "box annotation" :
setting==2 ? "rounded box annotation" :
setting==3 ? "circle annotation" :
setting==4 ? "inverted circle annotation" :
setting==5 ? "parenthesis Annotation" :
setting==6 ? "period annotation" :
setting==7 ? "roman numeral annotation" :
setting==8 ? "diamond annotation" :
"Unknown" );
break;
case 25: /* kana spacing */
return( setting==0 ? "full width kana" :
setting==1 ? "proportional kana" : /* Proportional Japanese glyphs */
"Unknown" );
break;
case 26: /* ideograph spacing */
return( setting==0 ? "full width ideograph" :
setting==1 ? "proportional ideograph" :
"Unknown" );
break;
case 27: /* Accented letters (determined empirically) */
return( setting==0 ? "On" :
setting==1 ? "Off" :
"Unknown" );
break;
case 103: /* CJK Spacing */
return( setting==0 ? "halfwidth CJK Roman" : /* No change */
setting==1 ? "proportional CJK Roman" :
setting==2 ? "default CJK Roman" : /* Ideal metrics */
setting==3 ? "fullwidth CJK Roman" :
"Unknown" );
break;
case 16000: /* Decomposed Unicode (determined empirically) */
return( setting==0 ? "Compose" :
setting==1 ? "Off" :
"Unknown" );
break;
case 16001: /* Combining character (determined empirically) */
return( setting==0 ? "Combine" :
setting==1 ? "Off" :
"Unknown" );
break;
default:
return( setting==0 ? "Unknown (?On?)" :
setting==1 ? "Unknown (?Off?)" :
"Unknown" );
break;
}
return( "Unknown" );
}
static int showbinsearchheader(FILE *ttf) {
int size, cnt;
printf( "\t Binary search header\n" );
printf( "\t Entry size=%d\n", size = getushort(ttf));
printf( "\t Number of entries=%d\n", cnt = getushort(ttf));
printf( "\t Search range=%d\n", getushort(ttf));
printf( "\t Log2(nUnits)=%d\n", getushort(ttf));
printf( "\t Range Shift=%d\n", getushort(ttf));
return( cnt );
}
static void show_applelookuptable(FILE *ttf,struct ttfinfo *info,void (*show)(FILE *,struct ttfinfo *)) {
int i, j;
int format;
int first, last, cnt, glyph, data_offset;
uint32 here;
uint32 base = ftell(ttf);
printf( "\t Lookup table format=%d ", format = getushort(ttf));
switch ( format ) {
case 0:
printf( "Simple array\n" );
for ( i=0; i<info->glyph_cnt; ++i ) {
printf( "Glyph %d (%s)=", i, i>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ? info->glyph_names[i]: "" );
show( ttf,info );
}
break;
case 2:
printf( "Segment Single\n" );
cnt = showbinsearchheader(ttf);
for ( i=0; i<cnt; ++i ) {
last = getushort(ttf);
first = getushort(ttf);
printf( "All glyphs between %d (%s) and %d (%s)=",
first,
first>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ?
info->glyph_names[first]: "",
last,
last>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ?
info->glyph_names[last]: "" );
show( ttf,info );
}
break;
case 4:
printf( "Segment Array\n" );
cnt = showbinsearchheader(ttf);
for ( i=0; i<cnt; ++i ) {
last = getushort(ttf);
first = getushort(ttf);
data_offset = getushort(ttf);
here = ftell(ttf);
fseek(ttf,base+data_offset,SEEK_SET);
printf( "\t\tSegment %d, from glyph %d to glyph %d. Data offset=%d\n",
i, first, last, data_offset );
for ( j=first; j<=last; ++j ) {
printf( "Glyph %d (%s)=", j,
j>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ?
info->glyph_names[j]: "" );
show( ttf,info );
}
fseek(ttf,here,SEEK_SET);
}
break;
case 6:
printf( "Single table\n" );
cnt = showbinsearchheader(ttf);
for ( i=0; i<cnt; ++i ) {
glyph = getushort(ttf);
printf( "Glyph %d (%s)=", glyph,
glyph>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ?
info->glyph_names[glyph]: "" );
show( ttf,info );
}
break;
case 8:
printf( "Trimmed array\n" );
first = getushort(ttf);
cnt = getushort(ttf);
for ( i=0; i<cnt; ++i ) {
printf( "Glyph %d (%s)=", i+first,
i+first>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ?
info->glyph_names[i+first]: "" );
show( ttf,info );
}
break;
default:
printf( "Unknown format for lookup table %d\n", format );
}
}
/* some class codes are predefined:
0 => End of text
1 => out of bounds (anything outside the glyph range in the class header, and possibly some glyphs within
2 => deleted glyph (0xffff => a glyph has been deleted, should not be in array)
3 => End of line
4 - nclasses-1 => user defined
*/
struct classes {
};
struct statetable {
uint32 state_start;
int nclasses;
int nstates;
int nentries;
int state_offset;
int entry_size; /* size of individual entry */
int entry_extras; /* Number of extra glyph offsets */
int first_glyph; /* that's classifyable */
int nglyphs;
uint8 *classes;
uint8 *state_table; /* state_table[nstates][nclasses], each entry is an */
/* index into the following array */
uint16 *state_table2; /* morx version. States are have 2 byte entries */
uint16 *classes2;
uint8 *transitions;
uint32 extra_offsets[3];
int len; /* Size of the entire subtable */
};
static void show_statetable(struct statetable *st, struct ttfinfo *info, FILE *ttf,
void (*entry_print)(uint8 *entry,struct statetable *st,struct ttfinfo *info,FILE *ttf)) {
int i, j;
uint8 *pt;
printf( "\t State table\n" );
printf( "\t num classes = %d\n", st->nclasses );
printf( "\t num states = %d (derived)\n", st->nstates );
printf( "\t num entries = %d (derived)\n", st->nentries );
printf( "\t entry size = %d (derived)\n", st->entry_size );
printf( "\t first classified glyph = %d (%s), glyph_cnt=%d\n", st->first_glyph,
st->first_glyph>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL?info->glyph_names[st->first_glyph]:"",
st->nglyphs);
if ( info->glyph_names!=NULL ) {
for ( i=0; i<st->nglyphs; ++i )
printf( "\t Glyph %4d -> Class %d (%s)\n",
st->first_glyph+i, st->classes[i],
st->first_glyph+i>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names[st->first_glyph+i]);
} else {
for ( i=0; i<st->nglyphs; ++i )
printf( "\t Glyph %4d -> Class %d\n",
st->first_glyph+i, st->classes[i] );
}
/* Mapping from state x class => transition entry */
printf( "Classes: " );
for ( j=0; j<st->nclasses; ++j )
printf( "%4d", j );
printf( "\n" );
for ( i=0; i<st->nstates; ++i ) {
printf( "State %2d: ", i );
for ( j=0; j<st->nclasses; ++j )
printf( "%4d", st->state_table[i*st->nclasses+j]);
printf( "\n" );
}
/* Transition entries */
for ( i=0; i<st->nentries; ++i ) {
pt = st->transitions + i*st->entry_size;
printf( "\t Transition Entry %d\n", i );
printf( "\t New State %d\n", (((pt[0]<<8)|pt[1])-st->state_offset)/st->nclasses );
if ( entry_print!=NULL )
entry_print(pt,st,info,ttf);
else {
printf( "\t Flags %04x\n", (pt[2]<<8)|pt[3] );
for ( j=0; j<st->entry_extras; ++j )
printf( "\t GlyphOffset[%d] = %d\n", j, (pt[2*j+4]<<8)|pt[2*j+5]);
}
}
printf( "\n" );
}
static void show_statetablex(struct statetable *st, struct ttfinfo *info, FILE *ttf,
void (*entry_print)(uint8 *entry,struct statetable *st,struct ttfinfo *info,FILE *ttf)) {
int i, j;
uint8 *pt;
printf( "\t State table\n" );
printf( "\t num classes = %d\n", st->nclasses );
printf( "\t num states = %d (derived)\n", st->nstates );
printf( "\t num entries = %d (derived)\n", st->nentries );
printf( "\t entry size = %d (derived)\n", st->entry_size );
for ( i=0; i<info->glyph_cnt ; ++i ) if ( st->classes2[i]!=1 ) {
if ( info->glyph_names!=NULL ) {
printf( "\t Glyph %4d -> Class %d (%s)\n",
i, st->classes2[i],
i>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names[i]);
} else {
printf( "\t Glyph %4d -> Class %d\n",
i, st->classes2[i] );
}
}
/* Mapping from state x class => transition entry */
printf( "Classes: " );
for ( j=0; j<st->nclasses; ++j )
printf( "%4d", j );
printf( "\n" );
for ( i=0; i<st->nstates; ++i ) {
printf( "State %2d: ", i );
for ( j=0; j<st->nclasses; ++j )
printf( "%4d", st->state_table2[i*st->nclasses+j]);
printf( "\n" );
}
/* Transition entries */
for ( i=0; i<st->nentries; ++i ) {
pt = st->transitions + i*st->entry_size;
printf( "\t Transition Entry %d\n", i );
printf( "\t New State %d\n", ((pt[0]<<8)|pt[1]) );
if ( entry_print!=NULL )
entry_print(pt,st,info,ttf);
else {
printf( "\t Flags %04x\n", (pt[2]<<8)|pt[3] );
for ( j=0; j<st->entry_extras; ++j )
printf( "\t GlyphOffset[%d] = %d\n", j, (pt[2*j+4]<<8)|pt[2*j+5]);
}
}
printf( "\n" );
}
static void readttf_applelookup(FILE *ttf,struct ttfinfo *info,
void (*apply_values)(struct ttfinfo *info, int gfirst, int glast,FILE *ttf),
void (*apply_value)(struct ttfinfo *info, int gfirst, int glast,FILE *ttf),
void (*apply_default)(struct ttfinfo *info, int gfirst, int glast,void *def),
void *def) {
int format, i, first, last, data_off, cnt, prev;
uint32 here;
uint32 base = ftell(ttf);
switch ( format = getushort(ttf)) {
case 0: /* Simple array */
apply_values(info,0,info->glyph_cnt-1,ttf);
break;
case 2: /* Segment Single */
/* Entry size */ getushort(ttf);
cnt = getushort(ttf);
/* search range */ getushort(ttf);
/* log2(cnt) */ getushort(ttf);
/* range shift */ getushort(ttf);
prev = 0;
for ( i=0; i<cnt; ++i ) {
last = getushort(ttf);
first = getushort(ttf);
if ( apply_default!=NULL )
apply_default(info,prev,first-1,def);
apply_value(info,first,last,ttf);
prev = last+1;
}
break;
case 4: /* Segment multiple */
/* Entry size */ getushort(ttf);
cnt = getushort(ttf);
/* search range */ getushort(ttf);
/* log2(cnt) */ getushort(ttf);
/* range shift */ getushort(ttf);
prev = 0;
for ( i=0; i<cnt; ++i ) {
last = getushort(ttf);
first = getushort(ttf);
data_off = getushort(ttf);
here = ftell(ttf);
if ( apply_default!=NULL )
apply_default(info,prev,first-1,def);
fseek(ttf,base+data_off,SEEK_SET);
apply_values(info,first,last,ttf);
fseek(ttf,here,SEEK_SET);
prev = last+1;
}
break;
case 6: /* Single table */
/* Entry size */ getushort(ttf);
cnt = getushort(ttf);
/* search range */ getushort(ttf);
/* log2(cnt) */ getushort(ttf);
/* range shift */ getushort(ttf);
prev = 0;
for ( i=0; i<cnt; ++i ) {
first = getushort(ttf);
if ( apply_default!=NULL )
apply_default(info,prev,first-1,def);
apply_value(info,first,first,ttf);
prev = first+1;
}
break;
case 8: /* Simple array */
first = getushort(ttf);
cnt = getushort(ttf);
if ( apply_default!=NULL ) {
apply_default(info,0,first-1,def);
apply_default(info,first+cnt,info->glyph_cnt-1,def);
}
apply_values(info,first,first+cnt-1,ttf);
break;
default:
fprintf( stderr, "Invalid lookup table format. %d\n", format );
break;
}
}
static void mortclass_apply_values(struct ttfinfo *info, int gfirst, int glast,FILE *ttf) {
int i;
for ( i=gfirst; i<=glast; ++i )
info->morx_classes[i] = getushort(ttf);
}
static void mortclass_apply_value(struct ttfinfo *info, int gfirst, int glast,FILE *ttf) {
uint16 class;
int i;
class = getushort(ttf);
for ( i=gfirst; i<=glast; ++i )
info->morx_classes[i] = class;
}
static struct statetable *read_statetable(FILE *ttf, int ent_extras, int ismorx, struct ttfinfo *info) {
struct statetable *st = calloc(1,sizeof(struct statetable));
uint32 here = ftell(ttf);
int nclasses, class_off, state_off, entry_off;
int state_max, ent_max, old_state_max, old_ent_max;
int i, j, ent, new_state, ent_size;
st->state_start = here;
if ( ismorx ) {
nclasses = getlong(ttf);
class_off = getlong(ttf);
state_off = getlong(ttf);
entry_off = getlong(ttf);
st->extra_offsets[0] = getlong(ttf);
st->extra_offsets[1] = getlong(ttf);
st->extra_offsets[2] = getlong(ttf);
} else {
nclasses = getushort(ttf); /* Number of bytes per state in state subtable, equal to number of classes */
class_off = getushort(ttf);
state_off = getushort(ttf);
entry_off = getushort(ttf);
st->extra_offsets[0] = getushort(ttf);
st->extra_offsets[1] = getushort(ttf);
st->extra_offsets[2] = getushort(ttf);
}
st->nclasses = nclasses;
st->state_offset = state_off;
/* parse class subtable */
fseek(ttf,here+class_off,SEEK_SET);
if ( ismorx ) {
st->classes2 = info->morx_classes = malloc(info->glyph_cnt*sizeof(uint16));
for ( i=0; i<info->glyph_cnt; ++i )
st->classes2[i] = 1; /* Out of bounds */
readttf_applelookup(ttf,info,
mortclass_apply_values,mortclass_apply_value,NULL,NULL);
} else {
st->first_glyph = getushort(ttf);
st->nglyphs = getushort(ttf);
st->classes = malloc(st->nglyphs);
fread(st->classes,1,st->nglyphs,ttf);
}
/* The size of an entry is variable. There are 2 uint16 fields at the begin-*/
/* ning of all entries. There may be some number of shorts following these*/
/* used for indexing special tables. */
ent_size = 4 + 2*ent_extras;
st->entry_size = ent_size;
st->entry_extras = ent_extras;
/* Apple does not provide a way of figuring out the size of either of the */
/* state or entry tables, so we must parse both as we go and try to work */
/* out the maximum values... */
/* There are always at least 2 states defined. Parse them and find what */
/* is the biggest entry they use, then parse those entries and find what */
/* is the biggest state they use, and then repeat until we don't find any*/
/* more states or entries */
old_state_max = 0; old_ent_max = 0;
state_max = 2; ent_max = 0;
while ( old_state_max!=state_max ) {
i = old_state_max*nclasses;
fseek(ttf,here+state_off+(ismorx?i*sizeof(uint16):i),SEEK_SET);
old_state_max = state_max;
for ( ; i<state_max*nclasses; ++i ) {
ent = ismorx ? getushort(ttf) : getc(ttf);
if ( ent+1 > ent_max )
ent_max = ent+1;
}
if ( ent_max==old_ent_max ) /* Nothing more */
break;
if ( ent_max>1000 ) {
fprintf( stderr, "It looks to me as though there's a morx sub-table with more than 1000\n transitions. Which makes me think there's probably an error\n" );
return( NULL );
}
fseek(ttf,here+entry_off+old_ent_max*ent_size,SEEK_SET);
i = old_ent_max;
old_ent_max = ent_max;
for ( ; i<ent_max; ++i ) {
new_state = getushort(ttf);
if ( !ismorx )
new_state = (new_state-state_off)/nclasses;
/* flags = */ getushort(ttf);
for ( j=0; j<ent_extras; ++j )
/* glyphOffsets[j] = */ getushort(ttf);
if ( new_state+1>state_max )
state_max = new_state+1;
}
if ( state_max>1000 ) {
fprintf( stderr, "It looks to me as though there's a morx sub-table with more than 1000\n states. Which makes me think there's probably an error\n" );
return( NULL );
}
}
st->nstates = state_max;
st->nentries = ent_max;
fseek(ttf,here+state_off,SEEK_SET);
/* an array of arrays of state transitions, each represented by one byte */
/* which is an index into the Entry subtable, which comes next. */
/* One dimension is the number of states, and the other the */
/* number of classes (classes vary faster than states) */
/* The first two states are predefined, 0 is start of text, 1 start of line*/
if ( ismorx ) {
st->state_table2 = malloc(st->nstates*st->nclasses*sizeof(uint16));
for ( i=0; i<st->nstates*st->nclasses; ++i )
st->state_table2[i] = getushort(ttf);
} else {
st->state_table = malloc(st->nstates*st->nclasses);
fread(st->state_table,1,st->nstates*st->nclasses,ttf);
}
/* parse the entry subtable */
fseek(ttf,here+entry_off,SEEK_SET);
st->transitions = malloc(st->nentries*st->entry_size);
fread(st->transitions,1,st->nentries*st->entry_size,ttf);
return( st );
}
static void free_statetable(struct statetable *st) {
if ( st==NULL )
return;
free( st->state_table );
free( st->state_table2 );
free( st->transitions );
free( st->classes );
free( st->classes2 );
free( st );
}
static void show_contextkerndata(uint8 *entry,struct statetable *st,struct ttfinfo *info, FILE *ttf) {
int flags = (entry[2]<<8)|entry[3];
int offset = flags&0x3fff;
int i, k;
printf( "\t Flags %04x ", flags );
if ( flags&0x8000 )
printf( "Add to Kern Stack | ");
if ( flags&0x4000 )
printf( "Don't Advance Glyph" );
else
printf( "Advance Glyph" );
printf( ", ValueOffset = %d\n", offset );
if ( offset!=0 ) {
printf( "Offset=%d, len=%d\n", offset, st->len );
fseek(ttf,offset+st->state_start,SEEK_SET);
printf( "Kerns: " );
for ( i=0; i<8; ++i ) {
printf( "%d ", (k = (short) getushort(ttf)) & ~1 );
if ( k&1 ) /* list is terminated by an odd number */
break;
}
printf( "\n" );
}
}
static void readttfkern_context(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) {
struct statetable *st;
st = read_statetable(ttf,0,false,info);
st->len = stab_len;
show_statetable(st, info, ttf, show_contextkerndata);
free_statetable(st);
}
static void show_indicflags(uint8 *entry,struct statetable *st,struct ttfinfo *info,FILE *ttf) {
int flags = (entry[2]<<8)|entry[3];
printf( "\t Flags %04x ", flags );
if ( flags&0x8000 )
printf( "Mark First | ");
if ( flags&0x2000 )
printf( "Mark Last | " );
if ( flags&0x4000 )
printf( "Don't Advance Glyph " );
else
printf( "Advance Glyph " );
switch( flags&0xf ) {
case 0 :
printf( "No action\n" );
break;
case 1 :
printf( "Ax => xA\n" );
break;
case 2 :
printf( "xD => Dx\n" );
break;
case 3 :
printf( "AxD => DxA\n" );
break;
case 4 :
printf( "ABx => xAB\n" );
break;
case 5 :
printf( "ABx => xBA\n" );
break;
case 6 :
printf( "xCD => CDx\n" );
break;
case 7 :
printf( "xCD => DCx\n" );
break;
case 8 :
printf( "AxCD => CDxA\n" );
break;
case 9 :
printf( "AxCD => DCxA\n" );
break;
case 10 :
printf( "ABxD => DxAB\n" );
break;
case 11 :
printf( "ABxD => DxBA\n" );
break;
case 12 :
printf( "ABxCD => CDxAB\n" );
break;
case 13 :
printf( "ABxCD => CDxBA\n" );
break;
case 14 :
printf( "ABxCD => DCxAB\n" );
break;
case 15 :
printf( "ABxCD => DCxBA\n" );
break;
}
}
static void readttfmort_indic(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) {
struct statetable *st;
st = read_statetable(ttf,0,false,info);
show_statetable(st, info, ttf, show_indicflags);
free_statetable(st);
}
static void readttfmorx_indic(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) {
struct statetable *st;
st = read_statetable(ttf,2,true,info);
show_statetablex(st, info, ttf, show_indicflags);
free_statetable(st);
}
static void show_contextflags(uint8 *entry,struct statetable *st,struct ttfinfo *info, FILE *ttf) {
int flags = (entry[2]<<8)|entry[3];
/* the docs say this is unsigned, but that appears not to be the case */
int mark_offset = (int16) ((entry[4]<<8)|entry[5]);
int cur_offset = (int16) ((entry[6]<<8)|entry[7]);
int i, sub;
printf( "\t Flags %04x ", flags );
if ( flags&0x8000 )
printf( "Set Mark | ");
if ( flags&0x4000 )
printf( "Don't Advance Glyph\n" );
else
printf( "Advance Glyph\n" );
/* I hope this is right, docs leave much to the imagination */
/* (apple does not document the "per-glyph substitution table" used by the */
/* contextual glyph substitution sub-table. */
/* My initial assumption is that there is essentially an big array with one */
/* entry for every glyph indicating what glyph it will be replaced with */
/* Since not all glyphs would be valid the tables are probably trimmed and */
/* the offsets proporting to point to it actually point to garbarge until */
/* adjusted by the appropriate glyph indeces */
/* user will need to look at the table carefully to try and guess what is */
/* meaningful and what isn't */
if ( mark_offset!=0 || cur_offset!=0 ) {
printf( "!!!! Caveat !!!! I am printing out entries that look as though they might\n" );
printf( "!!!! be meaningful, but that is no guarantee. Examine them carefully to\n" );
printf( "!!!! find those sections which are actually used.\n" );
}
printf( "\t Offset to substitution table for marked glyph: %d\n", mark_offset );
if ( mark_offset!=0 ) {
fseek(ttf,2*(mark_offset+st->first_glyph)+st->state_start,SEEK_SET);
for ( i=0; i<st->nglyphs; ++i ) {
sub = getushort(ttf);
if ( sub==0 || (sub>=info->glyph_cnt && sub!=0xffff) )
continue;
printf( "\t Glyph %d ", st->first_glyph+i );
if ( st->first_glyph+i>=info->glyph_cnt )
printf( "!!! Bad Glyph !!! " );
else if ( info->glyph_names!=NULL )
printf( "%s ", info->glyph_names[st->first_glyph+i]);
if ( sub==0xffff )
printf( "-> Deleted" );
else {
printf( "-> Glyph %d ", sub );
if ( sub>=info->glyph_cnt )
printf( "!!! Bad Glyph !!! " );
else if ( info->glyph_names!=NULL )
printf( "%s", info->glyph_names[sub]);
}
putchar('\n');
}
}
printf( "\t Offset to substitution table for current glyph: %d\n", cur_offset );
if ( cur_offset!=0 ) {
fseek(ttf,2*(cur_offset+st->first_glyph)+st->state_start,SEEK_SET);
for ( i=0; i<st->nglyphs; ++i ) {
sub = getushort(ttf);
if ( sub==0 || (sub>=info->glyph_cnt && sub!=0xffff) )
continue;
printf( "\t Glyph %d ", st->first_glyph+i );
if ( st->first_glyph+i>=info->glyph_cnt )
printf( "!!! Bad Glyph !!! " );
else if ( info->glyph_names!=NULL )
printf( "%s ", info->glyph_names[st->first_glyph+i]);
if ( sub==0xffff )
printf( "-> Deleted" );
else {
printf( "-> Glyph %d ", sub );
if ( sub>=info->glyph_cnt )
printf( "!!! Bad Glyph !!! " );
else if ( info->glyph_names!=NULL )
printf( "%s", info->glyph_names[sub]);
}
putchar('\n');
}
}
}
static void readttfmort_context(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) {
struct statetable *st;
st = read_statetable(ttf,2,false,info);
show_statetable(st, info, ttf, show_contextflags);
free_statetable(st);
}
static void mort_noncontextualsubs_glyph( FILE *ttf, struct ttfinfo *info ) {
int gnum = getushort(ttf);
printf( " Glyph %d (%s)\n", gnum,
gnum>=info->glyph_cnt ? "!!!! Bad Glyph !!!!" : info->glyph_names!=NULL ?
info->glyph_names[gnum]: "" );
}
static void show_contextflagsx(uint8 *entry,struct statetable *st,struct ttfinfo *info, FILE *ttf) {
int flags = (entry[2]<<8)|entry[3];
int mark_index = ((entry[4]<<8)|entry[5]);
int cur_index = ((entry[6]<<8)|entry[7]);
printf( "\t Flags %04x ", flags );
if ( flags&0x8000 )
printf( "Set Mark | ");
if ( flags&0x4000 )
printf( "Don't Advance Glyph\n" );
else
printf( "Advance Glyph\n" );
printf( "\t Index to substitution table for marked glyph: %d\n", mark_index );
if ( mark_index!=0xffff ) {
fseek(ttf,st->state_start+st->extra_offsets[0]+4*mark_index,SEEK_SET);
fseek(ttf,st->state_start+st->extra_offsets[0]+getlong(ttf),SEEK_SET);
show_applelookuptable(ttf,info,
mort_noncontextualsubs_glyph);
}
printf( "\t Offset to substitution table for current glyph: %d\n", cur_index );
if ( cur_index!=0xffff ) {
fseek(ttf,st->state_start+st->extra_offsets[0]+4*cur_index,SEEK_SET);
fseek(ttf,st->state_start+st->extra_offsets[0]+getlong(ttf),SEEK_SET);
show_applelookuptable(ttf,info,
mort_noncontextualsubs_glyph);
}
}
static void readttfmorx_context(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) {
struct statetable *st;
st = read_statetable(ttf,2,true,info);
show_statetablex(st, info, ttf, show_contextflagsx);
free_statetable(st);
}
static void show_ligflags(uint8 *entry,struct statetable *st,struct ttfinfo *info, FILE *ttf) {
int flags = (entry[2]<<8)|entry[3];
uint32 val;
printf( "\t Flags %04x ", flags );
if ( flags&0x8000 )
printf( "Set Component | ");
if ( flags&0x4000 )
printf( "Don't Advance Glyph " );
else
printf( "Advance Glyph " );
printf( "Offset=%d\n", flags&0x3fff );
if ( (flags&0x3fff)==0 )
return;
fseek(ttf,st->state_start+(flags&0x3fff),SEEK_SET);
do {
val = getlong(ttf);
printf( "\t lig action %08x %s offset=%d\n", val,
(val&0x80000000)?"last (& store)":
(val&0x40000000)?"store": "delete",
(((int32)val)<<2)>>2 ); /* Sign extend */
/* I think we take 2 * (glyph_id-st->first_glyph + offset) + state_start */
/* we get the ?ushort? at this file address and we add it to an */
/* accumulated total. When we finally get to a store (or last) */
/* we take this accumulated total and ?look it up in the ligature */
/* table? to get a glyph index which is the ligature itself. */
/* Maybe. */
} while ( !(val&0x80000000) );
}
static void readttfmort_lig(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) {
struct statetable *st;
st = read_statetable(ttf,0,false,info);
show_statetable(st, info, ttf, show_ligflags);
free_statetable(st);
}
static void show_ligxflags(uint8 *entry,struct statetable *st,struct ttfinfo *info, FILE *ttf) {
int flags = (entry[2]<<8)|entry[3];
int index = (entry[4]<<8)|entry[5];
uint32 val;
printf( "\t Flags %04x ", flags );
if ( flags&0x8000 )
printf( "Set Component | ");
if ( flags&0x2000 )
printf( "Perform | ");
if ( flags&0x4000 )
printf( "Don't Advance Glyph " );
else
printf( "Advance Glyph " );
if ( flags&0x2000 )
printf( "Index=%d\n", index );
else
printf( "\n");
if ( (flags&0x2000)==0 )
return;
fseek(ttf,st->state_start+st->extra_offsets[0]+4*index,SEEK_SET);
do {
val = getlong(ttf);
printf( "\t lig action %08x %s offset=%d\n", val,
(val&0x80000000)?"last (& store)":
(val&0x40000000)?"store": "delete",
(((int32)val)<<2)>>2 ); /* Sign extend */
/* I think we take 2 * (glyph_id-st->first_glyph + offset) + state_start */
/* we get the ?ushort? at this file address and we add it to an */
/* accumulated total. When we finally get to a store (or last) */
/* we take this accumulated total and ?look it up in the ligature */
/* table? to get a glyph index which is the ligature itself. */
/* Maybe. */
} while ( !(val&0x80000000) );
}
static void readttfmorx_lig(FILE *ttf, FILE *util, struct ttfinfo *info, int stab_len) {
struct statetable *st;
st = read_statetable(ttf,1,true,info);
show_statetablex(st, info, ttf, show_ligxflags);
free_statetable(st);
}
static int32 memlong(uint8 *data,int offset) {
int ch1 = data[offset], ch2 = data[offset+1], ch3 = data[offset+2], ch4 = data[offset+3];
return( (ch1<<24)|(ch2<<16)|(ch3<<8)|ch4 );
}
static int memushort(uint8 *data,int offset) {
int ch1 = data[offset], ch2 = data[offset+1];
return( (ch1<<8)|ch2 );
}
#define MAX_LIG_COMP 16
struct statemachine {
uint8 *data;
int length;
uint32 nClasses;
uint32 classOffset, stateOffset, entryOffset, ligActOff, compOff, ligOff;
uint16 *classes;
uint16 lig_comp_classes[MAX_LIG_COMP];
uint16 lig_comp_glyphs[MAX_LIG_COMP];
int lcp;
uint8 *states_in_use;
int smax;
struct ttfinfo *info;
int cnt;
};
static void mort_figure_ligatures(struct statemachine *sm, int lcp, int off, int32 lig_offset) {
uint32 lig;
int i, j, lig_glyph;
if ( lcp<0 || off+3>sm->length )
return;
lig = memlong(sm->data,off);
off += sizeof(long);
for ( i=0; i<sm->info->glyph_cnt; ++i ) if ( sm->classes[i]==sm->lig_comp_classes[lcp] ) {
sm->lig_comp_glyphs[lcp] = i;
lig_offset += memushort(sm->data,2*( ((((int32) lig)<<2)>>2) + i ) );
if ( lig&0xc0000000 ) {
if ( lig_offset+1 > sm->length ) {
fprintf( stderr, "Invalid ligature offset\n" );
break;
}
lig_glyph = memushort(sm->data,lig_offset);
if ( lig_glyph>=sm->info->glyph_cnt ) {
fprintf(stderr, "Attempt to make a ligature for glyph %d out of ", lig_glyph );
for ( j=lcp; j<sm->lcp; ++j )
fprintf(stderr,"%d ",sm->lig_comp_glyphs[j]);
fprintf(stderr,"\n");
} else {
printf( "\t\tGlyph %d (%s) is a ligature of:\n",
lig_glyph, lig_glyph>=sm->info->glyph_cnt ? "!!!! Bad Glyph !!!!" : sm->info->glyph_names!=NULL ? sm->info->glyph_names[lig_glyph] : "" );
for ( j=lcp; j<sm->lcp; ++j )
printf( "\t\t\t%d (%s)\n", sm->lig_comp_glyphs[j],
sm->lig_comp_glyphs[j]>=sm->info->glyph_cnt ? "!!!! Bad Glyph !!!!" : sm->info->glyph_names!=NULL ? sm->info->glyph_names[sm->lig_comp_glyphs[j]] : "" );
}
} else
mort_figure_ligatures(sm,lcp-1,off,lig_offset);
lig_offset -= memushort(sm->data,2*( ((((int32) lig)<<2)>>2) + i ) );
}
}
static void follow_mort_state(struct statemachine *sm,int offset,int class) {
int state = (offset-sm->stateOffset)/sm->nClasses;
int class_top, class_bottom;
if ( state<0 || state>=sm->smax || sm->states_in_use[state] || sm->lcp>=MAX_LIG_COMP )
return;
++ sm->cnt;
if ( sm->cnt>=max_lig_nest ) {
if ( sm->cnt==max_lig_nest )
fprintf( stderr, "ligature state machine too complex, giving up\n" );
return;
}
sm->states_in_use[state] = true;
if ( class==-1 ) { class_bottom = 0; class_top = sm->nClasses; }
else { class_bottom = class; class_top = class+1; }
for ( class=class_bottom; class<class_top; ++class ) {
int ent = sm->data[offset+class];
int newState = memushort(sm->data,sm->entryOffset+4*ent);
int flags = memushort(sm->data,sm->entryOffset+4*ent+2);
if (( state!=0 && sm->data[sm->stateOffset+class] == ent ) || /* If we have the same entry as state 0, then presumably we are ignoring the components read so far and starting over with a new lig */
(state>1 && sm->data[sm->stateOffset+sm->nClasses+class]==ent )) /* Similarly for state 1 */
continue;
if ( flags&0x8000 ) /* Set component */
sm->lig_comp_classes[sm->lcp++] = class;
if ( flags&0x3fff ) {
mort_figure_ligatures(sm, sm->lcp-1, flags & 0x3fff, 0);
} else if ( flags&0x8000 )
follow_mort_state(sm,newState,(flags&0x4000)?class:-1);
if ( flags&0x8000 )
--sm->lcp;
}
sm->states_in_use[state] = false;
}
static void morx_figure_ligatures(struct statemachine *sm, int lcp, int ligindex, int32 lig_offset) {
uint32 lig;
int i, j, lig_glyph;
if ( lcp<0 || sm->ligActOff+4*ligindex+3>sm->length )
return;
lig = memlong(sm->data,sm->ligActOff+4*ligindex);
++ligindex;
for ( i=0; i<sm->info->glyph_cnt; ++i ) if ( sm->classes[i]==sm->lig_comp_classes[lcp] ) {
sm->lig_comp_glyphs[lcp] = i;
lig_offset += memushort(sm->data,sm->compOff + 2*( ((((int32) lig)<<2)>>2) + i ) );
if ( lig&0xc0000000 ) {
if ( sm->ligOff+2*lig_offset+1 > sm->length ) {
fprintf( stderr, "Invalid ligature offset\n" );
break;
}
lig_glyph = memushort(sm->data,sm->ligOff+2*lig_offset);
if ( lig_glyph>=sm->info->glyph_cnt ) {
fprintf(stderr, "Attempt to make a ligature for glyph %d out of " );
for ( j=lcp; j<sm->lcp; ++j )
fprintf(stderr,"%d ",sm->lig_comp_glyphs[j]);
fprintf(stderr,"\n");
} else {
printf( "\t\tGlyph %d (%s) is a ligature of:\n",
lig_glyph, lig_glyph>=sm->info->glyph_cnt ? "!!!! Bad Glyph !!!!" : sm->info->glyph_names!=NULL ? sm->info->glyph_names[lig_glyph] : "" );
for ( j=lcp; j<sm->lcp; ++j )
printf( "\t\t\t%d (%s)\n", sm->lig_comp_glyphs[j],
sm->lig_comp_glyphs[j]>=sm->info->glyph_cnt ? "!!!! Bad Glyph !!!!" : sm->info->glyph_names!=NULL ? sm->info->glyph_names[sm->lig_comp_glyphs[j]] : "" );
}
} else
morx_figure_ligatures(sm,lcp-1,ligindex,lig_offset);
lig_offset -= memushort(sm->data,sm->compOff + 2*( ((((int32) lig)<<2)>>2) + i ) );
}
}
static void follow_morx_state(struct statemachine *sm,int state,int class) {
int class_top, class_bottom;
if ( state<0 || state>=sm->smax || sm->states_in_use[state] || sm->lcp>=MAX_LIG_COMP )
return;
++ sm->cnt;
if ( sm->cnt>=max_lig_nest ) {
if ( sm->cnt==max_lig_nest )
fprintf( stderr, "ligature state machine too complex, giving up\n" );
return;
}
sm->states_in_use[state] = true;
if ( class==-1 ) { class_bottom = 0; class_top = sm->nClasses; }
else { class_bottom = class; class_top = class+1; }
for ( class=class_bottom; class<class_top; ++class ) {
int ent = memushort(sm->data, sm->stateOffset + 2*(state*sm->nClasses+class) );
int newState = memushort(sm->data,sm->entryOffset+6*ent);
int flags = memushort(sm->data,sm->entryOffset+6*ent+2);
int ligindex = memushort(sm->data,sm->entryOffset+6*ent+4);
/* If we have the same entry as state 0, then presumably we are */
/* ignoring the components read so far and starting over with a new */
/* lig (similarly for state 1) */
if (( state!=0 && memushort(sm->data, sm->stateOffset + 2*class) == ent ) ||
(state>1 && memushort(sm->data, sm->stateOffset + 2*(sm->nClasses+class))==ent ))
continue;
if ( flags&0x8000 ) /* Set component */
sm->lig_comp_classes[sm->lcp++] = class;
if ( flags&0x2000 ) {
morx_figure_ligatures(sm, sm->lcp-1, ligindex, 0);
} else if ( flags&0x8000 )
follow_morx_state(sm,newState,(flags&0x4000)?class:-1);
if ( flags&0x8000 )
--sm->lcp;
}
sm->states_in_use[state] = false;
}
static void readttf_mortx_lig(FILE *ttf,struct ttfinfo *info,int ismorx,uint32 base,uint32 length) {
uint32 here;
struct statemachine sm;
int first, cnt, i;
memset(&sm,0,sizeof(sm));
sm.info = info;
here = ftell(ttf);
length -= here-base;
sm.data = malloc(length);
sm.length = length;
if ( fread(sm.data,1,length,ttf)!=length ) {
free(sm.data);
fprintf( stderr, "Bad mort/morx ligature table. Not long enough\n");
return;
}
fseek(ttf,here,SEEK_SET);
if ( ismorx ) {
sm.nClasses = memlong(sm.data,0);
sm.classOffset = memlong(sm.data,sizeof(long));
sm.stateOffset = memlong(sm.data,2*sizeof(long));
sm.entryOffset = memlong(sm.data,3*sizeof(long));
sm.ligActOff = memlong(sm.data,4*sizeof(long));
sm.compOff = memlong(sm.data,5*sizeof(long));
sm.ligOff = memlong(sm.data,6*sizeof(long));
fseek(ttf,here+sm.classOffset,SEEK_SET);
sm.classes = info->morx_classes = malloc(info->glyph_cnt*sizeof(uint16));
for ( i=0; i<info->glyph_cnt; ++i )
sm.classes[i] = 1; /* Out of bounds */
readttf_applelookup(ttf,info,
mortclass_apply_values,mortclass_apply_value,NULL,NULL);
sm.smax = length/(2*sm.nClasses);
sm.states_in_use = calloc(sm.smax,sizeof(uint8));
follow_morx_state(&sm,0,-1);
} else {
sm.nClasses = memushort(sm.data,0);
sm.classOffset = memushort(sm.data,sizeof(uint16));
sm.stateOffset = memushort(sm.data,2*sizeof(uint16));
sm.entryOffset = memushort(sm.data,3*sizeof(uint16));
sm.ligActOff = memushort(sm.data,4*sizeof(uint16));
sm.compOff = memushort(sm.data,5*sizeof(uint16));
sm.ligOff = memushort(sm.data,6*sizeof(uint16));
sm.classes = malloc(info->glyph_cnt*sizeof(uint16));
for ( i=0; i<info->glyph_cnt; ++i )
sm.classes[i] = 1; /* Out of bounds */
first = memushort(sm.data,sm.classOffset);
cnt = memushort(sm.data,sm.classOffset+sizeof(uint16));
for ( i=0; i<cnt; ++i )
sm.classes[first+i] = sm.data[sm.classOffset+2*sizeof(uint16)+i];
sm.smax = length/sm.nClasses;
sm.states_in_use = calloc(sm.smax,sizeof(uint8));
follow_mort_state(&sm,sm.stateOffset,-1);
}
free(sm.data);
free(sm.states_in_use);
free(sm.classes);
}
static void readttfmetamorph(FILE *ttf, FILE *util, struct ttfinfo *info) {
int n, i, j, k, l, nf, ns, type, setting, stab_len, coverage;
uint32 chain_start, len, temp, stab_start, flags, here;
int features[32], settings[32], masks[32];
int ismorx = false;
if ( info->morx_start!=0 ) {
fseek(ttf,info->morx_start,SEEK_SET);
printf( "\nmorx table (at %d) (Glyph metamorphosis extended)\n", info->morx_start );
ismorx = true;
} else {
fseek(ttf,info->mort_start,SEEK_SET);
printf( "\nmort table (at %d) (Glyph metamorphosis)\n", info->mort_start );
}
printf( "\t version=%g\n", getfixed(ttf));
n = getlong(ttf);
printf( "\t number of chains=%d\n", n);
for ( i=0; i<n; ++i ) {
printf( "\t For Chain %d\n", i );
chain_start = ftell(ttf);
printf( "\t default flags=%lx\n", getlong(ttf));
printf( "\t chain length=%ld\n", (long) (len = getlong(ttf)));
printf( "\t number Feature Entries=%d\n", nf = ismorx ? getlong(ttf) : getushort(ttf));
printf( "\t number Subtables=%d\n", ns = ismorx ? getlong(ttf) : getushort(ttf));
for ( j=k=0; j<nf; ++j ) {
printf( "\t For Feature %d of Chain %d\n", j, i );
printf( "\t Feature Type=%d ", type = getushort(ttf));
printf( "%s\n", getfeaturename(info,type));
printf( "\t Feature Setting=%d ", setting=getushort(ttf));
printf( "%s\n", getsettingname(info,type, setting));
printf( "\t Enable Flags=%08lx\n", flags = getlong(ttf));
printf( "\t Disable Flags=%08lx ", (long) (temp=getlong(ttf)));
printf( "(Complement=%08lx)\n", ~temp);
/* try to get a unique flag value for this feature setting */
for ( l=0; l<k; ++l )
flags &= ~masks[l];
if ( k<32 && flags!=0 ) {
features[k] = type;
settings[k] = setting;
masks[k++] = flags;
}
}
for ( j=0; j<ns; ++j ) {
stab_start = ftell(ttf);
if ( ismorx ) {
stab_len = getlong(ttf);
coverage = getlong(ttf);
} else {
stab_len = getushort(ttf);
coverage = getushort(ttf);
coverage = ((coverage&0xe000)<<16) | (coverage&7); /* convert to morx format */
}
flags = getlong(ttf);
for ( l=0; l<k; ++l )
if ( masks[l]==flags )
break;
printf( "\t Subtable %d ", j);
if ( l!=k )
printf( "Probably for feature=%d (%s)\n\t\t setting=%d (%s)\n",
features[l], getfeaturename(info,features[l]),
settings[l], getsettingname(info,features[l],settings[l]));
else
printf( "\n" );
printf( "\t Length = %d\n", stab_len );
printf( "\t Coverage = %08x, Apply=%s Search=%s\n\t\tType=%s\n",
coverage,
(coverage&0x20000000) ? "Always" : (coverage&0x80000000) ? "Vertical" : "Horizontal",
(coverage&0x40000000) ? "Descending (?Right2Left?)" : "Ascending (?Left2Right?)",
(coverage&0xff)==0 ? "Indic rearrangement" :
(coverage&0xff)==1 ? "contextual glyph substitution" :
(coverage&0xff)==2 ? "Ligature substitution" :
(coverage&0xff)==4 ? "non-contextual glyph substitution" :
(coverage&0xff)==5 ? "contextual glyph insertion" :
"Unknown" );
printf( "\t Flags=%08lx\n", (long) flags );
switch( (coverage&0x7) ) {
case 0:
if ( !ismorx )
readttfmort_indic(ttf,util,info,stab_len);
else
readttfmorx_indic(ttf,util,info,stab_len);
break;
case 1:
if ( !ismorx )
readttfmort_context(ttf,util,info,stab_len);
else
readttfmorx_context(ttf,util,info,stab_len);
break;
case 2:
here = ftell(ttf);
readttf_mortx_lig(ttf,info,ismorx,stab_start,stab_len);
if ( verbose ) {
fseek(ttf,here,SEEK_SET);
if ( !ismorx )
readttfmort_lig(ttf,util,info,stab_len);
else
readttfmorx_lig(ttf,util,info,stab_len);
}
break;
case 4:
show_applelookuptable(ttf,info,
mort_noncontextualsubs_glyph);
break;
case 5:
break;
}
fseek(ttf,stab_start+stab_len,SEEK_SET);
}
len = ((len+3)>>2)<<2;
fseek(ttf,chain_start+len,SEEK_SET);
}
}
static void showagproperties( uint16 props ) {
printf( "%04x=", props );
if ( props&0x8000 ) printf( "Floater|" );
if ( props&0x4000 ) printf( "HangLeft|" );
if ( props&0x2000 ) printf( "HangRight|" );
if ( props&0x1000 ) printf( "Mirror += %d|", (((int32) props)<<20)>>28 );
if ( props&0x0080 ) printf( "AttachRight|" );
switch (props&0x1f ) {
case 0: printf( "Strong L2R" ); break;
case 1: printf( "Strong Hebrew" ); break;
case 2: printf( "Strong Arabic" ); break;
case 3: printf( "Euro Digit" ); break;
case 4: printf( "Euro Num Sep" ); break;
case 5: printf( "Euro Num Term" ); break;
case 6: printf( "Arabic Digit" ); break;
case 7: printf( "Common Num Sep" ); break;
case 8: printf( "Block Sep" ); break;
case 9: printf( "Segment Sep" ); break;
case 10: printf( "White Space" ); break;
case 11: printf( "Other Neutral" ); break;
default: printf( "Undocumented Unicode 3 direction %d", props&0x1f ); break;
}
putchar('\n');
}
static void prop_show( FILE *ttf, struct ttfinfo *info ) {
showagproperties( getushort(ttf));
}
static void readttfappleprop(FILE *ttf, FILE *util, struct ttfinfo *info) {
fseek(ttf,info->prop_start,SEEK_SET);
printf( "\nprop table (at %d) (Glyph properties)\n", info->prop_start );
printf( "\t version=%g\n", getfixed(ttf));
printf( "\t has lookup data=%d\n", getushort(ttf));
printf( "\t default properties=" );
showagproperties( getushort(ttf));
show_applelookuptable(ttf,info,prop_show);
}
static void lcar_show( FILE *ttf, struct ttfinfo *info ) {
uint32 here;
int cnt,i,off;
off = getushort(ttf);
here = ftell(ttf);
fseek(ttf, info->lcar_start+off,SEEK_SET );
printf( " caret cnt=%d\n", cnt = getushort(ttf));
for ( i=0; i<cnt; ++i )
printf( "\t\tcaret %d at %d\n", i, getushort(ttf));
fseek(ttf,here,SEEK_SET);
}
static void readttfapplelcar(FILE *ttf, FILE *util, struct ttfinfo *info) {
fseek(ttf,info->lcar_start,SEEK_SET);
printf( "\nlcar table (at %d) (Ligature carets)\n", info->lcar_start );
printf( "\t version=%g\n", getfixed(ttf));
printf( "\t data are points=%d\n", getushort(ttf));
show_applelookuptable(ttf,info,lcar_show);
}
static void opbd_show( FILE *ttf, struct ttfinfo *info ) {
uint32 here;
int off;
off = getushort(ttf);
here = ftell(ttf);
fseek(ttf, info->opbd_start+off,SEEK_SET );
printf( " optical left=%d\n", (short) getushort(ttf));
printf( " optical top=%d\n", (short) getushort(ttf));
printf( " optical right=%d\n", (short) getushort(ttf));
printf( " optical bottom=%d\n", (short) getushort(ttf));
fseek(ttf,here,SEEK_SET);
}
static void readttfappleopbd(FILE *ttf, FILE *util, struct ttfinfo *info) {
fseek(ttf,info->opbd_start,SEEK_SET);
printf( "\nopbd table (at %d) (Optical Bounds)\n", info->opbd_start );
printf( "\t version=%g\n", getfixed(ttf));
printf( "\t data are points=%d\n", getushort(ttf));
show_applelookuptable(ttf,info,opbd_show);
}
static void readttfapplefvar(FILE *ttf, FILE *util, struct ttfinfo *info) {
int dataoff, countsizepairs, axiscount, instancecount, instancesize, nameid;
uint32 tag;
char *name;
int i,j;
fseek(ttf,info->fvar_start,SEEK_SET);
printf( "\nfvar table (at %d) (Font Variations)\n", info->fvar_start );
printf( "\t version=%g\n", getfixed(ttf));
printf( "\t offset to data=%d\n", dataoff = getushort(ttf));
printf( "\t # size pairs=%d\n", countsizepairs = getushort(ttf));
printf( "\t Axis count=%d\n", axiscount = getushort(ttf));
info->fvar_axiscount = axiscount;
printf( "\t Axis size=%d\n", getushort(ttf));
printf( "\t Instance count=%d\n", instancecount = getushort(ttf));
printf( "\t Instance size=%d\n", instancesize = getushort(ttf));
for ( i=0; i<axiscount; ++i ) {
printf( "\t Axis %d\n", i );
tag = getlong(ttf);
printf( "\t Axis Tag '%c%c%c%c'\n",
tag>>24, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff);
printf( "\t minValue=%g\n", getfixed(ttf));
printf( "\t defaultValue=%g\n", getfixed(ttf));
printf( "\t maxValue=%g\n", getfixed(ttf));
printf( "\t flags=%x\n", getushort(ttf));
nameid = getushort(ttf);
name = getttfname(util,info,nameid);
printf( "\t nameid=%d (%s)\n", nameid, name==NULL ? "Not Found" : name );
}
for ( i=0; i<instancecount; ++i ) {
printf( "\t Instance %d\n", i );
nameid = getushort(ttf);
name = getttfname(util,info,nameid);
printf( "\t nameid=%d (%s)\n", nameid, name==NULL ? "Not Found" : name );
printf( "\t flags=%x\n", getushort(ttf));
printf( "\t Blend coefficients: ");
for ( j=0; j<axiscount; ++j )
printf( "%g, ", getfixed(ttf));
printf( "\n" );
}
printf( "\n" );
}
static void readttfapplegvar(FILE *ttf, FILE *util, struct ttfinfo *info) {
int axiscount, gcc, glyphCount, flags;
uint32 *offsets, offset2Coord, offset2Data;
int tupleCount, offset;
int i, j, k, index;
fseek(ttf,info->gvar_start,SEEK_SET);
printf( "\ngvar table (at %d) (Glyph Variations)\n", info->gvar_start );
printf( "\t version=%g\n", getfixed(ttf));
printf( "\t Axis count=%d\n", axiscount = getushort(ttf));
if ( axiscount!=info->fvar_axiscount )
fprintf( stderr, "The axis count in the gvar table differs from that in the fvar table.\n 'gvar' axes=%d, 'fvar' axes=%d\n", axiscount, info->fvar_axiscount );
printf( "\t global coord count=%d\n", gcc = getushort(ttf));
printf( "\t offset to coord=%d\n", offset2Coord = getlong(ttf));
printf( "\t glyph count=%d\n", glyphCount = getushort(ttf));
printf( "\t flags=%x\n", flags = getushort(ttf));
printf( "\t offset to data=%x\n", offset2Data = getlong(ttf));
offsets = malloc(glyphCount*sizeof(uint32));
if ( flags&1 ) {
for ( i=0; i<glyphCount; ++i )
offsets[i] = getlong(ttf) + offset2Data + info->gvar_start;
} else {
for ( i=0; i<glyphCount; ++i )
offsets[i] = getushort(ttf)*2 + offset2Data + info->gvar_start;
}
for ( i=0; i<glyphCount; ++i ) if ( offsets[i]!=offsets[i+1] ) {
fseek(ttf,offsets[i],SEEK_SET);
printf( "\t Glyph %d %s\n", i, info->glyph_names!=NULL? info->glyph_names[i]: "" );
tupleCount = getushort(ttf);
offset = getushort(ttf);
printf( "\t Tuple count=%x, (count=%d) tuples %sshare points\n",
tupleCount, tupleCount&0xfff,
(tupleCount&0x8000)? "" : "do not " );
printf( "\t Offset=%d\n", offset );
for ( j=0; j<(tupleCount&0xfff); ++j ) {
printf( "\t Tuple %d\n", j );
printf( "\t Size %d\n", getushort(ttf) );
index = getushort(ttf);
printf( "\t Index %d%s%s%s\n", index&0xfff,
index&0x8000 ? ", Embedded tuple" : "",
index&0x4000 ? ", Intermediate tuple" : "",
index&0x2000 ? ", Private points" : "" );
if ( index&0x8000 ) {
printf( "\t Coords[%g", ((short) getushort(ttf))/16384.0 );
for ( k=1; k<axiscount; ++k )
printf( ",%g", ((short) getushort(ttf))/16384.0 );
printf( "]\n" );
}
if ( index&0x4000 ) {
printf( "\t Intermediate[%g-%g", ((short) getushort(ttf)/16384.0),
((short) getushort(ttf)/16384.0));
for ( k=1; k<axiscount; ++k )
printf( ",%g-%g", ((short) getushort(ttf)/16384.0),
((short) getushort(ttf)/16384.0));
printf( "]\n" );
}
if ( !(index&0xc000) ) {
int here = ftell(ttf);
fseek(ttf,info->gvar_start+offset2Coord+(index&0xfff)*axiscount*2,SEEK_SET);
printf( "\t Global Coords[%g", ((short) getushort(ttf))/16384.0 );
for ( k=1; k<axiscount; ++k )
printf( ",%g", ((short) getushort(ttf))/16384.0 );
printf( "]\n" );
fseek(ttf,here,SEEK_SET);
}
}
}
printf( "\n" );
}
static void readttfgasp(FILE *ttf, FILE *util, struct ttfinfo *info) {
int n, i, ppem, flags, last=0;
fseek(ttf,info->gasp_start,SEEK_SET);
printf( "\ngasp table (at %d) (grid fitting and scan conversion table)\n", info->gasp_start );
printf( "\t version=%d\n", getushort(ttf));
printf( "\t Number of gasp entries=%d\n", n = getushort(ttf));
for ( i=0; i<n; ++i ) {
ppem = getushort(ttf);
flags = getushort(ttf);
if ( i==0 && ppem==0xffff )
printf( "\t All sizes: " );
else if ( i==0 )
printf( "\t Sizes below %d: \t", ppem );
else if ( ppem!=0xffff )
printf( "\t Sizes >= %d and <%d:\t", last, ppem );
else
printf( "\t All sizes >= %d: \t", last );
last = ppem;
if ( flags==0 )
printf( "Nothing (No gridfitting, no anti-aliasing)\n" );
else if ( flags==1 )
printf( "Grid Fit (no anti-aliasing)\n" );
else if ( flags==2 )
printf( "Anti-alias (no grid fitting)\n" );
else
printf( "Both Grid Fitting and Anti-Aliasing\n" );
}
}
#if 0
static void readtablebytes(FILE *ttf, int start, int len, char *string) {
int i;
if ( start==0 )
return;
fseek(ttf,start,SEEK_SET);
printf( "\n%s table (at %d for %d bytes)\n\t", string, start, len );
for ( i=0; i<len; ++i )
printf( "0x%x, ", getc(ttf));
printf("\n");
}
#endif
static void readtableinstr(FILE *ttf, int start, int len, char *string) {
int i, j, ch, n, ch1, ch2;
if ( start==0 )
return;
fseek(ttf,start,SEEK_SET);
printf( "\n%s table (at %d for %d bytes)\n\t", string, start, len );
for ( i=0; i<len; ++i ) {
printf( "%s ", instrs[ch = getc(ttf)]);
if ( ch==0x40 ) { /* NPUSHB */
printf( "(%d) ", n = getc(ttf)); ++i;
for ( j=0; j<n; ++j, ++i )
printf( "%d ", getc(ttf));
printf( "\n" );
} else if ( ch==0x41 ) { /* NPUSHW */
printf( "(%d) ", n = getc(ttf)); ++i;
for ( j=0; j<n; ++j, i += 2 ) {
ch1=getc(ttf); ch2 = getc(ttf);
printf( "%d ", (short) ((ch1<<8)|ch2) );
}
printf( "\n" );
} else if ( ch>=0xb0 && ch<=0xb7 ) { /* PUSHBn */
n = (ch-0xb0)+1;
for ( j=0; j<n; ++j, ++i )
printf( "%d ", getc(ttf));
printf( "\n" );
} else if ( ch>=0xb8 && ch<=0xbf ) {
n = (ch-0xb8)+1;
for ( j=0; j<n; ++j, i += 2 ) {
ch1=getc(ttf); ch2 = getc(ttf);
printf( "%d ", (short) ((ch1<<8)|ch2) );
}
printf( "\n" );
}
}
printf("\n");
}
static char **readcfffontnames(FILE *ttf, int ltype) {
uint16 count = getushort(ttf);
int offsize;
uint32 *offsets;
char **names;
int i,j;
static char *labels[] = { "Font Name", "String", NULL };
static char *lab2[] = { "fontnames", "strings", NULL };
printf( "\nThere %s %d %s in this cff\n", count==1?"is":"are", count, lab2[ltype] );
if ( count==0 )
return( NULL );
offsets = malloc((count+1)*sizeof(uint32));
offsize = getc(ttf);
printf( " Name Index Offset Size: %d\n Offsets: ", offsize );
for ( i=0; i<=count; ++i ) {
offsets[i] = getoffset(ttf,offsize);
if ( i==0 && offsets[0]!=1 )
fprintf(stderr, "!! Initial offset must be one in %s\n", labels[ltype]);
printf( "%d ", offsets[i]);
}
putchar('\n');
names = malloc((count+1)*sizeof(char *));
for ( i=0; i<count; ++i ) {
names[i] = malloc(offsets[i+1]-offsets[i]+1);
for ( j=0; j<offsets[i+1]-offsets[i]; ++j )
names[i][j] = getc(ttf);
names[i][j] = '\0';
printf( " %s %2d: %s\n", labels[ltype], i, names[i]);
}
names[i] = NULL;
free(offsets);
return( names );
}
static char *addnibble(char *pt, int nib) {
if ( nib<=9 )
*pt++ = nib+'0';
else if ( nib==10 )
*pt++ = '.';
else if ( nib==11 )
*pt++ = 'E';
else if ( nib==12 ) {
*pt++ = 'E';
*pt++ = '-';
} else if ( nib==14 )
*pt++ = '-';
else if ( nib==15 )
*pt++ = '\0';
return( pt );
}
static int readcffthing(FILE *ttf,int *_ival,double *dval,int *operand) {
char buffer[50], *pt;
int ch, ival;
ch = getc(ttf);
if ( ch==12 ) {
*operand = (12<<8) | getc(ttf);
return( 3 );
} else if ( ch<=21 ) {
*operand = ch;
return( 3 );
} else if ( ch==30 ) {
pt = buffer;
do {
ch = getc(ttf);
pt = addnibble(pt,ch>>4);
pt = addnibble(pt,ch&0xf);
} while ( pt[-1]!='\0' );
*dval = strtod(buffer,NULL);
return( 2 );
} else if ( ch>=32 && ch<=246 ) {
*_ival = ch-139;
return( 1 );
} else if ( ch>=247 && ch<=250 ) {
*_ival = ((ch-247)<<8) + getc(ttf)+108;
return( 1 );
} else if ( ch>=251 && ch<=254 ) {
*_ival = -((ch-251)<<8) - getc(ttf)-108;
return( 1 );
} else if ( ch==28 ) {
ival = getc(ttf)<<8;
*_ival = (short) (ival | getc(ttf));
return( 1 );
} else if ( ch==29 ) {
ival = getc(ttf)<<24;
ival = ival | getc(ttf)<<16;
ival = ival | getc(ttf)<<8;
*_ival = (int) (ival | getc(ttf));
return( 1 );
}
printf( "Unexpected value in dictionary %d\n", ch );
*_ival = 0;
return( 0 );
}
struct pschars {
int cnt, next;
char **keys;
uint8 **values;
int *lens;
int bias;
};
struct topdicts {
int32 cff_start;
char *fontname; /* From Name Index */
int version;
int notice; /* SID */
int copyright; /* SID */
int fullname; /* SID */
int familyname; /* SID */
int weight; /* SID */
int isfixedpitch;
double italicangle;
double underlinepos;
double underlinewidth;
int painttype;
int charstringtype;
double fontmatrix[6];
int uniqueid;
double fontbb[4];
double strokewidth;
int xuid[20];
int charsetoff; /* from start of file */
int encodingoff; /* from start of file */
int charstringsoff; /* from start of file */
int private_size;
int private_offset; /* from start of file */
int synthetic_base; /* font index */
int postscript_code; /* SID */
/* synthetic fonts only */
int basefontname; /* SID */
int basefontblend[16]; /* delta */
/* CID fonts only (what we expect to get) */
int ros_registry; /* SID */
int ros_ordering; /* SID */
int ros_supplement;
int cidfontversion;
int cidfontrevision;
int cidfonttype;
int cidcount;
int uidbase;
int fdarrayoff; /* from start of file */
int fdselectoff; /* from start of file */
int sid_fontname; /* SID */
/* Private stuff */
double bluevalues[14];
double otherblues[10];
double familyblues[14];
double familyotherblues[10];
double bluescale;
double blueshift;
double bluefuzz;
int stdhw;
int stdvw;
double stemsnaph[10];
double stemsnapv[10];
int forcebold;
int languagegroup;
double expansionfactor;
int initialRandomSeed;
int subrsoff; /* from start of this private table */
int defaultwidthx;
int nominalwidthx;
struct pschars glyphs;
struct pschars local_subrs;
uint16 *charset;
};
static void ShowCharString(uint8 *str,int len,int type) {
int v;
int val;
/* most things are the same about type1 and type2 strings. Type2 just has */
/* extra operators (and gets rid of seac). The 5 byte number sequence is */
/* different though... */
do {
if ( (v = *str++)>=32 ) {
if ( v<=246) {
val = v - 139;
} else if ( v<=250 ) {
val = (v-247)*256 + *str++ + 108;
--len;
} else if ( v<=254 ) {
val = -(v-251)*256 - *str++ - 108;
--len;
} else {
val = (*str<<24) | (str[1]<<16) | (str[2]<<8) | str[3];
str += 4;
len -= 4;
}
if ( v==0xff && type==2 )
printf( "%g ", val/65536. );
else
printf( "%d ", val );
} else if ( v==28 ) {
val = (short) ((str[0]<<8) | str[1]);
str += 2;
len -= 2;
printf( "%d ", val );
} else if ( v==12 ) {
v = *str++;
--len;
switch ( v ) {
case 3: printf( "and " ); break;
case 4: printf( "or " ); break;
case 5: printf( "not " ); break;
case 9: printf( "abs " ); break;
case 10: printf( "add " ); break;
case 11: printf( "sub " ); break;
case 12: printf( "div " ); break;
case 14: printf( "neg " ); break;
case 15: printf( "eq " ); break;
case 18: printf( "drop " ); break;
case 20: printf( "put " ); break;
case 21: printf( "get " ); break;
case 22: printf( "ifelse " ); break;
case 23: printf( "random " ); break;
case 24: printf( "mul " ); break;
case 26: printf( "sqrt " ); break;
case 27: printf( "dup " ); break;
case 28: printf( "exch " ); break;
case 29: printf( "index " ); break;
case 30: printf( "roll " ); break;
case 34: printf( "hflex " ); break;
case 35: printf( "flex " ); break;
case 36: printf( "hflex1 " ); break;
case 37: printf( "flex1 " ); break;
/* Type 1 codes */
case 0: printf( "dotsection " ); break;
case 1: printf( "vstem3 " ); break;
case 2: printf( "hstem3 " ); break;
case 6: printf( "seac " ); break;
case 7: printf( "sbw " ); break;
case 16: printf( "callothersubr " ); break;
case 17: printf( "pop " ); break;
case 33: printf( "setcurrentpoint " ); break;
/* End obselete codes */
default: printf( "???-12-%d-??? ", v ); break;
}
} else switch ( v ) {
case 1: printf( "hstem " ); break;
case 3: printf( "vstem " ); break;
case 4: printf( "vmoveto " ); break;
case 5: printf( "rlineto " ); break;
case 6: printf( "hlineto " ); break;
case 7: printf( "vlineto " ); break;
case 8: printf( "rrcurveto " ); break;
case 10: printf( "callsubr " ); break;
case 11: printf( "return " ); break;
case 14: printf( "endchar " ); break;
case 18: printf( "hstemhm " ); break;
case 19: printf( "hintmask " ); break;
case 20: printf( "cntrmask " ); break;
case 21: printf( "rmoveto " ); break;
case 22: printf( "hmoveto " ); break;
case 23: printf( "vstemhm " ); break;
case 24: printf( "rcurveline " ); break;
case 25: printf( "rlinecurve " ); break;
case 26: printf( "vvcurveto " ); break;
case 27: printf( "hhcurveto " ); break;
case 29: printf( "callgsubr " ); break;
case 30: printf( "vhcurveto " ); break;
case 31: printf( "hvcurveto " ); break;
/* Type 1 codes */
case 9: printf( "closepath " ); break;
case 13: printf( "hsbw " ); break;
/* End obselete codes */
default: printf( "???-%d-??? ", v );
}
--len;
if ( v==19 || v==20 ) {
/* I need to skip as many bits (rounded into bytes) as there are */
/* hints. But figuring out the hint count is impossible in a subr */
/* and difficult in a glyph that calls subrs */
/* .... So we pretend the hintmask fits into one byte */
printf( "0x%02x ", *str++ );
--len;
}
} while ( len>0 );
printf( "\n" );
}
static void readcffsubrs(FILE *ttf,struct topdicts *dict,struct pschars *subs,
int type, char *label) {
uint16 count = getushort(ttf);
int offsize;
uint32 *offsets;
int i,j;
static char *text[] = { "char strings", "subrs", NULL };
uint8 *temp;
printf( "\nThere are %d %s in the index associated with %s\n",
count, text[type], label );
memset(subs,'\0',sizeof(struct pschars));
if ( count==0 )
return;
subs->cnt = count;
/*subs->lens = malloc(count*sizeof(int));*/
/*subs->values = malloc(count*sizeof(uint8 *));*/
subs->bias = dict->charstringtype==1 ? 0 :
count<1240 ? 107 :
count<33900 ? 1131 : 32768;
if ( type==1 )
printf( " Bias = %d\n", subs->bias );
offsets = malloc((count+1)*sizeof(uint32));
offsize = getc(ttf);
printf( " Subr Index Offset Size: %d\n Offsets: ", offsize );
for ( i=0; i<=count; ++i ) {
offsets[i] = getoffset(ttf,offsize);
if ( i==0 && offsets[0]!=1 )
fprintf( stderr, "!!! Initial offset must be 1 in %s in %s\n", text[type], label);
else if ( i!=0 && offsets[i]<offsets[i-1] )
fprintf( stderr, "!!! bad length for %d, %d in %s in %s\n",
i-1, offsets[i]-offsets[i-1], text[type], label);
printf( "%d ", offsets[i]);
}
putchar('\n');
for ( i=0; i<count; ++i ) {
/*subs->lens[i] = offsets[i+1]-offsets[i];*/
/*subs->values[i] = malloc(offsets[i+1]-offsets[i]+1);*/
temp = malloc(offsets[i+1]-offsets[i]+1);
for ( j=0; j<offsets[i+1]-offsets[i]; ++j )
temp[j] = getc(ttf);
temp[j] = '\0';
printf( " %s %d: ", text[type], i );
ShowCharString(temp,offsets[i+1]-offsets[i],dict->charstringtype);
free(temp);
}
free(offsets);
}
static struct topdicts *readcfftopdict(FILE *ttf, char *fontname, int len) {
struct topdicts *td = calloc(1,sizeof(struct topdicts));
long base = ftell(ttf);
int ival, oval, sp, ret, i;
double stack[50];
td->fontname = fontname;
td->underlinepos = -100;
td->underlinewidth = 50;
td->charstringtype = 2;
td->fontmatrix[0] = td->fontmatrix[3] = .001;
td->cidcount = 8720;
td->notice = td->copyright = td->fullname = td->familyname = td->weight = -1;
td->postscript_code = td->basefontname = -1;
td->synthetic_base = -1;
td->ros_registry = td->ros_ordering = td->fdarrayoff = td->fdselectoff = -1;
td->sid_fontname = -1;
if ( fontname!=NULL ) printf( " Top Dict for %s\n", fontname );
while ( ftell(ttf)<base+len ) {
sp = 0;
while ( (ret=readcffthing(ttf,&ival,&stack[sp],&oval))!=3 && ftell(ttf)<base+len ) {
if ( sp==0 ) putchar(' ');
if ( ret==1 ) printf( " %d", ival );
else printf( " %g", stack[sp] );
if ( ret==1 )
stack[sp]=ival;
if ( ret!=0 && sp<45 )
++sp;
}
if ( sp==0 )
fprintf( stderr, "No argument to operator\n" );
else if ( ret==3 ) switch( oval ) {
case 0:
printf( " Version\n" );
td->version = stack[sp-1];
break;
case 1:
printf( " notice\n" );
td->notice = stack[sp-1];
break;
case (12<<8)+0:
printf( " copyright\n" );
td->copyright = stack[sp-1];
break;
case 2:
printf( " fullname\n" );
td->fullname = stack[sp-1];
break;
case 3:
printf( " familyname\n" );
td->familyname = stack[sp-1];
break;
case 4:
printf( " weight\n" );
td->weight = stack[sp-1];
break;
case (12<<8)+1:
printf( " isfixedpitch\n" );
td->isfixedpitch = stack[sp-1];
break;
case (12<<8)+2:
printf( " italicangle\n" );
td->italicangle = stack[sp-1];
break;
case (12<<8)+3:
printf( " underlinepos\n" );
td->underlinepos = stack[sp-1];
break;
case (12<<8)+4:
printf( " underlinewidth\n" );
td->underlinewidth = stack[sp-1];
break;
case (12<<8)+5:
printf( " painttype\n" );
td->painttype = stack[sp-1];
break;
case (12<<8)+6:
printf( " charstringtype\n" );
td->charstringtype = stack[sp-1];
break;
case (12<<8)+7:
printf( " fontmatrix\n" );
memcpy(td->fontmatrix,stack,(sp>=6?6:sp)*sizeof(double));
break;
case 13:
printf( " uniqueid\n" );
td->uniqueid = stack[sp-1];
break;
case 5:
printf( " fontbb\n" );
memcpy(td->fontbb,stack,(sp>=4?4:sp)*sizeof(double));
break;
case (12<<8)+8:
printf( " strokewidth\n" );
td->strokewidth = stack[sp-1];
break;
case 14:
printf( " xuid\n" );
for ( i=0; i<sp && i<20; ++i )
td->xuid[i] = stack[i];
break;
case 15:
printf( " charsetoff\n" );
td->charsetoff = stack[sp-1];
break;
case 16:
printf( " encodingoff\n" );
td->encodingoff = stack[sp-1];
break;
case 17:
printf( " charstringsoff\n" );
td->charstringsoff = stack[sp-1];
break;
case 18:
printf( " private\n" );
td->private_size = stack[0];
td->private_offset = stack[1];
break;
case (12<<8)+20:
printf( " synthetic_base\n" );
td->synthetic_base = stack[sp-1];
break;
case (12<<8)+21:
printf( " postscript_code\n" );
td->postscript_code = stack[sp-1];
break;
case (12<<8)+22:
printf( " basefontname\n" );
td->basefontname = stack[sp-1];
break;
case (12<<8)+23:
printf( " basefontblend\n" );
for ( i=0; i<sp && i<16; ++i )
td->basefontblend[i] = stack[i];
break;
case (12<<8)+30:
printf( " ROS\n" );
td->ros_registry = stack[0];
td->ros_ordering = stack[1];
td->ros_supplement = stack[2];
break;
case (12<<8)+31:
printf( " CIDFontVersion\n" );
td->cidfontversion = stack[sp-1];
break;
case (12<<8)+32:
printf( " CIDFontRevision\n" );
td->cidfontrevision = stack[sp-1];
break;
case (12<<8)+33:
printf( " CIDFontType\n" );
td->cidfonttype = stack[sp-1];
break;
case (12<<8)+34:
printf( " CIDCount\n" );
td->cidcount = stack[sp-1];
break;
case (12<<8)+35:
printf( " UIDBase\n" );
td->uidbase = stack[sp-1];
break;
case (12<<8)+36:
printf( " FDArray Off\n" );
td->fdarrayoff = stack[sp-1];
break;
case (12<<8)+37:
printf( " FDSelect Off\n" );
td->fdselectoff = stack[sp-1];
break;
case (12<<8)+38:
printf( " Fontname\n" );
td->sid_fontname = stack[sp-1];
break;
default:
fprintf(stderr,"Unknown operator in %s: %x\n", fontname, oval );
break;
}
}
return( td );
}
static void dumpsid(char *label, int sid, char **strings, int smax ) {
if ( sid==-1 )
return;
if ( sid<nStdStrings )
printf( "%s%d %s\n", label, sid, cffnames[sid]);
else if ( sid<nStdStrings+smax )
printf( "%s%d %s\n", label, sid, strings[sid-nStdStrings]);
else
printf( "%s%d >> Bad SID (max=%d) <<\n", label, sid, smax );
}
static char *getsid(int sid, char **strings,int smax ) {
if ( sid==-1 )
return(NULL);
if ( sid<nStdStrings )
return( strdup(cffnames[sid]));
else if ( sid<nStdStrings+smax )
return( strdup(strings[sid-nStdStrings]));
else
return( strdup(">> Bad SID <<"));
}
static void readcffprivate(FILE *ttf, struct topdicts *td, char **strings, int smax) {
int ival, oval, sp, ret, i;
double stack[50];
int32 end = td->cff_start+td->private_offset+td->private_size;
char *name;
fseek(ttf,td->cff_start+td->private_offset,SEEK_SET);
td->subrsoff = -1;
td->expansionfactor = .06;
td->bluefuzz = 1;
td->blueshift = 7;
td->bluescale = .039625;
name = td->fontname?td->fontname:
td->sid_fontname?getsid(td->sid_fontname,strings,smax):"<Nameless>";
printf( "\n Private Dict for %s\n", name );
while ( ftell(ttf)<end ) {
sp = 0;
while ( (ret=readcffthing(ttf,&ival,&stack[sp],&oval))!=3 && ftell(ttf)<end ) {
if ( sp==0 ) putchar(' ');
if ( ret==1 ) printf( " %d", ival );
else printf( " %g", stack[sp] );
if ( ret==1 )
stack[sp]=ival;
if ( ret!=0 && sp<45 )
++sp;
}
if ( sp==0 )
fprintf( stderr, "No argument to operator\n" );
else if ( ret==3 ) switch( oval ) {
case 6:
printf( " BlueValues\n" );
for ( i=0; i<sp && i<14; ++i ) {
td->bluevalues[i] = stack[i];
if ( i!=0 )
td->bluevalues[i] += td->bluevalues[i-1];
}
break;
case 7:
printf( " OtherBlues\n" );
for ( i=0; i<sp && i<10; ++i ) {
td->otherblues[i] = stack[i];
if ( i!=0 )
td->otherblues[i] += td->otherblues[i-1];
}
break;
case 8:
printf( " FamilyBlues\n" );
for ( i=0; i<sp && i<14; ++i ) {
td->familyblues[i] = stack[i];
if ( i!=0 )
td->familyblues[i] += td->familyblues[i-1];
}
break;
case 9:
printf( " FamilyOtherBlues\n" );
for ( i=0; i<sp && i<10; ++i ) {
td->familyotherblues[i] = stack[i];
if ( i!=0 )
td->familyotherblues[i] += td->familyotherblues[i-1];
}
break;
case (12<<8)+9:
printf( " BlueScale\n" );
td->bluescale = stack[sp-1];
break;
case (12<<8)+10:
printf( " BlueShift\n" );
td->blueshift = stack[sp-1];
break;
case (12<<8)+11:
printf( " BlueFuzz\n" );
td->bluefuzz = stack[sp-1];
break;
case 10:
printf( " StdHW\n" );
td->stdhw = stack[sp-1];
break;
case 11:
printf( " StdVW\n" );
td->stdvw = stack[sp-1];
break;
case (12<<8)+12:
printf( " StemSnapH\n" );
for ( i=0; i<sp && i<10; ++i ) {
td->stemsnaph[i] = stack[i];
if ( i!=0 )
td->stemsnaph[i] += td->stemsnaph[i-1];
}
break;
case (12<<8)+13:
printf( " StemSnapV\n" );
for ( i=0; i<sp && i<10; ++i ) {
td->stemsnapv[i] = stack[i];
if ( i!=0 )
td->stemsnapv[i] += td->stemsnapv[i-1];
}
break;
case (12<<8)+14:
printf( " ForceBold\n" );
td->forcebold = stack[sp-1];
break;
case (12<<8)+17:
printf( " LanguageGroup\n" );
td->languagegroup = stack[sp-1];
break;
case (12<<8)+18:
printf( " ExpansionFactor\n" );
td->expansionfactor = stack[sp-1];
break;
case (12<<8)+19:
printf( " InitialRandomSeed\n" );
td->initialRandomSeed = stack[sp-1];
break;
case 19:
printf( " Subrs\n" );
td->subrsoff = stack[sp-1];
break;
case 20:
printf( " DefaultWidthX\n" );
td->defaultwidthx = stack[sp-1];
break;
case 21:
printf( " NominalWidthX\n" );
td->nominalwidthx = stack[sp-1];
break;
default:
fprintf(stderr,"Unknown operator in %s: %x\n", td->fontname, oval );
break;
}
}
if ( td->subrsoff!=-1 ) {
fseek(ttf,td->cff_start+td->private_offset+td->subrsoff,SEEK_SET);
readcffsubrs(ttf,td,&td->local_subrs, 1, name );
}
}
static struct topdicts **readcfftopdicts(FILE *ttf, char **fontnames, int cff_start) {
uint16 count = getushort(ttf);
int offsize;
uint32 *offsets;
struct topdicts **dicts;
int i;
if ( fontnames!=NULL )
printf( "There %s %d top dictionar%s in this cff\n", count==1?"is":"are",count, count==1?"y":"ies" );
else
printf( "There %s %d subdictionary dictionar%s in this font\n", count==1?"is":"are",count, count==1?"y":"ies" );
if ( count==0 )
return( NULL );
offsets = malloc((count+1)*sizeof(uint32));
offsize = getc(ttf);
printf( " %s Dict Index Offset Size: %d\n Offsets: ",
fontnames!=NULL?"Top":"Sub", offsize );
for ( i=0; i<=count; ++i ) {
offsets[i] = getoffset(ttf,offsize);
if ( i==0 && offsets[0]!=1 )
fprintf(stderr, "!! Initial offset must be one in Top Dict Index\n" );
printf( "%d ", offsets[i]);
}
putchar('\n');
dicts = malloc((count+1)*sizeof(struct topdicts *));
for ( i=0; i<count; ++i ) {
dicts[i] = readcfftopdict(ttf,fontnames!=NULL?fontnames[i]:NULL,
offsets[i+1]-offsets[i]);
dicts[i]->cff_start = cff_start;
}
dicts[i] = NULL;
free(offsets);
return( dicts );
}
static void showdict(struct topdicts *dict, char **strings, int smax) {
int i, j;
if ( dict->sid_fontname==-1 )
printf( "\nDump of top dictionary for %s\n", dict->fontname);
else
dumpsid("\nDump of sub dictionary ", dict->sid_fontname, strings, smax );
dumpsid(" Version=", dict->version, strings, smax );
dumpsid(" Notice=", dict->notice, strings, smax );
dumpsid(" copyright=", dict->copyright, strings, smax );
dumpsid(" fullname=", dict->fullname, strings, smax );
dumpsid(" familyname=", dict->familyname, strings, smax );
dumpsid(" weight=", dict->weight, strings, smax );
printf( " fixedpitch=%d\n", dict->isfixedpitch);
printf( " ItalicAngle=%g\n", dict->italicangle);
printf( " underlinepos=%g\n", dict->underlinepos);
printf( " underlinewidth=%g\n", dict->underlinewidth);
printf( " painttype=%d\n", dict->painttype);
printf( " charstringtype=%d\n", dict->charstringtype);
printf( " fontmatrix=[%g %g %g %g %g %g]\n",
dict->fontmatrix[0], dict->fontmatrix[1],
dict->fontmatrix[2], dict->fontmatrix[3],
dict->fontmatrix[4], dict->fontmatrix[5]);
printf( " uniqueid=%d\n", dict->uniqueid);
printf( " fontbb=[%g %g %g %g]\n",
dict->fontbb[0], dict->fontbb[1],
dict->fontbb[2], dict->fontbb[3]);
printf( " strokewidth=%g\n", dict->strokewidth);
for ( i=19; i>=0; --i )
if ( dict->xuid[i]!=0 )
break;
if ( i>=0 ) {
printf( " XUID=[" );
for ( j=0; j<=i; ++j )
printf("%d ", dict->xuid[j]);
printf("]\n");
}
printf( " charsetoff=%d\n", dict->charsetoff);
printf( " encodingoff=%d\n", dict->encodingoff);
printf( " charstringsoff=%d\n", dict->charstringsoff);
printf( " private size=%d off=%d\n", dict->private_size, dict->private_offset);
if ( dict->synthetic_base!=-1 )
printf( " synthetic_base=%d\n", dict->synthetic_base );
dumpsid(" postscript_code=", dict->postscript_code, strings, smax );
dumpsid(" basefontname=", dict->basefontname, strings, smax );
for ( i=15; i>=0; --i )
if ( dict->basefontblend[i]!=0 )
break;
if ( i>=0 ) {
printf( " basefontblend=[" );
for ( j=0; j<=i; ++j )
printf("%d ", dict->basefontblend[i]);
printf("]\n");
}
if ( dict->ros_registry!=-1 ) {
dumpsid(" ros (Registry)=", dict->ros_registry, strings, smax );
dumpsid(" (Ordering)=", dict->ros_ordering, strings, smax );
printf(" (Supplement)=%d\n", dict->ros_supplement );
printf( " cidfontversion=%d\n", dict->cidfontversion);
printf( " cidfontrevision=%d\n", dict->cidfontrevision);
printf( " cidfonttype=%d\n", dict->cidfonttype);
printf( " cidcount=%d\n", dict->cidcount);
printf( " uidbase=%d\n", dict->uidbase);
printf( " FDArray off=%d\n", dict->fdarrayoff );
}
if ( dict->fdselectoff!=-1 )
printf( " FDSelect off=%d\n", dict->fdselectoff );
printf( "\n" );
}
/* The real encoding is done in the cmap ttf table, not sure why we bother here */
static void readcffenc(FILE *ttf,struct topdicts *dict,char **strings,int smax) {
int format, cnt, i;
if ( dict->encodingoff==0 ) {
printf( "\nAdobe Standard Encoding\n" );
return;
} else if ( dict->encodingoff==1 ) {
printf( "\nExpert Encoding\n" );
return;
}
fseek(ttf,dict->cff_start+dict->encodingoff,SEEK_SET);
format = getc(ttf);
printf( "\nCFF Encoding format=%x\n", format );
if ( (format&0x7f)==0 ) {
cnt = getc(ttf);
printf( " Enc cnt=%d\n Enc: ", cnt );
for ( i=0; i<cnt; ++i )
printf( "%02x ", getc(ttf));
printf("\n");
} else if ( (format&0x7f)==1 ) {
cnt = getc(ttf);
printf( " Enc range cnt=%d\n" );
for ( i=0; i<cnt; ++i ) {
printf( " Enc Range %d: First=%02x ", i, getc(ttf));
printf( "nLeft=%d\n", getc(ttf));
}
}
if ( format&0x80 ) {
cnt = getc(ttf);
printf( " Supplemental entries[%d]\n", cnt );
for ( i=0; i<cnt; ++i ) {
printf( " Supplement[%d]: Encoding %d -> ", i, getc(ttf));
dumpsid("",getushort(ttf),strings, smax);
}
}
}
static void readcffset(FILE *ttf,struct topdicts *dict,char **strings,int smax,
struct ttfinfo *info) {
int len = dict->glyphs.cnt;
int i;
int format, cnt, j, first;
if ( dict->charsetoff==0 ) {
/* ISO Adobe charset */
printf( "\nISOAdobe charset\n" );
dict->charset = malloc(len*sizeof(uint16));
for ( i=0; i<len && i<=228; ++i )
dict->charset[i] = i;
} else if ( dict->charsetoff==1 ) {
printf( "\nExpert charset\n" );
/* Expert charset */
dict->charset = malloc((len<162?162:len)*sizeof(uint16));
dict->charset[0] = 0; /* .notdef */
dict->charset[1] = 1;
for ( i=2; i<len && i<=238-227; ++i )
dict->charset[i] = i+227;
dict->charset[12] = 13;
dict->charset[13] = 14;
dict->charset[14] = 15;
dict->charset[15] = 99;
for ( i=16; i<len && i<=248-223; ++i )
dict->charset[i] = i+223;
dict->charset[25] = 27;
dict->charset[26] = 28;
for ( i=27; i<len && i<=266-222; ++i )
dict->charset[i] = i+222;
dict->charset[44] = 109;
dict->charset[45] = 110;
for ( i=46; i<len && i<=318-221; ++i )
dict->charset[i] = i+221;
dict->charset[96] = 158;
dict->charset[97] = 155;
dict->charset[98] = 163;
for ( i=99; i<len && i<=326-220; ++i )
dict->charset[i] = i+220;
dict->charset[107] = 150;
dict->charset[108] = 164;
dict->charset[109] = 169;
for ( i=110; i<len && i<=378-217; ++i )
dict->charset[i] = i+217;
} else if ( dict->charsetoff==2 ) {
printf( "\nExpert subset charset\n" );
/* Expert subset charset */
dict->charset = malloc((len<130?130:len)*sizeof(uint16));
dict->charset[0] = 0; /* .notdef */
dict->charset[1] = 1;
for ( i=2; i<len && i<=238-227; ++i )
dict->charset[i] = i+227;
dict->charset[12] = 13;
dict->charset[13] = 14;
dict->charset[14] = 15;
dict->charset[15] = 99;
for ( i=16; i<len && i<=248-223; ++i )
dict->charset[i] = i+223;
dict->charset[25] = 27;
dict->charset[26] = 28;
for ( i=27; i<len && i<=266-222; ++i )
dict->charset[i] = i+222;
dict->charset[44] = 109;
dict->charset[45] = 110;
for ( i=46; i<len && i<=272-221; ++i )
dict->charset[i] = i+221;
dict->charset[51] = 300;
dict->charset[52] = 301;
dict->charset[53] = 302;
dict->charset[54] = 305;
dict->charset[55] = 314;
dict->charset[56] = 315;
dict->charset[57] = 158;
dict->charset[58] = 155;
dict->charset[59] = 163;
for ( i=60; i<len && i<=326-260; ++i )
dict->charset[i] = i+260;
dict->charset[67] = 150;
dict->charset[68] = 164;
dict->charset[69] = 169;
for ( i=110; i<len && i<=346-217; ++i )
dict->charset[i] = i+217;
} else {
dict->charset = malloc(len*sizeof(uint16));
dict->charset[0] = 0; /* .notdef */
fseek(ttf,dict->cff_start+dict->charsetoff,SEEK_SET);
format = getc(ttf);
printf( "\nCharset format=%d\n", format );
if ( format==0 ) {
for ( i=1; i<len; ++i )
dict->charset[i] = getushort(ttf);
} else if ( format==1 ) {
for ( i = 1; i<len; ) {
first = dict->charset[i++] = getushort(ttf);
cnt = getc(ttf);
for ( j=0; j<cnt; ++j )
dict->charset[i++] = ++first;
}
} else if ( format==2 ) {
for ( i = 1; i<len; ) {
first = dict->charset[i++] = getushort(ttf);
cnt = getushort(ttf);
for ( j=0; j<cnt; ++j )
dict->charset[i++] = ++first;
}
}
}
while ( i<len ) dict->charset[i++] = 0;
printf( " Which means...\n" );
if ( dict->ros_registry==-1 ) {
info->glyph_names = calloc(len,sizeof(char *));
for ( i=0; i<len; ++i ) {
printf( "Glyph %d is named ", i );
dumpsid("", dict->charset[i], strings, smax);
info->glyph_names[i] = getsid(dict->charset[i], strings,smax);
}
} else
for ( i=0; i<len; ++i )
printf( "Glyph %d -> CID %d\n", i, dict->charset[i]);
}
static int readcff(FILE *ttf,FILE *util, struct ttfinfo *info) {
int offsize;
int hdrsize;
char **fontnames;
char **strings;
struct topdicts **dicts, **subdicts;
int i, j, smax;
struct pschars gsubs;
fseek(ttf,info->cff_start,SEEK_SET);
printf( "\nPostscript CFF table (at %d for %d bytes)\n", info->cff_start, info->cff_length);
printf( "\tMajor Version: %d\n", getc(ttf));
printf( "\tMinor Version: %d\n", getc(ttf));
printf( "\tTable Header size: %d\n", hdrsize = getc(ttf));
printf( "\tOffset size: %d\n", offsize = getc(ttf)); /* Er is this ever used? */
if ( hdrsize!=4 )
fseek(ttf,info->cff_start+hdrsize,SEEK_SET);
fontnames = readcfffontnames(ttf,0);
dicts = readcfftopdicts(ttf,fontnames,info->cff_start);
/* String index is just the same as fontname index */
strings = readcfffontnames(ttf,1);
for ( smax=0; strings[smax]!=NULL; ++smax );
for ( i=0; fontnames[i]!=NULL; ++i )
showdict(dicts[i],strings,smax);
readcffsubrs(ttf,dicts[0],&gsubs, 1, "Global" );
for ( i=0; fontnames[i]!=NULL; ++i ) {
if ( dicts[i]->charstringsoff!=-1 ) {
fseek(ttf,info->cff_start+dicts[i]->charstringsoff,SEEK_SET);
readcffsubrs(ttf,dicts[i],&dicts[i]->glyphs, 0, fontnames[i]);
}
if ( dicts[i]->private_offset!=-1 )
readcffprivate(ttf,dicts[i],strings,smax);
if ( dicts[i]->charsetoff!=-1 )
readcffset(ttf,dicts[i],strings,smax,info);
if ( dicts[i]->ros_registry==-1 )
readcffenc(ttf,dicts[i],strings,smax);
if ( dicts[i]->fdarrayoff!=-1 ) {
fseek(ttf,info->cff_start+dicts[i]->fdarrayoff,SEEK_SET);
subdicts = readcfftopdicts(ttf,NULL,info->cff_start);
for ( j=0; subdicts[j]!=NULL; ++j ) {
showdict(subdicts[j],strings,smax);
if ( subdicts[j]->private_offset!=-1 )
readcffprivate(ttf,subdicts[j],strings,smax);
}
}
}
return( 1 );
}
static void readttfBigGlyphMetrics(FILE *ttf,char *indent) {
printf( "%sBitmap rows=%d\n", indent, getc(ttf));
printf( "%sBitmap columns=%d\n", indent, getc(ttf));
printf( "%shoriBearingX=%d\n", indent, (signed char) getc(ttf));
printf( "%shoriBearingY=%d\n", indent, (signed char) getc(ttf));
printf( "%shoriAdvance=%d\n", indent, getc(ttf));
printf( "%svertBearingX=%d\n", indent, (signed char) getc(ttf));
printf( "%svertBearingY=%d\n", indent, (signed char) getc(ttf));
printf( "%svertAdvance=%d\n", indent, getc(ttf));
}
static void ShowGlyph(FILE *ttf,long offset,long len,int imageFormat, struct ttfinfo *info) {
int h,w,sbX,sbY,advance;
int i,j,k,ch;
long here;
if ( imageFormat!=1 && imageFormat!=2 )
return;
here = ftell(ttf);
fseek(ttf,info->bitmapdata_start+offset,SEEK_SET);
h = getc(ttf);
w = getc(ttf);
sbX = (signed char) getc(ttf);
sbY = (signed char) getc(ttf);
advance = getc(ttf);
printf( "\t\theight=%d width=%d sbX=%d sbY=%d advance=%d %s aligned\n",
h,w,sbX,sbY,advance,imageFormat==1?"Byte":"Bit");
len -= 5;
if ( imageFormat==1 ) {
/* Byte aligned data */
for ( i=0; i<h; ++i ) {
putchar('\t');
for ( j=0; j<(w+7)/8; ++j ) {
ch = getc(ttf); --len;
for ( k=0; k<8 && j*8+k<w; ++k ) {
if ( ch&(0x80>>k))
putchar('*');
else
putchar('.');
}
}
putchar('\n');
}
} else {
k=8;
for ( i=0; i<h; ++i ) {
putchar('\t');
for ( j=0; j<w; ++j ) {
if ( ++k>=8 ) {
ch = getc(ttf); --len;
k=0;
}
if ( ch&(0x80>>k))
putchar('*');
else
putchar('.');
}
putchar('\n');
}
}
if ( len!=0 )
printf("!!!\tLength field wrong. %d left\n", len );
fseek(ttf,here,SEEK_SET);
}
static void readttfIndexSubTab(FILE *ttf,long offset, int first, int last,
struct ttfinfo *info) {
int i, indexFormat, imageFormat, bdatOff;
long curstart, nextstart;
fseek(ttf,offset,SEEK_SET);
printf( "\t index Format=%d ", indexFormat=getushort(ttf));
if ( indexFormat==1 || indexFormat==3 ) printf( "Proportional\n" );
else if ( indexFormat==2 ) printf( "Monospace\n" );
else printf( "Unknown\n" );
printf( "\t image Format=%d\n", imageFormat=getushort(ttf));
printf( "\t Offset in bitmap data table=%d\n", bdatOff=getlong(ttf));
if ( indexFormat==1 || indexFormat==3 ) {
curstart = (indexFormat==1?getlong(ttf):getushort(ttf));
for ( i=first; i<=last; ++i ) {
nextstart = (indexFormat==1?getlong(ttf):getushort(ttf));
if ( info->glyph_names==NULL )
printf( "\t Glyph %d starts at %5d length=%d\n", i, curstart, nextstart-curstart );
else if ( i<info->glyph_cnt && info->glyph_names[i]!=NULL )
printf( "\t Glyph %d (%10s) starts at %5d length=%d\n", i,
info->glyph_names[i], curstart, nextstart-curstart );
else
printf( "\t Glyph %d ( ) starts at %5d length=%d\n", i,
curstart, nextstart-curstart );
ShowGlyph(ttf,bdatOff+curstart,nextstart-curstart,imageFormat,info);
curstart = nextstart;
}
} else if ( indexFormat==2 ) {
printf( "\t Bitmap Image Size=%d\n", getlong(ttf));
printf( "\t big Metrics for any glyph\n" );
readttfBigGlyphMetrics(ttf,"\t ");
}
}
static void readttfIndexSizeSubTab(FILE *ttf,long offset, long size, long num,
struct ttfinfo *info) {
int i, first, last;
long here, moreoff;
fseek(ttf,offset,SEEK_SET);
for ( i=0; i<num; ++i ) {
printf( "\t indexSubTable[%d]\n", i );
printf( "\t first glyph=%d\n", first = getushort(ttf));
printf( "\t last glyph=%d\n", last = getushort(ttf));
printf( "\t additional offset=%d\n", moreoff = getlong(ttf));
here = ftell(ttf);
readttfIndexSubTab(ttf,offset+moreoff,first,last,info);
fseek(ttf,here,SEEK_SET);
}
}
static void sbitLineMetrics(FILE *ttf) {
printf( "\t ascender: %d\n", (signed char) getc(ttf));
printf( "\t descender: %d\n", (signed char) getc(ttf));
printf( "\t widthMax: %d\n", getc(ttf));
printf( "\t caretSlopeNumerator: %d\n", (signed char) getc(ttf));
printf( "\t caretSlopeDenominator: %d\n", (signed char) getc(ttf));
printf( "\t caretOffset: %d\n", (signed char) getc(ttf));
printf( "\t minOriginSB: %d\n", (signed char) getc(ttf));
printf( "\t minAdvanceSB: %d\n", (signed char) getc(ttf));
printf( "\t maxBeforeBL: %d\n", (signed char) getc(ttf));
printf( "\t maxAfterBL: %d\n", (signed char) getc(ttf));
/* padding */ getushort(ttf);
}
static int readttfbitmapscale(FILE *ttf,FILE *util, struct ttfinfo *info) {
int cnt,i;
int newx, newy, oldx, oldy;
fseek(ttf,info->bitmapscale_start,SEEK_SET);
printf( "\nBitmap scaling data (at %d)\n", info->bitmapscale_start);
printf( "\tVersion: 0x%08x\n", getlong(ttf));
printf( "\tnum Sizes: %d\n", cnt = getlong(ttf));
for ( i=0; i<cnt; ++i ) {
printf( " Scaling Info %d\n", i );
printf( " Horizontal metrics\n" );
sbitLineMetrics(ttf);
printf( " Vertical metrics\n" );
sbitLineMetrics(ttf);
newx = getc(ttf);
newy = getc(ttf);
oldx = getc(ttf);
oldy = getc(ttf);
printf( " Scale original bitmap (xppem=%d,yppem=%d) to (xppem=%d,yppem=%d)\n",
oldx, oldy, newx, newy );
}
return( 1 );
}
static int readttfbitmaps(FILE *ttf,FILE *util, struct ttfinfo *info) {
int cnt,i, num;
long here, offset, size;
fseek(ttf,info->bitmaploc_start,SEEK_SET);
printf( "\nBitmap location data (at %d for %d bytes)\n", info->bitmaploc_start, info->bitmaploc_length);
printf( "\tVersion: 0x%08\n", getlong(ttf));
printf( "\tnumStrikes: %d\n", cnt = getlong(ttf));
for ( i=0; i<cnt; ++i ) {
printf( "\t indexSubTableArrayOffset: %d\n", offset = getlong(ttf));
printf( "\t indexTableSize: %d\n", size = getlong(ttf));
printf( "\t numberOfIndexSubTables: %d\n", num = getlong(ttf));
printf( "\t colorRef: %d\n", getlong(ttf));
printf( "\t horizontal metrics\n" );
sbitLineMetrics(ttf);
printf( "\t vertical metrics\n" );
sbitLineMetrics(ttf);
printf( "\t startGlyph: %d\n", getushort(ttf));
printf( "\t endGlyph: %d\n", getushort(ttf));
printf( "\t ppemX: %d\n", getc(ttf));
printf( "\t ppemY: %d\n", getc(ttf));
printf( "\t bitDepth: %d\n", getc(ttf));
printf( "\t flags: 0x%x\n\n", getc(ttf));
here = ftell(ttf);
readttfIndexSizeSubTab(ttf,info->bitmaploc_start+offset,size,num,info);
fseek(ttf,here,SEEK_SET);
}
return( 1 );
}
static int readttfhdmx(FILE *ttf,FILE *util, struct ttfinfo *info) {
int cnt,size,i;
int gid;
int pos;
fseek(ttf,info->hdmx_start,SEEK_SET);
printf( "\nHorizontal device metrics (at %d)\n", info->hdmx_start);
printf( "\tVersion: 0x%08\n", getushort(ttf));
printf( "\tnum Records: %d\n", cnt = getushort(ttf));
printf( "\trecord Size: %d\n", size = getlong(ttf));
pos = ftell(ttf);
for ( i=0; i<cnt; ++i ) {
fseek(ttf,pos+i*size,SEEK_SET);
printf( " Device widths at %dppem\n", getc(ttf));
printf( " Max Width %d\n", getc(ttf));
for ( gid=0; gid<info->glyph_cnt; ++gid ) {
if ( info->glyph_names!=NULL && info->glyph_names[gid]!=NULL )
printf("\t\t%s:\t%d\n", info->glyph_names[gid], getc(ttf));
}
}
return( 1 );
}
static void PrintDeviceTable(FILE *ttf, uint32 start) {
uint32 here = ftell(ttf);
int first, last, type;
signed char *corrections;
int i,b,c, w;
int any;
fseek(ttf,start,SEEK_SET);
first = getushort(ttf);
last = getushort(ttf);
type = getushort(ttf);
if ( type!=1 && type!=2 && type!=3 )
fprintf( stderr, "! > Bad device table type: %d (must be 1,2, or 3)\n",
type );
if ( first>last )
fprintf( stderr, "! > Bad device table first>last (first=%d last=%d)\n",
first, last );
else {
c = last-first+1;
corrections = malloc(c);
if ( type==1 ) {
for ( i=0; i<c; i+=8 ) {
w = getushort(ttf);
for ( b=0; b<8 && i+b<c; ++b )
corrections[i+b] = ((int16) ((w<<(b*2))&0xc000))>>14;
}
} else if ( type==2 ) {
for ( i=0; i<c; i+=4 ) {
w = getushort(ttf);
for ( b=0; b<4 && i+b<c; ++b )
corrections[i+b] = ((int16) ((w<<(b*4))&0xf000))>>12;
}
} else {
for ( i=0; i<c; ++i )
corrections[i] = (int8) getc(ttf);
}
putchar('{');
any = false;
for ( i=0; i<c; ++i ) {
if ( corrections[i]!=0 ) {
if ( any ) putchar(' ');
any = true;
printf( "%d:%d", first+i, corrections[i]);
}
}
free( corrections );
printf( "}[%d-%d sized %d]", first,last, type );
}
fseek( ttf, here, SEEK_SET );
}
static void PrintMathValueRecord(FILE *ttf, uint32 start) {
int val;
uint32 devtaboffset;
val = (short) getushort(ttf);
devtaboffset = getushort(ttf);
printf( "%d", val );
if ( devtaboffset!=0 )
PrintDeviceTable(ttf,start+devtaboffset);
}
static void readttfmathConstants(FILE *ttf,uint32 start, struct ttfinfo *info) {
int i;
fseek(ttf,start,SEEK_SET);
printf( "\n MATH Constants sub-table (at %d)\n", start);
for ( i=0; i<4; ++i )
printf( "\t Constant %d: %d\n", i, getushort(ttf));
for ( ; i<4+51; ++i ) {
printf( "\t Constant %d: ", i );
PrintMathValueRecord(ttf,start);
printf( "\n");
}
/* And one final constant */
printf( "\t Constant %d: %d\n", i, getushort(ttf));
printf( "\n");
if ( feof(ttf) ) {
fprintf( stderr, "!> Unexpected end of file!\n" );
return;
}
}
static void readttfmathICTA(FILE *ttf,uint32 start, struct ttfinfo *info, int is_ic) {
int coverage, cnt, i;
uint16 *glyphs;
uint32 here;
fseek(ttf,start,SEEK_SET);
if ( is_ic )
printf( "\n MATH Italics Correction sub-table (at %d)\n", start);
else
printf( "\n MATH Top Accent Attachment sub-table (at %d)\n", start);
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf));
printf( "\t Count=%d\n", cnt = getushort(ttf));
if ( feof(ttf) ) {
fprintf( stderr, "!> Unexpected end of file!\n" );
return;
}
here = ftell(ttf);
glyphs = showCoverageTable(ttf,start+coverage,cnt);
fseek(ttf,here,SEEK_SET);
for ( i=0; i<cnt; ++i ) {
printf( "\t\tGlyph %s(%d): ",
glyphs[i]>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[glyphs[i]],
glyphs[i]);
PrintMathValueRecord(ttf,start);
printf( "\n");
}
free(glyphs);
printf( "\n");
}
static void PrintMathKernTable(FILE *ttf,uint32 start, struct ttfinfo *info) {
int cnt, i;
uint32 here = ftell(ttf);
fseek(ttf,start,SEEK_SET);
cnt = getushort(ttf);
for ( i=0; i<cnt; ++i ) {
printf( "\t\t\tHeights %d: ", i );
PrintMathValueRecord(ttf,start);
printf( "\n");
}
for ( i=0; i<=cnt; ++i ) {
printf( "\t\t\tKerns %d: ", i );
PrintMathValueRecord(ttf,start);
printf( "\n");
}
fseek(ttf,here,SEEK_SET);
}
static void readttfmathKern(FILE *ttf,uint32 start, struct ttfinfo *info) {
int coverage, cnt, i, j;
uint16 *glyphs;
uint32 here;
static char *cornernames[] = { "TopRight:", "TopLeft:", "BottomRight:", "BottomLeft:" };
fseek(ttf,start,SEEK_SET);
printf( "\n MATH Kerning sub-table (at %d)\n", start);
printf( "\t Coverage Offset=%d\n", coverage = getushort(ttf));
printf( "\t Count=%d\n", cnt = getushort(ttf));
if ( feof(ttf) ) {
fprintf( stderr, "!> Unexpected end of file!\n" );
return;
}
here = ftell(ttf);
glyphs = showCoverageTable(ttf,start+coverage,cnt);
fseek(ttf,here,SEEK_SET);
for ( i=0; i<cnt; ++i ) {
printf( "\t\tGlyph %s(%d):\n",
glyphs[i]>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[glyphs[i]],
glyphs[i]);
for ( j=0; j<4; ++j ) {
int offset = getushort(ttf);
if ( offset!=0 ) {
printf( "\t\t %s\n", cornernames[j]);
PrintMathKernTable(ttf,start+offset,info);
}
}
}
free(glyphs);
printf( "\n");
}
static void readttfmathGlyphInfo(FILE *ttf,uint32 start, struct ttfinfo *info) {
uint32 ic, ta, es, mk;
fseek(ttf,start,SEEK_SET);
printf( "\n MATH Glyph Info sub-table (at %d)\n", start);
printf( "\tOffset to Italic Correction: %d\n", ic = getushort(ttf));
printf( "\tOffset to Top Accent: %d\n", ta = getushort(ttf));
printf( "\tOffset to Extended Shape: %d\n", es = getushort(ttf));
printf( "\tOffset to Math Kern: %d\n", mk = getushort(ttf));
if ( feof(ttf) ) {
fprintf( stderr, "!> Unexpected end of file!\n" );
return;
}
if ( ic!=0 )
readttfmathICTA(ttf,start+ic,info,1);
if ( ta!=0 )
readttfmathICTA(ttf,start+ta,info,0);
if ( es!=0 ) {
printf( "\n MATH Extended Shape sub-table (at %d)\n", start+es);
free( showCoverageTable(ttf,start+es,-1));
}
if ( mk!=0 )
readttfmathKern(ttf,start+mk,info);
}
static void PrintMathGlyphConstruction(FILE *ttf,uint32 start, struct ttfinfo *info) {
uint32 here = ftell(ttf);
int offset, variant_cnt, part_cnt;
int i;
fseek(ttf,start,SEEK_SET);
printf( "\t\t Glyph Assembly Offset=%d\n", offset = getushort(ttf));
printf( "\t\t Variant Count=%d\n", variant_cnt = getushort(ttf));
if ( feof(ttf) ) {
fprintf( stderr, "!> Unexpected end of file!\n" );
return;
}
if ( variant_cnt!=0 ) {
printf("\t\t Variants: " );
for ( i=0; i<variant_cnt; ++i ) {
int gid, adv;
gid = getushort(ttf);
adv = getushort(ttf);
printf( " %s:%d",
gid>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[gid],
adv);
}
printf( "\n" );
}
if ( offset!=0 ) {
fseek(ttf,start+offset,SEEK_SET);
printf( "\t\t Glyph Assembly Italic Correction: " );
PrintMathValueRecord(ttf,start+offset);
printf( "\n\t\t Part Count=%d\n", part_cnt = getushort(ttf));
for ( i=0; i<part_cnt; ++i ) {
int gid = getushort(ttf), flags;
printf( "\t\t %s",
gid>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[gid]);
printf( " start=%d", getushort(ttf));
printf( " end=%d", getushort(ttf));
printf( " full=%d", getushort(ttf));
flags = getushort(ttf);
printf( " flags=%04x(%s%s)\n", flags, (flags&1)?"Extender":"Required",
(flags&0xfffe)?",Unknown flags!!!!":"");
}
}
fseek(ttf,here,SEEK_SET);
}
static void readttfmathVariants(FILE *ttf,uint32 start, struct ttfinfo *info) {
int vcoverage, vcnt, hcoverage, hcnt, i, offset;
uint16 *vglyphs=NULL, *hglyphs=NULL;
uint32 here;
fseek(ttf,start,SEEK_SET);
printf( "\n MATH Variants sub-table (at %d)\n", start);
printf( "\t MinConnectorOverlap=%d\n", getushort(ttf));
printf( "\t VCoverage Offset=%d\n", vcoverage = getushort(ttf));
printf( "\t HCoverage Offset=%d\n", hcoverage = getushort(ttf));
printf( "\t VCount=%d\n", vcnt = getushort(ttf));
printf( "\t HCount=%d\n", hcnt = getushort(ttf));
if ( feof(ttf) ) {
fprintf( stderr, "!> Unexpected end of file!\n" );
return;
}
here = ftell(ttf);
if ( vcoverage!=0 )
vglyphs = showCoverageTable(ttf,start+vcoverage,vcnt);
else {
vglyphs = NULL;
if ( vcnt!=0 )
fprintf( stderr, "! > Bad coverage table: Offset=NUL, but cnt=%d\n", vcnt );
}
if ( hcoverage!=0 )
hglyphs = showCoverageTable(ttf,start+hcoverage,hcnt);
else {
hglyphs = NULL;
if ( hcnt!=0 )
fprintf( stderr, "! > Bad coverage table: Offset=NUL, but cnt=%d\n", hcnt );
}
fseek(ttf,here,SEEK_SET);
for ( i=0; i<vcnt; ++i ) {
printf( "\t\tV Glyph %s(%d):\n",
vglyphs[i]>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[vglyphs[i]],
vglyphs[i]);
offset = getushort(ttf);
PrintMathGlyphConstruction(ttf,start+offset,info);
}
free(vglyphs);
for ( i=0; i<hcnt; ++i ) {
printf( "\t\tH Glyph %s(%d):\n",
hglyphs[i]>=info->glyph_cnt ? "!!! Bad Glyph !!!" : info->glyph_names==NULL ? "" : info->glyph_names[hglyphs[i]],
hglyphs[i]);
offset = getushort(ttf);
PrintMathGlyphConstruction(ttf,start+offset,info);
}
free(hglyphs);
printf( "\n");
}
static int readttfmath(FILE *ttf,FILE *util, struct ttfinfo *info) {
int version;
uint32 constants, glyphinfo, variants;
fseek(ttf,info->math_start,SEEK_SET);
printf( "\nMATH table (at %d)\n", info->math_start);
printf( "\tVersion: 0x%08x\n", version = getlong(ttf));
if ( version!=0x00010000 )
fprintf( stderr, "!> Bad version number for math table.\n" );
printf( "\tOffset to Constants: %d\n", constants = getushort(ttf));
printf( "\tOffset to GlyphInfo: %d\n", glyphinfo = getushort(ttf));
printf( "\tOffset to Variants: %d\n", variants = getushort(ttf));
if ( feof(ttf) ) {
fprintf( stderr, "!> Unexpected end of file!\n" );
return( 0 );
}
if ( constants!=0 )
readttfmathConstants(ttf,info->math_start+constants,info);
else
fprintf( stderr, "!> NUL Offset not expected for math constant table.\n" );
if ( glyphinfo!=0 )
readttfmathGlyphInfo(ttf,info->math_start+glyphinfo,info);
else
fprintf( stderr, "!> NUL Offset not expected for math Glyph Info table.\n" );
if ( variants!=0 )
readttfmathVariants(ttf,info->math_start+variants,info);
else
fprintf( stderr, "!> NUL Offset not expected for math Variants table.\n" );
return( 1 );
}
static void readttfbaseminmax(FILE *ttf,uint32 offset,struct ttfinfo *info,
uint32 script_tag,uint32 lang_tag) {
int min, max;
int j,feat_cnt;
fseek(ttf,offset,SEEK_SET);
min = (short) getushort(ttf);
max = (short) getushort(ttf);
if ( lang_tag == 0 )
printf( "\t min extent=%d max extent=%d for script '%c%c%c%c'\n",
min, max,
script_tag>>24, script_tag>>16, script_tag>>8, script_tag );
else
printf( "\t min extent=%d max extent=%d for language '%c%c%c%c' in script '%c%c%c%c'\n",
min, max,
lang_tag>>24, lang_tag>>16, lang_tag>>8, lang_tag,
script_tag>>24, script_tag>>16, script_tag>>8, script_tag );
feat_cnt = getushort(ttf);
for ( j=0; j<feat_cnt; ++j ) {
uint32 feat_tag = getlong(ttf);
min = (short) getushort(ttf);
max = (short) getushort(ttf);
if ( lang_tag == 0 )
printf( "\t min extent=%d max extent=%d in feature '%c%c%c%c' of script '%c%c%c%c'\n",
min, max,
feat_tag>>24, feat_tag>>16, feat_tag>>8, feat_tag,
script_tag>>24, script_tag>>16, script_tag>>8, script_tag );
else
printf( "\t min extent=%d max extent=%d in feature '%c%c%c%c' of language '%c%c%c%c' in script '%c%c%c%c'\n",
min, max,
feat_tag>>24, feat_tag>>16, feat_tag>>8, feat_tag,
lang_tag>>24, lang_tag>>16, lang_tag>>8, lang_tag,
script_tag>>24, script_tag>>16, script_tag>>8, script_tag );
}
}
struct tagoff { uint32 tag; uint32 offset; };
static int readttfbase(FILE *ttf,FILE *util, struct ttfinfo *info) {
int version;
uint32 axes[2];
uint32 basetags, basescripts;
int basetagcnt, basescriptcnt;
uint32 *tags;
struct tagoff *bs;
int axis,i,j;
fseek(ttf,info->base_start,SEEK_SET);
printf( "\nBASE table (at %d)\n", info->base_start);
printf( "\tVersion: 0x%08x\n", version = getlong(ttf));
if ( version!=0x00010000 )
fprintf( stderr, "!> Bad version number for BASE table.\n" );
axes[0] = getushort(ttf); /* Horizontal */
axes[1] = getushort(ttf); /* Vertical */
for ( axis=0; axis<2; ++axis ) {
if ( axes[axis]==0 ) {
printf("\tNO %s axis data\n", axis==0 ? "Horizontal": "Vertical" );
continue;
}
printf("\t%s axis data\n", axis==0 ? "Horizontal": "Vertical" );
fseek(ttf,info->base_start+axes[axis],SEEK_SET);
basetags = getushort(ttf);
basescripts = getushort(ttf);
if ( basetags==0 ) {
printf("\t NO %s base tags data\n", axis==0 ? "Horizontal": "Vertical" );
basetagcnt = 0;
tags = NULL;
} else {
fseek(ttf,info->base_start+axes[axis]+basetags,SEEK_SET);
basetagcnt = getushort(ttf);
tags = calloc(basetagcnt,sizeof(uint32));
for ( i=0; i<basetagcnt; ++i )
tags[i] = getlong(ttf);
printf( "\t %d Baseline tags for %s\n", basetagcnt, axis==0 ? "Horizontal": "Vertical" );
for ( i=0; i<basetagcnt; ++i )
printf( "\t '%c%c%c%c'\n", tags[i]>>24, tags[i]>>16, tags[i]>>8, tags[i]);
}
if ( basescripts==0 )
printf("\t NO %s base script data\n", axis==0 ? "Horizontal": "Vertical" );
else {
fseek(ttf,info->base_start+axes[axis]+basescripts,SEEK_SET);
basescriptcnt = getushort(ttf);
bs = calloc(basescriptcnt,sizeof(struct tagoff));
for ( i=0; i<basescriptcnt; ++i ) {
bs[i].tag = getlong(ttf);
bs[i].offset = getushort(ttf);
if ( bs[i].offset != 0 )
bs[i].offset += info->base_start+axes[axis]+basescripts;
}
for ( i=0; i<basescriptcnt; ++i ) if ( bs[i].offset!=0 ) {
int basevalues, defminmax;
int langsyscnt;
struct tagoff *ls;
printf("\t %s baseline data for '%c%c%c%c' script\n",
axis==0 ? "Horizontal": "Vertical",
bs[i].tag>>24, bs[i].tag>>16, bs[i].tag>>8, bs[i].tag );
fseek(ttf,bs[i].offset,SEEK_SET);
basevalues = getushort(ttf);
defminmax = getushort(ttf);
langsyscnt = getushort(ttf);
ls = calloc(langsyscnt,sizeof(struct tagoff));
for ( j=0; j<langsyscnt; ++j ) {
ls[j].tag = getlong(ttf);
ls[j].offset = getushort(ttf);
}
if ( basevalues==0 )
printf("\t No %s baseline positions for '%c%c%c%c' script\n",
axis==0 ? "Horizontal": "Vertical",
bs[i].tag>>24, bs[i].tag>>16, bs[i].tag>>8, bs[i].tag );
else {
int defbl, coordcnt;
int *coords;
fseek( ttf,bs[i].offset+basevalues,SEEK_SET);
defbl = getushort(ttf);
coordcnt = getushort(ttf);
printf("\t The default baseline for '%c%c%c%c' script is '%c%c%c%c'\n",
bs[i].tag>>24, bs[i].tag>>16, bs[i].tag>>8, bs[i].tag,
tags[defbl]>>24, tags[defbl]>>16, tags[defbl]>>8, tags[defbl]);
if ( coordcnt!=basetagcnt )
fprintf( stderr, "!!!!! Coord count (%d) for '%c%c%c%c' script does not match base tag count (%d) in 'BASE' table\n",
coordcnt,
bs[i].tag>>24, bs[i].tag>>16, bs[i].tag>>8, bs[i].tag,
basetagcnt );
coords = calloc(coordcnt,sizeof(int));
for ( j=0; j<coordcnt; ++j )
coords[j] = getushort(ttf);
for ( j=0; j<coordcnt; ++j ) if ( coords[j]!=0 ) {
int format, coord, gid, pt, devtab_off;
fseek( ttf,bs[i].offset+basevalues+coords[j],SEEK_SET);
format = getushort(ttf);
coord = (short) getushort(ttf);
if ( format==3 ) {
devtab_off = getushort(ttf);
printf("\t Baseline '%c%c%c%c' in script '%c%c%c%c' is at %d, with device table\n",
tags[j]>>24, tags[j]>>16, tags[j]>>8, tags[j],
bs[i].tag>>24, bs[i].tag>>16, bs[i].tag>>8, bs[i].tag,
coord );
} else if ( format==2 ) {
gid = getushort(ttf);
pt = getushort(ttf);
printf("\t Baseline '%c%c%c%c' in script '%c%c%c%c' is at %d, modified by point %d in glyph %d\n",
tags[j]>>24, tags[j]>>16, tags[j]>>8, tags[j],
bs[i].tag>>24, bs[i].tag>>16, bs[i].tag>>8, bs[i].tag,
coord, pt, gid );
} else {
printf("\t Baseline '%c%c%c%c' in script '%c%c%c%c' is at %d\n",
tags[j]>>24, tags[j]>>16, tags[j]>>8, tags[j],
bs[i].tag>>24, bs[i].tag>>16, bs[i].tag>>8, bs[i].tag,
coord );
if ( format!=1 )
fprintf( stderr, "!!!!! Bad Base Coord format (%d) for '%c%c%c%c' in '%c%c%c%c' script in 'BASE' table\n",
format,
tags[j]>>24, tags[j]>>16, tags[j]>>8, tags[j],
bs[i].tag>>24, bs[i].tag>>16, bs[i].tag>>8, bs[i].tag );
}
}
free(coords);
}
if ( defminmax==0 )
printf("\t No %s min/max extents for '%c%c%c%c' script\n",
axis==0 ? "Horizontal": "Vertical",
bs[i].tag>>24, bs[i].tag>>16, bs[i].tag>>8, bs[i].tag );
else
readttfbaseminmax(ttf,bs[i].offset+defminmax,info,bs[i].tag,0);
if ( langsyscnt==0 )
printf("\t No %s min/max extents for specific langs in '%c%c%c%c' script\n",
axis==0 ? "Horizontal": "Vertical",
bs[i].tag>>24, bs[i].tag>>16, bs[i].tag>>8, bs[i].tag );
else
for ( j=0; j<langsyscnt; ++j ) if ( ls[j].offset!=0 )
readttfbaseminmax(ttf,bs[i].offset+ls[j].offset,info,bs[i].tag,ls[j].tag);
free(ls);
}
}
free(bs);
free(tags);
}
return( 1 );
}
static void readttfjustmax(char *label,FILE *ttf,int base,int offset, struct ttfinfo *info) {
int lcnt,i;
int *offsets;
if ( offset==0 ) {
printf( "\t No %s data\n", label );
return;
}
base += offset;
fseek(ttf,base,SEEK_SET);
lcnt = getushort(ttf);
offsets = malloc(lcnt*sizeof(int));
printf( "\t %d lookup%s for %s\n", lcnt, lcnt==1? "" : "s", label );
for ( i=0; i<lcnt; ++i )
printf( "\t\tOffset to lookup %d\n", offsets[i] = getushort(ttf));
for ( i=0; i<lcnt; ++i )
showgpossublookup(ttf,base, offsets[i], info, true);
free(offsets);
}
static void readttfjustlookups(char *label,FILE *ttf,int base,int offset) {
int lcnt,i;
if ( offset==0 ) {
printf( "\t No %s data\n", label );
return;
}
base += offset;
fseek(ttf,base,SEEK_SET);
lcnt = getushort(ttf);
printf( "\t %d lookup%s for %s\n", lcnt, lcnt==1? "" : "s", label );
for ( i=0; i<lcnt; ++i )
printf( "\t\tLookup %d\n", getushort(ttf));
}
static void readttfjustlangsys(FILE *ttf,int offset,uint32 stag, uint32 ltag, struct ttfinfo *info) {
int pcnt,j;
int *offsets;
int shrinkenablesub, shrinkenablepos, shrinkdisablesub, shrinkdisablepos;
int extendenablesub, extendenablepos, extenddisablesub, extenddisablepos;
int shrinkmax, extendmax;
fseek(ttf,offset,SEEK_SET);
printf("\t Justification priority data for '%c%c%c%c' script, '%c%c%c%c' lang.\n",
stag>>24, stag>>16, stag>>8, stag,
ltag>>24, ltag>>16, ltag>>8, ltag );
pcnt = getushort(ttf);
offsets = malloc(pcnt*sizeof(int));
for ( j=0; j<pcnt; ++j )
offsets[j] = getushort(ttf);
printf( "\t %d Priority level%s\n", pcnt, pcnt==1 ? "" : "s" );
for ( j=0; j<pcnt; ++j ) {
if ( offsets[j]==0 ) {
printf( "\t No data for priority level %d\n", j );
continue;
}
printf( "\t Priority level %d\n", j );
fseek(ttf,offset+offsets[j],SEEK_SET);
shrinkenablesub = getushort(ttf);
shrinkdisablesub = getushort(ttf);
shrinkenablepos = getushort(ttf);
shrinkdisablepos = getushort(ttf);
shrinkmax = getushort(ttf);
extendenablesub = getushort(ttf);
extenddisablesub = getushort(ttf);
extendenablepos = getushort(ttf);
extenddisablepos = getushort(ttf);
extendmax = getushort(ttf);
readttfjustlookups("ShrinkageEnableGSUB",ttf,offset+offsets[j],shrinkenablesub);
readttfjustlookups("ShrinkageDisableGSUB",ttf,offset+offsets[j],shrinkdisablesub);
readttfjustlookups("ShrinkageEnableGPOS",ttf,offset+offsets[j],shrinkenablepos);
readttfjustlookups("ShrinkageDisableGPOS",ttf,offset+offsets[j],shrinkdisablepos);
readttfjustmax("ShrinkageMax",ttf,offset+offsets[j],shrinkmax,info);
readttfjustlookups("ExtensionEnableGSUB",ttf,offset+offsets[j],extendenablesub);
readttfjustlookups("ExtensionDisableGSUB",ttf,offset+offsets[j],extenddisablesub);
readttfjustlookups("ExtensionEnableGPOS",ttf,offset+offsets[j],extendenablepos);
readttfjustlookups("ExtensionDisableGPOS",ttf,offset+offsets[j],extenddisablepos);
readttfjustmax("ExtensionMax",ttf,offset+offsets[j],extendmax,info);
}
free(offsets);
}
static void readttfjstf(FILE *ttf,FILE *util, struct ttfinfo *info) {
int version;
int i,j,cnt, lcnt, lmax=0;
struct tagoff *scripts, *langs=NULL;
int extenderOff, defOff;
fseek(ttf,info->JSTF_start,SEEK_SET);
printf( "\nJSTF table (at %d)\n", info->JSTF_start);
printf( "\tVersion: 0x%08x\n", version = getlong(ttf));
if ( version!=0x00010000 )
fprintf( stderr, "!> Bad version number for BASE table.\n" );
cnt = getushort(ttf); /* Script count */
printf( "\t %d scripts\n", cnt );
scripts = malloc(cnt*sizeof(struct tagoff));
for ( i=0; i<cnt; ++i ) {
scripts[i].tag = getlong(ttf);
scripts[i].offset = getushort(ttf);
}
for ( i=0; i<cnt; ++i ) {
printf("\t Justification data for '%c%c%c%c' script\n",
scripts[i].tag>>24, scripts[i].tag>>16, scripts[i].tag>>8, scripts[i].tag );
if ( scripts[i].offset==0 ) {
printf("\t Nothing for this script\n" );
continue;
}
fseek(ttf,info->JSTF_start+scripts[i].offset,SEEK_SET);
extenderOff = getushort(ttf);
defOff = getushort(ttf);
lcnt = getushort(ttf);
if ( lcnt>lmax )
langs = realloc(langs,(lmax = lcnt+20)*sizeof(struct tagoff));
for ( j=0; j<lcnt; ++j ) {
langs[j].tag = getlong(ttf);
langs[j].offset = getushort(ttf);
}
if ( extenderOff==0 )
printf( "\t No extension glyphs.\n" );
else {
int gcnt;
fseek(ttf,info->JSTF_start+scripts[i].offset+extenderOff,SEEK_SET);
gcnt = getushort(ttf);
printf( "\t %d extension glyph%s.\n", gcnt, gcnt==1?"":"s" );
for ( j=0; j<gcnt; ++j ) {
int gid = getushort(ttf);
printf( "\t Extension Glyph %d (%s)\n", gid,
gid>=info->glyph_cnt ? "!!! Bad glyph !!!" :
info->glyph_names == NULL ? "" : info->glyph_names[gid]);
}
}
if ( defOff==0 )
printf( "\t No default just language system table\n" );
else
readttfjustlangsys(ttf,info->JSTF_start+scripts[i].offset+defOff,
scripts[i].tag, CHR('d','f','l','t'),info);
printf( "\t %d langsys table%s.\n", lcnt, lcnt==1?"":"s" );
for ( j=0; j<lcnt; ++j ) {
readttfjustlangsys(ttf,info->JSTF_start+scripts[i].offset+langs[j].offset,
scripts[i].tag, langs[j].tag,info);
}
}
free( langs );
free( scripts );
}
static void readit(FILE *ttf, FILE *util) {
struct ttfinfo info;
int i;
memset(&info,'\0',sizeof(info));
readttfheader(ttf,util,&info);
if ( info.ttccnt!=0 ) {
for ( i=0; i<info.ttccnt; ++i ) {
printf( "\n=============================> TTC font %d\n", i );
fseek(ttf,info.ttcoffsets[i],SEEK_SET);
readit(ttf,util);
}
return;
}
if ( just_headers )
return;
if ( info.fftm_start!=0 )
readttfFFTM(ttf,util,&info);
if ( info.head_start!=0 )
readttfhead(ttf,util,&info);
if ( info.hhea_start!=0 )
readttfhhead(ttf,util,&info);
if ( info.copyright_start!=0 )
readttfname(ttf,util,&info);
if ( info.os2_start!=0 )
readttfos2(ttf,util,&info);
if ( info.maxp_start!=0 )
readttfmaxp(ttf,util,&info);
if ( info.gasp_start!=0 )
readttfgasp(ttf,util,&info);
if ( info.encoding_start!=0 )
readttfencodings(ttf,util,&info);
if ( info.postscript_len!= 0 )
readttfpost(ttf,util,&info);
if ( info.cvt_length!=0 )
readttfcvt(ttf,util,&info);
if ( info.cff_start!=0 )
readcff(ttf,util,&info);
if ( info.gsub_start!=0 )
readttfgsub(ttf,util,&info);
if ( info.gpos_start!=0 )
readttfgpos(ttf,util,&info);
if ( info.kern_start!=0 )
readttfkern(ttf,util,&info);
if ( info.gdef_start!=0 )
readttfgdef(ttf,util,&info);
if ( info.base_start!=0 )
readttfbase(ttf,util,&info);
if ( info.JSTF_start!=0 )
readttfjstf(ttf,util,&info);
if ( info.bitmaploc_start!=0 && info.bitmapdata_start!=0 )
readttfbitmaps(ttf,util,&info);
if ( info.bitmapscale_start!=0 )
readttfbitmapscale(ttf,util,&info);
if ( info.prep_length!=0 )
readtableinstr(ttf,info.prep_start,info.prep_length,"prep");
if ( info.fpgm_length!=0 )
readtableinstr(ttf,info.fpgm_start,info.fpgm_length,"fpgm");
if ( info.fdsc_start!=0 )
readttffontdescription(ttf,util,&info);
if ( info.feat_start!=0 )
readttffeatures(ttf,util,&info);
if ( info.mort_start!=0 || info.morx_start!=0 )
readttfmetamorph(ttf,util,&info);
if ( info.prop_start!=0 )
readttfappleprop(ttf,util,&info);
if ( info.lcar_start!=0 )
readttfapplelcar(ttf,util,&info);
if ( info.opbd_start!=0 )
readttfappleopbd(ttf,util,&info);
if ( info.fvar_start!=0 )
readttfapplefvar(ttf,util,&info);
if ( info.gvar_start!=0 )
readttfapplegvar(ttf,util,&info);
if ( info.hdmx_start!=0 )
readttfhdmx(ttf,util,&info);
if ( info.math_start!=0 )
readttfmath(ttf,util,&info);
if ( info.glyphlocations_start!=0 ) {
int i, pos;
fseek(ttf,info.glyphlocations_start,SEEK_SET);
if ( info.index_to_loc_is_long ) {
for ( i=0; 4*i<info.loca_length; ++i ) {
pos = getlong(ttf);
if ( pos&3 )
fprintf( stderr, "Not aligned GID=%d, pos=0x%x\n", i, pos);
}
} else {
for ( i=0; 2*i<info.loca_length; ++i ) {
pos = getushort(ttf);
if ( pos&1 )
fprintf( stderr, "Not aligned GID=%d, pos=0x%x\n", i, pos<<1 );
}
}
}
}
int main(int argc, char **argv) {
FILE *ttf, *util;
char *filename = NULL;
int i;
char *pt;
for ( i=1; i<argc; ++i ) {
if ( *argv[i]=='-' ) {
pt = argv[i]+1;
if ( *pt=='-' ) ++pt;
if ( strcmp(pt,"v")==0 || strcmp(pt,"verbose")==0 )
verbose = true;
if ( strcmp(pt,"h")==0 || strcmp(pt,"headers")==0 )
just_headers = true;
else {
fprintf( stderr, "%s [-verbose] ttf-file\n", argv[0]);
exit(1);
}
} else {
if ( filename!=NULL )
printf( "\n\n\n******************** %s *****************\n\n\n", argv[i]);
filename = argv[i];
ttf = fopen(filename,"rb");
if ( ttf==NULL ) {
fprintf( stderr, "Can't open %s\n", argv[1]);
return( 1 );
}
util = fopen(filename,"rb");
readit(ttf,util);
fclose(ttf);
fclose(util);
}
}
if ( filename==NULL ) {
fprintf( stderr, "%s [-verbose] [-headers] ttf-file\n", argv[0]);
exit(1);
}
return( 0 );
}
|