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
|
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 1999, 2001 SIL International. All rights reserved.
Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.
File: PreCompiler.cpp
Responsibility: Sharon Correll
Last reviewed: Not yet.
Description:
Methods to implement the pre-compiler, which does error checking and adjustments.
-------------------------------------------------------------------------------*//*:End Ignore*/
/***********************************************************************************************
Include files
***********************************************************************************************/
#include "main.h"
#ifdef _MSC_VER
#pragma hdrstop
#endif
#undef THIS_FILE
DEFINE_THIS_FILE
/***********************************************************************************************
Tables, Passes, and Rules
***********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Do the pre-compilation tasks for the tables, passes, and rules. Return false if
compilation cannot continue due to an unrecoverable error.
----------------------------------------------------------------------------------------------*/
bool GrcManager::PreCompileRules(GrcFont * pfont)
{
int cpassValid; // number of valid passes
if (!m_prndr->CheckTablesAndPasses(this, &cpassValid))
return false;
// Fix up the rules that have items in the context before the first modified item.
Symbol psymAnyClass = m_psymtbl->FindSymbol("ANY");
if (!m_prndr->FixRulePreContexts(psymAnyClass))
return false;
// In preparation for the next step, create the fsm class vectors for each pass.
m_prgvpglfcFsmClasses = new std::vector<GdlGlyphClassDefn *>[cpassValid];
if (!AssignClassInternalIDs())
return false;
if (!m_prndr->CheckRulesForErrors(m_pgax, pfont))
return false;
if (!m_prndr->CheckLBsInRules())
return false;
m_prndr->ReplaceKern(this);
int fxdVersionNeeded;
bool fFixPassConstraints = true; // remains true if the only thing that is incompatible are
// the pass constraints
int fxdRequested = SilfTableVersion();
SetCompilerVersionFor(fxdRequested);
int fxdCompilerVersionNeeded = m_fxdCompilerVersion;
if (!CompatibleWithVersion(fxdRequested, &fxdVersionNeeded, &fxdCompilerVersionNeeded,
&fFixPassConstraints))
{
if (fFixPassConstraints && fxdRequested <= 0x00030000 && fxdVersionNeeded > 0x00030000)
{
if (UserSpecifiedVersion())
{
// Converting pass constraints to rule constraints should take care of the
// incompatibility.
m_prndr->MovePassConstraintsToRules(fxdRequested);
}
else
{
g_errorList.AddWarning(3501, NULL,
"Version ",
VersionString(fxdRequested),
" of the Silf table is inadequate to handle pass constraints; version ",
VersionString(fxdVersionNeeded),
" will be generated.");
SetSilfTableVersion(fxdVersionNeeded, false);
}
}
else
{
if (UserSpecifiedVersion())
{
g_errorList.AddWarning(3501, NULL,
"Version ",
VersionString(fxdRequested),
" of the Silf table is inadequate for your specification; version ",
VersionString(fxdVersionNeeded),
" will be generated instead.");
}
SetSilfTableVersion(fxdVersionNeeded, false);
}
}
else if (fxdVersionNeeded > fxdRequested)
{
// Eg, 2.0 -> 2.1
SetSilfTableVersion(fxdVersionNeeded, false);
}
return true;
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Assign each pass a global ID number. Record a warning if the pass numbers are not
sequential for a given table, or if there are rules in an unspecified pass. Return
the number of valid passes (those with rules in them).
----------------------------------------------------------------------------------------------*/
bool GdlRenderer::CheckTablesAndPasses(GrcManager * pcman, int * pcpassValid)
{
int nPassNum = 0;
GdlRuleTable * prultbl;
if ((prultbl = FindRuleTable("linebreak")) != NULL)
prultbl->CheckTablesAndPasses(pcman, &nPassNum);
if ((prultbl = FindRuleTable("substitution")) != NULL)
prultbl->CheckTablesAndPasses(pcman, &nPassNum);
if (Bidi())
m_iPassBidi = nPassNum;
else
m_iPassBidi = -1;
if ((prultbl = FindRuleTable("justification")) != NULL)
prultbl->CheckTablesAndPasses(pcman, &nPassNum);
if ((prultbl = FindRuleTable("positioning")) != NULL)
prultbl->CheckTablesAndPasses(pcman, &nPassNum);
// At this point nPassNum = the number of valid passes.
*pcpassValid = nPassNum;
if (nPassNum >= kMaxPasses)
{
char rgch1[20];
char rgch2[20];
itoa(nPassNum, rgch1, 10);
itoa(kMaxPasses - 1, rgch2, 10);
g_errorList.AddError(3101, NULL,
"Number of passes (",
rgch1,
") exceeds maximum of ",
rgch2);
}
else if (nPassNum == 0)
{
g_errorList.AddWarning(3502, NULL,
"No valid passes");
}
return true;
}
/*--------------------------------------------------------------------------------------------*/
void GdlRuleTable::CheckTablesAndPasses(GrcManager * pcman, int *pnPassNum)
{
if (m_vppass.size() > 1 && m_vppass[0]->HasRules())
{
g_errorList.AddError(3102, this,
m_psymName->FullName(),
" table is multi-pass, so all rules must be explicitly placed in a pass");
// but go ahead and treat it as the zeroth pass for now
}
for (size_t ipass = 0; ipass < m_vppass.size(); ++ipass)
{
if (m_vppass[ipass]->HasRules())
{
m_vppass[ipass]->AssignGlobalID(*pnPassNum);
(*pnPassNum)++;
if (pcman->Renderer()->Bidi()
&& (m_psymName->LastFieldIs("positioning") || m_psymName->LastFieldIs("justification")))
{
m_vppass[ipass]->SetPreBidiPass(1);
}
}
else if (ipass == 0)
{
// okay--zeroth pass *should* be empty if there are other passes
m_vppass[ipass]->AssignGlobalID(-1);
}
else
{
char rgch[20];
itoa(ipass, rgch, 10);
g_errorList.AddWarning(3503, this,
"Pass ",
rgch,
" of ",
m_psymName->FullName(),
" table contains no rules");
m_vppass[ipass]->AssignGlobalID(-1);
}
}
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Add ANY classes to the beginning of rules to ensure that all rules in a pass have
the same number of items before the first modified item.
----------------------------------------------------------------------------------------------*/
bool GdlRenderer::FixRulePreContexts(Symbol psymAnyClass)
{
for (size_t iprultbl = 0; iprultbl < m_vprultbl.size(); iprultbl++)
{
m_vprultbl[iprultbl]->FixRulePreContexts(psymAnyClass);
}
return true;
}
/*--------------------------------------------------------------------------------------------*/
void GdlRuleTable::FixRulePreContexts(Symbol psymAnyClass)
{
for (size_t ippass = 0; ippass < m_vppass.size(); ippass++)
{
m_vppass[ippass]->FixRulePreContexts(psymAnyClass);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlPass::FixRulePreContexts(Symbol psymAnyClass)
{
m_critMinPreContext = kMaxSlotsPerRule;
m_critMaxPreContext = 0;
// First, calculate the maximum and minimum pre-contexts lengths for all the rules
// in this pass. Also record the original rule length to use as a sort key.
size_t iprule;
for (iprule = 0; iprule < m_vprule.size(); iprule++)
{
int crit = m_vprule[iprule]->CountRulePreContexts();
m_critMinPreContext = min(m_critMinPreContext, crit);
m_critMaxPreContext = max(m_critMaxPreContext, crit);
}
// Now add "ANY" class slots to the beginning of each rule to make every rule have
// the same number of pre-context items.
for (iprule = 0; iprule < m_vprule.size(); iprule++)
{
m_vprule[iprule]->FixRulePreContexts(psymAnyClass, m_critMaxPreContext);
}
}
/*----------------------------------------------------------------------------------------------
Return the number of items at the beginning of the context that are not modified.
Also record the original rule length to use as a sort key (before it is modified
by adding ANY classes to the beginning of the rule).
----------------------------------------------------------------------------------------------*/
int GdlRule::CountRulePreContexts()
{
m_critOriginal = m_vprit.size();
m_critPreModContext = 0;
for (size_t irit = 0; irit < m_vprit.size(); irit++)
{
if (dynamic_cast<GdlSetAttrItem *>(m_vprit[irit]))
return m_critPreModContext;
m_critPreModContext++;
}
// Should have hit at least on modified item.
Assert(false);
return m_critPreModContext;
}
/*----------------------------------------------------------------------------------------------
Add instances of ANY slots to the beginning of the rule until the rule has the given
number of items before the first modified item.
----------------------------------------------------------------------------------------------*/
void GdlRule::FixRulePreContexts(Symbol psymAnyClass, int critNeeded)
{
m_critPrependedAnys = critNeeded - m_critPreModContext;
if (m_critPrependedAnys == 0)
return;
for (int iritToAdd = 0; iritToAdd < m_critPrependedAnys; iritToAdd++)
{
GdlRuleItem * prit = new GdlRuleItem(psymAnyClass);
prit->SetLineAndFile(LineAndFile());
prit->m_iritContextPos = iritToAdd;
m_vprit.insert(m_vprit.begin() + iritToAdd, prit);
}
// Increment the item positions following the inserted items, and adjust any slot
// references.
for (int irit = m_critPrependedAnys; irit < signed(m_vprit.size()); irit++)
{
m_vprit[irit]->IncContextPosition(m_critPrependedAnys);
m_vprit[irit]->AdjustSlotRefsForPreAnys(m_critPrependedAnys);
}
// Increment the scan advance position, if any.
if (m_nScanAdvance > -1)
m_nScanAdvance += m_critPrependedAnys;
}
/*----------------------------------------------------------------------------------------------
Adjust slot references to take into account the fact that ANYS have been prepended
to the beginning of the rule.
----------------------------------------------------------------------------------------------*/
void GdlRuleItem::AdjustSlotRefsForPreAnys(int critPrependedAnys)
{
if (m_pexpConstraint)
m_pexpConstraint->AdjustSlotRefsForPreAnys(critPrependedAnys);
}
/*--------------------------------------------------------------------------------------------*/
void GdlLineBreakItem::AdjustSlotRefsForPreAnys(int critPrependedAnys)
{
GdlRuleItem::AdjustSlotRefsForPreAnys(critPrependedAnys);
}
/*--------------------------------------------------------------------------------------------*/
void GdlSetAttrItem::AdjustSlotRefsForPreAnys(int critPrependedAnys)
{
GdlRuleItem::AdjustSlotRefsForPreAnys(critPrependedAnys);
for (size_t i = 0; i < m_vpavs.size(); i++)
m_vpavs[i]->AdjustSlotRefsForPreAnys(critPrependedAnys, this);
}
/*--------------------------------------------------------------------------------------------*/
void GdlSubstitutionItem::AdjustSlotRefsForPreAnys(int critPrependedAnys)
{
GdlSetAttrItem::AdjustSlotRefsForPreAnys(critPrependedAnys);
if (m_pexpSelector)
m_pexpSelector->AdjustSlotRefsForPreAnys(critPrependedAnys);
for (size_t ipexp = 0; ipexp < m_vpexpAssocs.size(); ipexp++)
m_vpexpAssocs[ipexp]->AdjustSlotRefsForPreAnys(critPrependedAnys);
}
/*--------------------------------------------------------------------------------------------*/
void GdlAttrValueSpec::AdjustSlotRefsForPreAnys(int critPrependedAnys, GdlRuleItem * /*prit*/)
{
Assert(m_psymName->FitsSymbolType(ksymtSlotAttr));
m_pexpValue->AdjustSlotRefsForPreAnys(critPrependedAnys);
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Mark classes that are used for substitution and FSM matching, and assign them
internal IDs.
----------------------------------------------------------------------------------------------*/
bool GrcManager::AssignClassInternalIDs()
{
ReplacementClassSet setpglfc;
m_prndr->MarkReplacementClasses(this, setpglfc);
// Now that we've given warnings about invalid glyphs, delete them from the classes.
m_prndr->DeleteAllBadGlyphs();
// Now actually assign the IDs for all substitution classes in the resulting set.
// The first batch of sub-IDs are assigned to the output classes, the second
// batch to input classes. Note that some classes may have both an input
// and an output ID.
int nSubID = 0;
ReplacementClassSet::iterator itset;
for (itset = setpglfc.begin();
itset != setpglfc.end();
++itset)
{
if ((*itset)->ReplcmtOutputClass())
{
(*itset)->SetReplcmtOutputID(nSubID);
m_vpglfcReplcmtClasses.push_back(*itset);
nSubID++;
}
}
// Next do the input classes that have only one glyph; they can also be in linear format.
for (itset = setpglfc.begin();
itset != setpglfc.end();
++itset)
{
GdlGlyphClassDefn * pglfc = *itset;
if (pglfc->ReplcmtInputClass() && pglfc->GlyphIDCount() <= 1)
{
if (pglfc->ReplcmtOutputClass())
// Already an output class; don't need to include it again.
pglfc->SetReplcmtInputID(pglfc->ReplcmtOutputID());
else
{
pglfc->SetReplcmtInputID(nSubID);
m_vpglfcReplcmtClasses.push_back(*itset);
nSubID++;
}
}
}
m_cpglfcLinear = nSubID;
// Finally do the input classes that have multiple glyphs. These are the classes that
// cannot be in linear format; they must be in indexed format (glyph ID / index pair,
// ordered by glyph ID).
for (itset = setpglfc.begin();
itset != setpglfc.end();
++itset)
{
GdlGlyphClassDefn * pglfc = *itset;
if (pglfc->ReplcmtInputClass() && pglfc->GlyphIDCount() > 1)
{
pglfc->SetReplcmtInputID(nSubID);
m_vpglfcReplcmtClasses.push_back(*itset);
nSubID++;
}
}
Assert(static_cast<size_t>(nSubID) == m_vpglfcReplcmtClasses.size());
if (nSubID >= kMaxReplcmtClasses)
{
char rgch1[20];
char rgch2[20];
itoa(nSubID, rgch1, 10);
itoa(kMaxReplcmtClasses - 1, rgch2, 10);
g_errorList.AddError(3103, NULL,
"Number of classes used in glyph substitution (",
rgch1,
") exceeds maximum of ",
rgch2);
}
return true;
}
/*----------------------------------------------------------------------------------------------
Mark classes that are used for substitution and FSM matching. Also assign internal IDs
for use in the FSMs.
----------------------------------------------------------------------------------------------*/
void GdlRenderer::MarkReplacementClasses(GrcManager * pcman,
ReplacementClassSet & setpglfc)
{
for (size_t iprultbl = 0; iprultbl < m_vprultbl.size(); iprultbl++)
{
m_vprultbl[iprultbl]->MarkReplacementClasses(pcman, setpglfc);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlRuleTable::MarkReplacementClasses(GrcManager * pcman,
ReplacementClassSet & setpglfc)
{
for (size_t ippass = 0; ippass < m_vppass.size(); ippass++)
{
m_vppass[ippass]->MarkReplacementClasses(pcman, setpglfc);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlPass::MarkReplacementClasses(GrcManager * pcman,
ReplacementClassSet & setpglfc)
{
for (size_t iprule = 0; iprule < m_vprule.size(); iprule++)
{
m_vprule[iprule]->MarkReplacementClasses(pcman, m_nGlobalID, setpglfc);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlRule::MarkReplacementClasses(GrcManager * pcman, int nPassID,
ReplacementClassSet & setpglfcReplace)
{
// Make lists of flags indicating whether each slot serves as an input replacement slot
// and/or an output replacement slot.
std::vector<bool> vfInput;
std::vector<bool> vfOutput;
vfInput.resize(m_vprit.size(), false);
vfOutput.resize(m_vprit.size(), false);
size_t irit;
for (irit = 0; irit < m_vprit.size(); irit++)
{
m_vprit[irit]->AssignFsmInternalID(pcman, nPassID);
m_vprit[irit]->FindSubstitutionSlots(irit, vfInput, vfOutput);
}
for (irit = 0; irit < m_vprit.size(); irit++)
{
if (vfInput[irit])
m_vprit[irit]->MarkClassAsReplacementClass(pcman, setpglfcReplace, true);
if (vfOutput[irit])
m_vprit[irit]->MarkClassAsReplacementClass(pcman, setpglfcReplace, false);
}
}
/*----------------------------------------------------------------------------------------------
Assign an internal ID to the input class, if any, to be used by the pass's FSM.
----------------------------------------------------------------------------------------------*/
void GdlRuleItem::AssignFsmInternalID(GrcManager * pcman, int nPassID)
{
if (!m_psymInput)
// Already recorded an error--undefined class.
return;
if (m_psymInput->Data())
{
GdlGlyphClassDefn * pglfcIn = m_psymInput->GlyphClassDefnData();
Assert(pglfcIn);
pcman->AddToFsmClasses(pglfcIn, nPassID);
}
// else insertion
}
/*----------------------------------------------------------------------------------------------
Mark the class as being needed for the FSM for the given pass.
----------------------------------------------------------------------------------------------*/
void GrcManager::AddToFsmClasses(GdlGlyphClassDefn * pglfc, int nPassID)
{
std::vector<GdlGlyphClassDefn *> * pvpglfcThisPass = m_prgvpglfcFsmClasses + nPassID;
if (pglfc->IsFsmClass(nPassID))
{
// Already assigned an ID for this pass.
Assert((*pvpglfcThisPass)[pglfc->FsmID(nPassID)] == pglfc);
return;
}
pglfc->MarkFsmClass(nPassID, pvpglfcThisPass->size());
pvpglfcThisPass->push_back(pglfc);
}
/*----------------------------------------------------------------------------------------------
Record the FSM ID for the given pass in the class.
----------------------------------------------------------------------------------------------*/
void GdlGlyphClassDefn::MarkFsmClass(int nPassID, int nClassID)
{
if (m_vfFsm.size() >= unsigned(nPassID + 1))
{
// Once it's set it shouldn't be changed.
Assert(!m_vfFsm[nPassID] || m_vnFsmID[nPassID] == nClassID);
}
else
{
m_vfFsm.resize(nPassID + 1, false);
m_vnFsmID.resize(nPassID + 1, -1);
}
m_vfFsm[nPassID] = true;
m_vnFsmID[nPassID] = nClassID;
}
/*----------------------------------------------------------------------------------------------
If this item is performing an substitution, set the flags for input and output slots.
----------------------------------------------------------------------------------------------*/
void GdlRuleItem::FindSubstitutionSlots(int /*irit*/,
std::vector<bool> & /*vfInput*/, std::vector<bool> & /*vfOutput*/)
{
// Do nothing.
}
/*--------------------------------------------------------------------------------------------*/
void GdlSubstitutionItem::FindSubstitutionSlots(int irit,
std::vector<bool> & vfInput, std::vector<bool> & vfOutput)
{
if (!m_psymOutput)
{
return; // no output, therefore no substitution (if another item does a substitution
// based on the input, that item will set the flag)
}
if (m_psymOutput->FitsSymbolType(ksymtClass))
{
if (m_pexpSelector)
{
// The selector indicates the input slot.
int nValue = m_pexpSelector->SlotNumber();
if (nValue >= 1 && nValue <= signed(vfInput.size()))
vfInput[nValue - 1] = true; // selectors are 1-based
else
// error condition--already handled
return;
}
else if (m_psymInput->FitsSymbolType(ksymtSpecialUnderscore))
{ // no input class, but the output class still needs an output ID.
}
else
vfInput[irit] = true;
vfOutput[irit] = true;
}
}
/*----------------------------------------------------------------------------------------------
Mark this item's class as a replacement class, and add it to the list.
----------------------------------------------------------------------------------------------*/
void GdlRuleItem::MarkClassAsReplacementClass(GrcManager * pcman,
ReplacementClassSet & setpglfcReplace, bool fInput)
{
GdlDefn * pdefn = NULL;
if (fInput)
{
if (m_psymInput)
pdefn = m_psymInput->Data();
else
{
g_errorList.AddError(3104, this,
"Item ",
PosString(),
" used as selector has no class specified");
return;
}
}
else // output
{
if (OutputSymbol())
{
// This item must be a substitution item itself.
Assert(dynamic_cast<GdlSubstitutionItem*>(this));
Assert(OutputSymbol()->FitsSymbolType(ksymtClass));
pdefn = OutputSymbol()->Data();
}
}
if (!pdefn)
return; // error--undefined class
GdlGlyphClassDefn * pglfc = dynamic_cast<GdlGlyphClassDefn *>(pdefn);
Assert(pglfc);
pglfc->FlattenMyGlyphList();
if (pcman->IgnoreBadGlyphs())
pglfc->WarnAboutBadGlyphs(true);
(fInput) ? pglfc->MarkReplcmtInputClass() : pglfc->MarkReplcmtOutputClass();
if (fInput)
{
int cw = pglfc->GlyphIDCount();
if (cw > kMaxGlyphsPerInputClass)
{
char rgchMax[20];
itoa(kMaxGlyphsPerInputClass, rgchMax, 10);
char rgchCount[20];
itoa(cw, rgchCount, 10);
g_errorList.AddError(3105, this,
"Number of glyphs (",
rgchCount,
") in class ",
pglfc->Name(),
" exceeds maximum of ",
rgchMax,
" allowed for input side of substitution");
}
}
setpglfcReplace.insert(pglfc);
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Do general error checking for all rules:
* inappropriate inclusion of LHS (substitution items)
* LB symbol in line-break pass
* non-integer selector or association
* inserted item used as selector/association
* in-rule constraint on inserted item
* LB used as selector/association
* attribute assignment inappropriate for table type
* inappropriate presence or absence of unit specifier
* inappropriate operator type (eg, assignment rather than logical)
* setting the attribute or association of a deleted item
* mismatch between associations component.X.ref settings
* reference to slot beyond length of rule
* setting something other than a slot attribute
* too many slots in the rule
* invalid glyphs in replacement class
* mismatch between size of class in left- and right-hand-sides
* invalid user-definable slot attribute
----------------------------------------------------------------------------------------------*/
bool GdlRenderer::CheckRulesForErrors(GrcGlyphAttrMatrix * pgax, GrcFont * pfont)
{
for (size_t iprultbl = 0; iprultbl < m_vprultbl.size(); iprultbl++)
{
m_vprultbl[iprultbl]->CheckRulesForErrors(pgax, pfont, this);
}
return true;
}
/*--------------------------------------------------------------------------------------------*/
void GdlRuleTable::CheckRulesForErrors(GrcGlyphAttrMatrix * pgax, GrcFont * pfont,
GdlRenderer * prndr)
{
int grfrco = kfrcoNone;
if (m_psymName->LastFieldIs("linebreak"))
grfrco = (kfrcoSetBreak | kfrcoSetDir | kfrcoPreBidi);
else if (m_psymName->LastFieldIs("substitution"))
grfrco = (kfrcoLb | kfrcoSubst | kfrcoSetCompRef | kfrcoSetDir |
kfrcoSetInsert | kfrcoPreBidi);
else if (m_psymName->LastFieldIs("justification"))
grfrco = (kfrcoNeedJust | kfrcoLb | kfrcoSubst | kfrcoSetCompRef |
kfrcoSetInsert);
else if (m_psymName->LastFieldIs("positioning"))
grfrco = (kfrcoLb | kfrcoSetInsert | kfrcoSetPos);
else
{
Assert(false);
}
for (size_t ippass = 0; ippass < m_vppass.size(); ippass++)
{
m_vppass[ippass]->CheckRulesForErrors(pgax, pfont, prndr, m_psymName, grfrco);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlPass::CheckRulesForErrors(GrcGlyphAttrMatrix * pgax, GrcFont * pfont,
GdlRenderer * prndr, Symbol psymTable, int grfrco)
{
for (size_t iprule = 0; iprule < m_vprule.size(); iprule++)
{
m_vprule[iprule]->CheckRulesForErrors(pgax, pfont, prndr, psymTable, grfrco);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlRule::CheckRulesForErrors(GrcGlyphAttrMatrix * pgax, GrcFont * pfont,
GdlRenderer * prndr, Symbol psymTable, int grfrco)
{
if (m_vprit.size() > kMaxSlotsPerRule)
{
char rgchMax[20];
itoa(kMaxSlotsPerRule, rgchMax, 10);
char rgchCount[20];
itoa(m_vprit.size(), rgchCount, 10);
g_errorList.AddError(3106, this,
"Number of slots (",
rgchCount,
") exceeds maximum of ",
rgchMax);
}
// Create lists of flags indicating which items are line-break items, insertions,
// or deletions. Also create a vector giving the size of classes in the left-hand-side.
std::vector<bool> vfLb;
std::vector<bool> vfInsertion;
std::vector<bool> vfDeletion;
size_t crit = m_vprit.size();
vfLb.resize(crit, false);
vfInsertion.resize(crit, false);
vfDeletion.resize(crit, false);
std::vector<int> vcwClassSizes;
vcwClassSizes.resize(crit, false);
bool fAnyAssocs = false;
size_t irit;
for (irit = 0; irit < crit; irit++)
{
GdlRuleItem * prit = m_vprit[irit];
GdlLineBreakItem * pritlb = dynamic_cast<GdlLineBreakItem *>(prit);
if (pritlb)
vfLb[irit] = true;
if (!prit->m_psymInput)
{ // Invalid class
vcwClassSizes[irit] = 0;
}
else
{
if (prit->OutputSymbol()->FitsSymbolType(ksymtSpecialUnderscore))
vfDeletion[irit] = true;
if (prit->m_psymInput->FitsSymbolType(ksymtSpecialUnderscore))
vfInsertion[irit] = true;
if (prit->m_psymInput->FitsSymbolType(ksymtClass))
{
GdlGlyphClassDefn * pglfc = prit->m_psymInput->GlyphClassDefnData();
if (pglfc)
vcwClassSizes[irit] = pglfc->GlyphIDCount();
else
vcwClassSizes[irit] = 0;
if (vcwClassSizes[irit] == 0)
g_errorList.AddError(3162, this,
"Empty class ", prit->m_psymInput->FullName(), " for item ", prit->PosString());
}
else
vcwClassSizes[irit] = 0;
fAnyAssocs = (fAnyAssocs || prit->AnyAssociations()
// an @ has an implied association
|| (prit->OutputSymbol() && prit->OutputSymbol()->FitsSymbolType(ksymtSpecialAt)));
}
}
bool fOkay = true;
if (grfrco & kfrcoNeedJust)
{
// Check that there is a constraint on the rule that tests for justification status.
CheckForJustificationConstraint();
}
// Do the checks for each item.
for (irit = 0; irit < crit; irit++)
{
// if (m_nScanAdvance > -1 && irit >= m_nScanAdvance &&
// (vfInsertion[irit] || vfDeletion[irit]))
// {
// g_errorList.AddError(3107, m_vprit[irit],
// "Cannot place the scan advance position (^) before insertions or deletions");
// fOkay = false;
// }
if (!m_vprit[irit]->CheckRulesForErrors(pgax, pfont, prndr, this, psymTable,
grfrco, irit, fAnyAssocs, vfLb,
vfInsertion, vfDeletion, vcwClassSizes))
{
fOkay = false;
}
}
// If all items were okay, calculate the input and ouput indices and make the
// adjustments.
if (fOkay)
{
CalculateIOIndices();
if (grfrco & kfrcoSetPos) // positioning pass
GiveOverlapWarnings(pfont, prndr->ScriptDirections());
}
else
{
m_fBadRule = true;
}
}
/*--------------------------------------------------------------------------------------------*/
bool GdlRuleItem::CheckRulesForErrors(GrcGlyphAttrMatrix * pgax, GrcFont * pfont,
GdlRenderer * prndr, GdlRule * /*prule*/, Symbol /*psymTable*/,
int /*grfrco*/, int /*irit*/, bool /*fAnyAssocs*/,
std::vector<bool> & vfLb, std::vector<bool> & vfIns, std::vector<bool> & vfDel,
std::vector<int> & /*vcwClassSizes*/ )
{
bool fOkay = true;
// Check constraint.
if (m_pexpConstraint)
{
ExpressionType expt;
bool fKeepChecking = m_pexpConstraint->CheckTypeAndUnits(&expt);
if (expt != kexptBoolean && expt != kexptOne && expt != kexptZero)
{
g_errorList.AddWarning(3504, m_pexpConstraint,
"Boolean value expected as result of constraint");
}
if (fKeepChecking)
{
if (!m_pexpConstraint->CheckRuleExpression(pfont, prndr, vfLb, vfIns, vfDel,
false, false))
{
fOkay = false;
}
}
if (fOkay)
{
bool fCanSub;
SymbolSet setBogus;
GdlExpression * pexpNew =
m_pexpConstraint->SimplifyAndUnscale(pgax, 0, setBogus, pfont, false, &fCanSub);
if (pexpNew && pexpNew != m_pexpConstraint)
{
if (fCanSub)
{
delete m_pexpConstraint;
m_pexpConstraint = pexpNew;
}
else
delete pexpNew;
}
pexpNew->CheckAttachToLookup();
}
}
return fOkay;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlLineBreakItem::CheckRulesForErrors(GrcGlyphAttrMatrix * pgax, GrcFont * pfont,
GdlRenderer * prndr, GdlRule * prule, Symbol psymTable,
int grfrco, int irit, bool fAnyAssocs,
std::vector<bool> & vfLb, std::vector<bool> & vfIns, std::vector<bool> & vfDel,
std::vector<int> & vcwSizes)
{
bool fOkay = true;
if ((grfrco & kfrcoLb) == 0)
{
g_errorList.AddError(3108, this,
"Line-break inappropriate in ",
psymTable->FullName(),
" table");
fOkay = false;
}
// method on superclass: check constraints.
if(!GdlRuleItem::CheckRulesForErrors(pgax, pfont, prndr, prule, psymTable,
grfrco, irit, fAnyAssocs, vfLb, vfIns, vfDel, vcwSizes))
{
fOkay = false;
}
return fOkay;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlSetAttrItem::CheckRulesForErrors(GrcGlyphAttrMatrix * pgax, GrcFont * pfont,
GdlRenderer * prndr, GdlRule * prule, Symbol psymTable,
int grfrco, int irit, bool fAnyAssocs,
std::vector<bool> & vfLb, std::vector<bool> & vfIns, std::vector<bool> & vfDel,
std::vector<int> & vcwSizes)
{
bool fOkay = GdlRuleItem::CheckRulesForErrors(pgax, pfont, prndr, prule, psymTable,
grfrco, irit, fAnyAssocs, vfLb, vfIns, vfDel, vcwSizes);
for (size_t ipavs = 0; ipavs < m_vpavs.size(); ipavs++)
{
if (!m_vpavs[ipavs]->CheckRulesForErrors(pgax, pfont, prndr, psymTable,
grfrco, this, irit, vfLb, vfIns, vfDel))
{
fOkay = false;
}
}
return fOkay;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlSubstitutionItem::CheckRulesForErrors(GrcGlyphAttrMatrix * pgax, GrcFont * pfont,
GdlRenderer * prndr, GdlRule * prule, Symbol psymTable,
int grfrco, int irit, bool fAnyAssocs,
std::vector<bool> & vfLb, std::vector<bool> & vfIns, std::vector<bool> & vfDel,
std::vector<int> & vcwClassSizes)
{
int crit = signed(vfLb.size());
bool fOkay = true;
if ((grfrco & kfrcoSubst) == 0)
{
g_errorList.AddError(3109, this,
"Substitution (left-hand-side) not permitted in ",
psymTable->FullName(),
" table");
fOkay = false;
}
if (OutputSymbol()->FitsSymbolType(ksymtSpecialUnderscore))
{
// Deletion
if (m_vpavs.size())
{
g_errorList.AddWarning(3505, this,
"Item ", PosString(),
": setting attributes of a deleted item");
for (size_t ipavs = 0; ipavs < m_vpavs.size(); ipavs++)
delete m_vpavs[ipavs];
m_vpavs.clear();
fOkay = false;
}
if (m_vpexpAssocs.size())
{
g_errorList.AddWarning(3506, this,
"Item ", PosString(),
": setting associations of a deleted item");
for (size_t ipexp = 0; ipexp < m_vpexpAssocs.size(); ipexp++)
delete m_vpexpAssocs[ipexp];
m_vpexpAssocs.clear();
fOkay = false;
}
if (!fAnyAssocs)
{
if (prule->ItemCountOriginal() == 2)
{
// Automatically associate the deleted item with the single other item in the rule.
// Also associate that item with itself.
int iritSub = prule->FindSubstitutionItem(irit);
if (iritSub > -1)
{
GdlRuleItem * pritSub = prule->Rule(iritSub);
pritSub->AddAssociation(prule->LineAndFile(), 1); // 1-based
pritSub->AddAssociation(prule->LineAndFile(), 2);
char rgch[20];
itoa(int(iritSub+1), rgch, 10);
g_errorList.AddWarning(3532, this,
"Item ", PosString(),
": deleted slot automatically associated with slot ", rgch);
}
}
else
{
g_errorList.AddWarning(3529, this,
"Item ", PosString(),
": deleted item was not associated with another slot");
}
}
}
if (m_psymInput->FitsSymbolType(ksymtSpecialUnderscore))
{
// Insertion
if (m_vpexpAssocs.size() == 0 && !m_psymOutput->FitsSymbolType(ksymtSpecialAt))
{
if (prule->ItemCount() == 2)
{
// Automatically associate the inserted item with the single item in the LHS.
int iritOther = (irit == 0) ? 1 : 0;
//GdlRuleItem * pritOther = prule->Rule(iritOther);
int nOther = (irit == 0) ? 2 : 1;
this->AddAssociation(prule->LineAndFile(), nOther); // 1-based
char rgch[20];
itoa(int(nOther), rgch, 10);
g_errorList.AddWarning(3533, this,
"Item ", PosString(),
": inserted item automatically associated with slot ", rgch);
}
else
{
g_errorList.AddWarning(3507, this,
"Item ", PosString(),
": inserted item was not given association");
}
}
if (m_pexpConstraint)
{
g_errorList.AddError(3110, this,
"Item ", PosString(),
": cannot include constraint on inserted item");
}
}
// If there are any component.X.ref settings, give a warning if they are not equal
// to the associations.
std::set<int> setsrCompRef;
for (size_t ipavs = 0; ipavs < m_vpavs.size(); ipavs++)
{
if (m_vpavs[ipavs]->m_psymName->IsComponentRef())
{
GdlSlotRefExpression * pexpsr =
dynamic_cast<GdlSlotRefExpression *>(m_vpavs[ipavs]->m_pexpValue);
if (pexpsr)
{
int sr = pexpsr->SlotNumber();
setsrCompRef.insert(sr);
}
}
}
if (setsrCompRef.size() > 0)
{
std::set<int> setsrAssocs;
for (size_t ipexp = 0; ipexp < m_vpexpAssocs.size() && fOkay; ipexp++)
{
int sr = m_vpexpAssocs[ipexp]->SlotNumber();
setsrAssocs.insert(sr);
}
bool fOkay = (setsrCompRef.size() == setsrAssocs.size());
for (std::set<int>::iterator it = setsrCompRef.begin(); fOkay && it != setsrCompRef.end(); ++it)
{
if (setsrAssocs.find(*it) == setsrAssocs.end()) // not a member
fOkay = false;
}
if (!fOkay)
{
g_errorList.AddWarning(3508, this,
"Item ", PosString(),
": mismatch between associations and component references");
}
}
// Mismatched class sizes.
if (OutputSymbol()->FitsSymbolType(ksymtClass))
{
int nSel;
if (m_pexpSelector)
nSel = m_pexpSelector->SlotNumber() - 1;
else
nSel = irit;
int cwInput = vcwClassSizes[nSel];
GdlGlyphClassDefn * pglfc = OutputSymbol()->GlyphClassDefnData();
if (pglfc) // otherwise, undefined class
{
int cwOutput = OutputSymbol()->GlyphClassDefnData()->GlyphIDCount();
if (cwOutput == 0)
g_errorList.AddWarning(3509, this,
"Item ", PosString(),
": empty class '",
OutputSymbol()->FullName(),
"' in right-hand-side");
else if (cwInput == 0 && cwOutput > 1)
g_errorList.AddWarning(3510, this,
"Item ", PosString(),
": class '",
OutputSymbol()->FullName(),
"' in rhs has multiple glyphs but selector class is empty");
else if (cwInput == 0 && cwOutput == 1)
{ // okay
}
else if (cwInput > cwOutput && cwOutput > 1)
g_errorList.AddWarning(3511, this,
"Item ", PosString(),
": class '",
OutputSymbol()->FullName(),
"' in rhs is smaller than selector class");
else if (cwInput < cwOutput)
g_errorList.AddWarning(3512, this,
"Item ", PosString(),
": mismatched class sizes");
else
{
Assert(cwOutput <= 1 || cwInput == cwOutput);
}
}
}
if (!GdlSetAttrItem::CheckRulesForErrors(pgax, pfont, prndr, prule, psymTable,
grfrco, irit, fAnyAssocs, vfLb, vfIns, vfDel, vcwClassSizes))
{
fOkay = false;
}
if (m_pexpSelector) // the lhs item to match in the substitution
{
int srSel = m_pexpSelector->SlotNumber();
if (srSel < 1 || srSel > crit)
{
// error condition--already handled
fOkay = false;
}
else if (vfLb[srSel - 1])
{
g_errorList.AddError(3111, this,
"Item ", PosString(),
": line-break item (#) cannot serve as glyph selector");
fOkay = false;
}
else if (vfIns[srSel - 1])
{
g_errorList.AddError(3112, this,
"Item ", PosString(),
": glyph selector cannot indicate an inserted item");
fOkay = false;
}
}
for (size_t ipexp = 0; ipexp < m_vpexpAssocs.size(); ipexp++)
{
int srAssoc = m_vpexpAssocs[ipexp]->SlotNumber(); // 1-based
if (srAssoc < 1 || srAssoc > crit)
{
g_errorList.AddError(3113, this,
"Item ", PosString(),
": association out of range");
fOkay = false;
}
else if (vfLb[srAssoc - 1])
{
g_errorList.AddError(3114, this,
"Item ", PosString(),
": association cannot be made with line-break item (#)");
fOkay = false;
}
else if (vfIns[srAssoc - 1])
{
g_errorList.AddError(3115, this,
"Item ", PosString(),
": association with an inserted item");
fOkay = false;
}
}
return fOkay;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlAttrValueSpec::CheckRulesForErrors(GrcGlyphAttrMatrix * pgax, GrcFont * pfont,
GdlRenderer * prndr, Symbol psymTable, int grfrco,
GdlRuleItem * prit, int irit,
std::vector<bool> & vfLb, std::vector<bool> & vfIns, std::vector<bool> & vfDel)
{
if (!m_psymOperator->FitsSymbolType(ksymtOpAssign))
g_errorList.AddError(3116, this,
"Attribute assignment must use an assignment operator");
bool fValueIsInputSlot = false; // true if the value of an attribute indicates a slot
// in the input stream (ie, comp.X.ref) as opposed to
// an output slot (ie, attach.to)
if (!m_psymName->FitsSymbolType(ksymtSlotAttr))
{
if (m_psymName->FitsSymbolType(ksymtGlyphAttr))
g_errorList.AddError(3117, this,
"Cannot set glyph attributes in rules");
else if (m_psymName->FitsSymbolType(ksymtGlyphMetric))
g_errorList.AddError(3118, this,
"Cannot set glyph metrics");
else
g_errorList.AddError(3119, this,
"Cannot set anything but slot attributes in rules");
return false;
}
bool fOkay = true;
if (m_psymName->IsReadOnlySlotAttr())
{
g_errorList.AddError(3120, this,
"The '",
m_psymName->FullName(),
"' attribute is read-only");
fOkay = false;
}
else if (m_psymName->IsMovement())
{
if ((grfrco & kfrcoSetPos) == 0)
{
g_errorList.AddError(3121, this,
"Cannot set the ",
m_psymName->FullName(),
" attribute in the ",
psymTable->FullName(),
" table");
fOkay = false;
}
GdlGlyphClassDefn * pglfc = prit->OutputSymbol()->GlyphClassDefnData();
if (pglfc && pglfc->IncludesGlyph(g_cman.LbGlyphId()))
{
g_errorList.AddWarning(3513, this,
"Moving a line-break glyph will have no effect");
}
// else undefined class
}
else if (m_psymName->IsAttachment())
{
if ((grfrco & kfrcoSetPos) == 0)
{
g_errorList.AddError(3122, this,
"Cannot set the ",
m_psymName->FullName(),
" attribute in the ",
psymTable->FullName(),
" table");
fOkay = false;
}
GdlGlyphClassDefn * pglfcTmp = prit->OutputSymbol()->GlyphClassDefnData();
if (pglfcTmp && pglfcTmp->IncludesGlyph(g_cman.LbGlyphId()))
{
g_errorList.AddWarning(3514, this,
"Attaching a line-break glyph will have no effect");
}
}
else if (m_psymName->LastFieldIs("breakweight"))
{
if ((grfrco & kfrcoSetBreak) == 0)
{
g_errorList.AddError(3123, this,
"Cannot set the breakweight attribute in the ",
psymTable->FullName(),
" table");
fOkay = false;
}
}
else if (m_psymName->IsComponentRef())
{
if ((grfrco & kfrcoSetCompRef) == 0)
{
g_errorList.AddError(3124, this,
"Cannot set the ",
m_psymName->FullName(),
" attribute in the ",
psymTable->FullName(),
" table");
fOkay = false;
}
fValueIsInputSlot = true;
}
else if (m_psymName->LastFieldIs("directionality"))
{
if ((grfrco & kfrcoSetDir) == 0)
{
g_errorList.AddError(3125, this,
"Cannot set the directionality attribute in the ",
psymTable->FullName(),
" table");
fOkay = false;
}
}
else if (m_psymName->LastFieldIs("insert"))
{
if ((grfrco & kfrcoSetInsert) == 0)
{
g_errorList.AddError(3126, this,
"Cannot set the insert attribute in the ",
psymTable->FullName(),
" table");
fOkay = false;
}
}
else if (m_psymName->DoesJustification())
{
if (grfrco & kfrcoPreBidi)
{
if (m_psymName->LastFieldIs("width"))
{
g_errorList.AddWarning(3515, this,
"Setting ",
m_psymName->FullName(),
" too early in the process (should be before the bidi pass)");
}
}
else
{
if (m_psymName->LastFieldIs("stretch") || m_psymName->LastFieldIs("shrink") ||
m_psymName->LastFieldIs("step") || m_psymName->LastFieldIs("weight"))
{
g_errorList.AddWarning(3516, this,
"Setting ",
m_psymName->FullName(),
" too late in the process (should be before the bidi pass)");
}
}
}
else if (m_psymName->IsMeasureAttr())
{
// These can pretty much go anywhere, as far as I can see.
}
else if (m_psymName->IsUserDefinableSlotAttr())
{
int nIndex = m_psymName->UserDefinableSlotAttrIndex();
if (nIndex < 0)
{
g_errorList.AddError(3127, this,
"Invalid slot attribute: ", m_psymName->FullName());
fOkay = false;
}
else if (nIndex >= kMaxUserDefinableSlotAttrs)
{
char rgch[20];
itoa(kMaxUserDefinableSlotAttrs, rgch, 10);
g_errorList.AddError(3128, this,
"Invalid slot attribute: ", m_psymName->FullName(),
"; maximum is ", rgch);
fOkay = false;
}
else
{
prndr->SetNumUserDefn(nIndex);
}
}
else
{
Assert(false);
return false;
}
ExpressionType exptExpected = m_psymName->ExpType();
Assert(exptExpected != kexptUnknown);
ExpressionType exptFound;
bool fKeepChecking = m_pexpValue->CheckTypeAndUnits(&exptFound);
if (!EquivalentTypes(exptExpected, exptFound))
{
if (exptExpected == kexptSlotRef)
{
// Make it an error, not a warning, because we can't do adequate checking below.
g_errorList.AddError(3129, this,
"Value for ",
m_psymName->FullName(),
" attribute must be a slot reference");
fKeepChecking = false;
fOkay = false;
}
else if (exptExpected == kexptMeas && exptFound == kexptNumber)
{
g_errorList.AddWarning(3517, this,
"Slot attribute ",
m_psymName->FullName(),
" expects a scaled number");
}
else if (exptFound == kexptUnknown)
{
g_errorList.AddError(3130, this,
"Invalid value for ",
m_psymName->FullName());
fOkay = false;
fKeepChecking = false;
}
else if (m_psymName->IsUserDefinableSlotAttr())
{
// any value is appropriate
}
else
g_errorList.AddWarning(3518, this,
"Assigned value has inappropriate type for '",
m_psymName->FullName(),
"' attribute");
}
if (fKeepChecking)
{
int nTmp;
if (m_psymName->IsAttachTo() && m_pexpValue->ResolveToInteger(&nTmp, true) && nTmp == 0)
{
// okay - attach.to = @0 has a special meaning
}
else
{
if (!m_pexpValue->CheckRuleExpression(pfont, prndr, vfLb, vfIns, vfDel,
true, fValueIsInputSlot))
{
fOkay = false;
}
if (m_psymName->IsAttachTo())
{
GdlSlotRefExpression * pexpsr = dynamic_cast<GdlSlotRefExpression *>(m_pexpValue);
if (pexpsr)
{
if (pexpsr->SlotNumber() == irit + 1)
g_errorList.AddWarning(3519, this,
"Item ", prit->PosString(),
": slot is being attached to itself--no attachment will result");
}
}
}
bool fCanSub;
SymbolSet setBogus;
GdlExpression * pexpNewValue =
m_pexpValue->SimplifyAndUnscale(pgax, 0, setBogus, pfont, false, &fCanSub);
if (pexpNewValue && pexpNewValue != m_pexpValue)
{
if (fCanSub)
{
delete m_pexpValue;
m_pexpValue = pexpNewValue;
}
else
delete pexpNewValue;
}
// Use a special zero value for attach.at.gpoint and attach.with.gpoint, to
// distinguish from the unspecified case.
if ((m_psymName->IsAttachAtField() || m_psymName->IsAttachWithField()) &&
m_psymName->LastFieldIs("gpoint"))
{
int n;
m_pexpValue->ResolveToInteger(&n, false);
if (n == 0)
m_pexpValue->SetSpecialZero();
}
}
return fOkay;
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Return true if this item sets has any associations.
----------------------------------------------------------------------------------------------*/
bool GdlRuleItem::AnyAssociations()
{
return false;
}
bool GdlSubstitutionItem::AnyAssociations()
{
return (m_vpexpAssocs.size() > 0);
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Check that there is a constraint on the rule, or on at least one of its items, that
tests justification status. This is expected in the justification table. If not,
give a warning.
TODO: if we implement pass constraints, these tests should be in the pass constraints.
----------------------------------------------------------------------------------------------*/
bool GdlRule::CheckForJustificationConstraint()
{
for (size_t ipexp = 0; ipexp < m_vpexpConstraints.size(); ipexp++)
{
GdlExpression * pexp = m_vpexpConstraints[ipexp];
if (pexp->TestsJustification())
return true;
}
// No such constraint on the rule itself. Look at the items.
for (size_t irit = 0; irit < m_vprit.size(); irit++)
{
GdlRuleItem * prit = m_vprit[irit];
if (prit->CheckForJustificationConstraint())
return true;
}
// No such constraint on the items. Record a warning.
g_errorList.AddWarning(3520, this,
"Rules in justification table should test justification status.");
return false;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlRuleItem::CheckForJustificationConstraint()
{
if (m_pexpConstraint)
return m_pexpConstraint->TestsJustification();
else
return false;
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Calculate input and output indices for each rule item, that is, indices relative to the
input and output streams. Specifically, the input index is the rule index
ignoring inserted items, and the output index is the rule index ignoring deleted items.
Make the associations and slot references use the appropriate ones: component.X.ref and
associations use input indices, and attach.to uses output indices.
Also calculate the scan-advance value for both input and output.
Inserted items have a negative input-index, equal to (-1 * the next item's input-index);
deleted items have a negative output-index, equal to (-1 * the next item's output-index).
----------------------------------------------------------------------------------------------*/
void GdlRule::CalculateIOIndices()
{
int critInput = 0;
int critOutput = 0;
// Assign the indices for each item. Generate a map of indices to use in later steps.
size_t irit;
for (irit = 0; irit < m_vprit.size(); irit++)
m_vprit[irit]->AssignIOIndices(&critInput, &critOutput, m_viritInput, m_viritOutput);
// Adjust the slot references to use the new indices.
for (irit = 0; irit < m_vprit.size(); irit++)
m_vprit[irit]->AdjustToIOIndices(m_viritInput, m_viritOutput);
// Adjust the scan-advance indicator to take the deleted items into account.
if (m_nScanAdvance == -1)
{
m_nOutputAdvance = -1;
}
else
{
if (m_nScanAdvance >= signed(m_vprit.size()))
{
Assert(static_cast<size_t>(m_nScanAdvance) == m_vprit.size());
m_nOutputAdvance = m_viritOutput[m_vprit.size() - 1];
m_nOutputAdvance = (m_nOutputAdvance < 0) ?
m_nOutputAdvance * -1 :
m_nOutputAdvance + 1;
}
else
{
m_nOutputAdvance = m_viritOutput[m_nScanAdvance];
if (m_nOutputAdvance < 0) // just before a deleted item
m_nOutputAdvance = (m_nOutputAdvance * -1) - 1;
}
}
}
/*----------------------------------------------------------------------------------------------
Assign each rule item an input and an output index.
----------------------------------------------------------------------------------------------*/
void GdlRuleItem::AssignIOIndices(int * pcritInput, int * pcritOutput,
std::vector<int> & viritInput, std::vector<int> & viritOutput)
{
m_nInputIndex = (*pcritInput)++;
m_nOutputIndex = (*pcritOutput)++;
viritInput.push_back(m_nInputIndex);
viritOutput.push_back(m_nOutputIndex);
}
/*--------------------------------------------------------------------------------------------*/
void GdlSubstitutionItem::AssignIOIndices(int * pcritInput, int * pcritOutput,
std::vector<int> & viritInput, std::vector<int> & viritOutput)
{
if (m_psymInput && m_psymInput->FitsSymbolType(ksymtSpecialUnderscore))
{
// insertion
m_nInputIndex = (*pcritInput * -1) - 1;
viritInput.push_back(m_nInputIndex);
}
else
{
m_nInputIndex = (*pcritInput)++;
viritInput.push_back(m_nInputIndex);
}
if (m_psymOutput && m_psymOutput->FitsSymbolType(ksymtSpecialUnderscore))
{
// deletion
m_nOutputIndex = (*pcritOutput * -1) - 1;
viritOutput.push_back(m_nOutputIndex);
}
else
{
m_nOutputIndex = (*pcritOutput)++;
viritOutput.push_back(m_nOutputIndex);
}
}
/*----------------------------------------------------------------------------------------------
Modify the rule items to use either input or output indices.
----------------------------------------------------------------------------------------------*/
void GdlRuleItem::AdjustToIOIndices(std::vector<int> & viritInput, std::vector<int> & /*viritOutput*/)
{
// Constraints are read from the input stream.
if (m_pexpConstraint)
m_pexpConstraint->AdjustToIOIndices(viritInput, NULL);
}
/*--------------------------------------------------------------------------------------------*/
void GdlLineBreakItem::AdjustToIOIndices(std::vector<int> & viritInput, std::vector<int> & viritOutput)
{
GdlRuleItem::AdjustToIOIndices(viritInput, viritOutput);
}
/*--------------------------------------------------------------------------------------------*/
void GdlSetAttrItem::AdjustToIOIndices(std::vector<int> & viritInput, std::vector<int> & viritOutput)
{
GdlRuleItem::AdjustToIOIndices(viritInput, viritOutput);
for (size_t i = 0; i < m_vpavs.size(); i++)
m_vpavs[i]->AdjustToIOIndices(this, viritInput, viritOutput);
}
/*--------------------------------------------------------------------------------------------*/
void GdlSubstitutionItem::AdjustToIOIndices(std::vector<int> & viritInput, std::vector<int> & viritOutput)
{
GdlSetAttrItem::AdjustToIOIndices(viritInput, viritOutput);
// for selectors: use input indices
if (m_pexpSelector)
{
int sr = m_pexpSelector->SlotNumber(); // 1-based;
m_nSelector = viritInput[sr - 1];
Assert(m_nSelector >= 0); // otherwise, error of using an inserted item as a selector
}
else
m_nSelector = -1; // default, same item
// for associations: use input indices
for (size_t ipexp = 0; ipexp < m_vpexpAssocs.size(); ipexp++)
{
int srAssoc = m_vpexpAssocs[ipexp]->SlotNumber(); // 1-based
Assert(srAssoc >= 1 && static_cast<size_t>(srAssoc) <= viritInput.size());
m_vnAssocs.push_back(viritInput[srAssoc - 1]);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlAttrValueSpec::AdjustToIOIndices(GdlRuleItem * prit,
std::vector<int> & viritInput, std::vector<int> & viritOutput)
{
Assert(m_psymName->FitsSymbolType(ksymtSlotAttr));
if (m_psymName->ExpType() == kexptSlotRef)
{
if (m_psymName->IsComponentRef())
m_pexpValue->AdjustToIOIndices(viritInput, NULL);
else if (m_psymName->IsAttachment())
{
Assert(m_psymName->LastFieldIs("to")); // must be attach.to
m_pexpValue->AdjustToIOIndices(viritOutput, prit);
}
else
{
Assert(false);
}
}
else
m_pexpValue->AdjustToIOIndices(viritInput, NULL);
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Generate warning messages if there are any contiguous glyphs whose bounding boxes
overlap (in the vertical dimension) but are not attached.
Note that these checks are only run for positioning rules.
----------------------------------------------------------------------------------------------*/
void GdlRule::GiveOverlapWarnings(GrcFont * pfont, int grfsdc)
{
for (int irit = 0; irit < signed(m_vprit.size()) - 1; irit++)
{
GdlRuleItem * prit1 = m_vprit[irit];
GdlRuleItem * prit2 = m_vprit[irit + 1];
if (prit1->m_iritContextPosOrig < 0 || prit1->m_iritContextPosOrig >= signed(m_vprit.size())) // eg, ANY
continue;
if (prit2->m_iritContextPosOrig < 0 || prit2->m_iritContextPosOrig >= signed(m_vprit.size())) // eg, ANY
continue;
// Figure out what these items are attached to. A value of zero means it is
// deliberately attached to nothing.
int nAtt1 = prit1->AttachedToSlot();
int nAtt2 = prit2->AttachedToSlot();
if (nAtt1 == 0 || nAtt2 == 0)
continue;
if (nAtt1 == prit2->m_iritContextPos + 1) // m_iritContextPos is 0-based
continue;
if (nAtt2 == prit1->m_iritContextPos + 1)
continue;
if (prit1->OverlapsWith(prit2, pfont, grfsdc))
{
// Give warning.
g_errorList.AddWarning(3521, this,
"Vertical overlap between glyphs in items ", prit1->PosString(), " and ",
prit2->PosString(), "; attachment may be needed");
}
}
}
/*----------------------------------------------------------------------------------------------
Return the slot the item is attached to, or -1 if none.
----------------------------------------------------------------------------------------------*/
int GdlRuleItem::AttachedToSlot()
{
return -1;
}
int GdlSetAttrItem::AttachedToSlot()
{
Assert(m_nInputIndex == m_nOutputIndex); // because this is a positioning rule
for (size_t ipavs = 0; ipavs < m_vpavs.size(); ipavs++)
{
if (m_vpavs[ipavs]->m_psymName->IsAttachTo())
{
int nSlot;
m_vpavs[ipavs]->m_pexpValue->ResolveToInteger(&nSlot, true);
return nSlot;
}
}
return -1;
}
/*----------------------------------------------------------------------------------------------
Return true if any glyph in the recipient item's glyph class overlaps along the
vertical axis with any glyph in the argument item's glyph class.
----------------------------------------------------------------------------------------------*/
bool GdlRuleItem::OverlapsWith(GdlRuleItem * prit, GrcFont * pfont, int grfsdc)
{
Symbol psymGlyphs1 = this->m_psymInput;
Symbol psymGlyphs2 = prit->m_psymInput;
GdlGlyphClassDefn * glfd1 = psymGlyphs1->GlyphClassDefnData();
GdlGlyphClassDefn * glfd2 = psymGlyphs2->GlyphClassDefnData();
if (!glfd1 || !glfd2)
return false;
if ((grfsdc & kfsdcHorizLtr || grfsdc == 0) && glfd1->HasOverlapWith(glfd2, pfont))
return true;
if (grfsdc & kfsdcHorizRtl && glfd2->HasOverlapWith(glfd1, pfont))
return true;
return false;
}
/*----------------------------------------------------------------------------------------------
Return true if there are any overlaps along the x-axis between any glyphs in the two
classes.
----------------------------------------------------------------------------------------------*/
bool GdlGlyphClassDefn::HasOverlapWith(GdlGlyphClassMember * pglfdLeft, GrcFont * pfont)
{
for (size_t iglfd = 0; iglfd < m_vpglfdMembers.size(); iglfd++)
{
if (m_vpglfdMembers[iglfd]->HasOverlapWith(pglfdLeft, pfont))
return true;
}
return false;
}
bool GdlGlyphDefn::HasOverlapWith(GdlGlyphClassMember * pglfdLeft, GrcFont * pfont)
{
GdlGlyphDefn * pglfLeft = dynamic_cast<GdlGlyphDefn*>(pglfdLeft);
if (m_glft == kglftPseudo)
{
return m_pglfOutput->HasOverlapWith(pglfdLeft, pfont);
}
else if (pglfLeft)
{
if (pglfLeft->m_glft == kglftPseudo)
{
return HasOverlapWith(pglfLeft->m_pglfOutput, pfont);
}
else
{
for (size_t iw1 = 0; iw1 < this->m_vwGlyphIDs.size(); iw1++)
{
utf16 w1 = this->m_vwGlyphIDs[iw1];
if (w1 == kBadGlyph)
continue;
utf16 nActual = g_cman.ActualForPseudo(w1);
if (nActual != 0)
w1 = nActual;
int nLsb = pfont->GetGlyphMetric(w1, kgmetLsb, this);
for (size_t iw2 = 0; iw2 < pglfLeft->m_vwGlyphIDs.size(); iw2++)
{
utf16 w2 = pglfLeft->m_vwGlyphIDs[iw2];
if (w2 == kBadGlyph)
continue;
utf16 nActual = g_cman.ActualForPseudo(w2);
if (nActual != 0)
w2 = nActual;
int nRsb = pfont->GetGlyphMetric(w2, kgmetRsb, pglfLeft);
if (nLsb + nRsb < 0)
return true;
}
}
}
}
else
{
GdlGlyphClassDefn * pglfcLeft = dynamic_cast<GdlGlyphClassDefn*>(pglfdLeft);
Assert(pglfcLeft);
for (size_t iglfd = 0; iglfd < pglfcLeft->m_vpglfdMembers.size(); iglfd++)
{
if (HasOverlapWith(pglfcLeft->m_vpglfdMembers[iglfd], pfont))
return true;
}
}
return false;
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Delete all invalid glyphs.
----------------------------------------------------------------------------------------------*/
void GdlRenderer::DeleteAllBadGlyphs()
{
for (size_t iglfc = 0; iglfc < m_vpglfc.size(); iglfc++)
m_vpglfc[iglfc]->DeleteBadGlyphs();
}
/*----------------------------------------------------------------------------------------------
Delete invalid glyphs from the class
----------------------------------------------------------------------------------------------*/
bool GdlGlyphClassDefn::DeleteBadGlyphs()
{
bool fRet = false;
for (size_t iglfd = 0; iglfd < m_vpglfdMembers.size(); iglfd++)
{
fRet = (fRet || m_vpglfdMembers[iglfd]->DeleteBadGlyphs());
}
return fRet;
}
bool GdlGlyphDefn::DeleteBadGlyphs()
{
bool fRet = false;
for (int i = signed(m_vwGlyphIDs.size()) - 1; i >=0; i--)
{
if (m_vwGlyphIDs[i] == kBadGlyph)
{
m_vwGlyphIDs.erase(m_vwGlyphIDs.begin() + i);
fRet = true;
}
}
return fRet;
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Give a warning about any invalid glyphs in the class.
----------------------------------------------------------------------------------------------*/
bool GdlGlyphClassDefn::WarnAboutBadGlyphs(bool fTop)
{
bool fRet = false;
for (size_t iglfd = 0; iglfd < m_vpglfdMembers.size(); iglfd++)
{
fRet = (fRet || m_vpglfdMembers[iglfd]->WarnAboutBadGlyphs(false));
}
if (fRet && fTop)
g_errorList.AddWarning(3522, this,
"Class '", m_staName, "' is used in substitution but has invalid glyphs");
return fRet;
}
#ifdef NDEBUG
bool GdlGlyphDefn::WarnAboutBadGlyphs(bool)
#else
bool GdlGlyphDefn::WarnAboutBadGlyphs(bool fTop)
#endif
{
Assert(!fTop);
bool fRet = false;
for (int i = signed(m_vwGlyphIDs.size()) - 1; i >=0; i--)
{
fRet = (fRet || m_vwGlyphIDs[i] == kBadGlyph);
}
return fRet;
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Check for the error of cross-line contextualization across more than two lines.
Record the maximum number of slots occurring in a cross-line contextualization rule.
----------------------------------------------------------------------------------------------*/
bool GdlRenderer::CheckLBsInRules()
{
for (size_t iprultbl = 0; iprultbl < m_vprultbl.size(); iprultbl++)
{
m_vprultbl[iprultbl]->CheckLBsInRules();
}
return true;
}
/*--------------------------------------------------------------------------------------------*/
void GdlRuleTable::CheckLBsInRules()
{
for (size_t ippass = 0; ippass < m_vppass.size(); ippass++)
{
m_vppass[ippass]->CheckLBsInRules(m_psymName);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlPass::CheckLBsInRules(Symbol psymTable)
{
m_fLB = false;
m_fCrossLB = false;
m_critPreLB = 0;
m_critPostLB = 0;
m_fReproc = false;
int critPreLB = 0;
int critPostLB = 0;
for (size_t iprule = 0; iprule < m_vprule.size(); iprule++)
{
if (m_vprule[iprule]->IsBadRule())
continue; // don't process if we've discovered errors
bool fAnyLB = m_vprule[iprule]->CheckLBsInRules(psymTable, &critPreLB, &critPostLB);
m_fLB = (m_fLB || fAnyLB);
if (critPreLB > 0 && critPostLB > 0)
{
m_fCrossLB = true;
m_critPreLB = max(m_critPreLB, critPreLB);
m_critPostLB = max(m_critPostLB, critPostLB);
}
if (m_vprule[iprule]->HasReprocessing())
m_fReproc = true;
}
Assert(!m_fCrossLB || m_fLB);
Assert(!m_fCrossLB || m_critPreLB > 0 || m_critPostLB > 0);
}
/*--------------------------------------------------------------------------------------------*/
bool GdlRule::CheckLBsInRules(Symbol /*psymTable*/, int * pcritPreLB, int * pcritPostLB)
{
// Check to make sure that there are at most two line-break slots in the rule,
// and if there are two, they are the first and last. While we're at it, count the
// items before and after the line-break.
int critLB = 0;
int critPreTmp = 0;
int critPostTmp = 0;
int critPost2Tmp = 0;
for (size_t iprit = 0; iprit < m_vprit.size(); iprit++)
{
if (dynamic_cast<GdlSetAttrItem *>(m_vprit[iprit]) == NULL &&
m_vprit[iprit]->OutputSymbol()->LastFieldIs("#"))
{
critLB++;
}
else
{
if (signed(iprit) < m_critPrependedAnys)
{
// prepended ANY doesn't count
}
else if (critLB == 0)
critPreTmp++;
else if (critLB == 1)
critPostTmp++;
else
critPost2Tmp++;
}
}
if (critLB == 0)
{
// No line-breaks in this rule.
*pcritPreLB = 0;
*pcritPostLB = 0;
return false;
}
if (critLB > 2 || (critLB == 2 && (critPreTmp > 0 || critPost2Tmp > 0)))
{
g_errorList.AddError(3131, this,
"Cross-line contextualization involving more than two lines.");
return true;
}
Assert(critPost2Tmp == 0);
*pcritPreLB = critPreTmp;
*pcritPostLB = critPostTmp;
return true;
}
/*----------------------------------------------------------------------------------------------
Return true if the rule has its scan position set so that reprocessing will occur.
As a side effect, if there was a caret in the rule, record the default scan position,
which will be used later in outputting the rule commands.
----------------------------------------------------------------------------------------------*/
bool GdlRule::HasReprocessing()
{
if (m_nOutputAdvance == -1)
return false;
// Count the number of unmodified items at the end of the rule; these do not need to
// be processed, and the default scan advance position is just before these.
size_t iritLim = m_vprit.size();
while (iritLim > 0 && !dynamic_cast<GdlSetAttrItem *>(m_vprit[iritLim - 1]))
iritLim--;
if (iritLim < m_vprit.size())
{
GdlRuleItem * pritLim = m_vprit[iritLim];
Assert(pritLim->m_nOutputIndex >= 0);
m_nDefaultAdvance = pritLim->m_nOutputIndex;
}
else
{
Assert(iritLim == m_vprit.size());
m_nDefaultAdvance = m_vprit.back()->m_nOutputIndex;
m_nDefaultAdvance++;
if (m_nDefaultAdvance < 0)
// Note that when the last slot is a deletion, the ++ above in effect subtracted
// 1, reflecting the fact that their is no output for the deletion.
m_nDefaultAdvance = m_nDefaultAdvance * -1;
}
return (m_nOutputAdvance < m_nDefaultAdvance);
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Replace any kern assigments with the equivalent shift and advance.
----------------------------------------------------------------------------------------------*/
void GdlRenderer::ReplaceKern(GrcManager * pcman)
{
for (size_t iprultbl = 0; iprultbl < m_vprultbl.size(); iprultbl++)
{
m_vprultbl[iprultbl]->ReplaceKern(pcman);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlRuleTable::ReplaceKern(GrcManager * pcman)
{
for (size_t ippass = 0; ippass < m_vppass.size(); ippass++)
{
m_vppass[ippass]->ReplaceKern(pcman);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlPass::ReplaceKern(GrcManager * pcman)
{
for (size_t iprule = 0; iprule < m_vprule.size(); iprule++)
{
m_vprule[iprule]->ReplaceKern(pcman);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlRule::ReplaceKern(GrcManager * pcman)
{
for (size_t iprit = 0; iprit < m_vprit.size(); iprit++)
{
m_vprit[iprit]->ReplaceKern(pcman);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlRuleItem::ReplaceKern(GrcManager * /*pcman*/)
{
// Do nothing.
}
/*--------------------------------------------------------------------------------------------*/
void GdlSetAttrItem::ReplaceKern(GrcManager * pcman)
{
for (size_t ipavs = 0; ipavs < m_vpavs.size(); ipavs++)
{
GdlAttrValueSpec * pavsShift;
GdlAttrValueSpec * pavsAdvance;
bool fKern = m_vpavs[ipavs]->ReplaceKern(pcman, &pavsShift, &pavsAdvance);
if (fKern)
{
delete m_vpavs[ipavs];
m_vpavs[ipavs] = pavsShift;
m_vpavs.insert(m_vpavs.begin() + ipavs + 1, pavsAdvance);
ipavs++;
}
}
}
/*----------------------------------------------------------------------------------------------
If this a statement setting the kern attribute, generate the corresponding shift and
advance statements, and return true. Return false otherwise.
Specifically,
kern.x = -10m becomes shift.x = -10m; adv.x = advancewidth - 10m
kern.x += 10m becomes shift.x += 10m; adv.x += 10m
----------------------------------------------------------------------------------------------*/
bool GdlAttrValueSpec::ReplaceKern(GrcManager * pcman,
GdlAttrValueSpec ** ppavsShift, GdlAttrValueSpec ** ppavsAdvance)
{
if (!m_psymName->FieldIs(0, "kern"))
return false;
GrcStructName xns;
m_psymName->GetStructuredName(&xns);
xns.DeleteField(0);
xns.InsertField(0, "advance");
Symbol psymNameAdvance = pcman->SymbolTable()->FindSymbol(xns);
if (!psymNameAdvance)
{
g_errorList.AddError(3132, this,
"Invalid kern assignment");
return false;
}
xns.DeleteField(0);
xns.InsertField(0, "shift");
Symbol psymNameShift = pcman->SymbolTable()->FindSymbol(xns);
if (!psymNameShift)
{
g_errorList.AddError(3133, this,
"Invalid kern assignment");
return false;
}
GdlExpression * pexpValueShift = m_pexpValue->Clone();
*ppavsShift = new GdlAttrValueSpec(psymNameShift, m_psymOperator, pexpValueShift);
GdlExpression * pexpValueAdvance = m_pexpValue->Clone();
if (m_psymOperator->FieldIs(0, "="))
{
// Base 'advance' off of advancewidth (or advanceheight).
Symbol psymAdvMetric =
pcman->SymbolTable()->FindSymbol("advancewidth");
if (xns.FieldEquals(1, "y"))
psymAdvMetric = pcman->SymbolTable()->FindSymbol("advanceheight");
Assert(psymAdvMetric);
GdlLookupExpression * pexplook = new GdlLookupExpression(psymAdvMetric);
Symbol psymPlus = pcman->SymbolTable()->FindSymbol("+");
Assert(psymPlus);
pexpValueAdvance = new GdlBinaryExpression(psymPlus, pexplook, pexpValueAdvance);
}
*ppavsAdvance = new GdlAttrValueSpec(psymNameAdvance, m_psymOperator, pexpValueAdvance);
return true;
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Check that the rules and glyph attributes are compatible with the requested version of the
Silf table. If not, return the version required.
Also return the compiler version needed to support the GDL.
This routine assumes that we can always sucessfully use a later version.
----------------------------------------------------------------------------------------------*/
bool GrcManager::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded, int * pfxdCpilrNeeded,
bool * pfFixPassConstraints)
{
*pfxdNeeded = fxdVersion;
if (fxdVersion >= kfxdMaxSilfVersion)
return true;
if (!m_fBasicJust)
{
// We need version 2.0 for basic justification.
*pfxdNeeded = max(0x00020000, *pfxdNeeded);
*pfxdCpilrNeeded = max(0x00020000, *pfxdCpilrNeeded);
}
if (m_vpglfcReplcmtClasses.size() >= kMaxReplcmtClassesV1_2)
{
// For a large set of replacement classes, we need 3.0.
*pfxdNeeded = max(0x00030000, *pfxdNeeded);
*pfxdCpilrNeeded = max(0x00030000, *pfxdCpilrNeeded);
}
// For now, the Glat table version does not affect the other tables.
//if (m_vpsymGlyphAttrs.size() >= kMaxGlyphAttrsGlat1)
//{
// // For a large number of glyph attributes, we need 3.0.
// *pfxdNeeded = max(0x00030000, *pfxdNeeded);
//}
if (*pfxdNeeded > fxdVersion)
*pfFixPassConstraints = false;
bool fRet = (*pfxdNeeded <= fxdVersion);
fRet = (m_prndr->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded, pfFixPassConstraints)
&& fRet);
return fRet;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlRenderer::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded, int * pfxdCpilrNeeded,
bool * pfFixPassConstraints)
{
bool fRet = true;
// Glyph atrributes:
for (size_t ipglfc = 0; ipglfc < m_vpglfc.size(); ipglfc++)
{
fRet = m_vpglfc[ipglfc]->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded)
&& fRet;
if (!fRet)
*pfFixPassConstraints = false; // something else is a problem
}
// Rules:
for (size_t iprultbl = 0; iprultbl < m_vprultbl.size(); iprultbl++)
{
fRet = m_vprultbl[iprultbl]->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded,
pfFixPassConstraints)
&& fRet;
}
return fRet;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlGlyphClassDefn::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded, int * pfxdCpilrNeeded)
{
bool fRet = true;
// For each attribute assignment in the value list:
for (size_t ipglfa = 0; ipglfa < m_vpglfaAttrs.size(); ipglfa++)
{
Symbol psym = m_vpglfaAttrs[ipglfa]->GlyphSymbol();
if (psym->IsMeasureAttr() || psym->DoesJustification())
{
// For justification, we need Silf version 2.0.
fRet = (fxdVersion >= 0x00020000);
*pfxdNeeded = max(*pfxdNeeded, 0x00020000);
*pfxdCpilrNeeded = max(*pfxdCpilrNeeded, 0x00020000);
}
else if (psym->IsMirrorAttr())
{
// For mirroring, we need version Silf 2.1 or 3.2.
fRet = (fxdVersion >= 0x00020000);
if (*pfxdNeeded < 0x00030000)
*pfxdNeeded = max(*pfxdNeeded, 0x00020001);
else
*pfxdNeeded = max(*pfxdNeeded, 0x00030002);
*pfxdCpilrNeeded = max(*pfxdCpilrNeeded, 0x00040001);
}
}
return fRet;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlRuleTable::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded, int * pfxdCpilrNeeded,
bool * pfFixPassConstraints)
{
bool fRet = true;
for (size_t ippass = 0; ippass < m_vppass.size(); ippass++)
{
fRet = m_vppass[ippass]->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded,
pfFixPassConstraints)
&& fRet;
}
return fRet;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlPass::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded, int * pfxdCpilrNeeded,
bool * pfFixPassConstraints)
{
bool fRet = true;
if (m_vpexpConstraints.size() > 0)
{
// Pass constraints need 3.1. (Version 3.0 outputs empty pass constraints.)
fRet = (fxdVersion >= 0x00030001);
*pfxdNeeded = max(*pfxdNeeded, 0x00030001);
*pfxdCpilrNeeded = max(*pfxdCpilrNeeded, 0x00040000);
}
for (size_t iprule = 0; iprule < m_vprule.size(); iprule++)
{
bool fRetTmp = m_vprule[iprule]->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded);
if (!fRetTmp)
*pfFixPassConstraints = false; // something else is a problem
fRet = fRet && fRetTmp;
}
return fRet;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlRule::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded, int * pfxdCpilrNeeded)
{
bool fRet = true;
for (size_t iprit = 0; iprit < m_vprit.size(); iprit++)
{
fRet = m_vprit[iprit]->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded)
&& fRet;
}
return fRet;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlRuleItem::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded, int * pfxdCpilrNeeded)
{
if (m_pexpConstraint)
{
return m_pexpConstraint->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded);
}
else
return true;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlSetAttrItem::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded, int * pfxdCpilrNeeded)
{
bool fRet = GdlRuleItem::CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded);
for (size_t ipavs = 0; ipavs < m_vpavs.size(); ipavs++)
{
fRet = m_vpavs[ipavs]->CompatibleWithVersion(fxdVersion, pfxdNeeded, pfxdCpilrNeeded)
&& fRet;
}
return fRet;
}
/*--------------------------------------------------------------------------------------------*/
bool GdlAttrValueSpec::CompatibleWithVersion(int fxdVersion, int * pfxdNeeded, int * pfxdCpilrNeeded)
{
bool fRet = true;
if (m_psymName->IsMeasureAttr() || m_psymName->DoesJustification())
{
// Measuring and justification need 2.0.
*pfxdNeeded = max(*pfxdNeeded, 0x00020000);
*pfxdCpilrNeeded = max(*pfxdCpilrNeeded, 0x00020000);
fRet = (fxdVersion >= 0x00020000);
}
return fRet;
}
/**********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Convert pass constraints to rule constraints.
This is needed when the version to be output is earlier than what is compatible with
pass constraints.
----------------------------------------------------------------------------------------------*/
void GdlRenderer::MovePassConstraintsToRules(int fxdSilfVersion)
{
for (size_t iprultbl = 0; iprultbl < m_vprultbl.size(); iprultbl++)
{
m_vprultbl[iprultbl]->MovePassConstraintsToRules(fxdSilfVersion);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlRuleTable::MovePassConstraintsToRules(int fxdSilfVersion)
{
for (size_t ippass = 0; ippass < m_vppass.size(); ippass++)
{
m_vppass[ippass]->MovePassConstraintsToRules(fxdSilfVersion);
}
}
/*--------------------------------------------------------------------------------------------*/
void GdlPass::MovePassConstraintsToRules(int fxdSilfVersion)
{
if (m_vpexpConstraints.size() > 0)
{
g_errorList.AddWarning(3530, this,
"Pass constraints are not compatible with version ",
VersionString(fxdSilfVersion),
"; constraint will be applied directly to rules.");
for (size_t iprule = 0; iprule < m_vprule.size(); iprule++)
{
m_vprule[iprule]->MovePassConstraintsToRule(m_vpexpConstraints);
}
}
// Delete pass constraint(s).
for (size_t i = 0; i < m_vpexpConstraints.size(); ++i)
delete m_vpexpConstraints[i];
m_vpexpConstraints.clear();
}
/*--------------------------------------------------------------------------------------------*/
void GdlRule::MovePassConstraintsToRule(std::vector<GdlExpression *> & m_vpexpPassConstr)
{
for (size_t ipexp = 0; ipexp < m_vpexpPassConstr.size(); ipexp++)
{
m_vpexpConstraints.push_back(m_vpexpPassConstr[ipexp]->Clone());
}
}
/*----------------------------------------------------------------------------------------------
Return the original number of items in the rule. Don't include ANY items.
----------------------------------------------------------------------------------------------*/
int GdlRule::ItemCountOriginal()
{
int crit = 0;
for (size_t irit = 0; irit <m_vprit.size(); irit++)
{
GdlRuleItem * prit = m_vprit[irit];
if (prit->OutputSymbol()->FullName() != "ANY")
crit++;
}
return crit;
}
/*----------------------------------------------------------------------------------------------
Give a deletion slot, return the indices of the substitution item it should be associated
with.
Assumes there are exactly two items in the rule (not including ANY items).
----------------------------------------------------------------------------------------------*/
int GdlRule::FindSubstitutionItem(int iritDel)
{
for (size_t irit = 0; irit <m_vprit.size(); irit++)
{
GdlRuleItem * prit = m_vprit[irit];
if (prit->OutputSymbol()->FullName() == "ANY")
continue;
if (irit == iritDel)
continue;
if (dynamic_cast<GdlSubstitutionItem *>(prit) != NULL)
return irit;
}
return -1;
}
|