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
|
fontforge
=========
.. default-domain:: py
.. module:: fontforge
:synopsis: The primary module for interacting with FontForge
Module attributes
-----------------
.. data:: hooks
A dictionary which the user may fill to associate certain FontForge
events with a python function to be run when those events happen.
The function will be passed the font (or possibly glyph) for which
the relevant event occurred.
**Hook names**
.. object:: newFontHook
This function will be called when a new font has been created.
.. object:: loadFontHook
This function will be called when a font is loaded from disk.
(if a font has an "initScriptString" entry in its persistent
dictionary, that script will be invoked before this function).
Other hooks are defined in a font's own temporary and persistent dictionaries.
.. data:: splineCorner
A point type enumeration of value 0
.. data:: splineCurve
A point type enumeration of value 1
.. data:: splineHVCurve
A point type enumeration of value 2
.. data:: splineTangent
A point type enumeration of value 3
.. data:: fontforge.spiroG4
A spiro point type enumeration of value 1.
A Spiro G4 curve point
.. data:: fontforge.spiroG2
A spiro point type enumeration of value 2.
A Spiro G2 curve point
.. data:: fontforge.spiroCorner
A spiro point type enumeration of value 3.
A Spiro corner point
.. data:: fontforge.spiroLeft
A spiro point type enumeration of value 4.
A Spiro left "tangent" point
.. data:: fontforge.spiroRight
A spiro point type enumeration of value 5.
A Spiro right "tangent" point
.. data:: fontforge.spiroOpen
A spiro point type enumeration of value 6.
This may only be used on the first point in a spiro tuple. It indicates that the tuple
describes an open contour.
.. data:: fontforge.unspecifiedMathValue
A constant, used when the value is unspecified
Module functions
----------------
.. function:: getPrefs(pref_name)
returns the value of the named preference item
.. function:: setPrefs(pref_name, value)
sets the value of the named preference item
.. function:: hasSpiro()
Returns a boolean, ``True`` if Raph Levien's spiro package is available for
use in FontForge.
.. function:: savePrefs()
Saves the current preference settings
.. function:: loadPrefs()
Loads the user's default preference settings. Not done automatically in a
script.
.. function:: defaultOtherSubrs()
Sets the type1 PostScript OtherSubrs to the default value
.. function:: readOtherSubrsFile(filename)
Sets the type1 PostScript OtherSubrs to the stuff found in the file.
.. function:: loadEncodingFile(filename[, encname])
Loads an encoding file, returns the name of the encoding or ``None``. When
loading encodings in Unicode consortium format, an encname has to be specified
or the encoding will be ignored and ``None`` will be returned.
.. function:: loadNamelist(filename)
Loads a namelist
.. function:: loadNamelistDir(dirname)
Loads all namelist files in the directory
.. function:: preloadCidmap(filename, registry, order, supplement)
Loads a FontForge cidmap file (first three args are strings, last is an integer)
.. function:: printSetup(type[, printer|cmd|file, width, height])
Prepare to :func:`print a font sample <font.printSample>`.
The first argument may be one of:
.. object:: lp
Queues postscript output to the printer using lp.
You may use the optional second argument to specify the printer name.
.. object:: lpr
Queues postscript output to the printer using lpr.
You may use the optional second argument to specify the printer name.
.. object:: ghostview
Displays the output using ghostview (or gv). The second argument is ignored.
.. object:: command
Use a custom shell command to print the output.
The second argument should contain the command and its arguments.
.. object:: ps-file
Dump the postscript output to a file. The second argument specifies the filename.
.. pdf-file
Dump the output as pdf to a file. The second argument specifies the filename.
The third and fourth arguments are optional and specify the page size
(in points) for the output. The third argument is the page width and the
fourth is the height. These settings remain until changed.
.. function:: nameFromUnicode(uni[, namelist])
Finds the glyph name associated with a given unicode codepoint. If a
namelist is specified the name will be taken from that.
.. function:: UnicodeAnnotationFromLib(n)
Returns the Unicode Annotations for this value as described by
www.unicode.org. If there is no unicode annotation for this value, or no
library available, then return empty string "". It can execute with no
current font.
.. function:: UnicodeBlockCountFromLib(n)
Return the number of Unicode Blocks as described by www.unicode.org.
Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
If there is no value, then return -1. This can execute with no current font.
.. function:: UnicodeBlockEndFromLib(n)
Returns the Unicode Block end value as described by www.unicode.org.
Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
If there is no value, then return -1. This can execute with no current font.
.. function:: UnicodeBlockNameFromLib(n)
Returns the Unicode Block Name as described by www.unicode.org.
Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
If there is no value, then return empty string "". This can execute with no
current font.
.. function:: UnicodeBlockStartFromLib(n)
Returns the Unicode Block start value as described by www.unicode.org.
Currently, the blocks are {0..233}, spanning unicode values {uni0..uni10FFFF}.
If there is no value, then return -1. This can execute with no current font.
.. function:: unicodeFromName(glyphname)
Looks up glyph name in its dictionary and if it is associated with a unicode
code point returns that number. Otherwise it returns -1
.. function:: UnicodeNameFromLib(n)
Returns the Unicode Name for this value as described by www.unicode.org.
If there is no unicode name for this value, then return empty string "".
It can execute with no current font.
.. function:: UnicodeNamesListVersion()
Return the Unicode Nameslist Version (as described by www.unicode.org).
This can execute with no current font.
.. function:: UnicodeNames2FromLib(val)
Errors and corrections happen, therefore names can be corrected in the next
Unicode Nameslist version. This function returns the formal alias for the
unicode value given, or an empty string if there is no such alias.
.. function:: scriptFromUnicode(n)
Return the script tag for the given Unicode codepoint. So, for ``ord('Q')``,
it would return ``latn``. This is most useful with :meth:`font.addLookup()`,
like: ::
# Add a `mark` lookup for an arbitrary glyph...
script = fontforge.scriptFromUnicode(glyph.unicode)
font.addLookup("l1", "gpos_mark2base", None, (("mark",((script,("dflt")),)),))
font.addLookupSubtable("l1", "l1-1")
font.addAnchorClass("l1-1", "top")
.. function:: SpiroVersion()
Returns the version of LibSpiro available to FontForge. Versions 0.1 to 0.5
do not have a method to indicate version numbers, but there is a limited
method to estimate versions {'0.0'..'0.5'}. '0.0' if FontForge has no LibSpiro
available. '0.1' if LibSpiro 20071029 is available. '0.2' if LibSpiro 0.2 to
0.5 is available. LibSpiro 0.6 and higher reports back it's version available.
.. function:: version()
Returns FontForge's version number. This will be a large number like 20070406.
.. function:: loadPlugins()
Discovers and loads FontForge python plugins according to the current
configuration, if not already loaded. This is primarily intended when
importing FontForge into a python process but can also be when loading
is delayed by the ``-skippyplug`` command-line flag.
.. function:: getPluginInfo()
Returns a list of dictionary objects describing configured and/or discovered
plugins. Configured plugins are listed first in loading order followed by
any newly discovered plugins. Each dictionary object will have the keys:
.. object:: name
The name of the plugin as defined by its author.
.. object:: enabled
"On" if the plugin is enabled, "Off" if it is disabled, "New" if the
user has not yet configured this plugin.
.. object:: status
"Not Found" if the plugin is configured but was not discovered.
"Couldn't Load" if the plugin was discovered and its load status is
"On" but the relevant module could not be imported. "Couldn't Start"
if the module could be imported but the initialization function
was missing or returned an error. "Unloaded" if the plugin was discovered
and its load status is "On" but loading has not been attempted (most
likely because of a configuration change or startup flag). ``None``
if the plugin was discovered but has load status "Off" or New" or if
it was loaded successfully.
.. object:: package_name
The name of the Python package containing the plugin.
.. object:: module_name
The name of the Python module carrying the initialization function.
.. object:: attrs
Additional sub-objects or properties of the module needed to pick
out the location of the initialization function (if any).
.. object:: prefs
A boolean indicating whether the plugin has configurable preferences.
.. object:: package_url
The "Home-page" URL listed in the package, if any.
.. object:: summary
The "Summary" line in the package's metadata with a brief description
of the plugin.
Some of these values will be ``None`` if the plugin has not been loaded
and a few more will be ``None`` if the plugin was not discovered.
.. function:: configurePlugins([List of dictionaries])
This method allows plugins to be reconfigured using the Python API. It
accepts a list (or any other iterable object) of dictionaries similar to
those provided by ``getPluginInfo()`` except that only the ``name`` and
``enabled`` fields are examined. The ``name`` value must be the name of a
known (currently configured or discovered) plugin. The ``enabled`` value
must be "On" or "Off". The configuration will be updated to correspond to
the listed plugins in the specified order.
If a plugin that was *not* discovered is missing from the list it will be
removed from the configuration. Any missing but discovered plugins will
be added to the end of the configuration list with load status "New".
.. function:: runInitScripts()
Runs the system or user initialization scripts, if not already run. This is
primarily intended when importing FontForge into a python process.
.. function:: scriptPath()
Returns a tuple listing the directory paths which are searched for python
scripts during FontForge initialization.
.. function:: fonts()
Returns a tuple of all fonts currently loaded into FontForge for editing
.. function:: activeFont()
If the script were invoked from the File->Execute Script... dialog, or
invoked by a menu item in the font view, this returns the font that was
active at the time. Otherwise it returns ``None``.
.. function:: activeGlyph()
If the script were invoked from the File->Execute Script... dialog or a menu
item from an outline glyph window or a glyph import/export command this
returns the glyph that was active at the time. Otherwise it returns ``None``.
.. function:: activeLayer()
This returns the currently active layer as an integer between 0 (inclusive)
and the font/glyph's layer count (exclusive). It may also be set to -1 if the
current glyph window is displaying the font's guideline layer.
.. function:: fontsInFile(filename)
Returns a tuple of all font names found in the specified file. The tuple may
be empty if FontForge couldn't find any.
.. function:: open(filename[, flags])
Opens a filename and returns the font it contains (if any). The optional
``flags`` argument can be string tuple or integer combination of the
following flags:
.. object:: fstypepermitted (1)
The user has the appropriate license to examine the font no matter what
the fstype setting is.
.. object:: allglyphsinttc (4)
Load all glyphs from the 'glyf' table of a ttc font (rather than only the
glyphs used in the font picked).
.. object:: fontlint (8)
Report more error conditions.
.. object:: hidewindow (16)
Do not create a view window for this font even if the UI is active.
.. note::
This option supports efficient bulk processing of fonts in scripts run
through the UI but using it can be tricky. Open fonts will be listed at
the bottom of the "Window" menu but choosing them will have no effect.
If some fonts are not closed you may need to "force-quit" the
application using your OS.
.. object:: alltables (32)
Retain all recognized font tables that do not have a native format.
.. function:: parseTTInstrs(string)
Returns a binary string each byte of which corresponds to a truetype
instruction. The input string should contain a set of instruction names as ::
"SRP0 MIRP[min,rnd,black]"
.. function:: unParseTTInstrs(sequence)
Reverse of the above. Converts a binary string into a human (sort of)
readable string
.. function:: unitShape(n)
Returns a closed contour which is a regular n-gon. The contour will be
inscribed in the unit circle. If n is negative, then the contour will be
circumscribed around the unit circle. A value of 0 will produce a unit circle.
If n==1 it is treated as if n were -4 -- a circumscribed square where each
side is 2 units long (this is for historical reasons). Behavior is undefined
for n=2,-1,-2.
.. function:: registerGlyphSeparationHook(hook)
The GlyphSeparationHook is a python routine which FontForge will call when
it wants to figure out the optical separation between two glyphs. If you
never call this, or if you call it with a value of ``None`` FontForge will
use a built-in default. This routine gets called during AutoWidth, AutoKern,
and computing the optical left and right side bearings (for 'lfbd' and 'rtbd'
features). For more information see its own section.
.. _fontforge.ui_functions:
User Interface Module Functions
-------------------------------
Users may define scripts to be run when menu items are invoked. Some of these
scripts will want to ask users questions, so this section provides routines to
determine if FontForge has a user interface, a command to add menu items, and
various small standard dialogs to interact with the user. I do not currently
provide a mechanism for allowing people to define special purpose dialogs (for
example they might want to ask more than one question in a dialog, and I don't
support that).
When FontForge starts (if it's a FontForge with python) it will look at the
directories ``$(PREFIX)/share/fontforge/python`` and ``~/.FontForge/python``
and attempt to run all files in those directories which end in ``".py"``.
Presumably these files will allow people to customize the user interface to
suit their needs.
Currently it reads the files in directory order (which is generally somewhere
between creation order and totally random). It will read the system directory
before the user directory.
.. rubric:: Example
::
import fontforge
def nameGlyph(junk, glyph):
print(glyph.glyphname)
fontforge.registerMenuItem(callback=nameGlyph, context="Glyph",
name=("Print Glyph Name", "MyExt_PrintGlyphName"))
def neverEnableMe(junk, glyph):
return False
fontforge.registerMenuItem(callback=nameGlyph, enable=neverEnableMe, context="Glyph",
submenu=("SubMenu", "MyExt_SubMenu"),
name=("Print Glyph Name", "MyExt_PrintGlyphName"))
def importGlyph(junk, glyph, filename, toback):
print("Import")
print(glyph.glyphname)
print(filename)
def exportGlyph(junk, glyph, filename):
print("Import")
print(glyph.glyphname)
print(filename)
fontforge.registerImportExport(importGlyph, exportGlyph, None, "foosball", "foo", "foo,foobar")
The first call will define a menu item in the Tools menu of the Glyph window.
The menu will be called "Print Glyph Name". It has no shortcut to invoke it. It
needs no external data. It is always enabled. And when activated it will invoke
the function "nameGlyph" which prints the name of the glyph in the window from
which the command is invoked.
The second call defines a menu item in a submenu of the Tools menu. This submenu
is called "SubMenu". This item will never be enabled -- but if it were enabled
it would again call "nameGlyph" to print the name of the current glyph.
The last provides a way to import and export files of type "foosball" (or it
would if the routines did anything).
Not a very useful example.
.. function:: hasUserInterface()
Returns ``True`` if this session of FontForge has a user interface
.. function:: registerMenuItem(callback, enable, data, context, hotkey, {submenu_names, } name)
(Positional interface)
.. function:: registerMenuItem(callback=, enable=None, data=None, context=, hotkey=None, name=, submenu=None, keyword_only=False)
(Keyword interface)
:noindex:
.. function:: registerMenuItem(context=, divider=, submenu=None)
(Divider interface)
:noindex:
If FontForge has a user interface this will add this menu item to the
FontForge menu(s) specified by the ``context`` parameter. This second
keyword interface is explained in the ``divider`` section.
We also recommend reading the :ref:`Menu <fontforge.plugin_menu>` section
of :doc:`Extending FontForge with Python </techref/pyextend>`
**Note:** The positional interface is forward-compatible with earlier
verions of FontForge.
.. object:: callback
This is the function that will be called when the menu item is activated.
It will be passed two arguments, the first is the data value specified
here (which defaults to ``None``) and the second is a :class:`fontforge.glyph`
or :class:`fontforge.font` object (depending on the ``context``).
The callback's return value is ignored.
.. object:: enable
When specified this function is called with the same arguments as ``callback``
right before the menu or submenu is diplayed. When it returns ``True``
the menu item will be enabled and when it returns``False`` it will be
disabled. (When ``enable`` is ``None`` the menu item is always enabled.)
.. object:: data
``data`` can be whatever you want; it defaults to ``None``. FontForge
passes it to both of the above functions. It can be used to provide
context or default arguments for the function (so that one function can
be used for multiple menu items.)
.. object:: context
Currently this can the string ``"Font"``, the string ``"Glyph"``
or the tuple ``("Font", "Glyph")``). ``"Font"`` will add the menu item
to the FontView "Tools" menu or its submenu, while ``"Glyph"`` will
add it to the CharView tools menu or its submenu.
.. object:: hotkey
``hotkey`` must be either ``None`` or a string in hotkey format,
which is the same as the second part of a
:ref:`HotKey assignment <HotKeys.hotkeyassign>`.
Because hotkeys are a "limited
resource" this string is only a `suggestion`; it has no effect
when the specified HotKey is already taken. Therefore, before picking
a candidate HotKey you should at least verify that it is not already
used by the relevant window in FontForge.
Even when the specified HotKey is taken a user can still specify their
own in the HotKeys file. You can make this easier to do, now and in the
future, by providing the full triplet of names for each "level" using
the current interface.
.. object:: name
``name`` can be a string but ideally it is a tuple of three strings
``(localized_name, english_name, identifier_string)`` or of two strings
``(english_name, identifier_string)``. Use the three-tuple version when
your plugin or other extension is localized and the two-tuple version
when it is not localized or the user has configured the base locale.
**Note:** The ``english_name`` and ``localized_name`` can and should
include a *mnemonic*, picked out by a leading underscore. However,
mnemonics at the top level (so the first ``submenu`` name or the ``name``
if ``submenu`` is ``None``) are taken as a suggestion, similar to the
``hotkey`` argument. Please read the sections on Internationalization and
Localization and on Mnemonics in Extending FontForge with Python.
The ``identifier_string`` should be a single alphanumeric (plus
underscores, but no spaces) string to identify this menu item. In the
future this will serve as the representation of the menu item in menu
configuration files, allowing a user or administrator to put the item
where they like. It should include the name of your plugin or an
abbreviation of it. For a plugin called "Feature File Helpers" and an
item with (English) name "Save Fragment" a reasonable option would be
"FeatFileHelp_SaveFragment". (This is for the future, as configurable
menus are not yet supported by FontForge.)
.. object:: submenu
**Note:** ``submenu`` is a keyword-only argument.
``submenu`` can be any of: ``None``, a string, a two-tuple or three-tuple
as with ``name``, or a Python *list* of any of these, with each
specifying a level of sub-menu. (You cannot specify muitple levels of
submenu with a tuple, as this would be ambiguous.) The tuple elements are
analogous to ``name``: a three-tuple of ``(localized_name, english_name,
identifier_string)``, a two-tuple of ``(english_name,
identifier_string)``, or a string which is treated as the
``localized_name``. Submenus can and should also specify a *mnemonic*.
In the future the ``identfier_string`` will allow a whole submenu to be
moved to a different location in the menu hierarchy.
.. object:: submenu_names
When using the positional interface, each of these "intermediate" entries
can be a three-tuple, two-tuple, or string, corresponding to an entry
in the ``submenu`` list.
.. object:: keyword_only
When ``keyword_only`` is ``False`` (the default) the function will attempt
to fall back to the positional interface and any reported errors will be
relative to that interface. If you're having trouble with keyword parameters
set ``keyword_only`` to ``True`` to see a more specific error message.
.. object:: divider
This special form of the function adds a horizontal line to the menu.
The ``context`` keyword is required and ``divider`` must be set to ``True``.
If the ``submenu`` keyword is omitted the divider is added to the top level.
.. function:: registerImportExport(import_function, export_function, data, name, extension, [extension_list])
This will add the capability to import or export files of a given type,
presumably a way of specifying the splines in a given glyph.
.. object:: import-function
The function to call to import a file into a glyph. It will be called
with: The data argument (specified below), A pointer to the glyph into
which the import is to happen, A filename, A flag indicating whether the
import should go to the background layer or foreground. This function may
be ``None``. In which case there is no import method for this file type.
.. object:: export-function
The function to call to export a glyph into a file. It will be called
with: The data argument (see below), a pointer to the glyph, and a
filename. This function may be ``None``, in which case there is no export
method for this file type.
.. object:: data
Anything you like (including ``None``). It will be passed to the
import/export routines and can provide them with context if they need that.
name The name to be displayed in the user interface for this file type.
This may just be the extension, or it might be something more informative.
.. object:: extension
This is the default extension for this file type. It is used by the
export dialog to pick an extension for the generated filename.
.. object:: extension-list
Some file types have more than one common extension (eps files are usually
named "eps", but I have also seen "ps" and "art" used). The import dialog
needs to filter all possible filenames of this file type. This argument
should be a comma separated list of extensions. It may be omitted, in
which case it defaults to being the same as the "extension" argument above.
.. function:: logWarning(msg)
Adds the message (a string) to FontForge's Warnings window. (if you wish to
display a % character you must represent it as two percents). If there is no
user interface the output will go to stderr.
.. function:: postError(win_title, msg)
Creates a popup dialog to display the message (a string) in that dlg. (if you
wish to display a % character you must represent it as two percents). If
there is no user interface the output will go to stderr.
.. function:: postNotice(win_title, msg)
Creates a little window which will silently vanish after a minute or two and
displays the message (a string) in that window. (if you wish to display a %
character you must represent it as two percents). If there is no user
interface the output will go to stderr.
.. function:: openFilename(question, [def_name, [filter]])
All arguments are strings. The first is a question asked to the user (for
which a filename to open is presumed to be the answer). The second is
optional and provides a default filename. The third is optional and provides
a filter (like "\*.sfd")
The result is either a filename or ``None`` if the user canceled the dialog.
Throws an exception if there is no user interface.
.. function:: saveFilename(question, [def_name, [filter]])
All arguments are strings. The first is a question asked to the user (for
which a filename to save something to is presumed to be the answer). The
second is optional and provides a default filename. The third is optional and
provides a filter (like "\*.sfd")
The result is either a filename or ``None`` if the user canceled the dialog.
Throws an exception if there is no user interface.
.. function:: ask(title, question, answers, [def, cancel])
Allows you to ask the user a multiple choice question. It pops up a dialog
posing the question with a list of buttons ranged underneath it -- one for
each answer.
The first argument is the dialog's title, the second is the question to be
asked, the third is a tuple of strings -- each string will become a button,
the fourth and fifth arguments are option, the fourth is the index in the
answer array that will be the default answer (the one invoked if the user
presses the [Return] key), and the fifth is the answer invoked if the user
presses the [Escape] key. If omitted the default answer will be the first,
and the cancel answer will be the last.
The function returns the index in the answer array of the answer chosen by
the user.
Throws an exception if there is no user interface.
.. function:: askChoices(title, question, answers[,default=,multiple=])
Similar to the above allows you to ask the user a multiple choice question.
It pops up a dialog posing the question with a scrollable list of choices --
one for each answer.
The first argument is the dialog's title, the second is the question to be
asked, the third is a tuple of strings -- each string will become a button,
the fourth and fifth arguments are option, the fourth is the index in the
answer array that will be the default answer (the one invoked if the user
presses the [Return] key). If omitted the default answer will be the first.
The fifth argument means that multiple options can be selected. If true,
the fourth argument should be a tuple of Boolean values or a single integer
index into the answer tuple. So, if there are three options, it should look
like ``(True, False, True)``, which would select the first and last option.
The function returns the index in the answer array of the answer chosen by
the user. If the user
cancels the dialog, a -1 is returned.
``default`` and ``multiple`` may be passed by position if desired.
Throws an exception if there is no user interface.
.. function:: askString(title, question, [def_string])
Allows you to ask the user a question for which a string is the answer.
The first argument is the dialog's title, the second is the question to be
asked, the third is optional and specified a default answer.
The function returns the string the user typed or ``None`` if they cancelled
the dialog.
Throws an exception if there is no user interface.
.. function:: askMulti(title, specification)
This method raises a dialog with multiple questions for the user, optionally
organized into separate tabs. The answers can be choices (similar to
:func:`fontforge.askChoices()`) a string (similar to
:func:`fontforge.askString()`) an existing filename (similar to
:func:`fontforge.openFilename()`) or a save filename (similar to
:func:`fontforge.saveFilename()`.
Due to the variety of potential ``specification`` parameters this facility is
explained in a separate :doc:`document </techref/askmulti>`.
The method throws an exception if there is no user interface or the
specification is not valid. Otherwise it either returns a dictionary of answers
or ``None`` if the user chose "Cancel" or closed the dialog without choosing "OK".
Point
-----
.. class:: point([x, y, on_curve, type, selected])
Creates a new point. Optionally specifying its x,y location,
on-curve status and selected status. x and y must be supplied together.
A "point initializer tuple" is any tuple (x,y[,True|False[,0|1|2|3[,True|False]]]),
where x and y are numbers, the third value corresponds to on-curve, the
fourth to type, and the fifth to selected.
.. attribute:: point.x
The x location of the point
.. attribute:: point.y
The y location of the point
.. attribute:: point.on_curve
Whether this is an on curve point or an off curve point (a control point)
.. attribute:: point.selected
The value of this member also determines the selected status in the UI on
setting a layer. FontForge usually retains the selection status of any point
between and that of an on-curve point when saving, whether or not a UI is present.
.. attribute:: point.type
For an on-curve point, its FontForge point type.
There are four types: :data:`fontforge.splineCorner`, :data:`fontforge.splineCurve`,
:data:`fontforge.splineHVCurve` and :data:`fontforge.splineTangent`.
A new point will have type :data:`splineCorner`. When assigning a layer to
:attr:`glyph.layers`, :attr:`glyph.background` or :attr:`glyph.foreground`
the type value is ignored. To influence the type FontForge will associate
with an on-curve point use :meth:`glyph.setLayer`.
.. attribute:: point.interpolated
``True`` if FontForge treats this (quadratic, on-curve) point as interpolated.
All interpolated points should be mid-way between their off-curve points,
but some such points are not treated as interpolated. This flag is ignored
when setting a layer.
Older versions of FontForge omitted interpolated points. This was equivalent
to executing the following on a contour: ::
c[:] = [ p for p in c if not p.interpolated ]
This member will be false for a point marked "Never interpolate" in FontForge
but there is currently no way of setting or preserving that mark when a layer
is replaced using the Python interfaces. A "round trip" through a Python
contour therefore clears that mark on any points that have it, and FontForge
treats mid-placed and omitted :attr:`on_curve` points as equivalent.
.. attribute:: point.name
The point name (generally there is no name)
.. method:: point.dup()
Returns a copy of the current point.
.. method:: point.transform(tuple)
Transforms the point by the transformation matrix
.. method:: point.__reduce__()
This function allows the pickler to work on this type. I don't think it is
useful for anything else.
Contour
-------
A contour is a collection of points. A contour may be either based on cubic or
quadratic splines.
If based on cubic splines there should be either 0 or 2 off-curve points
between every two on-curve points. If there are no off-curve points then
we have a line between those two points. If there are 2 off-curve points
we have a cubic bezier curve between the two end points.
If based on quadratic splines things are more complex. Again, two
adjacent on-curve points yield a line between those points. Two on-curve
points with an off-curve point between them yields a quadratic bezier
curve. However if there are two adjacent off-curve points then an
on-curve point will be interpolated between them. (This should be
familiar to anyone who has read the truetype 'glyf' table docs).
For examples of what these splines can look like see the
:doc:`section on bezier curves </techref/bezier>`.
A contour may be open in which case it is just a long wiggly line, or
closed when it is more like a circle with an inside and an outside.
Unless you are making stroked fonts all your contours should eventually
be closed.
Contours may also be expressed in terms of Raph Levien's spiro points.
This is an alternate representation for the contour, and is not always
available (Only if :func:`fontforge.hasSpiro()` is ``True``. If
available the spiro member will return a tuple of spiro control points,
while assigning to this member will change the shape of the contour to
match the new spiros.
Two contours may be compared to see if they describe similar paths.
.. class:: contour(is_quadratic=False)
Creates a new contour.
.. attribute:: contour.is_quadratic
Whether the contour should be interpreted as a set of quadratic or cubic
splines. Setting this value has the side effect of converting the point list
to the appropriate format.
.. attribute:: contour.closed
Whether the contour is open or closed.
.. attribute:: contour.name
The contour name (generally there is no name).
.. attribute:: contour.spiros
This is an alternate representation of a curve. This member is only
available if :meth:`fontforge.hasSpiro()` is ``True``. Returns a tuple
of spiro control points. Each of these is itself a tuple of four
elements; an x,y location, a type field, and a set of flags. The type
field takes on values (which are predefined constants in the
:mod:`fontforge` module):
* :data:`fontforge.spiroG4`
* :data:`fontforge.spiroG2`
* :data:`fontforge.spiroCorner`
* :data:`fontforge.spiroLeft`
* :data:`fontforge.spiroRight`
* :data:`fontforge.spiroOpen`
For more information on what these point types mean see
`Raph Levien's work <https://www.levien.com/spiro/>`_.
The flags argument is treated as a bitmap of which currently on one bit (0x1)
is defined. This indicates that this point is selected in the UI.
When you assign a tuple of spiro control points to this member, the point
list for the Bezier interpretation of the contour will change. And when you
change the Bezier interpretation the set of spiro points will change.
.. method:: contour.dup()
Returns a deep copy of the contour. That is, it copies the points that make
up the contour.
.. method:: contour.isEmpty()
Returns whether the contour is empty (contains no points)
.. method:: contour.boundingBox()
Returns a tuple representing a rectangle ``(xmin,ymin, xmax,ymax)`` into
which the contour fits. It is not guaranteed to be the smallest such
rectangle, but it will often be.
.. method:: contour.getSplineAfterPoint(pos)
Returns a tuple of two four-element tuples. These tuples are x and y splines
for the curve after the specified point.
.. method:: contour.draw(pen)
Draw the contour to the pen argument.
.. method:: contour.__reduce__()
This function allows the pickler to work on this type. I don't think it is
useful for anything else.
.. method:: contour.__iter__()
Returns an iterator for the contour which will return the points in order.
.. rubric:: Sequence Protocol
Does not support the repeat concept.
.. object:: len(c)
The number of points in the contour
.. object:: c[i]
The ``i`` th point on the contour. You may assign a point or point
initializer to this (keeping the number of points constant) or use
``del c[i]`` to remove the entry (reducing the number by one).
.. object:: c[i:j]
The contour containing points between i and j; i must be >= j.
Alternatively, ``c[j:i:-1]`` returns those points in reverse order (larger
strides are not supported).
.. object:: c[i:j] = d
The points between i and j are replaced by those in d; i must be >= j.
d can be a contour or a sequence of point initializer tuples, as in
``[(1,1,False),(2,1)]``. If ``c[j:i:-1]`` is used instead the points of d
are assigned in reverse order.
.. object:: c + d
A contour concatenating c and d. d may be or encode either another contour
or a point.
.. object:: c += d
Appends d to c. d may be or encode either another contour or a point.
.. object:: p in c
When p is a point, returns whether some point ``(p.x, p.y)`` is in the
contour c. p can also be a tuple of two numbers.
.. rubric:: Contour construction
.. method:: contour.moveTo(x, y)
Adds an initial, on-curve point at ``(x,y)`` to the contour
.. method:: contour.lineTo(x, y[, pos])
Adds an line to the contour. If the optional third argument is give, the
line will be added after the pos'th point, otherwise it will be at the end
of the contour.
.. method:: contour.cubicTo((cp1x, cp1y)(cp2x, cp2y)(x, y)[, pos])
Adds a cubic curve to the contour. If the optional third argument is give,
the line will be added after the pos'th point, otherwise it will be at the
end of the contour.
.. method:: contour.quadraticTo((cpx, cpy)(x, y)[, pos])
Adds a quadratic curve to the contour. If the optional third argument is
give, the line will be added after the pos'th point, otherwise it will be at
the end of the contour.
.. method:: contour.insertPoint(point[, pos])
Adds point to the contour. If the optional third argument is give, the line
will be added after the pos'th point, otherwise it will be at the end of the
contour. The point may be either a point or a point initializer tuple.
.. method:: contour.makeFirst(pos)
Rotate the point list so that the pos'th point becomes the first point
.. method:: contour.isClockwise()
Returns whether the contour is drawn in a clockwise direction. A return
value of -1 indicates that no consistent direction could be found (the
contour self-intersects).
.. method:: contour.reverseDirection()
Reverse the order in which the contour is drawn (turns a clockwise contour
into a counter-clockwise one). See also :meth:`layer.correctDirection`.
.. method:: contour.similar(other_contour[, error])
Checks whether this contour is similar to the other one where error is the
maximum distance (in em-units) allowed for the two contours to diverge.
This is like the comparison operator, but that doesn't allow you to specify
an error bound.
.. method:: contour.xBoundsAtY(ybottom[, ytop])
Finds the minimum and maximum x positions attained by the contour when y is
between ybottom and ytop (if ytop is not specified it is assumed the same as
ybottom). If the contour does not have any y values in the specified range
then ff will return ``None``.
.. method:: contour.yBoundsAtX(xleft[, xright])
Finds the minimum and maximum y positions attained by the contour when x is
between xleft and xright (if xright is not specified it is assumed the same
as xleft). If the contour does not have any x values in the specified range
then ff will return ``None``.
.. rubric:: Contour manipulation
.. method:: contour.addExtrema([flags, emsize])
Extrema should be marked by on-curve points. If a curve lacks a point at an
extrema this command will add one. Flags may be one of the following strings:
.. object:: all
Add all missing extrema
.. object:: only_good
Only add extrema on longer splines (with respect to the em-size)
.. object:: only_good_rm
As above but also merge away on-curve points which are very close to, but
not on, an added extremum
.. method:: contour.cluster([within, max])
Moves clustered coordinates to a standard central value.
See also :meth:`contour.round()`.
.. method:: contour.merge(pos)
Removes the on-curve point a the given position and rearranges the other
points to make the curve as similar to the original as possible. (pos may
also be a tuple of positions, all of which will be removed)
See also :meth:`contour.simplify()`.
.. method:: contour.round([factor])
Rounds the x and y coordinates. If factor is specified then ::
new_coord = round(factor*old_coord)/factor
See also :meth:`contour.cluster()`.
.. method:: contour.selfIntersects()
Returns whether this contour intersects itself.
.. method:: contour.simplify([error_bound, flags, tan_bounds, linefixup, linelenmax])
Tries to remove excess points on the contour if doing so will not perturb
the curve by more than error-bound. Flags is a tuple of the following strings:
.. object:: ignoreslopes
Allow slopes to change
.. object:: ignoreextrema
Allow removal of extrema
.. object:: smoothcurves
Allow curve smoothing
.. object:: choosehv
Snap to horizontal or vertical
.. object:: forcelines
flatten bumps on lines
.. object:: nearlyhvlines
Make nearly horizontal/vertical lines be so
.. object:: mergelines
Merge adjacent lines into one
.. object:: setstarttoextremum
Rotate the point list so that the start point is on an extremum
.. object:: removesingletonpoints
If the contour contains just one point then remove it
See also :meth:`contour.merge()`.
.. method:: contour.transform(matrix)
Transforms the contour by the matrix
.. seealso::
`Curvatura documentation <https://github.com/linusromer/curvatura/blob/master/curvatura-doc.pdf>`_
Documentation for adding points of inflection, balancing and harmonizing.
.. method:: contour.addInflections()
If the curvature of a spline in the contour changes sign then break the
spline so that there will be a point at all points of inflection.
.. method:: contour.balance()
For all cubic bezier splines of the contour make the line between the control
points parallel to the chord such that the area is preserved. This is an
improved version of the algorithm known as "tunnify".
.. method:: contour.harmonize()
For all bezier splines of the contour move the smooth on-curve points between
its adjacent control points such that the adjacent curvatures become equal.
Layer
-----
A layer is a collection of contours. All the contours must be the same order
(all quadratic or all cubic). Currently layers do not contain references.
Layers may be compared to see if their contours are similar.
.. class:: layer()
Creates a new layer
.. method:: layer.is_quadratic()
Whether the contours should be interpreted as a set of quadratic cubic
splines. Setting this value has the side effect of converting the contour
list to the appropriate format.
.. method:: layer.__iter__()
Returns an iterator for the layer which will return the contours in order.
.. method:: layer.__reduce__()
This function allows the pickler to work on this type. I don't think it is
useful for anything else.
.. method:: layer.dup()
Returns a deep copy of the layer. That is, it will copy all the contours and
all the points as well as copying the layer object itself.
.. method:: layer.isEmpty()
Returns whether the layer is empty (contains no contour)
.. method:: layer.addExtrema([flags, emsize])
Extrema should be marked by on-curve points. If a curve lacks a point at an
extrema this command will add one. Flags may be one of the following strings:
.. object:: all
Add all missing extrema
.. object:: only_good
Only add extrema on longer splines (with respect to the em-size)
.. object:: only_good_rm
As above but also merge away on-curve points which are very close to, but
not on, an added extremum
.. method:: layer.cluster([within, max])
Moves clustered coordinates to a standard central value.
See also :meth:`layer.round()`.
.. method:: layer.correctDirection()
Orients all contours so that external ones are clockwise and internal
counter-clockwise. See also :meth:`contour.isClockwise()`.
.. method:: layer.export(filename[, KEYWORD])
Exports the current layer (in outline format) to a file. The type of file is
determined by the extension.
The following optional keywords modify the export process for various formats:
.. object:: usetransform (boolean, default=False)
Flip the Y-axis of exported SVGs with a transform element rather than
modifying the individual Y values.
.. object:: usesystem (boolean, default=False)
Ignore the above keyword settings and use the values set by the user
in the Import options dialog.
.. object:: asksystem (boolean, default=False)
If the UI is present show the Import options dialog to the user
and use the chosen values (does nothing otherwise).
.. method:: layer.exclude(excluded_layer)
Removes the excluded area from the current contours. See also
:meth:`layer.removeOverlap()` and :meth:`layer.intersect()`.
.. method:: layer.intersect()
Leaves only areas in the intersection of contours. See also
:meth:`layer.removeOverlap()` and :meth:`layer.exclude()`.
.. method:: layer.removeOverlap()
Removes overlapping areas. See also :meth:`layer.intersect()` and
:meth:`layer.exclude()`.
.. method:: layer.interpolateNewLayer(other_layer, amount)
Creates (and returns) a new layer which contains splines interpolated from
the current layer and the first argument. If amount is 0 the result will
look like the current layer, if 1 then like the first argument.
.. method:: layer.round([factor])
Rounds the x and y coordinates. If factor is specified then ::
new_coord = round(factor*old_coord)/factor
See also :meth:`layer.cluster()`.
.. method:: layer.selfIntersects()
Returns whether any of the contours on this layer intersects any other
contour (including itself).
.. method:: layer.similar(other_layer[, error])
Checks whether this layer is similar to the other one where error is the
maximum distance (in em-units) allowed for any two corresponding contours
in the layers to diverge.
This is like the comparison operator, but that doesn't allow you to specify
an error bound.
.. method:: layer.simplify([error_bound, flags, tan_bounds, linefixup, linelenmax])
Tries to remove excess points on the layer if doing so will not perturb the
curve by more than error-bound. Flags is a tuple of the following strings:
.. object:: ignoreslopes
Allow slopes to change
.. object:: ignoreextrema
Allow removal of extrema
.. object:: smoothcurves
Allow curve smoothing
.. object:: choosehv
Snap to horizontal or vertical
.. object:: forcelines
flatten bumps on lines
.. object:: nearlyhvlines
Make nearly horizontal/vertical lines be so
.. object:: mergelines
Merge adjacent lines into one
.. object:: setstarttoextremum
Rotate the point list so that the start point is on an extremum
.. object:: removesingletonpoints
If the contour contains just one point then remove it
.. method:: layer.stemControl(stem_width_scale, [hscale, stem_height_scale, vscale, xheight])
Allows you to scale counters and stems independently of each other.
``stem_width_scale`` specifies by how much the widths of stems should be
scaled (this should be a number around 1).
If omitted, ``hscale`` defaults to 1, otherwise it will indicate the
horizontal scaling factor for the glyph as a whole.
If omitted, ``stem_height_scale`` defaults to ``stem_width_scale``,
otherwise it specifies the scaling for stem heights.
If omitted, ``vscale`` defaults to ``hscale``, otherwise it specifies the
vertical scale factor for the glyph as a whole. ``xheight`` is optional; if
specified it will fix the points at that height so that they will be at the
same level across glyphs.
.. method:: layer.stroke("circular", width[, CAP, JOIN, FLAGS])
layer.stroke("elliptical", width, minor_width, ANGLE [, CAP, JOIN, FLAGS])
layer.stroke("calligraphic", width, height, angle[, FLAGS])
layer.stroke("polygon", contour[, FLAGS])
(Legacy interface)
:noindex:
.. method:: layer.stroke("circular", width [, CAP, JOIN, ANGLE, KEYWORD])
layer.stroke("elliptical", width, minor_width [, ANGLE, CAP, JOIN, KEYWORD])
layer.stroke("calligraphic", width, height [, ANGLE, CAP, JOIN, KEYWORD])
layer.stroke("convex", contour[, ANGLE, CAP, JOIN, KEYWORD])
(Current interface)
Strokes the lines of each contour in the layer according to the supplied
parameters. See the corresponding :meth:`glyph.stroke()` for a description
of the syntax and the :doc:`stroke </techref/stroke>` documentation for more general
information.
.. method:: layer.transform(matrix)
Transforms the layer by the matrix
.. method:: layer.nltransform(xexpr, yexpr)
xexpr and yexpr are strings specifying non-linear transformations that will
be applied to all points in the layer (with xexpr being applied to x values,
and yexpr to y values, of course). The syntax for the expressions is
explained in the :ref:`non-linear transform dialog <transform.Non-Linear>`.
.. method:: layer.boundingBox()
Returns a tuple representing a rectangle ``(xmin,ymin, xmax,ymax)`` into
which the layer fits. It is not guaranteed to be the smallest such
rectangle, but it will often be.
.. method:: layer.xBoundsAtY(ybottom[, ytop])
Finds the minimum and maximum x positions attained by the contour when y is
between ybottom and ytop (if ytop is not specified it is assumed the same as
ybottom). If the layer does not have any y values in the specified range
then FontForge will return ``None``.
.. method:: layer.yBoundsAtX(xleft[, xright])
Finds the minimum and maximum y positions attained by the contour when x is
between xleft and xright (if xright is not specified it is assumed the same
as xleft). If the layer does not have any x values in the specified range
then FontForge will return ``None``.
.. method:: layer.draw(pen)
Draw the layer to the :class:`pen <glyphPen>` argument.
.. method:: layer.addInflections()
Please see :meth:`contour.addInflections()`.
.. method:: layer.balance()
Please see :meth:`contour.balance()`.
.. method:: layer.harmonize()
Please see :meth:`contour.harmonize()`.
.. rubric:: Sequence Protocol
Does not support the repeat, slice and contains concepts.
.. object:: len(l)
The number of contours in the layer
.. object:: l[i]
The ``i`` th contour in the layer. You may assign a contour to this (keeping
the number of contours constant) or use ``del l[i]`` to remove the entry
(reducing the number by one)
.. object:: l + m
A layer concatenating l and m. m may be either another layer or a contour.
.. object:: l += m
Appends m to l. m may be either another layer or a contour.
Glyph Pen
---------
This implements the `Pen Protocol <http://robofab.org/objects/pens.html>`_ to
draw a FontForge :class:`glyph`. You create a :class:`glyphPen` with
:meth:`glyph.glyphPen()`. You then draw into it with the operators below.
This type may not be pickled.
.. rubric:: Example
::
import fontforge
font = fontforge.open("Ambrosia.sfd") # Open a font
pen = font["B"].glyphPen() # Create a pen to draw into glyph "B"
pen.moveTo((100,100)) # draw a square
pen.lineTo((100,200))
pen.lineTo((200,200))
pen.lineTo((200,100))
pen.closePath() # end the contour
font["A"].draw(pen) # or you can copy from one glyph to another
# by having a glyph draw itself into the pen
pen = None # Finalize the pen. This tells FontForge
# that the drawing is done and causes
# it to refresh the display (if a UI is active).
.. class:: glyphPen
.. method:: glyphPen.moveTo((x, y))
With one exception this call begins every contor and creates an on curve
point at ``(x,y)`` as the start point of that contour. This should be the
first call after a pen has been created and the call that follows a
:meth:`glyphPen.closePath()`, :meth:`glyphPen.endPath()`.
.. method:: glyphPen.lineTo((x, y))
Draws a line from the last point to ``(x,y)`` and adds that to the contour.
.. method:: glyphPen.curveTo((cp1.x, cp1.y), (cp2.x, cp2.y), (x, y)) ((cp.x, cp.y), (x, y))
This routine has slightly different arguments depending on the type of the
font. When drawing into a cubic font (PostScript) use the first set of
arguments (with two control points -- off curve points -- between each on
curve point). When drawing into a quadratic font (TrueType) use the second
format with one control point between adjacent on-curve points.
The standard appears to support super-bezier curves with more than two
control points between on-curve points. FontForge does not. Nor does
FontForge allow you to draw a quadratic spline into a cubic font, nor vice versa.
.. method:: glyphPen.qCurveTo([(cp.x, cp.y)]*, (x, y)) ([(cp.x, cp.y)]*, None))
This routine may only be used in quadratic (TrueType) fonts and has two
different formats. It is used to express the TrueType idiom where an on-curve
point mid-way between its control points may be omitted, leading to a run of
off-curve points (with implied but unspecified on-curve points between them).
The first format allows an arbetary number of off-curve points followed by
one on-curve point.
It is possible to have a contour which consists solely of off-curve points.
When this happens the contour is NOT started with a :meth:`glyphPen.moveTo()`,
instead the entire contour, all the off curve points, are listed in one call,
and the argument list is terminated by a ``None`` to indicate there are no
on-curve points.
.. method:: glyphPen.closePath()
Closes the contour (connects the last point to the first point to make a
loop) and ends it.
.. method:: glyphPen.endPath()
Ends the contour without closing it. This is only relevant if you are
stroking contours.
.. method:: glyphPen.addComponent(glyph_name[, transform, selected])
Adds a reference (a component) to the glyph. The PostScript transformation
matrix is a 6 element tuple (with a default of the identity transformation).
When ``selected`` is true the reference will be marked as selected in the
UI and related API calls.
Glyph
-----
The glyph type refers to a :class:`glyph` object. It has no independent life
of its own, it always lives within a font. It has all the things you expect to
be associated with a glyph: a glyph name, a unicode encoding, a drawing layer,
GPOS/GSUB features...
This type may not be pickled.
This type may not be created directly -- all glyphs are bound to a font and
must be created through the font.
.. class:: glyph
**Note:** Glyphs do not have an independent existence. They live in fonts.
You may not create them stand-alone, only in the context of a font. See
:meth:`font.createChar()`.
.. attribute:: glyph.activeLayer
Returns currently active layer in the glyph (as an integer). May be set to
an integer or a layer name to change the active layer.
.. attribute:: glyph.altuni
Returns additional unicode code points for this glyph. For a primary code
point, see :attr:`glyph.unicode` .
Returns either None or a tuple of alternate encodings. Each alternate
encoding is a tuple of ::
(unicode-value, variation-selector, reserved-field)
The first is an unicode value of this alternate code point. The second is an
integer for variation selector and can be set to -1 if not used. The third
is an empty field reserved for future use and currently must be set to zero.
:attr:`glyph.altuni` can be set to None to clear all alternates, or to a
tuple. The elements of the tuple may be either integers (an alternate
unicode value with no variation selector) or a tuple with up to 3 values in
it as explained above.
.. attribute:: glyph.anchorPoints
Returns the list of anchor points in the glyph. Each anchor point is a
tuple of ::
(anchor-class-name, type, x,y [,ligature-index])
The first two are strings, the next two doubles, and the last (which is only
present if ``type=="ligature"``) is an integer. Type may be
* ``mark``
* ``base``
* ``ligature``
* ``basemark``
* ``entry``
* ``exit``
.. attribute:: glyph.anchorPointsWithSel
Same as the above, except also includes whether the anchor point is selected
in the UI. Returns a tuple of all anchor points in the glyph. Each anchor
point is a tuple of ::
(anchor-class-name, type, x,y, selected [,ligature-index])
The first two are strings, the next two doubles, then a boolean, and the
last (which is only present if ``type=="ligature"``) is an integer.
Type may be
* ``mark``
* ``base``
* ``ligature``
* ``basemark``
* ``entry``
* ``exit``
.. attribute:: glyph.background
The glyph's background layer. This is a *copy* of the glyph's data. See
also :attr:`glyph.foreground` and :attr:`glyph.layers`.
.. attribute:: glyph.changed
Whether this glyph has been modified. This is (should be) maintained
automatically, but you may set it if you wish.
.. attribute:: glyph.color
The color of the glyph in the fontview. A 6 hex-digit RGB number or -1 for
default. 0xffffff is white, 0x0000ff is blue, etc.
.. attribute:: glyph.comment
Any comment you wish to associate with the glyph. UTF-8
.. attribute:: glyph.dhints
A tuple with one entry for each diagonal stem hint. Each stem hint is itself
represented by a tuple of three coordinate pairs (themselves tuples of two
numbers), these three are: a point on one side of the stem, a point on the
other side, and a unit vector pointing in the stem's direction.
.. attribute:: glyph.encoding
Returns the glyph's encoding in the font's encoding. (readonly)
If the glyph has multiple encodings, one will be picked at random.
If the glyph is not in the font's encoding then a number will be returned
beyond the encoding size (or in some cases -1 will be returned).
.. attribute:: glyph.font
The font containing this glyph. (readonly)
.. attribute:: glyph.foreground
The glyph's foreground layer. This is a *copy* of the glyph's data. See also
:attr:`glyph.background`, :attr:`glyph.layers` and :attr:`glyph.references`.
.. attribute:: glyph.glyphclass
An opentype glyphclass, one of automatic, noclass, baseglyph, baseligature,
mark, component
.. attribute:: glyph.glyphname
The name of the glyph
.. attribute:: glyph.hhints
A tuple of all horizontal postscript hints. Each hint is itself a tuple of
starting locations and widths.
.. attribute:: glyph.horizontalComponents
A tuple of tuples.
This allows :ref:`constructing <math.GlyphConstruction>` very large versions
of the glyph by stacking the components together. Some components may be
repeated so there is no bound on the size.
This is different from horizontalVariants which expects prebuilt glyphs of
various fixed sizes.
The components are stacked in the order they appear in the (top-level) tuple.
Each sub-tuple represents information on one component. The subtuple should
contain: (String glyph-name, Boolean is-extender, Int startConnectorLength,
Int endConnectorLength, Int fullAdvance). Any of these may be omitted (except
the glyph name) and will be assumed to be 0 if so.
.. attribute:: glyph.horizontalComponentItalicCorrection
The italic correction for any composite glyph made with the horizontalComponents.
.. attribute:: glyph.horizontalVariants
A string containing a list of glyph names. These are
:ref:`alternate forms <math.Variants>` of the current glyph for use in
typesetting math. Presumably the variants are of different sizes.
Although ff will always return a string of glyph names, you may assign to it
with a tuple of glyphs and ff will convert that to corresponding names.
.. attribute:: glyph.isExtendedShape
A boolean containing the MATH "is extended shape" field.
.. attribute:: glyph.italicCorrection
The glyph's italic correction field. Used by both TeX and MATH. The special
value :data:`fontforge.unspecifiedMathValue` means the value is unspecified
(An unspecified value will not go into the output tables, a value of 0 will)
.. attribute:: glyph.layer_cnt
The number of layers in this glyph. (Cannot be set)
.. attribute:: glyph.layers
A dictionary like object containing the layers of the glyph. It may be
indexed by either a layer name or an integer between 0 and
``glyph.layer_cnt-1`` to produce a :class:`layer` object. Layer 0 is the
background layer. Layer 1 is the foreground layer.
.. attribute:: glyph.layerrefs
A dictionary like object containing the references in the layers of the
glyph. It may be indexed by either a layer name, or an integer between 0 and
``glyph.layer_cnt-1`` to produce a :attr:`reference tuple<glyph.references>`
object. Layer 0 is the background layer. Layer 1 is the foreground layer.
.. attribute:: glyph.lcarets
A tuple containing the glyph's ligature caret locations. Setting this will
also either enable or disable the "Default Ligature Caret Count" flag
depending from the number of elements in the tuple.
.. attribute:: glyph.left_side_bearing
The left side bearing of the glyph. Setting this value will adjust all
layers so that guides in the background etc will be adjusted with the rest
of the glyph
.. attribute:: glyph.manualHints
The glyph's hints have been set by hand, and the glyph should not be
autohinted without a specific request from the user. The "Don't AutoHint" flag.
.. attribute:: glyph.mathKern.bottomLeft
The glyph's math kerning data associated with the bottom left vertex. This
returns a tuple of two element tuples, each of which contains a kerning
offset and an associated height (in the last entry the height term is
meaningless, but present).
.. attribute:: glyph.mathKern.bottomRight
The glyph's math kerning data associated with the bottom right vertex. This
returns a tuple of two element tuples, each of which contains a kerning
offset and an associated height (in the last entry the height term is
meaningless, but present).
.. attribute:: glyph.mathKern.topLeft
The glyph's math kerning data associated with the top left vertex. This
returns a tuple of two element tuples, each of which contains a kerning
offset and an associated height (in the last entry the height term is
meaningless, but present).
.. attribute:: glyph.mathKern.topRight
The glyph's math kerning data associated with the top right vertex. This
returns a tuple of two element tuples, each of which contains a kerning
offset and an associated height (in the last entry the height term is
meaningless, but present).
.. attribute:: glyph.originalgid
The GID of this glyph in the font it was read from. (readonly)
.. attribute:: glyph.persistent
Whatever you want (these data will be saved as a pickled object in the
sfd file. It is your job to insure that whatever you put here can be pickled).
See also the :attr:`glyph.temporary` field.
.. attribute:: glyph.references
A tuple of tuples containing, for each reference in the foreground, a
glyph-name, a transformation matrix, and whether the reference is currently
selected. When assigning to the object the matrix and ``selected`` values
are optional. See also :attr:`glyph.foreground` and :attr:`glyph.layerrefs`.
.. attribute:: glyph.right_side_bearing
The right side bearing of the glyph
.. attribute:: glyph.script
A string containing the OpenType 4 letter tag for the script associated with
this glyph (readonly)
.. attribute:: glyph.temporary
Whatever you want (these data will be lost once the font is closed)
See also :attr:`glyph.persistent`.
.. attribute:: glyph.texheight
The Tex height. The special value :data:`fontforge.unspecifiedMathValue`
means the field is unspecified (An unspecified value will not go into the
output tables, a value of 0 will)
.. attribute:: glyph.texdepth
The Tex depth. The special value :data:`fontforge.unspecifiedMathValue`
means the field is unspecified (An unspecified value will not go into the
output tables, a value of 0 will)
.. attribute:: glyph.topaccent
The glyph's top accent position field. Used by MATH. The special value
:data:`fontforge.unspecifiedMathValue` means the field is unspecified (An
unspecified value will not go into the output tables, a value of 0 will)
.. attribute:: glyph.ttinstrs
Any truetype instructions, returned as a binary string
.. attribute:: glyph.unicode
The glyph's unicode code point, or -1. In addition to this primary mapping,
a glyph can have multiple secondary mappings - see :attr:`glyph.altuni`.
.. attribute:: glyph.unlinkRmOvrlpSave
A flag that indicates the glyph's references should be unlinked and remove
overlap run on it before the font is saved (and then the original references
replaced after the save finishes)
.. attribute:: glyph.user_decomp
Your preferred decomposition for this glyph; used by :meth:`glyph.build()`.
.. attribute:: glyph.userdata
.. warning:: Deprecated name for :attr:`glyph.temporary`
.. attribute:: glyph.vhints
A tuple of all vertical postscript hints. Each hint is itself a tuple of
starting locations and widths.
.. attribute:: glyph.validation_state
A bit mask indicating some problems this glyph might have. (readonly)
.. object:: 0x1
If set then this glyph has been validated.
If unset then other bits are meaningless.
.. object:: 0x2
Glyph has an open contour.
.. object:: 0x4
Glyph intersects itself somewhere.
.. object:: 0x8
At least one contour is drawn in the wrong direction
.. object:: 0x10
At least one reference in the glyph has been flipped
(and so is drawn in the wrong direction)
.. object:: 0x20
Missing extrema
.. object:: 0x40
A glyph name referred to from this glyph, in an opentype table, is not
present in the font.
.. object:: 0x40000
Points (or control points) are too far apart. (Coordinates must be
within 32767)
**Postscript only**
.. object:: 0x80
PostScript has a limit of 1500 points in a glyph.
.. object:: 0x100
PostScript has a limit of 96 hints in a glyph.
.. object:: 0x200
Invalid glyph name.
**TrueType only, errors in original file**
.. object:: 0x400
More points in a glyph than allowed in 'maxp'
.. object:: 0x800
More paths in a glyph than allowed in 'maxp'
.. object:: 0x1000
More points in a composite glyph than allowed in 'maxp'
.. object:: 0x2000
More paths in a composite glyph than allowed in 'maxp'
.. object:: 0x4000
Instructions longer than allowed in 'maxp'
.. object:: 0x8000
More references in a glyph than allowed in 'maxp'
.. object:: 0x10000
References nested more deeply than allowed in 'maxp'
.. object:: 0x40000
Points too far apart. TrueType and Type2 fonts are limited to 16 bit
numbers, and so adjacent points must be within 32767 em-units of each other.
.. object:: 0x80000
Points non-integral. TrueType points and control points must be integer
aligned. (FontForge will round them if they aren't)
.. object:: 0x100000
Missing anchor. According to the opentype spec, if a glyph contains an
anchor point for one anchor class in a subtable, it must contain anchor
points for all anchor classes in the subtable. Even it, logically, they
do not apply and are unnecessary.
.. object:: 0x200000
Duplicate glyph name. Two (or more) glyphs in this font have the same
name. When outputting a PostScript font only one of them will ever be seen.
It's a little hard to detect this in normal use, but if you change the
encoding to "Glyph Order", and then use Edit->Select->Wildcard and enter
the glyph name, both of them should be selected.
.. object:: 0x400000
Duplicate unicode code point. Two (or more) glyphs in this font have the
code point. When outputting an sfnt (TrueType/OpenType) font only one of
them will ever be seen.
It's a little hard to detect this in normal use, but if you change the
encoding to "Glyph Order", and then use Edit->Select->Wildcard and enter
the code point, both of them should be selected.
.. object:: 0x800000
Overlapped hints. Either the glyph has no hint masks and there are
overlapped hints, or a hint mask specifies two overlapping hints.
.. attribute:: glyph.verticalComponents
A tuple of tuples.
This allows :ref:`constructing <math.GlyphConstruction>` very large versions
of the glyph by stacking the components together. Some components may be
repeated so there is no bound on the size.
This is different from verticalVariants which expects prebuilt glyphs of
various fixed sizes.
The components are stacked in the order they appear in the (top-level) tuple.
Each sub-tuple represents information on one component. The subtuple should
contain: (String glyph-name, Boolean is-extender, Int startConnectorLength,
Int endConnectorLength, Int fullAdvance). Any of these may be omitted
(except the glyph name) and will be assumed to be 0 if so.
.. attribute:: glyph.verticalComponentItalicCorrection
The italic correction for any composite glyph made with the verticalComponents.
.. attribute:: glyph.verticalVariants
A string containing a list of glyph names. These are
:ref:`alternate forms <math.Variants>`
of the current glyph for use in typesetting math. Presumably the variants
are of different sizes.
.. attribute:: glyph.width
The advance width of the glyph. See also :attr:`glyph.vwidth`.
.. attribute:: glyph.vwidth
The vertical advance width of the glyph. See also :attr:`glyph.width`.
.. method:: glyph.addAnchorPoint(anchor_class_name, anchor_type, x, y[, ligature_index])
Adds an anchor point. anchor-type may be one of the strings
* ``"mark"``
* ``"base"``
* ``"ligature"``
* ``"basemark"``
* ``"entry"``
* ``"exit"``
If there is an anchor point with the same ``anchor_class_name`` and:
* lookup type is ``"gpos_mark2base"`` or
* lookup type is ``"gpos_mark2ligature"`` and ``ligature_index`` is the same or
* ``anchor_type`` is the same
then the existing anchor will be overwritten.
.. method:: glyph.addExtrema([flags, emsize])
Extrema should be marked by on-curve points. If a curve lacks a point at an
extrema this command will add one. Flags may be one of the following strings
.. object:: all
Add all missing extrema
.. object:: only_good
Only add extrema on longer splines (with respect to the em-size)
.. object:: only_good_rm
As above but also merge away on-curve points which are very close to,
but not on, an added extremum
.. method:: glyph.addReference(glyph_name[, transform, selected])
Adds a reference to the specified glyph into the current glyph. Optionally
specifying a transformation matrix and whether the reference is to be
marked selected in the UI and related API calls.
.. method:: glyph.addHint(is_vertical, start, width)
Adds a postscript hint. Takes a boolean flag indicating whether the hint is
horizontal or vertical, a start location and the hint's width.
.. method:: glyph.addPosSub(subtable_name, variant)
glyph.addPosSub(subtable_name, variants)
glyph.addPosSub(subtable_name, ligature_components)
glyph.addPosSub(subtable_name, xoff, yoff, xadv, yadv)
glyph.addPosSub(subtable_name, other_glyph_name, kerning)
glyph.addPosSub(subtable_name, other_glyph_name, xoff1, yoff1, xadv1, yadv1, xoff2, yoff2, xadv2, yadv2)
Adds position/substitution data to the glyph. The number and type of the
arguments vary according to the type of the lookup containing the subtable.
The first argument should always be a lookup subtable name.
If the lookup is for single substitutions then the second argument should be
a string containing a single glyph name.
For multiple and alternated substitutions a tuple of glyph names. For
ligatures, a tuple of the ligature components (glyph names).
For single positionings the second through fifth arguments should be small
integers representing the adjustment along the appropriate axis.
For pairwise positionings (kerning) the second argument should be the name
of the other glyph being kerned with, and the third through tenth should be
small integers -- or, if there are exactly three arguments then the third
specifies traditional, one-axis, kerning.
If there is a previously existing entry, this will replace it (except for
ligatures).
.. method:: glyph.appendAccent(name="glyph_name")
glyph.appendAccent(unicode=<codepoint>)
Makes a reference to the specified glyph, adds that reference to the current
layer of this glyph, and positions it to make a reasonable accent.
.. method:: glyph.autoHint()
Generates PostScript hints for this glyph.
.. method:: glyph.autoInstr()
Generates TrueType instructions for this glyph.
.. method:: glyph.autoTrace()
Auto traces any background images
.. method:: glyph.boundingBox()
Returns a tuple representing a rectangle (xmin,ymin, xmax,ymax) which is
the minimum bounding box of the glyph.
.. method:: glyph.build()
If the character is a composite character, then clears it and inserts
references to its components.
.. method:: glyph.canonicalContours()
Orders the contours in the current glyph by the x coordinate of their
leftmost point. (This can reduce the size of the charstring needed to
describe the glyph(s).
.. method:: glyph.canonicalStart()
Sets the start point of all the contours of the current glyph to be the
leftmost point on the contour. (If there are several points with that value
then use the one which is closest to the baseline). This can reduce the size
of the charstring needed to describe the glyph(s). By regularizing things it
can also make more things available to be put in subroutines.
.. method:: glyph.changeWeight(stroke_width[, type, serif_height, serif_fuzz, counter_type, removeoverlap, custom_zones])
See the :ref:`Element->Style->Change Width <Styles.Embolden>` command for a
more complete description of these arguments.
``stroke_width`` is the amount by which all stems are expanded.
``type`` is one of ``"LCG"``, ``"CJK"``, ``"auto"``, ``"custom"``.
``serif_height`` tells ff not to expand serifs which are that much off the
baseline, while serif_fuzz specifies the amount of fuzziness allowed in the
match. If you don't want special serif behavior set this to 0.
``counter_type`` is one of ``"squish"``, ``"retain"``, ``"auto"``.
``removeoverlap`` (Cleanup Self Intersect) is a boolean int
(0=false, 1=true). When activated, and FontForge detects that an expanded
stroke will self-intersect, then setting this option will cause it to try to
make things nice by removing the intersections.
``custom_zones`` is only meaningful if the type argument were ``"custom"``.
It may be either a number, which specifies the "top hint" value (bottom hint
is assumed to be 0, others are between), or a tuple of 4 numbers (top hint,
top zone, bottom zone, bottom hint).
.. method:: glyph.condenseExtend(c_factor, c_add[, sb_factor, sb_add, correct])
Condenses or extends the size of the counters and side-bearings of the glyph.
The first two arguments provide information on shrinking/growing the
counters, the second two the sidebearings. If the last two are omitted they
default to the same values as the first two.
A counter's width will become: ::
new_width = c_factor * old_width + c_add
If present the ``correct`` argument allows you to specify whether you want
to correct for the italic angle before condensing the glyph.
(it defaults to``True``)
.. method:: glyph.clear([layer])
With no arguments, clears the contents of the glyph (and marks it as not :meth:`glyph.isWorthOutputting()`).
It is not possible to clear the guide layer with this function.
``layer`` may be either an integer index or a string.
.. method:: glyph.cluster([within, max])
Moves clustered coordinates to a standard central value.
See also :meth:`glyph.round()`.
.. method:: glyph.correctDirection()
Orients all contours so that external ones are clockwise and internal
counter-clockwise.
.. method:: glyph.doUndoLayer([layer, redo])
When ``redo`` is False this method is equivalent to the "Undo" UI menu item.
It restores the last preserved layer state discarding the current state.
When ``redo`` is True it is equivalent to "Redo". You may omit the
``layer`` parameter, in which case the currently active layer will be used.
Otherwise it must either be a layer name or an integer between 0 and
``glyph.layer_cnt-1``.
``doUndoLayer`` is normally used in conjunction with
:meth:`glyph.preserveLayerAsUndo()`
.. method:: glyph.exclude(excluded_layer)
Removes the excluded area from the current glyph. Takes an argument which is
a layer. See also :meth:`glyph.removeOverlap()` and :meth:`glyph.intersect()`.
.. method:: glyph.export(filename[, KEYWORD])
Creates a file with the specified name containing a representation of
the glyph. Uses the file's extension to determine output file type.
The following optional keywords modify the export process for various formats:
.. object:: layer (string or integer, default=glyph.activeLayer)
For vector formats, the layer to export.
.. object:: pixelsize (integer, default=100)
For raster formats, the size of the image to output.
.. object:: bitdepth (integer, default=8)
For raster formats, the depth of the image to output. Must be 1 or 8.
.. object:: usetransform (boolean, default=False)
Flip the Y-axis of exported SVGs with a transform element rather than
modifying the individual Y values.
.. object:: usesystem (boolean, default=False)
Ignore the above keyword settings and use the values set by the user
in the Import options dialog.
.. object:: asksystem (boolean, default=False)
If the UI is present show the Import options dialog to the user
and use the chosen values (does nothing otherwise).
Note: The old positional layer/pixelsize,bitdepth calling conventions are
still supported but are not compatible with the other keyword parameters.
.. method:: glyph.genericGlyphChange(stemType=<str>, thickThreshold=<double>, stemScale=<double>, stemAdd=<double>, stemHeightScale=<double>, stemHeightAdd=<double>, stemWidthScale=<double>, stemWidthAdd=<double>, thinStemScale=<double>, thinStemAdd=<double>, thickStemScale=<double>, thickStemAdd=<double>, processDiagonalStems=<boolean>, hCounterType=<str>, hCounterScale=<double>, hCounterAdd=<double>, lsbScale=<double>, lsbAdd=<double>, rsbScale=<double>, rsbAdd=<double>, vCounterType=<str>, vCounterScale=<double>, vCounterAdd=<double>, vScale=<double>, vMap=<tuple of tuples>)
Similar to :meth:`font.genericGlyphChange`, but acting on this glyph only.
.. method:: glyph.getPosSub(lookup_subtable_name)
Returns any positioning/substitution data attached to the glyph controlled
by the lookup-subtable. If the name is ``"*"`` then returns data from all
subtables.
The data are returned as a tuple of tuples. The first element of the
subtuples is the name of the lookup-subtable. The second element will be one
of the strings: ``"Position"``, ``"Pair"``, ``"Substitution"``,
``"AltSubs"``, ``"MultSubs"``, ``"Ligature"``.
Positioning data will be followed by four small integers representing
adjustments to the: x position of the glyph, the y position, the horizontal
advance, and the vertical advance.
Pair data will be followed by the name of the other glyph in the pair and
then eight small integers representing adjustments to the: x position of the
first glyph, the y position, the horizontal advance, and the vertical
advance, and then a similar foursome for the second glyph.
Substitution data will be followed by a string containing the name of the
glyph to replace the current one.
Multiple and Alternate data will be followed by several strings each
containing the name of a replacement glyph.
Ligature data will be followed by several strings each containing the name
of a ligature component glyph.
.. method:: glyph.importOutlines(filename, [KEYWORD])
Uses the file's extension to determine behavior. Imports outline descriptions
(eps, svg, glif files) into the foreground layer. Imports image descriptions
(bmp, png, xbm, etc.) into the background layer. The following optional keywords modify the import process for various formats:
.. object:: scale (boolean, default=True)
Scale imported images and SVGs to ascender height
.. object:: simplify (boolean, default=True)
Run simplify on the output of stroked paths
.. object:: accuracy (float, default=0.25)
The minimum accuracy (in em-units) of stroked paths.
.. object:: default_joinlimit (float, default=-1)
Override the format's default miterlimit for stroked paths, which is
10.0 for PostScript and 4.0 for SVG. (Value -1 means "inherit" those
defaults.)
.. object:: handle_eraser (boolean, default=False)
Certain programs use pens with white ink as erasers. When this flag is
set FontForge will attempt to simulate that.
.. object:: correctdir (boolean, default=False)
Run "Correct direction" on (some) PostScript paths
.. object:: usesystem (boolean, default=False)
Ignore the above keyword settings and use the values set by the user
in the Import options dialog.
.. object:: asksystem (boolean, default=False)
If the UI is present show the Import options dialog to the user
and use the chosen values (does nothing otherwise).
Note: The old PostScript correctdir/handle_eraser flag tuple is still
supported but is not compatible with the other keywords.
.. method:: glyph.intersect()
Leaves only areas in the intersection of contours. See also
:meth:`glyph.removeOverlap()` and :meth:`glyph.exclude()`.
.. method:: glyph.isWorthOutputting()
Returns whether the glyph is worth outputting into a font file. Basically a
glyph is worth outputting if it contains any contours, or references or has
had its width set.
.. method:: glyph.preserveLayerAsUndo([layer, dohints])
Normally undo handling is turned off during python scripting. This method
preserves the current state of a layer so that whatever you do after can be
undone by the user. You may omit the ``layer`` parameter, in which case the
currently active layer will be used. Otherwise it must either be a layer name
or an integer between 0 and ``glyph.layer_cnt-1``. When ``dohints`` is True
then hints will also be preserved (they are not by default).
.. method:: glyph.removeOverlap()
Removes overlapping areas.
See also :meth:`glyph.intersect()` and :meth:`glyph.exclude()`.
.. method:: glyph.removePosSub(lookup_subtable_name)
Removes all data from the glyph corresponding to the given lookup-subtable.
If the name is "*" then all data will be removed.
.. method:: glyph.round([factor])
Rounds the x and y coordinates of each point in the glyph. If factor is
specified then ::
new-coord = round(factor*old-coord)/factor
See also :meth:`glyph.cluster()`.
.. method:: glyph.selfIntersects()
Returns whether any of the contours in this glyph intersects any other
contour in the glyph (including itself).
.. method:: glyph.setLayer(layer, layer_index[, flags])
An alternative to assigning to :attr:`glyph.layers`, :attr:`glyph.background`,
or :attr:`glyph.foreground`, and equivalent to those when not using the
optional ``flags`` argument. When present, ``flags`` can be used to influence
the types FontForge will assign to on-curve points. It should be a tuple of
up to three of the following strings.
(In the following descriptions *selected* refers to points picked out by the
chosen ``select_`` flag, which is unrelated to :attr:`point.selected`. At
most one ``"select_"`` flag and one mode flag should be included.)
.. object:: select_none
Each (on-curve) point will be assigned a type corresponding to its
:attr:`point.type` value.
.. object:: select_all
(default) Each point will have a type assigned according to the chosen mode.
.. object:: select_smooth
Each point with the type :data:`splineCorner` will retain that type,
others will be assigned a type according to the chosen mode. This makes
:attr:`point.type` function like the ``smooth`` tag in the UFO glif
format and some other spline storage formats.
.. object:: select_incompat
Each point with a type compatible with its current geometry will retain
that type, others will be assigned a type according to the chosen mode.
.. object:: by_geom
(default) In this mode, each *selected* point will be assigned a type
based on only its geometry. (However, see ``"hvcurve"``` below.)
.. object:: downgrade
In this mode, each *selected* point will be assigned the most specific
type compatible with its geometry and its :attr:`point.type`. A point
marked :data:`splineHVCurve` can keep that type or be downgraded to
:data:`splineCurve` or :data:`splineCorner`, while a :data:`splineCurve`
or :data:`splineTangent` can keep that (respective) type or be downgraded
to :data:`splineCorner`. (:data:`splineCorner` is compatible with any
geometry.)
.. object:: check
In this mode, the type of each *selected* point is verified to be
compatible with its geometry. If it is not compatible the function raises
an exception. (At present this exception is not very informative. However,
to identify the specific problem one can duplicate the layer, use
:meth:`glyph.setLayer()` with ``downgrade``, and then retrieve the layer
and compare it with the original.)
.. object:: force
In this mode, the geometry of each *selected* point is altered to match
its :attr:`point.type`, similar to changing a point's type using the UI.
Note that FontForge's point conversion algorithm is not sophisticated
and may not have the desired result.
.. object:: hvcurve
This extra flag can be used to include :data:`splineHVCurve` among the
types that can be assigned "by geometry". Normally FontForge assigns
:data:`splineCurve` to on-curve points with strictly horizontal or
vertical off-curve points.
.. method:: glyph.simplify([error_bound, flags, tan_bounds, linefixup, linelenmax])
Tries to remove excess points in the glyph if doing so will not perturb the
curve by more than ``error-bound``. Flags is a tuple of the following strings
.. object:: ignoreslopes
Allow slopes to change
.. object:: ignoreextrema
Allow removal of extrema
.. object:: smoothcurves
Allow curve smoothing
.. object:: choosehv
Snap to horizontal or vertical
.. object:: forcelines
flatten bumps on lines
.. object:: nearlyhvlines
Make nearly horizontal/vertical lines be so
.. object:: mergelines
Merge adjacent lines into one
.. object:: setstarttoextremum
Rotate the point list so that the start point is on an extremum
.. object:: removesingletonpoints
If the contour contains just one point then remove it
.. method:: glyph.stroke("circular", width[, CAP, JOIN, FLAGS])
glyph.stroke("elliptical", width, minor_width, ANGLE[, CAP, JOIN, FLAGS])
glyph.stroke("calligraphic", width, height, angle[, FLAGS])
glyph.stroke("polygon", contour[, FLAGS])
(Legacy interface)
:noindex:
.. method:: glyph.stroke("circular", width[, CAP, JOIN, ANGLE, KEYWORD])
glyph.stroke("elliptical", width, minor_width[, ANGLE, CAP, JOIN, KEYWORD])
glyph.stroke("calligraphic", width, height[, ANGLE, CAP, JOIN, KEYWORD])
glyph.stroke("convex", contour[, ANGLE, CAP, JOIN, KEYWORD])
(Current interface)
Strokes the contours of the glyph according to the supplied parameters. See
the :doc:`stroke </techref/stroke>` documentation for a more complete description of
the facility and its parameters.
A ``"circular"`` nib just has a ``width`` (the diameter), while an
``"elliptical"`` nib has a ``width`` (major axis) and a ``minor_width``
(minor axis). A ``"calligraphic"`` or ``"rectangular"`` nib is similar in
that it has a ``width`` and a ``height``. Finally a ``"convex"`` nib is one
supplied by the user as a :class:`fontforge.contour` or :class:`fontforge.layer`.
It must be *convex* as defined in the main stroke facility documentation.
``ANGLE`` is optional. It can be specified either positionally or with
``angle=float``. It must be a floating point number in units of radians and
defaults to zero. The nib is rotated by this angle before stroking the path.
``CAP`` is optional. It can be specified either positionally or with
``cap=string``. It must be one of the strings "nib" (the default), "butt",
"round", and "bevel".
``JOIN`` is optional. It can be specified either positionally or with
``join=string``. It must be one of the strings "nib" (the default), "bevel",
"miter", and "miterclip", "round", and "arcs".
``KEYWORD`` Parameters:
.. object:: removeinternal (boolean, default=False)
When a contour is closed and clockwise, only the smaller "inside" contour
is retained. When a contour is closed and counter-clockwise only the
larger "outside" contour is retained.
.. object:: removeexternal (boolean, default=False)
When a contour is closed and clockwise, only the larger "outside" contour
is retained. When a contour is closed and counter-clockwise only the
smaller "inside" contour is retained.
.. object:: extrema (boolean, default=True)
When true, any missing extrema on the stroked paths are added.
.. object:: simplify (boolean, default=True)
When true, simplify is called on the path before it is returned. The
``error-bound`` is set to the ``accuracy`` value.
.. object:: removeoverlap (string, default="layer")
Specifies whether, and on what basis, remove-overlap should be run.
"layer" corresponds to running remove-overlap on the :class:`layer` as a
whole. "contour" corresponds to running remove-overlap on individual
contours. "none" corresponds to not running remove-overlap. Note that
because the stroke facility relies on remove-overlap to eliminate cusps
and other artifacts, "none" is an unusual choice and available primarily
for debugging purposes.
.. object:: accuracy (float, default=0.25)
This is a target (but not a guarantee) for the allowed error, in em-units,
of the output relative to the input path and nib geometries. Higher values
allow more error will typically yield contours with fewer points.
.. object:: jlrelative (boolean, default=True)
See below.
.. object:: joinlimit (float, default=20)
Specifies the maximum length of a "miter", "miterclip", or "arcs" join.
For "miter" joins that would be longer will fall back to "bevel". With
"miterclip" and "arcs" a longer join will be trimmed to the specified
length. Note, however, that no join is trimmed past the "bevel line" and
therefore lower values do not guarantee a given length.
When ``jlrelative`` is false the value is interpreted as a length in
em-units. Otherwise the value is interpreted as a multiple of
"stroke-widths": the average of the spans of the nib at the incoming
and outgoing join angles.
.. object:: ecrelative (boolean, default=True)
See below.
.. object:: extendcap (float, default=0)
When the contour being stroked is open and the ``cap`` style is "butt" or
"round", this parameter adds area between the end of that contour and the
cap. The length of that area will never be less than the specified value
but may be more, depending on the geometry of the nib and the join.
(However, it will always be exact for circular nibs.)
When ``ecrelative`` is false the value is interpreted as a length in
em-units. Otherwise the value is interpreted as a multiple of
"stroke-widths": the span of the stroked path at the angle at the cap.
.. object:: arcsclip (string, default="auto")
When using the "arcs" join style this parameter influences the algorithm
used to clip joins that exceed the ``joinlimit``. The value "svg2"
specifies the standard SVG algorithm while the value "ratio" specifies an
alternative algorithm that works better for longer and thinner nibs at
shorter limits. The default value "auto" chooses the "ratio" algorithm
for oblong elliptical and calligraphic nibs and
``jlrelative joinlimit`` < 4 and the "svg2" algorithm otherwise.
In the legacy interface, ``FLAGS`` is an optional tuple containing zero or
more of the strings "removeinternal", "removeexternal", and "cleanup". The
last is interpreted as ``simplify=True``, with a default of ``False`` when a
FLAGS tuple is present.
.. method:: glyph.transform(matrix[, flags])
Transforms the glyph by the matrix. The optional flags argument should be a
tuple containing any of the following strings:
.. object:: partialRefs
Don't transform any references in the glyph, but do transform their offsets.
This is useful if the referred glyph will be (or has been) transformed.
.. object:: round
Round to int after the transformation is done.
.. method:: glyph.nltransform(xexpr, yexpr)
xexpr and yexpr are strings specifying non-linear transformations that will
be applied to all points in the current layer (with xexpr being applied to x
values, and yexpr to y values, of course). The syntax for the expressions is
explained in the :ref:`non-linear transform dialog <transform.Non-Linear>`.
.. method:: glyph.unlinkRef([ref_name])
Unlinks the reference to the glyph named ``ref-name``. If ``ref-name`` is
omitted, unlinks all references.
.. method:: glyph.unlinkThisGlyph()
Unlinks all the references to the current glyph within any other glyph in
the font.
.. method:: glyph.useRefsMetrics(ref_name[, flag])
Finds a reference with the given name and sets the "use_my_metrics" flag on
it (so this glyph will have the same advance width as the glyph the
reference points to).
If the optional flag argument is False, then the glyph will no longer have
its metrics bound to the reference.
.. method:: glyph.validate([force])
Validates the glyph and returns the :attr:`validation_state` of the glyph
(except bit 0x1 will always be clear). If the glyph passed the validation
then the return value will be 0 (not 0x1). Otherwise the return value will
be the set of errors found. If force is specified true this will always be
validated, if force is unspecified (or specified as false) then it will
return the cached value if it is known, otherwise will validate it.
.. method:: glyph.draw(pen)
Draw the glyph's outline to the `pen argument. <http://robofab.org/objects/pens.html>`_
.. method:: glyph.glyphPen([replace=False])
Creates a new glyphPen which will draw into the current glyph. By default
the pen will replace any existing contours and references, but setting the
optional keyword argument, ``replace`` to false will retain the old contents.
.. method:: glyph.addInflections()
Please see :meth:`contour.addInflections()`.
.. method:: glyph.balance()
Please see :meth:`contour.balance()`.
.. method:: glyph.harmonize()
Please see :meth:`contour.harmonize()`.
Selection
---------
This represents a font's selection. You may index it with an encoding value (in
the encoding ISO-646-US (ASCII) the character "A" has encoding index 65), or
with a glyph's name, or with a string like ``"uXXXXX"`` where ``XXXXX``
represent the glyph's unicode codepoint in hex, or with a
:class:`fontforge.glyph` object. The value of indexing into a selection will be
either ``True`` or ``False``. ::
>>> print(fontforge.activeFont().selection[65])
True
This type may not be pickled.
.. class:: selection()
.. attribute:: selection.byGlyphs
Returns another selection, just the same as this one except that its iterator
function will return glyphs (rather than encoding slots) and will only return
those entries for which glyphs exist.
This is read-only.
.. method:: selection.__iter__()
Returns an iterator for the selection which will return all selected
encoding slots in encoding order.
.. method:: selection.all()
Select everything.
.. method:: selection.none()
Deselect everything.
.. method:: selection.changed()
Select all glyphs which have changed.
.. method:: selection.invert()
Invert the selection.
.. method:: selection.select(args)
There may be an arbitrary number of arguments. Each argument may be either:
* A glyph name
Note: There need not be a glyph with this name in the font yet, but if you
use a standard name (like "A") fontforge will still know where that glyph
should be.
* An integer (this will be interpreted as either an encoding index or
(default) a unicode code point depending on the flags).
* A fontforge glyph.
* A tuple of flags.
(If you wish to specify a single flag it must still be in a tuple, and you
must append a trailing comma to the flag (so ``("more",)`` rather than
just ``("more")`` ). FF needs the flags to be in a tuple otherwise it
can't distinguish them from glyph names)
.. object:: unicode
Interpret integer arguments as unicode code points
.. object:: encoding
Interpret integer arguments as encoding indeces.
.. object:: more
Specified items should be selected
.. object:: less
Specified items should be deselected.
.. object:: singletons
Specified items should be interpreted individually and mean the obvious.
.. object:: ranges
Specified items should be interpreted in pairs and represent all
encoding slots between the start and end points specified by the pair.
So ``.select(("ranges",None),"A","Z")`` would select all the upper case
(latin) letters.
If the first argument is not a flag argument (or if it doesn't specify
either "more" or "less") then the selection will be cleared. So
``.select("A")`` would produce a selection with only "A" selected,
``.select(("more",None),"A")`` would add "A" to the current selection, while
``.select(("less",None),"A")`` would remove "A" from the current selection.
Private
-------
This represents a font's postscript private dictionary. You may index it with
one of the standard names of things that live in the private dictionary.
This type may not be pickled.
.. class:: private
.. method:: private.__iter__()
Returns an iterator for the dictionary which will return all entres.
.. method:: private.guess(name)
Guess a value for this this entry in the private dictionary. If FontForge
can't make a guess it will simply ignore the request.
Math
----
This represents a font's math constant table. Not all fonts have math tables,
and checking this field will not create the underlying object, but examining or
assigning to its members will create it.
This type may not be pickled.
.. rubric:: Members
Any of the math constant names may be used as member names.
(These names begin with capital letters, not Python's conventions but Microsoft's)
These all take (16 bit) integer values.
I do not currently provide python access to any associated device tables.
.. attribute:: math.ScriptPercentScaleDown
Percentage scale down for script level 1
.. attribute:: math.ScriptScriptPercentScaleDown
Percentage scale down for script level 2
.. attribute:: math.DelimitedSubFormulaMinHeight
Minimum height at which to treat a delimited expression as a subformula
.. attribute:: math.DisplayOperatorMinHeight
Minimum height of n-ary operators (integration, summation, etc.)
.. attribute:: math.MathLeading
White space to be left between math formulae to ensure proper line spacing.
.. attribute:: math.AxisHeight
Axis height of the font
.. attribute:: math.AccentBaseHeight
Maximum (ink) height of accent base that does not require raising the accents.
.. attribute:: math.FlattenedAccentBaseHeight
Maximum (ink) height of accent base that does not require flattening the accents.
.. attribute:: math.SubscriptShiftDown
The standard shift down applied to subscript elements. Positive for
moving downward.
.. attribute:: math.SubscriptTopMax
Maximum height of the (ink) top of subscripts that does not require moving
subscripts further down.
.. attribute:: math.SubscriptBaselineDropMin
Maximum allowed drop of the baseline of subscripts relative to the bottom of
the base. Used for bases that are treated as a box or extended shape.
Positive for subscript baseline dropped below base bottom.
.. attribute:: math.SuperscriptShiftUp
Standard shift up applied to superscript elements.
.. attribute:: math.SuperscriptShiftUpCramped
Standard shift of superscript relative to base in cramped mode.
.. attribute:: math.SuperscriptBottomMin
Minimum allowed height of the bottom of superscripts that does not require
moving them further up.
.. attribute:: math.SuperscriptBaselineDropMax
Maximum allowed drop of the baseline of superscripts relative to the top of
the base. Used for bases that are treated as a box or extended shape.
Positive for superscript baseline below base top.
.. attribute:: math.SubSuperscriptGapMin
Minimum gap between the superscript and subscript ink.
.. attribute:: math.SuperscriptBottomMaxWithSubscript
The maximum level to which the (ink) bottom of superscript can be pushed to
increase the gap between superscript and subscript, before subscript starts
being moved down.
.. attribute:: math.SpaceAfterScript
Extra white space to be added after each sub/superscript.
.. attribute:: math.UpperLimitGapMin
Minimum gap between the bottom of the upper limit, and the top of the base
operator.
.. attribute:: math.UpperLimitBaselineRiseMin
Minimum distance between the baseline of an upper limit and the bottom of
the base operator.
.. attribute:: math.LowerLimitGapMin
Minimum gap between (ink) top of the lower limit, and (ink) bottom of the
base operator.
.. attribute:: math.LowerLimitBaselineDropMin
Minimum distance between the baseline of the lower limit and bottom of the
base operator.
.. attribute:: math.StackTopShiftUp
Standard shift up applied to the top element of a stack.
.. attribute:: math.StackTopDisplayStyleShiftUp
Standard shift up applied to the top element of a stack in display style.
.. attribute:: math.StackBottomShiftDown
Standard shift down applied to the bottom element of a stack. Positive
values indicate downward motion.
.. attribute:: math.StackBottomDisplayStyleShiftDown
Standard shift down applied to the bottom element of a stack in display
style. Positive values indicate downward motion.
.. attribute:: math.StackGapMin
Minimum gap between bottom of the top element of a stack, and the top of
the bottom element.
.. attribute:: math.StackDisplayStyleGapMin
Minimum gap between bottom of the top element of a stack and the top of the
bottom element in display style.
.. attribute:: math.StretchStackTopShiftUp
Standard shift up applied to the top element of the stretch stack.
.. attribute:: math.StretchStackBottomShiftDown
Standard shift down applied to the bottom element of the stretch stack.
Positive values indicate
downward motion.
.. attribute:: math.StretchStackGapAboveMin
Minimum gap between the ink of the stretched element and the ink bottom of
the element above.
.. attribute:: math.StretchStackGapBelowMin
Minimum gap between the ink of the stretched element and the ink top of
the element below.
.. attribute:: math.FractionNumeratorShiftUp
Standard shift up applied to the numerator.
.. attribute:: math.FractionNumeratorDisplayStyleShiftUp
Standard shift up applied to the numerator in display style.
.. attribute:: math.FractionDenominatorShiftDown
Standard shift down applied to the denominator. Positive values indicate
downward motion.
.. attribute:: math.FractionDenominatorDisplayStyleShiftDown
Standard shift down applied to the denominator in display style. Positive
values indicate downward motion.
.. attribute:: math.FractionNumeratorGapMin
Minimum tolerated gap between the ink bottom of the numerator and the ink of
the fraction bar.
.. attribute:: math.FractionNumeratorDisplayStyleGapMin
Minimum tolerated gap between the ink bottom of the numerator and the ink of
the fraction bar in display style.
.. attribute:: math.FractionRuleThickness
Thickness of the fraction bar.
.. attribute:: math.FractionDenominatorGapMin
Minimum tolerated gap between the ink top of the denominator and the ink of
the fraction bar.
.. attribute:: math.FractionDenominatorDisplayStyleGapMin
Minimum tolerated gap between the ink top of the denominator and the ink of
the fraction bar in display style.
.. attribute:: math.SkewedFractionHorizontalGap
Horizontal distance between the top and bottom elements of a skewed fraction.
.. attribute:: math.SkewedFractionVerticalGap
Vertical distance between the ink of the top and bottom elements of a skewed
fraction.
.. attribute:: math.OverbarVerticalGap
Distance between the overbar and the ink top of the base.
.. attribute:: math.OverbarRuleThickness
Thickness of the overbar.
.. attribute:: math.OverbarExtraAscender
Extra white space reserved above the overbar.
.. attribute:: math.UnderbarVerticalGap
Distance between underbar and the (ink) bottom of the base.
.. attribute:: math.UnderbarRuleThickness
Thickness of the underbar.
.. attribute:: math.UnderbarExtraDescender
Extra white space reserved below the underbar.
.. attribute:: math.RadicalVerticalGap
Space between the ink to of the expression and the bar over it.
.. attribute:: math.RadicalDisplayStyleVerticalGap
Space between the ink top of the expression and the bar over it in display
style.
.. attribute:: math.RadicalRuleThickness
Thickness of the radical rule in designed or constructed radical signs.
.. attribute:: math.RadicalExtraAscender
Extra white space reserved above the radical.
.. attribute:: math.RadicalKernBeforeDegree
Extra horizontal kern before the degree of a radical if such be present.
.. attribute:: math.RadicalKernAfterDegree
Negative horizontal kern after the degree of a radical if such be present.
.. attribute:: math.RadicalDegreeBottomRaisePercent
Height of the bottom of the radical degree, if such be present, in
proportion to the ascender of the radical sign.
.. attribute:: math.MinConnectorOverlap
Minimum overlap of connecting glyphs during glyph construction.
.. method:: math.exists()
Returns whether the font currently has an underlying math table associated
with it. Note that examining or assigning to one of the members will create
such a table.
.. method:: math.clear()
Removes any underlying math table from the font.
Font
----
The font type refers to a fontforge :class:`font` object. It generally contains
a list of :class:`glyphs <fontforge.glyph>`, an encoding to order those glyphs,
a fontname, a list of GPOS/GSUB lookups and many other things.
This type may not be pickled.
.. class:: font()
Creates a new font.
.. attribute:: font.activeLayer
Returns currently active layer in the font (as an integer). May be set to an
integer or a layer name to change the active layer.
.. attribute:: font.ascent
The font's ascent
.. attribute:: font.bitmapSizes
A tuple with an entry for each bitmap strike attached to the font. Each
strike is identified by pixelsize (if the strike is a grey scale font it
will be indicated by ``(bitmap-depth<<16)|pixelsize``.
When setting this value pass in a tuple of the same format. Any existing
strike not specified in the tuple will be removed. Any new sizes will be
created (but not rasterized -- use :meth:`font.regenBitmaps()` for that).
.. attribute:: font.capHeight
(readonly) Computes the Cap Height (the height of capital letters such as
"E"). A negative number indicates the value could not be computed (the font
might have no capital letters because it was lower case only, or didn't
include glyphs for a script with capital letters).
.. attribute:: font.changed
Bit indicating whether the font has been modified. This is (should be)
maintained automatically, but you may set it if you wish.
.. attribute:: font.cidcopyright
Copyright message of the cid-keyed font as a whole (ie. not the current subfont).
.. attribute:: font.cidfamilyname
Family name of the cid-keyed font as a whole (ie. not the current subfont).
.. attribute:: font.cidfontname
Font name of the cid-keyed font as a whole (ie. not the current subfont).
.. attribute:: font.cidfullname
Full name of the cid-keyed font as a whole (ie. not the current subfont).
.. attribute:: font.cidordering
.. attribute:: font.cidregistry
.. attribute:: font.cidsubfont
Returns the number index of the current subfont in the cid-keyed font (or -1
if this is not a cid-keyed font).
May be set to an index (an integer) or a subfont fontname (a string) to
change the current subfont. (To find the name of the current subfont,
simply use .fontname).
.. attribute:: font.cidsubfontcnt
Returns the number of subfonts in this cid-keyed font (or 0 if it is not a
cid-keyed font)
.. attribute:: font.cidsubfontnames
Returns a tuple of the subfont names in this cid-keyed font (or None if it
is not a cid-keyed font)
.. attribute:: font.cidsupplement
.. attribute:: font.cidversion
.. attribute:: font.cidweight
Weight of the cid-keyed font as a whole
.. attribute:: font.comment
A comment associated with the font. Can be anything.
.. attribute:: font.copyright
PostScript copyright notice
.. attribute:: font.cvt
Returns a sequence object containing the font's cvt table. Changes made
to this object will be made to the font (this is a reference not a copy).
The object has one additional method ``cvt.find(value[,low,high])`` which
finds the index of value in the cvt table (or -1 if not found). If low and
high are specified then the index will be between ``[low,high)``.
.. attribute:: font.default_base_filename
The default base for the filename when generating a font
.. attribute:: font.descent
The font's descent
.. attribute:: font.design_size
Size (in pica points) for which this font was designed.
.. attribute:: font.em
The em size of the font. Setting this will scale the entire font to the
new size.
.. attribute:: font.encoding
The name of the current encoding. Setting it will change the encoding used
for indexing. To compact the encoding, first set it to your desired encoding
(e.g. ``UnicodeBMP``), then set it to ``compacted``.
.. attribute:: font.familyname
PostScript font family name
.. attribute:: font.fondname
Mac fond name
.. attribute:: font.fontlog
A comment associated with the font. Can be anything.
.. attribute:: font.fontname
PostScript font name
Note that in a CID keyed font this will be the name of the current subfont.
Use cidfontname for the name of the font as a whole.
.. attribute:: font.fullname
PostScript font name
.. attribute:: font.gasp
Returns a tuple of all gasp table entries. Each item in the tuple is itself
a tuple composed of a ppem (an integer) and a tuple of flags. The flags are
chosen from:
* ``gridfit``
* ``antialias``
* ``symmetric-smoothing``
* ``gridfit+smoothing``
.. attribute:: font.gasp_version
The version of the 'gasp' table. Currently this may be 0 or 1.
.. attribute:: font.gpos_lookups
Returns a tuple of all positioning lookup names in the font.
This member cannot be set.
.. attribute:: font.gsub_lookups
Returns a tuple of all substitution lookup names in the font.
This member cannot be set.
.. attribute:: font.guide
A copy of the font's guide layer
.. attribute:: font.hasvmetrics
.. attribute:: font.head_optimized_for_cleartype
.. attribute:: font.hhea_ascent
.. attribute:: font.hhea_ascent_add
.. attribute:: font.hhea_descent
.. attribute:: font.hhea_descent_add
.. attribute:: font.hhea_linegap
.. attribute:: font.horizontalBaseline
Returns a tuple of tuples containing the horizontal baseline information in
the font (the 'BASE' table). If there is no information ``None`` will be
returned, otherwise the format of the tuple is: ::
((tuple of baseline tags used), (tuple of script information))
The ``(tuple of baseline tags used)`` is simply a tuple of 4 letter strings
as ``("hang", "ideo", "romn")`` these are standard baseline tag names as
defined in the opentype spec. The number of entries here, and their order is
important as there will be subsequent tuples (in the script tuple) which use
the same ordering.
The ``(tuple of script information)`` is again a tuple of
``script information`` tuples.
A ``script information`` tuple looks like ::
(script-tag,default-baseline-tag, (tuple of baseline positions), (tuple of language extents))
If there are no baseline tags defined (an empty tuple), then the
``default-baseline-tag`` and the ``(tuple of baseline positions)`` will be
``None``. Otherwise both tags will be 4 character strings, and the ``(tuple
of baseline positions)`` will be a tuple of numbers (in the same order as the
``(tuple of baseline tags used)`` above) specifying the relative positions
of each baseline for this script.
A ``(tuple of language extents)`` is a tuple of ``language extent`` tuples.
A ``language extent`` tuple is ::
(language-tag,min-extent,max-extent, (tuple of feature extents))
``language-tag`` is a 4 letter string specifying an opentype language,
``min``/``max-extent`` are numbers specifying how far above and below the
baseline characters go in this script/language.
A ``(tuple of feature extents>`` is a tuple of ``feature extent`` tuples.
A ``feature extent`` tuple is ::
(feature-tag,min-extent,max-extent)
``feature-tag`` is a 4 letter string specifying an opentype (GPOS or GSUB)
feature tag, ``min``/``max-extent`` are numbers specifying how far above and
below the baseline characters go in this script/language with the
feature applied.
**Example:**
::
(("hang","ideo","romn"),
(("cyrl","romn",(1405,-288,0),()),
("grek","romn",(1405,-288,0),()),
("latn","romn",(1405,-288,0),
(("dflt",-576,1913,
(("NoAc",-576,1482),
("ENG ",-576,1482))
),
)
)
)
)
(Note: The comma after the ``dflt`` tuple puts it into a one-element tuple.)
.. attribute:: font.is_cid
Indicates whether the font is a cid-keyed font or not. (Read-only)
.. attribute:: font.is_quadratic
Deprecated. Whether the contours should be interpreted as a set of quadratic
or cubic splines. Setting this value has the side effect of converting the
entire font into the other format
Now each layer may have its own setting for this value, which should be set
on the font's :attr:`font.layers`.
.. attribute:: font.isnew
A flag indicating that this is a new font
.. attribute:: font.italicangle
.. attribute:: font.macstyle
.. object:: Bit 0
Bold (if set to 1)
.. object:: Bit 1
Italic (if set to 1)
.. object:: Bit 2
Underline (if set to 1)
.. object:: Bit 3
Outline (if set to 1)
.. object:: Bit 4
Shadow (if set to 1)
.. object:: Bit 5
Condensed (if set to 1)
.. object:: Bit 6
Extended (if set to 1)
.. object:: Bits 7-15
Reserved (set to 0).
(`source <https://docs.microsoft.com/en-us/typography/opentype/spec/head>`_)
.. attribute:: font.layer_cnt
The number of layers in the font. (Read only. Can change using ``add``
and ``del`` operations on the :attr:`font.layers` array)
.. attribute:: font.layers
Returns a dictionary like object with information on the layers of the
font -- a name and a boolean indicating whether the layer is quadratic or not.
You may remove a layer with ::
del font.layers["unneeded layer"]
You may add a new layer with ::
font.layers.add("layer-name",is_quadratic[, is_background])
You may change a layer's name with ::
font.layers["layer"].name = "new-name"
You may change the type of splines in a layer with ::
font.layers["layer"].is_quadratic = True
You may change whether it is a background layer by ::
font.layers["layer"].is_background = True
Note: The layers that live in the font are different from layers that live
in a glyph. These objects do not have the Layer type documented earlier.
.. attribute:: font.loadState
A bitmask indicating non-fatal errors found when loading the font. (readonly)
.. object:: 0x01
Bad PostScript entry in 'name' table
.. object:: 0x02
Bad 'glyf' or 'loca' table
.. object:: 0x04
Bad 'CFF ' table
.. object:: 0x08
Bad 'hhea', 'hmtx', 'vhea' or 'vmtx' table
.. object:: 0x10
Bad 'cmap' table
.. object:: 0x20
Bad 'EBLC', 'bloc', 'EBDT' or 'bdat' (embedded bitmap) table
.. object:: 0x40
Bad Apple GX advanced typography table
.. object:: 0x80
Bad OpenType advanced typography table (GPOS, GSUB, GDEF, BASE)
.. object:: 0x100
Bad OS/2 version number
Windows will reject all fonts with a OS/2 version number of 0 and will
reject OT-CFF fonts with a version number of 1
.. attribute:: font.maxp_FDEFs
The number of function definitions used by the tt program
.. attribute:: font.maxp_IDEFs
The number of instruction definitions used by the tt program
.. attribute:: font.maxp_maxStackDepth
The maximum stack depth used by the tt program
.. attribute:: font.maxp_storageCnt
The number of storage locations used by the tt program
.. attribute:: font.maxp_twilightPtCnt
The number of points in the twilight zone of the tt program
.. attribute:: font.maxp_zones
The number of zones used in the tt program
.. attribute:: font.multilayer
.. attribute:: font.onlybitmaps
A flag indicating that this font only contains bitmaps. No outlines.
.. attribute:: font.os2_codepages
A 2 element tuple containing the OS/2 Codepages field
.. attribute:: font.os2_family_class
.. attribute:: font.os2_fstype
.. attribute:: font.os2_stylemap
Write access to fsSelection, keep in sync with :attr:`font.macstyle`
.. attribute:: font.os2_panose
.. attribute:: font.os2_strikeypos
.. attribute:: font.os2_strikeysize
.. attribute:: font.os2_subxoff
.. attribute:: font.os2_subxsize
.. attribute:: font.os2_subyoff
.. attribute:: font.os2_subysize
.. attribute:: font.os2_supxoff
.. attribute:: font.os2_supxsize
.. attribute:: font.os2_supyoff
.. attribute:: font.os2_supysize
.. attribute:: font.os2_typoascent
.. attribute:: font.os2_typoascent_add
.. attribute:: font.os2_typodescent
.. attribute:: font.os2_typodescent_add
.. attribute:: font.os2_typolinegap
.. attribute:: font.os2_use_typo_metrics
.. attribute:: font.os2_unicoderanges
A 4 element tuple containing the OS/2 Unicode Ranges field
.. attribute:: font.os2_vendor
.. attribute:: font.os2_version
.. attribute:: font.os2_weight
.. attribute:: font.os2_weight_width_slope_only
.. attribute:: font.os2_width
.. attribute:: font.os2_winascent
.. attribute:: font.os2_winascent_add
.. attribute:: font.os2_windescent
.. attribute:: font.os2_windescent_add
.. attribute:: font.path
(readonly) Returns a string containing the name of the file from which the
font was originally read (in this session), or if this is a new font, returns
a made up filename in the current directory named something like
"Untitled1.sfd". See also :attr:`font.sfd_path`.
.. attribute:: font.persistent
Whatever you want -- though I recommend you store a dict here (these data
will be saved as a pickled object in the sfd file. It is your job to ensure
that whatever you put here can be pickled)
If you do store a dict then the following entries will be treated specially:
.. object:: initScriptString
If present, and if this is a string, then each time the font is loaded
from an sfd file, this string will be passed to the python interpreter.
.. note::
This is a string, not a function.
Function code cannot be pickled. Since it is a string it will receive
no arguments, but the current font will be available in the activeFont
method of the fontforge module.
This string will be interpreted before the loadFontHook of the
:data:`fontforge.hooks` dictionary.
One possible behavior for this string is to define function hooks to
be stored in the temporary dict described below.
.. attribute:: font.math
Returns a :class:`math` object which provides information on the font's
underlying math constant table. There is only one of these per font.
.. attribute:: font.private
Returns a :class:`private` dictionary-like object representing the
PostScript private dictionary for the font. Changing entries in this object
will change them in the font. (It's a reference, not a copy).
There is an iterator associated with this entry.
.. attribute:: font.privateState
Checks the (PostScript) Private dictionary and returns a bitmask of some
common errors.
.. object:: 0x000001
Odd number of elements in either the BlueValues or OtherBlues array.
.. object:: 0x000002
Elements in either the BlueValues or OtherBlues are disordered.
.. object:: 0x000004
Too many elements in either the BlueValues or OtherBlues array.
.. object:: 0x000008
Elements in either the BlueValues or OtherBlues array are too close
(must be at least ``2*BlueFuzz +1`` apart).
.. object:: 0x000010
Elements in either the BlueValues or OtherBlues array are not integers.
.. object:: 0x000020
Alignment zone height in either the BlueValues or OtherBlues array is too
big for the value of BlueScale.
.. object:: 0x000100
Odd number of elements in either the FamilyBlues or FamilyOtherBlues array.
.. object:: 0x000200
Elements in either the FamilyBlues or FamilyOtherBlues are disordered.
.. object:: 0x000400
Too many elements in either the FamilyBlues or FamilyOtherBlues array.
.. object:: 0x000800
Elements in either the FamilyBlues or FamilyOtherBlues array are too
close (must be at least ``2*BlueFuzz +1`` apart).
.. object:: 0x001000
Elements in either the FamilyBlues or FamilyOtherBlues array are not
integers.
.. object:: 0x002000
Alignment zone height in either the FamilyBlues or FamilyOtherBlues array
is too big for the value of BlueScale.
.. object:: 0x010000
Missing BlueValues entry.
.. object:: 0x020000
Bad BlueFuzz entry.
.. object:: 0x040000
Bad BlueScale entry.
.. object:: 0x080000
Bad StdHW entry.
.. object:: 0x100000
Bad StdVW entry.
.. object:: 0x200000
Bad StemSnapH entry.
.. object:: 0x400000
Bad StemSnapV entry.
.. object:: 0x800000
StemSnapH does not include StdHW.
.. object:: 0x1000000
StemSnapV does not include StdVW.
.. object:: 0x2000000
Bad BlueShift entry.
.. attribute:: font.selection
Returns a reference to a :class:`array-like object representing the font's
selection <selection>`. There is one entry for each encoding slot (there may
not be a glyph attached to every encoding slot). You may set this with a
tuple of integers (or boolean values). There should not be more entries in
the tuple than there are encoding slots in the current encoding. A ``True``
or non-0 value means the slot is selected.
.. attribute:: font.sfd_path
(readonly) Returns a string (or None) containing the name of the sfd file
associated with this font. Sometimes this will be the same as :attr:`font.path`.
.. attribute:: font.sfnt_names
The strings in the sfnt 'name' table. A tuple of all MS names. Each name is
itself a tuple of strings ``(language,strid,string)``. Language may be
either the (english) name of the language/locale, or the number representing
that language in Microsoft's specification. Strid may be one of the
(English) string names ``(Copyright, Family, SubFamily, etc.)`` or the
numeric value of that item. The string itself is in UTF-8.
Mac names will be automagically created from MS names
.. attribute:: font.sfntRevision
The font revision field stored in the ``'head'`` table of an sfnt. This
is documented to be a fixed 16.16 number (that is a 32 bit number with the
binary point between bits 15 and 16).
The field may be unset (in which case when the font is generated, FontForge
will guess a default value from one of the version strings).
The value returned with be ``None`` if the field is unset or a double.
You may set it to ``None`` which "unsets" it, or to a double value, or to an
integer. The integer will be treated as a 32 bit integer and right shifted
by 16 to get a 16.16 value).
.. attribute:: font.size_feature
The OpenType 'size' feature has two formats. It may either represent the
design size of the font (and nothing else) or the design size, and range
(top and bottom point sizes for which this design works), a style id (used
to represent this design size throughout the font family) and a set of
language/string pairs used to represent this design size in the menu.
If no size information is specified in the font FontForge will return None.
If only the design size is specified, FontForge will return a tuple
containing a single element: the point size for which the font was designed.
(This is returned as a real number -- the field can represent tenths of a point).
Otherwise FontForge returns a tuple containing five elements, the design
size, the bottom of the design range, the top, the style id and a tuple of
tuples. Each sub-tuple is a language/string pair. Language may be either
the (english) name of the language/locale, or The string itself is in UTF-8.
.. attribute:: font.strokedfont
is this a stroked font?
.. attribute:: font.strokewidth
the stroke width of a stroked font
.. attribute:: font.temporary
Whatever you want -- though I recommend you store a dict here (these data
will be lost once the font is closed)
If you do store a dict then the following entries will be treated specially:
.. object:: generateFontPreHook
If present, and if this is a function it will be called just before a
font is generated. It will be called with the font and the filename to
which the font will be written.
.. object:: generateFontPostHook
If present, and if this is a function it will be called just after a font
is generated. It will be called with the font and the filename to which
the font will be written.
.. attribute:: font.texparameters
Returns a tuple of :ref:`TeX font parameters <fontinfo.TeX>`. TeX font type
followed by 22 parameters. Font type is one of:
* ``text``
* ``mathsym``
* ``mathext``
* ``unset``
In case of ``unset`` default values for font parameters will be returned.
.. attribute:: font.uniqueid
.. attribute:: font.upos
underline position
.. attribute:: font.userdata
.. warning:: Deprecated name for :attr:`font.temporary`
.. attribute:: font.uwidth
underline width
.. attribute:: font.version
PostScript font version string
.. attribute:: font.verticalBaseline
Same format as :attr:`font.horizontalBaseline`.
.. attribute:: font.vertical_origin
.. warning:: Deprecated
.. attribute:: font.vhea_linegap
.. attribute:: font.weight
PostScript font weight string
.. attribute:: font.woffMajor
The major version number of a woff file, an integer.
The field may be unset (in which case when the font is generated, FontForge
will guess a default value from one of the version strings).
The value returned with be ``None`` if the field is unset or an integer.
You may set it to ``None`` which "unsets" it, or to an integer.
.. attribute:: font.woffMinor
The minor version number of a woff file, an integer.
The field may be unset (in which case when the font is generated, FontForge
will guess a default value from one of the version strings).
The value returned with be ``None`` if the field is unset or an integer.
You may set it to ``None`` which "unsets" it, or to an integer.
.. attribute:: font.woffMetadata
Any metadata associated with a woff file. This is a utf8 string containing
unparsed xml.
.. attribute:: font.xHeight
(readonly) Computes the X Height (the height of lower case letters such as
"x"). A negative number indicates the value could not be computed (the font
might have no lower case letters because it was upper case only, or didn't
include glyphs for a script with lower case letters).
.. method:: font.__iter__()
Returns an iterator for the font which will run through the font, in gid
order, returning glyph names
.. method:: font.__contains__()
Returns whether the font contains a glyph with the given name.
.. method:: font.__len__()
The number of glyph slots in the current encoding
.. method:: font.__getitem__(key)
If ``key`` is an integer, then returns the glyph at that encoding. If a
string then returns the glyph with that name. May not be assigned to.
.. method:: font.addAnchorClass(lookup_subtable_name, new_anchor_class_name)
Adds an anchor class to the specified (anchor) subtable.
.. method:: font.addKerningClass(lookup_name, new_subtable_name, first_classes, second_classes, offsets[, after])
font.addKerningClass(lookup_name, new_subtable_name, separation, first_classes, second_classes[, onlyCloser, autokern, after])
font.addKerningClass(lookup_name, new_subtable_name, separation, class_distance, first_glyph_list, second_glyph_list, [, onlyCloser, autokern, after])
font.addKerningClass(lookup_name, new_subtable_name, separation, class_distance, [, onlyCloser, autokern, after])
Creates a new subtable and a new kerning class in the named lookup. The
classes arguments are tuples of tuples of glyph names (each sub-tuble of
glyph names is a kerning class). The offsets argument is a tuple of kerning
offsets. There must be as many entries as ::
len(first-class)*len(second-class)
The optional after argument is used to specify the order of the subtable
within the lookup.
The second format will cause FontForge to auto kern the subtable. The
separation argument specifies the desired optical distance between any two
glyphs (if this is specified as 0 then the kerning class will be designed so
glyphs just touch each other). Again the user specifies two sets of
predefined classes. If the (optional) ``onlyCloser`` flag is set true then
only negative kerning values will be inserted into the table.
In the third format the user merely specifies two lists of glyphs to be
used, fontforge will look for similarities among among the glyphs and guess
at classes. The class-distance argument to determine how precise the classes
should match (1 is very tight matching, 20 is rather loose).
In the last format the font's selection will be used to specify the list of
glyphs to be examined (and the same list will be used for both the left and
right glyphs -- but fontforge will probably find different classes).
.. method:: font.addLookup(new_lookup_name, type, flags, feature_script_lang_tuple[, after_lookup_name)
Creates a new lookup with the given name, type and flags. It will tag it
with any indicated features. The type of one of
* ``gsub_single``
* ``gsub_multiple``
* ``gsub_alternate``
* ``gsub_ligature``
* ``gsub_context``
* ``gsub_contextchain``
* ``gsub_revesechain``
* ``morx_indic``
* ``morx_context``
* ``morx_insert``
* ``gpos_single``
* ``gpos_pair``
* ``gpos_cursive``
* ``gpos_mark2base``
* ``gpos_mark2ligature``
* ``gpos_mark2mark``
* ``gpos_context``
* ``gpos_contextchain``
* ``kern_statemachine``
The flags argument is a tuple of strings, or ``None``. At most one of these
strings may be the name of a mark class. The others are:
* ``right_to_left``
* ``ignore_bases``
* ``ignore_ligatures``
* ``ignore_marks``
A feature-script-lang tuple is a tuple with one entry for each feature
(there may be no entries if there are no features). Each entry is itself a
two element tuple, the first entry is a string containing a 4 letter feature
tag, and the second entry is another tuple (potentially empty) with an entry
for each script for which the feature is active. Each entry here is itself a
two element tuple. The first element is a 4 letter script tag and the second
is a tuple of languages. Each entry in the language tuple is a four letter
language. Example: ``(("liga",(("latn",("dflt")),)),)``
The optional final argument allows you to specify the ordering of the lookup.
If not specified the lookup will be come the first lookup in its table.
.. method:: font.addLookupSubtable(lookup_name, new_subtable_name[, after_subtable_name])
Creates a new subtable within the specified lookup. The lookup name should
be a string specifying an existing lookup. The subtable name should also be
a string and should not match any currently existing subtable in the lookup.
The optional final argument allows you to specify the ordering within the
lookup. If not specified this subtable will be first in the lookup.
If you want to create a subtable in a contextual lookup, then use
:meth:`font.addContextualSubtable`. If you want to create a kerning class
subtable, then use :meth:`font.addKerningClass`.
.. method:: font.addContextualSubtable(lookup_name, new_subtable_name, type, rule[, afterSubtable=] [, bclasses=] [, mclasses=] [, fclasses=] [, bclassnames=] [, mclassnames=] [, fclassnames=])
Creates a new subtable within the specified contextual lookup (contextual,
contextual chaining, or reverse contextual chaining). The lookup name should
be a string specifying an existing lookup. The subtable name should also be
a string and should not match any currently existing subtable in the lookup.
The ``type`` should be one of the strings "glyph", "class", "coverage" or
"reversecoverage". The ``rule`` should be a string specifying a string to
match and a set of lookups to apply once the match has been made. (See
below for more details).
The remaining arguments are optional, keyword arguments.
* ``afterSubtable=``, if present this should be followed by a string, the
name of a subtable after which this one is to be placed in the lookup. If
not specified this subtable will be first in the lookup.
* ``bclasses=, fclasses=, mclasses=`` these three arguments specify sets of
glyph classes for when ``type="class"``. They should be a tuple of
thingies where each thingy is either a string containing a list of space
separated glyph names, or another tuple containing a set of strings, each
a glyph name. Note that the first class is magic and should usually be
left as a null string.
* ``bclassnames=, fclassnames=, mclassnames=`` These provide names for the
glyph classes described above. These names are optional, but can be
convenient. These are tuples of strings. There should be the same number
of entries in ``bclassnames`` as there are in ``bclasses``.
.. object:: When type="glyph"
The rule should look something like: ::
glyph-name1 glyph-name2 | glyph-name3 @<lookup-name> | glyph-name4
The ``|`` s divide between backtrack, match and lookahead sections. So
this example would match it the current glyph were named ``glyph-name3``
and it were preceded by ``glyph-name2`` and that by ``glyph-name1`` and
followed by ``glyph-name4``. If the match were successful then the lookup
named ``lookup-name`` would be applied. The ``@<>`` are literal
characters and should be present in the rule.
If the invoked lookup is a ligature lookup then it should be invoked
after the first glyph that forms the lookup (rather than the last) and
all glyphs that might make up the lookup should be in the match section.
So... ::
e | f @<ff-lig> f l | o
would only apply the ``ff-lig`` lookup if the ``ffl`` were preceded by
``e`` and followed by ``o``.
.. object:: When type="class"
The rule should look something like: ::
class-name1 class-name2 | class-name3 @<lookup-name> | class-name4
Very similar to the case of glyphs, except that instead of glyph names
we have class names here. It is possible to have different sets of class
names in the three different sections (backtrack, match and lookahead).
If you don't specify any class names then you must use numbers instead,
each number referring to the class at that position in the tuple (the first
class will be class 0, the second class 1, and so on).
.. object:: When type="coverage"
The rule should look something like: ::
[g1 g2] [g3 g4] | [g5 g6 g7] @<lookup-name> | [g8 g9]
Each entry within brackets, ``[]``, represents a coverage table and
should be a list of glyph names. The brackets are specified literally.
.. object:: When type="reversecoverage"
The rule should look something like: ::
[g1 g2] [g3 g4] | [g5 g6 g7] => [rg1 rg2 rg3] | [g8 g9]
Very similar to normal coverage tables except that instead of specifying
a lookup there are replacement glyphs inline. There must be the same
number of replacement glyphs (``rg1, rg2,rg3``) as match glyphs
(``g5, g6, g7``) and there may be only one coverage table in the match
section.
.. warning::
This format has some limitations, if there are multiple lookups they
will be applied in textual order (First lookup in the string is the first
one applied). This limitation is also present in Adobe's feature files so
I hope it shan't be a severe limitation.
.. method:: font.addSmallCaps(scheight=None, capheight=None, lcstem=None, ucstem=None, symbols=None, letter_extension=None, symbol_extension=None, stem_height_factor=None)
This function uses keyword parameters. None are required, if omitted a
default value will be used (generally found by analyzing the font).
For each selected letter, this function will create a corresponding small
caps glyph. If you set the ``symbol`` keyword to ``True`` it will also
create small caps variants of digits and symbols.
The outlines of the new glyph will be based on the outlines of the
upper-case variant of the letter. These will then be scaled so that a glyph
which was ``capheight`` high will now be ``scheight`` high, and so that
stems which were ``ucstem`` wide will be ``lcstem`` wide. Normally the ratio
of stem heights is the same as the ratio of stem widths, but you may change
that with ``stem_height_factor``.
When it creates a new glyph it will name that glyph by appending ".sc" to
the original lower case letter name (so "a" would become "a.sc") you may
change the extension used with ``letter_extension``. Similarly symbols and
digits will use the extension "taboldstyle", but you may change that with
``symbol_extension``.
When it creates a glyph it also creates two lookups one bound to the feature
"c2sc" and the other to "smcp". A mapping from the lower case letter to the
small caps letter will be provided under "smcp", while a mapping from the
upper case to the small caps under "c2sc". Symbols will have both lookup
maps attached to the original glyph.
.. method:: font.alterKerningClass(subtable_name, first_classes, second_classes, offsets)
Changes the kerning class in the named subtable. The classes arguments are
tuples of tuples of glyph names (each sub-tuble of glyph names is a kerning
class). The offsets argument is a tuple of kerning offsets. There must be as
many entries as ``len(first-class)*len(second-class)``. The optional after
argument is used to specify the order of the subtable within the lookup.
.. method:: font.autoKern(subtable_name, separation[, minKern=, onlyCloser=, touch=])
font.autoKern(subtable_name, separation, glyph_list1, glyph_list2[, minKern=, onlyCloser=, touch=])
The named subtable must be a kerning pair subtable that already exists.
This command will automatically generate kerning pairs for the named
subtable. If no glyph lists are specified it will look at all pairs of the
glyphs in the selection; if glyph lists are specified then it will look at
all pairs that can be made with one glyph from the first list and the second
from the second list.
It will attempt to guess a good kerning value between the two glyphs -- a
value which will make the optical separation between the two appear to be
``separation`` em-units. If ``minkern`` is specified then and the (absolute
value of the) kerning correction is less than this number then no kerning
pair will be generated. If ``onlyCloser`` is set true then only negative
kerning offsets will be generated (only thing which move two glyphs closer
together). If touch is set to 1 then the kerning offset will not be based on
optical distance but on the closest approach between two the two glyphs.
.. method:: font.appendSFNTName(language, strid, string)
Adds a new (or replaces an old) string in the sfnt 'name' table. Language
may be either the English name of the language/locale as a string, or the
number representing that language in MicroSoft's specification. Strid may be
one of the (english) string names (Copyright, Family, SubFamily, etc.) or
the numeric value of that item. The string itself is in UTF-8.
.. method:: font.buildOrReplaceAALTFeatures()
Removes any existing AALT features (and any lookups solely controlled by such
features) and creates new ones containing all possible single and alternate
substutions available for each glyph.
.. method:: font.cidConvertByCMap(cmap_filename)
Converts a normal font into a CID-keyed font with one subfont using
the CMAP to determine the mapping.
.. method:: font.cidConvertTo(registry, ordering, supplement)
Converts a normal font into a CID-keyed font with one subfont.
.. method:: font.cidFlatten()
Converts a CID font into a normal font (glyphs will be in CID order).
.. method:: font.cidFlattenByCMap(cmap_filename)
Converts a CID font into a normal font using the encoding specified in the
CMAP file.
.. method:: font.cidInsertBlankSubFont()
Adds a new (blank) sub-font into a cid-keyed font and changes the current
sub-font to be it.
.. method:: font.cidRemoveSubFont()
Removes the current subfont from a cid-keyed font.
.. method:: font.close()
Frees memory for the current font.
**Warning:** Any python references to it will become invalid.
.. method:: font.compareFonts(other_font, filename, flags_tuple)
This will compare the current font with the font in ``other-font`` (which
must already have been opened). It will write the results to the
``filename``, you may use "-" to send the output to stdout. The ``flags``
argument is a tuple of strings and controls what will be compared.
.. object:: outlines
compare outlines
.. object:: outlines-exactly
compare outlines exactly (otherwise allow slight errors and the unlinking
of references)
.. object:: warn-outlines-mismatch
warn if the outlines don't exactly match (but are pretty close)
.. object:: hints
compare hints
.. object:: warn-refs-unlink
warn if references need to be unlinked before a match is found
.. object:: strikes
compare bitmap strikes
.. object:: fontnames
compare font names
.. object:: gpos
compare glyph positioning
.. object:: gsub
compare glyph substitutions
.. object:: add-outlines
for any glyphs whose outlines differ, add the outlines of the glyph in
the second font to the background of the glyph in the first
.. object:: create-glyphs
if a glyph exists in the second font but not the first, create that
glyph in the first and add the outlines from the second into the
backgroun layer
.. method:: font.createChar(uni[, name])
Create (and return) a character at the specified unicode codepoint in this
font and optionally name it. If you wish to create a glyph with no unicode
codepoint, set the first argument to -1 and specify a name.
If there is already a character at that (positive) codepoint then it is
returned. If the optional name parameter is included and differs from its
current name then the character is also renamed.
.. method:: font.createInterpolatedGlyph(glyph1, glyph2, amount)
Create (and return) a glyph with the same unicode code point as glyph1.
The glyph may not already exist. The contents of the glyph will be formed
by interpolating between glyph1 and glyph2. If amount==0 the result will
look like glyph1, or 1 then like glyph2.
.. method:: font.createMappedChar(enc)
font.createMappedChar(name)
Create (and return) a character at the specified encoding in this font.
If there is already a character there, return it
.. method:: font.find(contour[, error_bound, search_flags])
Searches the font for all glyphs containing the contour (or layer) and
returns an iterator which returns those glyphs.
error-bound: defaults to 0.01.
search_flags: tuple of the strings: reverse, flips, rotate, scale.
When found, the glyph.temporary is set to a dict of:
::
{
"findMatchedRefs": matched_refs_bit_map,
"findMatchedContours": matched_contours_bit_map,
"findMatchedContoursStart": matched_contours_start_bit_map,
}
.. method:: font.findEncodingSlot(uni)
font.findEncodingSlot(name)
Tests whether a glyph with this codepoint or name is in the font's encoding
and returns the encoding slot. If the glyph is not present it returns -1.
(If a glyph with that name/unicode is in the font, but is not in the
encoding, then an value beyond the end of the encoding will be returned).
.. method:: font.glyphs([type])
Returns an iterator which will return the glyphs in the font. By default
they will be returned in "GID" order, but if type is specified as "encoding"
they will be returned in encoding order. If returned in encoding order it
is possible that a glyph will be returned more than once if there are
multiple encoding slots which reference it.
.. method:: font.generate(filename[, bitmap_type=, flags=, bitmap_resolution=, subfont_directory=, namelist=, layer=])
Generates a font. The type is determined by the font's extension. The bitmap
type (if specified) is also an extension. If layer is specified, then the
splines and references in that layer will be used instead of the foreground
layer.
Flags is a tuple containing some of
.. object:: afm
output an afm file
.. object:: pfm
output a pfm file
.. object:: tfm
output a tfm file
.. object:: ofm
output a ofm file
.. object:: composites-in-afm
Store composite info in the afm file
.. object:: glyph-map-file
Output a glyph map file giving the mapping between output gid and glyphnames
.. object:: short-post
Do not include glyphnames in a ttf/otf file
.. object:: apple
output apple advanced typography tables
.. object:: opentype
output opentype tables
.. object:: old-kern
output an old style 'kern' with opentype tables
.. object:: winkern
only add kern pairs for mapped glyphs (required for kerning in some/all
versions of Windows)
.. object:: dummy-dsig
output an empty DSIG table so MS will mark a font with .ttf extension as
an OpenType font.
.. object:: no-FFTM-table
Do not generate an 'FFTM' table
.. object:: TeX-table
Include a 'TeX ' table in an ttf/otf file
.. object:: round
Round PS coordinates to integers
.. object:: no-hints
Do not include PS hints
.. object:: no-flex
Do not include PS flex hints
.. object:: omit-instructions
Do not include TrueType instructions
.. object:: PfEd-comments
Include font and glyph comments in the 'PfEd' table
.. object:: PfEd-colors
Include glyph colors in the 'PfEd' table
.. object:: PfEd-lookups
Include lookup names in the 'PfEd' table
.. object:: PfEd-guidelines
Include guideline locations in the 'PfEd' table
.. object:: PfEd-background
Include background (and spiro) layers in the 'PfEd' table
.. object:: symbol
Generate an sfnt with a Symbol cmap entry rather than a Unicode entry.
See also :meth:`font.save()`.
.. method:: font.generateTtc(filename, others, [flags=, ttcflags=, namelist=, layer=])
Generates a truetype collection file containing the current font and all
others listed -- the ``others`` argument may be ``None``, a font, or a tuple
(or list) of fonts.
Flags are as above,
Ttcflags is a tuple consisting of the following
.. object:: merge
Try and share tables and glyphs among the various fonts.
.. object:: cff
Use the CFF glyph format rather than the TrueType format (the OpenType
documentation says that this does not work, but both the Mac and
unix/linux accept it).
.. method:: font.generateFeatureFile(filename[, lookup_name])
Generates an adobe feature file for the current font. If a lookup-name is
specified then only data for that lookup will be generated.
.. method:: font.genericGlyphChange(stemType=<str>, thickThreshold=<double>, stemScale=<double>, stemAdd=<double>, stemHeightScale=<double>, stemHeightAdd=<double>, stemWidthScale=<double>, stemWidthAdd=<double>, thinStemScale=<double>, thinStemAdd=<double>, thickStemScale=<double>, thickStemAdd=<double>, processDiagonalStems=<boolean>, hCounterType=<str>, hCounterScale=<double>, hCounterAdd=<double>, lsbScale=<double>, lsbAdd=<double>, rsbScale=<double>, rsbAdd=<double>, vCounterType=<str>, vCounterScale=<double>, vCounterAdd=<double>, vScale=<double>, vMap=<tuple of tuples>)
This function uses keyword parameters. Which ones are required depends on
the three type arguments (``stemType, hCounterType, vCounterType``).
If ``stemType`` is omitted, or is the string "uniform", then the
``stemScale`` parameter must be specified (and ``stemAdd`` may be).
``stemScale`` specifies a scaling factor by which all stems (horizontal and
vertical, thick and thin) will be scaled. A value of 1.0 means no change.
While ``stemAdd`` specifies the number of em-units to add to the width of
each stem.
If ``stemType`` is the string "horizontalVertical", then values must be
specified for ``stemHeightScale`` and ``stemWidthScale`` (and may be for
``stemHeightAdd, stemWidthAdd`` ). The first of these specifies scaling for
the height of horizontal stems, and the second scaling for the width of
vertical stems.
If ``stemType`` is the string "thickThin", then values must be specified for
``thinStemScale``, ``thickStemScale`` and ``thickThreshold`` (and may be for
``thinStemAdd, thickStemAdd`` ). The first of these specifies scaling for
the width/height of thin stems, and the second scaling for the width/height
of thick stems. While the ``thickThreshold`` argument specifies the size (in
em-units) at which a stem is classified as "thick".
If ``hCounterType`` is omitted, or is the string "uniform", then horizontal
counters, and the left and right side bearings will all be scaled using the
same rules, and ``hCounterScale`` must be specified to provide the scaling
factor (while ``hCounterAdd`` may be specified).
If ``hCounterType`` is the string "nonUniform", then horizontal counters,
and the left and right side bearings may all be scaled using different
rules, and ``hCounterScale, lsbScale`` and ``rsbScale`` must be specified
to provide the scaling factors (while ``hCounterAdd, lsbAdd,`` and
``rsbAdd`` may be specified).
If ``hCounterType`` is the string "center", then the left and right
side-bearings will be set so the new glyph is centered within the original
glyph's width. (Probably more useful for CJK fonts than LGC fonts).
If ``hCounterType`` is the string "retainScale", then the left and right
side-bearings will be set so the new glyph is within within the original
glyph's width, and the side-bearings remain in the same proportion to each
other as before.
If ``vCounterType`` is omitted, or is the string "mapped", then certain
zones on the glyph may be placed at new (or the same) locations -- similar
to BlueValues. So you can specify a zone for the baseline, one for the
x-height and another for the top of capitals and ascenders (and perhaps a
fourth for descenders). Each such zone is specified by the ``vMap`` argument
which is a tuple of 3-tuples, each 3-tuple specifying a zone with: Original
location, original width, and final location.
.. note::
No default value is providedfor this argument you must figure out all the
values yourself.
If ``vCounterType`` is the string "scaled", then vertical counters, and the
top and bottom side bearings will all be scaled using the same rules, and
``vCounterScale`` must be specified to provide the scaling factor (while
``vCounterAdd`` may be specified). This is probably most useful for CJK fonts.
.. method:: font.getKerningClass(subtable_name)
Returns a tuple whose entries are: (first-classes, second-classes, offsets).
The classes are themselves tuples of tuples of glyph names. The offsets will
be a tuple of numeric kerning offsetss a tuple whose entries are:
(first-classes, second-classes, offsets). The classes are themselves tuples
of tuples of glyph names. The offsets will be a tuple of numeric kerning
offsets.
.. method:: font.getLookupInfo(lookup_name)
Returns a tuple whose entries are: (lookup-type, lookup-flags,
feature-script-lang-tuple). The lookup type is a string as described in
:meth:`font.addLookup`, and the feature-script-lang tuple is also described
there.
.. method:: font.getLookupSubtables(lookup_name)
Returns a tuple of all subtable names in that lookup.
.. method:: font.getLookupSubtableAnchorClasses(subtable_name)
Returns a tuple of all anchor class names in that subtable.
.. method:: font.getLookupOfSubtable(subtable_name)
Returns the name of the lookup containing this subtable.
.. method:: font.getSubtableOfAnchor(anchor_class_name)
Returns the name of the subtable containing this anchor class.
.. method:: font.importBitmaps(bitmap_font_file[, to_background])
Load any bitmap strikes out of the bitmap-font-file into the current font
.. method:: font.importLookups(another_font, lookup_names[, before_name])
The first argument must be a :class:`font` object, the second a string or a
tuple of strings, and the third, another string.
It will search the other font for the named lookup(s) and import it into the
current font. (Contextual lookups which invoke other lookups will have any
nested lookups imported as well).
Lookups will be imported in the order listed. If a before-name is specified,
then it is looked up in the current font and all lookups will be added
before it, if not specified lookups will appear at the end of the list.
.. method:: font.interpolateFonts(fraction, filename)
Interpolates a font between the current font and the font contained in
filename.
.. method:: font.isKerningClass(subtable_name)
Returns whether the named subtable contains a kerning class.
.. method:: font.isVerticalKerning(subtable_name)
Returns whether the named subtable contains a vertical kerning data
.. method:: font.italicize(italic_angle=, ia=lc_condense=, lc=uc_condense=, uc=symbol_condense=, symbol=deserif_flat=, deserif_slant=, deserif_pen=, baseline_serifs=, xheight_serifs=, ascent_serifs=, descent_serifs=, diagonal_serifs=, a=, f=, u0438=, u043f=, u0442=, u0444=, u0448=, u0452=, u045f=)
This function uses keyword parameters. None are required, if omitted a
default value will be used. Some keywords have abbreviations ("ia" for
"italic_angle") you may use either.
This function will attempt to italicize each selected glyph. For a detailed
explanation of what this entails please see the information on the
:ref:`Italic dialog <Styles.Italic>`.
The ``*_condense`` keywords should be 4 element tuples of floating point
numbers; these numbers correspond to: Left side bearing condensation,
stem condensation, counter condensation and right side bearing condensation.
These numbers should be small numbers around 1 (scale factors, not
percentages).
Set at most one of the ``deserif_*`` keywords.
Setting ``a`` to ``True`` will turn on the transformation that applies to
the "a" glyph. Setting ``u0438`` will control the transformation that
applies to the glyph at unicode codepoint U+0438.
The ``f`` keyword is slightly more complex. Setting it to 0 turns off all
transformations of glyphs like "f", setting it to 1 will give "f" a tail
which looks like a rotated version of its head, and setting it to 2 will
simply extend the main stem of "f" below the baseline.
.. method:: font.lookupSetFeatureList(lookup_name, feature_script_lang_tuple)
Sets the feature list of indicated lookup. The feature-script-lang tuple is
described at :meth:`font.addLookup()`.
.. method:: font.lookupSetFlags(lookup_name, flags)
Sets the lookup flags for the named lookup.
.. method:: font.lookupSetStoreLigatureInAfm(lookup_name, boolean)
Sets whether this ligature lookup contains data to store in the afm.
.. method:: font.mergeFonts(filename[, preserveCrossFontKerning])(font[, preserveCrossFontKerning])
Merges the font in the file into the current font.
.. method:: font.mergeFeature(filename, boolean)
Merge feature and lookup information from an adobe feature file, or metrics
information from the (afm, tfm, etc) file into the current font. The
optional boolean will try to skip invalid feature lookups containing
replacement glyphs which do not exist in the font, which can help in reusing
large feature files.
.. method:: font.mergeKern(filename)
Deprecated name for mergeFeature above
.. method:: font.mergeLookups(lookup_name1, lookup_name2)
The lookups must be of the same type. All subtables from lookup_name2 will
be moved to lookup_name1, the features list of lookup_name2 will be merged
with that of lookup_name1, and lookup_name2 will be removed.
.. method:: font.mergeLookupSubtables(subtable_name1, subtable_name2)
The subtables must be in the same lookup. Not all lookup types allow their
subtables to be merged (contextual subtables may not be merged, kerning
classes may not be (kerning pairs may be)). Any information bound to
subtable2 will be bound to subtable1 and subtable2 will be removed.
.. method:: font.printSample(type, pointsize, sample, output_file)
Type is a string which must be one of
.. object:: fontdisplay
Display all glyphs in the font in encoding order
.. object:: chars
Display the selected glyphs scaled to fill a page
Ignores the pointsize argument.
.. object:: waterfall
Displays the selected glyphs at many pointsizes.
The pointsize argument should be a tuple of pointsizes here.
.. object:: fontsample
The third argument should contain a string which will be layed out
and displayed as well as FontForge can.
.. object:: fontsampleinfile
The third argument should contain the name of a file which contains
text to be layed out and displayed.
If output is to a file (see :func:`fontforge.printSetup()`) then the last
argument specifies a file name in which to store output.
.. method:: font.randomText(script[, lang])
Returns a random text sample using the letter frequencies of the specified
script (and optionally language). Both script and language should be
expressed as strings containing OpenType Script and Language tags. "dflt" is
a reasonable language tag. If the language is not specified, one will be
chosen at random. If ff has no frequency information for the script/language
specified it will use the letters in the script with equal frequencies.
.. method:: font.regenBitmaps(tuple_of_sizes)
A tuple with an entry for each bitmap strike to be regenerated
(rerasterized). Each strike is identified by pixelsize (if the strike is a
grey scale font it will be indicated by ``(bitmap-depth<<16)|pixelsize``.
.. method:: font.removeAnchorClass(anchor_class_name)
Removes the named AnchorClass (and all associated points) from the font.
.. method:: font.removeLookup(lookup_name[, remove_acs])
Remove the lookup (and any subtables within it). remove_acs (0 or 1),
specifies whether to remove associated anchor classes and points.
.. method:: font.removeLookupSubtable(subtable_name[, remove_acs])
Remove the subtable (and all data associated with it). remove_acs (0 or 1),
specifies whether to remove associated anchor classes and points
.. method:: font.removeGlyph(uni[, name])(name)(glyph)
You may either pass in a FontForge glyph object (from this font) or identify
a glyph in the font by unicode code point or name. In any case the glyph
will be removed from the font.
If you use (uni,name) to specify a name, set uni to -1.
.. warning::
This frees FontForge's storage to this glyph. If you have any python
references to that storage they will be looking at garbage. This does not
go through the usual python reference mechanism.
.. method:: font.replaceAll(srch, rpl[, error_bound])
Searches the font for all occurrences of the srch contour (or layer) and
replaces them with the replace contour (or layer).
.. method:: font.revert()
Reloads the font from the disk.
.. warning::
If you have any references to glyphs which live in the font those
references will no longer be valid, and using them will cause crashes.
This is very un-python-like.
.. method:: font.revertFromBackup()
Reloads the font from the backup file on the disk.
.. warning::
If you have any references to glyphs which live in the font those
references will no longer be valid, and using them will cause crashes.
This is very un-python-like.
.. method:: font.save([filename])
Saves the font to an sfd file. See also :meth:`font.generate()`
.. method:: font.saveNamelist(filename)
Saves the font's namelist to a file.
.. method:: font.getTableData(table_name)
Gets binary data from any saved table. FF will save 'fpgm', 'prep', 'cvt '
and 'maxp'. FF may also save tables which you explicitly request. Do not
expect to get binary data for tables like 'GPOS' or 'glyf' which FF will
generate when it creates a font... that information is not currently available.
Returns a binary string.
.. method:: font.setTableData(table_name, sequence)
Sets binary data of any saved table. FF will save 'fpgm', 'prep', 'cvt '
and 'maxp'. FF may also save tables which you explicitly request. Do not
expect to set binary data for tables like 'GPOS' or 'glyf' which FF will
generate when it creates a font... that information is not currently available.
If sequence is None, then the named table will be removed from the font.
.. method:: font.validate([force])
Validates the font and returns a bit mask of all errors from all glyphs (as
defined in the ``validation_state`` of a glyph -- except bit 0x1 is clear).
If the font passed the validation then the return value will be 0 (not 0x1).
Otherwise the return value will be the set of errors found.
Note: The set of errors is slightly different for TrueType and PostScript
output. The returned mask contains the list of potential errors. You must
figure out which apply to you.
Normally each glyph will cache its validation_state and it will not be
recalculated. If you pass a non-zero argument to the routine then it will
force recalculation of each glyph -- this can be slow.
.. rubric:: Selection Based Interface
See the :class:`selection` type for how to alter the selection.
.. method:: font.addExtrema()
Extrema should be marked by on-curve points. If a curve in any selected
glyph lacks a point at a significant extremum this command will add one.
.. method:: font.addInflections()
Please see :meth:`contour.addInflections()`.
.. method:: font.autoHint()
Generates PostScript hints for all selected glyphs.
.. method:: font.autoInstr()
Generates TrueType instructions for all selected glyphs.
.. method:: font.autoWidth(separation[, minBearing=, maxBearing=, height=, loopCnt=])
Guesses at reasonable horizontal advance widths for the selected glyphs
.. method:: font.autoTrace()
Auto traces any background images in all selected glyphs
.. method:: font.build()
If any of the selected characters is a composite character, then this
command will clear it and insert references to its components (this command
can create new glyphs).
.. method:: font.canonicalContours()
Orders the contours in the selected glyphs by the x coordinate of their
leftmost point. (This can reduce the size of the charstring needed to
describe the glyph(s).
.. method:: font.canonicalStart()
Sets the start point of all the contours of the selected glyphs to be the
leftmost point on the contour. (If there are several points with that value
then use the one which is closest to the baseline). This can reduce the size
of the charstring needed to describe the glyph(s). By regularizing things it
can also make more things available to be put in subroutines.
.. method:: font.changeWeight(stroke_width[, type, serif_height, serif_fuzz, counter_type, custom_zones])
See the :ref:`Element->Style->Change Width <Styles.Embolden>` command for a
more complete description of these arguments.
Stroke_width is the amount by which all stems are expanded.
Type is one of "LCG", "CJK", "auto", "custom".
Serif_height tells ff not to expand serifs which are that much off the
baseline, while serif_fuzz specifies the amount of fuzziness allowed in the
match. If you don't want special serif behavior set this to 0.
Counter_type is one of "squish", "retain", "auto".
Custom_zones is only meaningful if the type argument were "custom". It may
be either a number, which specifies the "top hint" value (bottom hint is
assumed to be 0, others are between), or a tuple of 4 numbers (top hint,
top zone, bottom zone, bottom hint).
.. method:: font.condenseExtend(c_factor, c_add[, sb_factor, sb_add, correct])
Condenses or extends the size of the counters and side-bearings of the
selected glyphs. The first two arguments provide information on
shrinking/growing the counters, the second two the sidebearings. If the last
two are omitted they default to the same values as the first two.
A counter's width will become: ::
new_width = c_factor * old_width + c_add
If present the ``correct`` argument allows you to specify whether you want
to correct for the italic angle before condensing the glyph. (it defaults to
True)
.. method:: font.clear()
Clears the contents of all selected glyphs
.. method:: font.cluster([within, max])
Moves clustered coordinates to a standard central value in all selected
glyphs. See also :meth:`font.round()`.
.. method:: font.copy()
Copies all selected glyphs into (FontForge's internal) clipboard.
.. method:: font.copyReference()
Copies all selected glyphs (as references) into (FontForge's internal)
clipboard.
.. method:: font.correctDirection()
Orients all contours so that external ones are clockwise and internal
counter-clockwise in all selected glyphs.
.. method:: font.correctReferences()
Checks a font for glyphs with mixed contours and references (or references
with transformation matrices which cannot be represented truetype (ie.
scaling by 2 or more)). If a mixed case is discovered FontForge will take
the contours out of the glyph, put them in a new glyph, and make a reference
to the new glyph.
.. method:: font.cut()
Copies all selected glyphs into (FontForge's internal) clipboard. And then
clears them.
.. method:: font.paste()
Pastes the contents of (FontForge's internal) clipboard into the selected
glyphs -- and removes what was there before.
.. method:: font.intersect()
Leaves only areas in the intersection of contours in all selected glyphs.
See also :meth:`font.removeOverlap()`.
.. method:: font.pasteInto()
Pastes the contents of (FontForge's internal) clipboard into the selected
glyphs -- and retains what was there before.
.. method:: font.removeOverlap()
Removes overlapping areas in all selected glyphs.
See also :meth:`font.intersect()`.
.. method:: font.replaceWithReference([fudge])
Finds any glyph which contains an inline copy of one of the selected glyphs,
and converts that copy into a reference to the appropriate glyph. Selection
is changed to the set of glyphs which the command alters.
If specified the fudge argument specifies the error allowed for coordinate
differences.
.. method:: font.round([factor])
Rounds the x and y coordinates of each point in all selected glyphs. If
factor is specified then ::
new-coord = round(factor*old-coord)/factor
See also :meth:`font.cluster()`.
.. method:: font.simplify([error_bound, flags, tan_bounds, linefixup, linelenmax])
Tries to remove excess points in all selected glyphs if doing so will not
perturb the curve by more than ``error-bound``. Flags is a tuple of the
following strings
.. object:: ignoreslopes
Allow slopes to change
.. object:: ignoreextrema
Allow removal of extrema
.. object:: smoothcurves
Allow curve smoothing
.. object:: choosehv
Snap to horizontal or vertical
.. object:: forcelines
flatten bumps on lines
.. object:: nearlyhvlines
Make nearly horizontal/vertical lines be so
.. object:: mergelines
Merge adjacent lines into one
.. object:: setstarttoextremum
Rotate the point list so that the start point is on an extremum
.. object:: removesingletonpoints
If the contour contains just one point then remove it
.. method:: font.stroke("circular", width[, CAP, JOIN, FLAGS])
font.stroke("elliptical", width, minor_width, ANGLE[, CAP, JOIN, FLAGS])
font.stroke("calligraphic", width, height, angle[, FLAGS])
font.stroke("polygon", contour[, FLAGS])
(Legacy interface)
:noindex:
.. method:: font.stroke("circular", width[, CAP, JOIN, ANGLE, KEYWORD])
font.stroke("elliptical", width, minor_width[, ANGLE, CAP, JOIN, KEYWORD])
font.stroke("calligraphic", width, height[, ANGLE, CAP, JOIN, KEYWORD])
font.stroke("convex", contour[, ANGLE, CAP, JOIN, KEYWORD])
(Current interface)
Strokes the lines of the contours in all selected glyphs according to the
supplied parameters. See :meth:`glyph.stroke()` for a description of the
syntax and the :doc:`stroke </techref/stroke>` documentation for more general
information.
.. method:: font.transform(matrix[, flags])
Transforms all selected glyphs by the matrix. The optional flags argument
should be a tuple containing any of the following strings:
.. object:: activeLayer
Transform :attr:`font.activeLayer` only. (By default all layers are
transformed.)
.. object:: guide
Also transform :attr:`font.guide` layer.
.. object:: noWidth
Do not change :attr:`glyph.width`.
.. object:: round
Round to int after the transformation is done.
.. object:: simplePos
Also transform simple positioning features and kern pairs.
.. object:: kernClasses
Also transform kerning classes.
.. method:: font.nltransform(xexpr, yexpr)
xexpr and yexpr are strings specifying non-linear transformations that will
be applied to all points in the selected glyphs of the font (with xexpr
being applied to x values, and yexpr to y values, of course). The syntax
for the expressions is explained in the
:ref:`non-linear transform dialog <transform.Non-Linear>`.
.. method:: font.unlinkReferences()
Unlinks all references in all selected glyphs and replaces them with splines.
|