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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "node.hxx"
#include "rect.hxx"
#include "symbol.hxx"
#include "smmod.hxx"
#include "document.hxx"
#include "view.hxx"
#include "mathtype.hxx"
#include "tmpdevice.hxx"
#include "visitors.hxx"
#include <comphelper/string.hxx>
#include <tools/color.hxx>
#include <tools/fract.hxx>
#include <tools/gen.hxx>
#include <vcl/outdev.hxx>
#include <math.h>
#include <float.h>
SmNode::SmNode(SmNodeType eNodeType, const SmToken &rNodeToken)
: aNodeToken( rNodeToken )
, eType( eNodeType )
, eScaleMode( SCALE_NONE )
, eRectHorAlign( RHA_LEFT )
, nFlags( 0 )
, nAttributes( 0 )
, bIsPhantom( false )
, bIsDebug( false )
, bIsSelected( false )
, nAccIndex( -1 )
, aParentNode( NULL )
{
}
SmNode::~SmNode()
{
}
bool SmNode::IsVisible() const
{
return false;
}
sal_uInt16 SmNode::GetNumSubNodes() const
{
return 0;
}
SmNode * SmNode::GetSubNode(sal_uInt16 /*nIndex*/)
{
return NULL;
}
SmNode * SmNode::GetLeftMost()
// returns leftmost node of current subtree.
//! (this assumes the one with index 0 is always the leftmost subnode
//! for the current node).
{
SmNode *pNode = GetNumSubNodes() > 0 ?
GetSubNode(0) : NULL;
return pNode ? pNode->GetLeftMost() : this;
}
void SmNode::SetPhantom(bool bIsPhantomP)
{
if (! (Flags() & FLG_VISIBLE))
bIsPhantom = bIsPhantomP;
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->SetPhantom(bIsPhantom);
}
void SmNode::SetColor(const Color& rColor)
{
if (! (Flags() & FLG_COLOR))
GetFont().SetColor(rColor);
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->SetColor(rColor);
}
void SmNode::SetAttribut(sal_uInt16 nAttrib)
{
if (
(nAttrib == ATTR_BOLD && !(Flags() & FLG_BOLD)) ||
(nAttrib == ATTR_ITALIC && !(Flags() & FLG_ITALIC))
)
{
nAttributes |= nAttrib;
}
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->SetAttribut(nAttrib);
}
void SmNode::ClearAttribut(sal_uInt16 nAttrib)
{
if (
(nAttrib == ATTR_BOLD && !(Flags() & FLG_BOLD)) ||
(nAttrib == ATTR_ITALIC && !(Flags() & FLG_ITALIC))
)
{
nAttributes &= ~nAttrib;
}
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->ClearAttribut(nAttrib);
}
void SmNode::SetFont(const SmFace &rFace)
{
if (!(Flags() & FLG_FONT))
GetFont() = rFace;
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->SetFont(rFace);
}
void SmNode::SetFontSize(const Fraction &rSize, sal_uInt16 nType)
//! 'rSize' is in units of pts
{
Size aFntSize;
if (!(Flags() & FLG_SIZE))
{
Fraction aVal (SmPtsTo100th_mm(rSize.GetNumerator()),
rSize.GetDenominator());
long nHeight = (long)aVal;
aFntSize = GetFont().GetSize();
aFntSize.Width() = 0;
switch(nType)
{
case FNTSIZ_ABSOLUT:
aFntSize.Height() = nHeight;
break;
case FNTSIZ_PLUS:
aFntSize.Height() += nHeight;
break;
case FNTSIZ_MINUS:
aFntSize.Height() -= nHeight;
break;
case FNTSIZ_MULTIPLY:
aFntSize.Height() = (long) (Fraction(aFntSize.Height()) * rSize);
break;
case FNTSIZ_DIVIDE:
if (rSize != Fraction(0L))
aFntSize.Height() = (long) (Fraction(aFntSize.Height()) / rSize);
break;
default:
break;
}
// check the requested size against maximum value
static int const nMaxVal = SmPtsTo100th_mm(128);
if (aFntSize.Height() > nMaxVal)
aFntSize.Height() = nMaxVal;
GetFont().SetSize(aFntSize);
}
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->SetFontSize(rSize, nType);
}
void SmNode::SetSize(const Fraction &rSize)
{
GetFont() *= rSize;
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->SetSize(rSize);
}
void SmNode::SetRectHorAlign(RectHorAlign eHorAlign, bool bApplyToSubTree )
{
if (!(Flags() & FLG_HORALIGN))
eRectHorAlign = eHorAlign;
if (bApplyToSubTree)
{
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->SetRectHorAlign(eHorAlign);
}
}
void SmNode::PrepareAttributes()
{
GetFont().SetWeight((Attributes() & ATTR_BOLD) ? WEIGHT_BOLD : WEIGHT_NORMAL);
GetFont().SetItalic((Attributes() & ATTR_ITALIC) ? ITALIC_NORMAL : ITALIC_NONE);
}
void SmNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell)
{
#if OSL_DEBUG_LEVEL > 1
bIsDebug = true;
#else
bIsDebug = false;
#endif
bIsPhantom = false;
nFlags = 0;
nAttributes = 0;
switch (rFormat.GetHorAlign())
{ case AlignLeft: eRectHorAlign = RHA_LEFT; break;
case AlignCenter: eRectHorAlign = RHA_CENTER; break;
case AlignRight: eRectHorAlign = RHA_RIGHT; break;
}
GetFont() = rFormat.GetFont(FNT_MATH);
OSL_ENSURE( GetFont().GetCharSet() == RTL_TEXTENCODING_UNICODE,
"unexpected CharSet" );
GetFont().SetWeight(WEIGHT_NORMAL);
GetFont().SetItalic(ITALIC_NONE);
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->Prepare(rFormat, rDocShell);
}
sal_uInt16 SmNode::FindIndex() const
{
const SmStructureNode* pParent = GetParent();
if (!pParent) { return 0; }
for (sal_uInt16 i = 0; i < pParent->GetNumSubNodes(); ++i) {
if (pParent->GetSubNode(i) == this) {
return i;
}
}
DBG_ASSERT(false, "Connection between parent and child is inconsistent.");
return 0;
}
#if OSL_DEBUG_LEVEL > 1
void SmNode::ToggleDebug() const
// toggle 'bIsDebug' in current subtree
{
SmNode *pThis = (SmNode *) this;
pThis->bIsDebug = bIsDebug ? false : true;
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = pThis->GetSubNode(i)))
pNode->ToggleDebug();
}
#endif
void SmNode::Move(const Point& rPosition)
{
if (rPosition.X() == 0 && rPosition.Y() == 0)
return;
SmRect::Move(rPosition);
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->Move(rPosition);
}
void SmNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->Arrange(rDev, rFormat);
}
void SmNode::CreateTextFromNode(OUString &rText)
{
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
if (nSize > 1)
rText += "{";
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->CreateTextFromNode(rText);
if (nSize > 1)
{
rText = comphelper::string::stripEnd(rText, ' ');
rText += "} ";
}
}
void SmNode::AdaptToX(const OutputDevice &/*rDev*/, sal_uLong /*nWidth*/)
{
}
void SmNode::AdaptToY(const OutputDevice &/*rDev*/, sal_uLong /*nHeight*/)
{
}
const SmNode * SmNode::FindTokenAt(sal_uInt16 nRow, sal_uInt16 nCol) const
// returns (first) ** visible ** (sub)node with the tokens text at
// position 'nRow', 'nCol'.
//! (there should be exactly one such node if any)
{
if ( IsVisible()
&& nRow == GetToken().nRow
&& nCol >= GetToken().nCol && nCol < GetToken().nCol + GetToken().aText.getLength())
return this;
else
{
sal_uInt16 nNumSubNodes = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nNumSubNodes; i++)
{ const SmNode *pNode = GetSubNode(i);
if (!pNode)
continue;
const SmNode *pResult = pNode->FindTokenAt(nRow, nCol);
if (pResult)
return pResult;
}
}
return 0;
}
const SmNode * SmNode::FindRectClosestTo(const Point &rPoint) const
{
long nDist = LONG_MAX;
const SmNode *pResult = 0;
if (IsVisible())
pResult = this;
else
{
sal_uInt16 nNumSubNodes = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nNumSubNodes; i++)
{ const SmNode *pNode = GetSubNode(i);
if (!pNode)
continue;
long nTmp;
const SmNode *pFound = pNode->FindRectClosestTo(rPoint);
if (pFound && (nTmp = pFound->OrientedDist(rPoint)) < nDist)
{ nDist = nTmp;
pResult = pFound;
// quit immediately if 'rPoint' is inside the *should not
// overlap with other rectangles* part.
// This (partly) serves for getting the attributes in eg
// "bar overstrike a".
// ('nDist < 0' is used as *quick shot* to avoid evaluation of
// the following expression, where the result is already determined)
if (nDist < 0 && pFound->IsInsideRect(rPoint))
break;
}
}
}
return pResult;
}
void SmNode::GetAccessibleText( OUStringBuffer &/*rText*/ ) const
{
SAL_WARN("starmath", "SmNode: GetAccessibleText not overloaded");
}
const SmNode * SmNode::FindNodeWithAccessibleIndex(sal_Int32 nAccIdx) const
{
const SmNode *pResult = 0;
sal_Int32 nIdx = GetAccessibleIndex();
OUStringBuffer aTxt;
if (nIdx >= 0)
GetAccessibleText( aTxt ); // get text if used in following 'if' statement
if (nIdx >= 0
&& nIdx <= nAccIdx && nAccIdx < nIdx + aTxt.getLength())
pResult = this;
else
{
sal_uInt16 nNumSubNodes = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nNumSubNodes; i++)
{
const SmNode *pNode = GetSubNode(i);
if (!pNode)
continue;
pResult = pNode->FindNodeWithAccessibleIndex(nAccIdx);
if (pResult)
return pResult;
}
}
return pResult;
}
#ifdef DEBUG_ENABLE_DUMPASDOT
void SmNode::DumpAsDot(std::ostream &out, OUString* label, int number, int& id, int parent) const
{
//If this is the root start the file
if(number == -1){
out<<"digraph {"<<std::endl;
if(label){
out<<"labelloc = \"t\";"<<std::endl;
OUString eq(*label);
//CreateTextFromNode(eq);
eq = eq.replaceAll("\n", " ");
eq = eq.replaceAll("\\", "\\\\");
eq = eq.replaceAll("\"", "\\\"");
out<<"label= \"Equation: \\\"";
out<< OUStringToOString(eq, RTL_TEXTENCODING_UTF8).getStr();
out<<"\\\"\";"<<std::endl;
}
}
//Some how out<<(int)this; doesn't work... So we do this nasty workaround...
char strid[100];
sprintf(strid, "%i", id);
char strnr[100];
sprintf(strnr, "%i", number);
//Dump connection to this node
if( parent != -1 ){
char pid[100];
sprintf(pid, "%i", parent);
out<<"n"<<pid<<" -> n"<<strid<<" [label=\""<<strnr<<"\"];"<<std::endl;
//If doesn't have parent and isn't a rootnode:
} else if(number != -1) {
out<<"orphaned -> n"<<strid<<" [label=\""<<strnr<<"\"];"<<std::endl;
}
//Dump this node
out<<"n"<< strid<<" [label=\"";
switch( GetType() ) {
case NTABLE: out<<"SmTableNode"; break;
case NBRACE: out<<"SmBraceNode"; break;
case NBRACEBODY: out<<"SmBracebodyNode"; break;
case NOPER: out<<"SmOperNode"; break;
case NALIGN: out<<"SmAlignNode"; break;
case NATTRIBUT: out<<"SmAttributNode"; break;
case NFONT: out<<"SmFontNode"; break;
case NUNHOR: out<<"SmUnHorNode"; break;
case NBINHOR: out<<"SmBinHorNode"; break;
case NBINVER: out<<"SmBinVerNode"; break;
case NBINDIAGONAL: out<<"SmBinDiagonalNode"; break;
case NSUBSUP: out<<"SmSubSupNode"; break;
case NMATRIX: out<<"SmMatrixNode"; break;
case NPLACE: out<<"SmPlaceNode"; break;
case NTEXT:
out<<"SmTextNode: ";
out<< OUStringToOString(((SmTextNode*)this)->GetText(), RTL_TEXTENCODING_UTF8).getStr();
break;
case NSPECIAL: out<<"SmSpecialNode"; break;
case NGLYPH_SPECIAL: out<<"SmGlyphSpecialNode"; break;
case NMATH:
out<<"SmMathSymbolNode: ";
out<< OUStringToOString(((SmMathSymbolNode*)this)->GetText(), RTL_TEXTENCODING_UTF8).getStr();
break;
case NBLANK: out<<"SmBlankNode"; break;
case NERROR: out<<"SmErrorNode"; break;
case NLINE: out<<"SmLineNode"; break;
case NEXPRESSION: out<<"SmExpressionNode"; break;
case NPOLYLINE: out<<"SmPolyLineNode"; break;
case NROOT: out<<"SmRootNode"; break;
case NROOTSYMBOL: out<<"SmRootSymbolNode"; break;
case NRECTANGLE: out<<"SmRectangleNode"; break;
case NVERTICAL_BRACE: out<<"SmVerticalBraceNode"; break;
case NMATHIDENT: out<<"SmMathIdentifierNode"; break;
case NINTDYNSYMBOL: out<<"SmDynIntegralSymbolNode"; break;
case NINTDYN: out<<"SmDynIntegralNode"; break;
default:
out<<"Unknown Node";
}
out<<"\"";
if(IsSelected())
out<<", style=dashed";
out<<"];"<<std::endl;
//Dump subnodes
int myid = id;
const SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->DumpAsDot(out, NULL, i, ++id, myid);
//If this is the root end the file
if( number == -1 )
out<<"}"<<std::endl;
}
#endif /* DEBUG_ENABLE_DUMPASDOT */
long SmNode::GetFormulaBaseline() const
{
SAL_WARN("starmath", "This dummy implementation should not have been called.");
return 0;
}
SmStructureNode::SmStructureNode( const SmStructureNode &rNode ) :
SmNode( rNode.GetType(), rNode.GetToken() )
{
sal_uLong i;
for (i = 0; i < aSubNodes.size(); i++)
delete aSubNodes[i];
aSubNodes.resize(0);
sal_uLong nSize = rNode.aSubNodes.size();
aSubNodes.resize( nSize );
for (i = 0; i < nSize; ++i)
{
SmNode *pNode = rNode.aSubNodes[i];
aSubNodes[i] = pNode ? new SmNode( *pNode ) : 0;
}
ClaimPaternity();
}
SmStructureNode::~SmStructureNode()
{
SmNode *pNode;
for (sal_uInt16 i = 0; i < GetNumSubNodes(); i++)
if (NULL != (pNode = GetSubNode(i)))
delete pNode;
}
SmStructureNode & SmStructureNode::operator = ( const SmStructureNode &rNode )
{
SmNode::operator = ( rNode );
sal_uLong i;
for (i = 0; i < aSubNodes.size(); i++)
delete aSubNodes[i];
aSubNodes.resize(0);
sal_uLong nSize = rNode.aSubNodes.size();
aSubNodes.resize( nSize );
for (i = 0; i < nSize; ++i)
{
SmNode *pNode = rNode.aSubNodes[i];
aSubNodes[i] = pNode ? new SmNode( *pNode ) : 0;
}
ClaimPaternity();
return *this;
}
void SmStructureNode::SetSubNodes(SmNode *pFirst, SmNode *pSecond, SmNode *pThird)
{
size_t nSize = pThird ? 3 : (pSecond ? 2 : (pFirst ? 1 : 0));
aSubNodes.resize( nSize );
if (pFirst)
aSubNodes[0] = pFirst;
if (pSecond)
aSubNodes[1] = pSecond;
if (pThird)
aSubNodes[2] = pThird;
ClaimPaternity();
}
void SmStructureNode::SetSubNodes(const SmNodeArray &rNodeArray)
{
aSubNodes = rNodeArray;
ClaimPaternity();
}
bool SmStructureNode::IsVisible() const
{
return false;
}
sal_uInt16 SmStructureNode::GetNumSubNodes() const
{
return (sal_uInt16) aSubNodes.size();
}
SmNode * SmStructureNode::GetSubNode(sal_uInt16 nIndex)
{
return aSubNodes[nIndex];
}
void SmStructureNode::GetAccessibleText( OUStringBuffer &rText ) const
{
sal_uInt16 nNodes = GetNumSubNodes();
for (sal_uInt16 i = 0; i < nNodes; ++i)
{
const SmNode *pNode = ((SmStructureNode *) this)->GetSubNode(i);
if (pNode)
{
if (pNode->IsVisible())
((SmStructureNode *) pNode)->nAccIndex = rText.getLength();
pNode->GetAccessibleText( rText );
}
}
}
bool SmVisibleNode::IsVisible() const
{
return true;
}
sal_uInt16 SmVisibleNode::GetNumSubNodes() const
{
return 0;
}
SmNode * SmVisibleNode::GetSubNode(sal_uInt16 /*nIndex*/)
{
return NULL;
}
void SmGraphicNode::GetAccessibleText( OUStringBuffer &rText ) const
{
rText.append(GetToken().aText);
}
void SmExpressionNode::CreateTextFromNode(OUString &rText)
{
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
if (nSize > 1)
rText += "{";
for (sal_uInt16 i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
{
pNode->CreateTextFromNode(rText);
//Just a bit of foo to make unary +asd -asd +-asd -+asd look nice
if (pNode->GetType() == NMATH)
if ((nSize != 2) ||
( !rText.endsWith("+") && !rText.endsWith("-") ))
rText += " ";
}
if (nSize > 1)
{
rText = comphelper::string::stripEnd(rText, ' ');
rText += "} ";
}
}
void SmTableNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
// arranges all subnodes in one column
{
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
// make distance depend on font size
long nDist = +(rFormat.GetDistance(DIS_VERTICAL)
* GetFont().GetSize().Height()) / 100L;
if (nSize < 1)
return;
// arrange subnodes and get maximum width of them
long nMaxWidth = 0,
nTmp;
sal_uInt16 i;
for (i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
{ pNode->Arrange(rDev, rFormat);
if ((nTmp = pNode->GetItalicWidth()) > nMaxWidth)
nMaxWidth = nTmp;
}
Point aPos;
SmRect::operator = (SmRect(nMaxWidth, 1));
for (i = 0; i < nSize; i++)
{ if (NULL != (pNode = GetSubNode(i)))
{ const SmRect &rNodeRect = pNode->GetRect();
const SmNode *pCoNode = pNode->GetLeftMost();
RectHorAlign eHorAlign = pCoNode->GetRectHorAlign();
aPos = rNodeRect.AlignTo(*this, RP_BOTTOM,
eHorAlign, RVA_BASELINE);
if (i)
aPos.Y() += nDist;
pNode->MoveTo(aPos);
ExtendBy(rNodeRect, nSize > 1 ? RCP_NONE : RCP_ARG);
}
}
// #i972#
if (HasBaseline())
nFormulaBaseline = GetBaseline();
else
{
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
SmRect aRect = (SmRect(aTmpDev, &rFormat, OUString("a"),
GetFont().GetBorderWidth()));
nFormulaBaseline = GetAlignM();
// move from middle position by constant - distance
// between middle and baseline for single letter
nFormulaBaseline += aRect.GetBaseline() - aRect.GetAlignM();
}
}
SmNode * SmTableNode::GetLeftMost()
{
return this;
}
long SmTableNode::GetFormulaBaseline() const
{
return nFormulaBaseline;
}
/**************************************************************************/
void SmLineNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell)
{
SmNode::Prepare(rFormat, rDocShell);
// Here we use the 'FNT_VARIABLE' font since it's ascent and descent in general fit better
// to the rest of the formula compared to the 'FNT_MATH' font.
GetFont() = rFormat.GetFont(FNT_VARIABLE);
Flags() |= FLG_FONT;
}
/**************************************************************************/
void SmLineNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
// arranges all subnodes in one row with some extra space between
{
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
sal_uInt16 i;
for (i = 0; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
pNode->Arrange(rDev, rFormat);
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
if (nSize < 1)
{
// provide an empty rectangle with alignment parameters for the "current"
// font (in order to make "a^1 {}_2^3 a_4" work correct, that is, have the
// same sub-/supscript positions.)
//! be sure to use a character that has explicitly defined HiAttribut
//! line in rect.cxx such as 'a' in order to make 'vec a' look same to
//! 'vec {a}'.
SmRect::operator = (SmRect(aTmpDev, &rFormat, OUString("a"),
GetFont().GetBorderWidth()));
// make sure that the rectangle occupies (almost) no space
SetWidth(1);
SetItalicSpaces(0, 0);
return;
}
// make distance depend on font size
long nDist = (rFormat.GetDistance(DIS_HORIZONTAL) * GetFont().GetSize().Height()) / 100L;
if (!IsUseExtraSpaces())
nDist = 0;
Point aPos;
// copy the first node into LineNode and extend by the others
if (NULL != (pNode = GetSubNode(0)))
SmRect::operator = (pNode->GetRect());
for (i = 1; i < nSize; i++)
if (NULL != (pNode = GetSubNode(i)))
{
aPos = pNode->AlignTo(*this, RP_RIGHT, RHA_CENTER, RVA_BASELINE);
// add horizontal space to the left for each but the first sub node
aPos.X() += nDist;
pNode->MoveTo(aPos);
ExtendBy( *pNode, RCP_XOR );
}
}
/**************************************************************************/
void SmExpressionNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
// as 'SmLineNode::Arrange' but keeps alignment of leftmost subnode
{
SmLineNode::Arrange(rDev, rFormat);
// copy alignment of leftmost subnode if any
SmNode *pNode = GetLeftMost();
if (pNode)
SetRectHorAlign(pNode->GetRectHorAlign(), false);
}
/**************************************************************************/
void SmUnHorNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
bool bIsPostfix = GetToken().eType == TFACT;
SmNode *pOper = GetSubNode(bIsPostfix ? 1 : 0),
*pBody = GetSubNode(bIsPostfix ? 0 : 1);
OSL_ENSURE(pOper, "Sm: NULL pointer");
OSL_ENSURE(pBody, "Sm: NULL pointer");
pOper->SetSize(Fraction (rFormat.GetRelSize(SIZ_OPERATOR), 100));
pOper->Arrange(rDev, rFormat);
pBody->Arrange(rDev, rFormat);
Point aPos = pOper->AlignTo(*pBody, bIsPostfix ? RP_RIGHT : RP_LEFT,
RHA_CENTER, RVA_BASELINE);
// add a bit space between operator and argument
// (worst case -{1 over 2} where - and over have almost no space inbetween)
long nDelta = pOper->GetFont().GetSize().Height() / 20;
if (bIsPostfix)
aPos.X() += nDelta;
else
aPos.X() -= nDelta;
pOper->MoveTo(aPos);
SmRect::operator = (*pBody);
long nOldBot = GetBottom();
ExtendBy(*pOper, RCP_XOR);
// workaround for Bug 50865: "a^2 a^+2" have different baselines
// for exponents (if size of exponent is large enough)
SetBottom(nOldBot);
}
/**************************************************************************/
void SmRootNode::GetHeightVerOffset(const SmRect &rRect,
long &rHeight, long &rVerOffset) const
// calculate height and vertical offset of root sign suitable for 'rRect'
{
rVerOffset = (rRect.GetBottom() - rRect.GetAlignB()) / 2;
rHeight = rRect.GetHeight() - rVerOffset;
OSL_ENSURE(rHeight >= 0, "Sm : Ooops...");
OSL_ENSURE(rVerOffset >= 0, "Sm : Ooops...");
}
Point SmRootNode::GetExtraPos(const SmRect &rRootSymbol,
const SmRect &rExtra) const
{
const Size &rSymSize = rRootSymbol.GetSize();
Point aPos = rRootSymbol.GetTopLeft()
+ Point((rSymSize.Width() * 70) / 100,
(rSymSize.Height() * 52) / 100);
// from this calculate topleft edge of 'rExtra'
aPos.X() -= rExtra.GetWidth() + rExtra.GetItalicRightSpace();
aPos.Y() -= rExtra.GetHeight();
// if there's enough space move a bit less to the right
// examples: "nroot i a", "nroot j a"
// (it looks better if we don't use italic-spaces here)
long nX = rRootSymbol.GetLeft() + (rSymSize.Width() * 30) / 100;
if (aPos.X() > nX)
aPos.X() = nX;
return aPos;
}
void SmRootNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
//! pExtra needs to have the smaller index than pRootSym in order to
//! not to get the root symbol but the pExtra when clicking on it in the
//! GraphicWindow. (That is because of the simplicity of the algorithm
//! that finds the node corresponding to a mouseclick in the window.)
SmNode *pExtra = GetSubNode(0),
*pRootSym = GetSubNode(1),
*pBody = GetSubNode(2);
OSL_ENSURE(pRootSym, "Sm: NULL pointer");
OSL_ENSURE(pBody, "Sm: NULL pointer");
pBody->Arrange(rDev, rFormat);
long nHeight,
nVerOffset;
GetHeightVerOffset(*pBody, nHeight, nVerOffset);
nHeight += rFormat.GetDistance(DIS_ROOT)
* GetFont().GetSize().Height() / 100L;
// font specialist advised to change the width first
pRootSym->AdaptToY(rDev, nHeight);
pRootSym->AdaptToX(rDev, pBody->GetItalicWidth());
pRootSym->Arrange(rDev, rFormat);
Point aPos = pRootSym->AlignTo(*pBody, RP_LEFT, RHA_CENTER, RVA_BASELINE);
//! override calculated vertical position
aPos.Y() = pRootSym->GetTop() + pBody->GetBottom() - pRootSym->GetBottom();
aPos.Y() -= nVerOffset;
pRootSym->MoveTo(aPos);
if (pExtra)
{ pExtra->SetSize(Fraction(rFormat.GetRelSize(SIZ_INDEX), 100));
pExtra->Arrange(rDev, rFormat);
aPos = GetExtraPos(*pRootSym, *pExtra);
pExtra->MoveTo(aPos);
}
SmRect::operator = (*pBody);
ExtendBy(*pRootSym, RCP_THIS);
if (pExtra)
ExtendBy(*pExtra, RCP_THIS, true);
}
void SmRootNode::CreateTextFromNode(OUString &rText)
{
SmNode *pExtra = GetSubNode(0);
if (pExtra)
{
rText += "nroot ";
pExtra->CreateTextFromNode(rText);
}
else
rText += "sqrt ";
if (!pExtra && GetSubNode(2)->GetNumSubNodes() > 1)
rText += "{ ";
GetSubNode(2)->CreateTextFromNode(rText);
if (!pExtra && GetSubNode(2)->GetNumSubNodes() > 1)
rText += "} ";
}
/**************************************************************************/
void SmDynIntegralNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
SmNode *pDynIntegralSym = Symbol(),
*pBody = Body();
OSL_ENSURE(pDynIntegralSym, "Sm: NULL pointer");
OSL_ENSURE(pBody, "Sm: NULL pointer");
pBody->Arrange(rDev, rFormat);
long nHeight = pBody->GetHeight();
pDynIntegralSym->AdaptToY(rDev, nHeight);
pDynIntegralSym->Arrange(rDev, rFormat);
Point aPos = pDynIntegralSym->AlignTo(*pBody, RP_LEFT, RHA_CENTER, RVA_BASELINE);
//! override calculated vertical position
aPos.Y() = pDynIntegralSym->GetTop() + pBody->GetBottom() - pDynIntegralSym->GetBottom();
pDynIntegralSym->MoveTo(aPos);
// override its own rectangle with pBody's
SmRect::operator = (*pBody);
// extends this rectangle with the symbol's one
ExtendBy(*pDynIntegralSym, RCP_THIS);
}
void SmDynIntegralNode::CreateTextFromNode(OUString &rText)
{
rText += "intd ";
SmNode *pBody = GetSubNode(1);
if (pBody->GetNumSubNodes() > 1)
rText += "{ ";
pBody->CreateTextFromNode(rText);
if (pBody->GetNumSubNodes() > 1)
rText += "} ";
}
/**************************************************************************/
void SmBinHorNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
SmNode *pLeft = GetSubNode(0),
*pOper = GetSubNode(1),
*pRight = GetSubNode(2);
OSL_ENSURE(pLeft != NULL, "Sm: NULL pointer");
OSL_ENSURE(pOper != NULL, "Sm: NULL pointer");
OSL_ENSURE(pRight != NULL, "Sm: NULL pointer");
pOper->SetSize(Fraction (rFormat.GetRelSize(SIZ_OPERATOR), 100));
pLeft ->Arrange(rDev, rFormat);
pOper ->Arrange(rDev, rFormat);
pRight->Arrange(rDev, rFormat);
const SmRect &rOpRect = pOper->GetRect();
long nDist = (rOpRect.GetWidth() *
rFormat.GetDistance(DIS_HORIZONTAL)) / 100L;
SmRect::operator = (*pLeft);
Point aPos;
aPos = pOper->AlignTo(*this, RP_RIGHT, RHA_CENTER, RVA_BASELINE);
aPos.X() += nDist;
pOper->MoveTo(aPos);
ExtendBy(*pOper, RCP_XOR);
aPos = pRight->AlignTo(*this, RP_RIGHT, RHA_CENTER, RVA_BASELINE);
aPos.X() += nDist;
pRight->MoveTo(aPos);
ExtendBy(*pRight, RCP_XOR);
}
/**************************************************************************/
void SmBinVerNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
SmNode *pNum = GetSubNode(0),
*pLine = GetSubNode(1),
*pDenom = GetSubNode(2);
OSL_ENSURE(pNum, "Sm : NULL pointer");
OSL_ENSURE(pLine, "Sm : NULL pointer");
OSL_ENSURE(pDenom, "Sm : NULL pointer");
bool bIsTextmode = rFormat.IsTextmode();
if (bIsTextmode)
{
Fraction aFraction(rFormat.GetRelSize(SIZ_INDEX), 100);
pNum ->SetSize(aFraction);
pLine ->SetSize(aFraction);
pDenom->SetSize(aFraction);
}
pNum ->Arrange(rDev, rFormat);
pDenom->Arrange(rDev, rFormat);
long nFontHeight = GetFont().GetSize().Height(),
nExtLen = nFontHeight * rFormat.GetDistance(DIS_FRACTION) / 100L,
nThick = nFontHeight * rFormat.GetDistance(DIS_STROKEWIDTH) / 100L,
nWidth = std::max(pNum->GetItalicWidth(), pDenom->GetItalicWidth()),
nNumDist = bIsTextmode ? 0 :
nFontHeight * rFormat.GetDistance(DIS_NUMERATOR) / 100L,
nDenomDist = bIsTextmode ? 0 :
nFontHeight * rFormat.GetDistance(DIS_DENOMINATOR) / 100L;
// font specialist advised to change the width first
pLine->AdaptToY(rDev, nThick);
pLine->AdaptToX(rDev, nWidth + 2 * nExtLen);
pLine->Arrange(rDev, rFormat);
// get horizontal alignment for numerator
const SmNode *pLM = pNum->GetLeftMost();
RectHorAlign eHorAlign = pLM->GetRectHorAlign();
// move numerator to its position
Point aPos = pNum->AlignTo(*pLine, RP_TOP, eHorAlign, RVA_BASELINE);
aPos.Y() -= nNumDist;
pNum->MoveTo(aPos);
// get horizontal alignment for denominator
pLM = pDenom->GetLeftMost();
eHorAlign = pLM->GetRectHorAlign();
// move denominator to its position
aPos = pDenom->AlignTo(*pLine, RP_BOTTOM, eHorAlign, RVA_BASELINE);
aPos.Y() += nDenomDist;
pDenom->MoveTo(aPos);
SmRect::operator = (*pNum);
ExtendBy(*pDenom, RCP_NONE).ExtendBy(*pLine, RCP_NONE, pLine->GetCenterY());
}
void SmBinVerNode::CreateTextFromNode(OUString &rText)
{
SmNode *pNum = GetSubNode(0),
*pDenom = GetSubNode(2);
pNum->CreateTextFromNode(rText);
rText += "over ";
pDenom->CreateTextFromNode(rText);
}
SmNode * SmBinVerNode::GetLeftMost()
{
return this;
}
/**************************************************************************/
/// @return value of the determinant formed by the two points
double Det(const Point &rHeading1, const Point &rHeading2)
{
return rHeading1.X() * rHeading2.Y() - rHeading1.Y() * rHeading2.X();
}
/// Is true iff the point 'rPoint1' belongs to the straight line through 'rPoint2'
/// and has the direction vector 'rHeading2'
bool IsPointInLine(const Point &rPoint1,
const Point &rPoint2, const Point &rHeading2)
{
OSL_ENSURE(rHeading2 != Point(), "Sm : 0 vector");
bool bRes = false;
const double eps = 5.0 * DBL_EPSILON;
double fLambda;
if (labs(rHeading2.X()) > labs(rHeading2.Y()))
{
fLambda = (rPoint1.X() - rPoint2.X()) / (double) rHeading2.X();
bRes = fabs(rPoint1.Y() - (rPoint2.Y() + fLambda * rHeading2.Y())) < eps;
}
else
{
fLambda = (rPoint1.Y() - rPoint2.Y()) / (double) rHeading2.Y();
bRes = fabs(rPoint1.X() - (rPoint2.X() + fLambda * rHeading2.X())) < eps;
}
return bRes;
}
sal_uInt16 GetLineIntersectionPoint(Point &rResult,
const Point& rPoint1, const Point &rHeading1,
const Point& rPoint2, const Point &rHeading2)
{
OSL_ENSURE(rHeading1 != Point(), "Sm : 0 vector");
OSL_ENSURE(rHeading2 != Point(), "Sm : 0 vector");
sal_uInt16 nRes = 1;
const double eps = 5.0 * DBL_EPSILON;
// are the direction vectors linearly dependent?
double fDet = Det(rHeading1, rHeading2);
if (fabs(fDet) < eps)
{
nRes = IsPointInLine(rPoint1, rPoint2, rHeading2) ? USHRT_MAX : 0;
rResult = nRes ? rPoint1 : Point();
}
else
{
// here we do not pay attention to the computational accurancy
// (that would be more complicated and is not really worth it in this case)
double fLambda = ( (rPoint1.Y() - rPoint2.Y()) * rHeading2.X()
- (rPoint1.X() - rPoint2.X()) * rHeading2.Y())
/ fDet;
rResult = Point(rPoint1.X() + (long) (fLambda * rHeading1.X()),
rPoint1.Y() + (long) (fLambda * rHeading1.Y()));
}
return nRes;
}
SmBinDiagonalNode::SmBinDiagonalNode(const SmToken &rNodeToken)
: SmStructureNode(NBINDIAGONAL, rNodeToken)
{
bAscending = false;
SetNumSubNodes(3);
}
/// @return position and size of the diagonal line
/// premise: SmRect of the node defines the limitation(!) consequently it has to be known upfront
void SmBinDiagonalNode::GetOperPosSize(Point &rPos, Size &rSize,
const Point &rDiagPoint, double fAngleDeg) const
{
const double fPi = 3.1415926535897932384626433;
double fAngleRad = fAngleDeg / 180.0 * fPi;
long nRectLeft = GetItalicLeft(),
nRectRight = GetItalicRight(),
nRectTop = GetTop(),
nRectBottom = GetBottom();
Point aRightHdg (100, 0),
aDownHdg (0, 100),
aDiagHdg ( (long)(100.0 * cos(fAngleRad)),
(long)(-100.0 * sin(fAngleRad)) );
long nLeft, nRight, nTop, nBottom; // margins of the rectangle for the diagonal
Point aPoint;
if (IsAscending())
{
// determine top right corner
GetLineIntersectionPoint(aPoint,
Point(nRectLeft, nRectTop), aRightHdg,
rDiagPoint, aDiagHdg);
// is there a point of intersection with the top border?
if (aPoint.X() <= nRectRight)
{
nRight = aPoint.X();
nTop = nRectTop;
}
else
{
// there has to be a point of intersection with the right border!
GetLineIntersectionPoint(aPoint,
Point(nRectRight, nRectTop), aDownHdg,
rDiagPoint, aDiagHdg);
nRight = nRectRight;
nTop = aPoint.Y();
}
// determine bottom left corner
GetLineIntersectionPoint(aPoint,
Point(nRectLeft, nRectBottom), aRightHdg,
rDiagPoint, aDiagHdg);
// is there a point of intersection with the bottom border?
if (aPoint.X() >= nRectLeft)
{
nLeft = aPoint.X();
nBottom = nRectBottom;
}
else
{
// there has to be a point of intersection with the left border!
GetLineIntersectionPoint(aPoint,
Point(nRectLeft, nRectTop), aDownHdg,
rDiagPoint, aDiagHdg);
nLeft = nRectLeft;
nBottom = aPoint.Y();
}
}
else
{
// determine top left corner
GetLineIntersectionPoint(aPoint,
Point(nRectLeft, nRectTop), aRightHdg,
rDiagPoint, aDiagHdg);
// is there a point of intersection with the top border?
if (aPoint.X() >= nRectLeft)
{
nLeft = aPoint.X();
nTop = nRectTop;
}
else
{
// there has to be a point of intersection with the left border!
GetLineIntersectionPoint(aPoint,
Point(nRectLeft, nRectTop), aDownHdg,
rDiagPoint, aDiagHdg);
nLeft = nRectLeft;
nTop = aPoint.Y();
}
// determine bottom right corner
GetLineIntersectionPoint(aPoint,
Point(nRectLeft, nRectBottom), aRightHdg,
rDiagPoint, aDiagHdg);
// is there a point of intersection with the bottom border?
if (aPoint.X() <= nRectRight)
{
nRight = aPoint.X();
nBottom = nRectBottom;
}
else
{
// there has to be a point of intersection with the right border!
GetLineIntersectionPoint(aPoint,
Point(nRectRight, nRectTop), aDownHdg,
rDiagPoint, aDiagHdg);
nRight = nRectRight;
nBottom = aPoint.Y();
}
}
rSize = Size(nRight - nLeft + 1, nBottom - nTop + 1);
rPos.X() = nLeft;
rPos.Y() = nTop;
}
void SmBinDiagonalNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
// Both arguments have to get into the SubNodes before the Operator so that clicking
// within the GraphicWindow sets the FormulaCursor correctly (cf. SmRootNode)
SmNode *pLeft = GetSubNode(0),
*pRight = GetSubNode(1);
OSL_ENSURE(pLeft, "Sm : NULL pointer");
OSL_ENSURE(pRight, "Sm : NULL pointer");
OSL_ENSURE(GetSubNode(2)->GetType() == NPOLYLINE, "Sm : wrong node type");
SmPolyLineNode *pOper = (SmPolyLineNode *) GetSubNode(2);
OSL_ENSURE(pOper, "Sm : NULL pointer");
//! some routines being called extract some info from the OutputDevice's
//! font (eg the space to be used for borders OR the font name(!!)).
//! Thus the font should reflect the needs and has to be set!
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
pLeft->Arrange(aTmpDev, rFormat);
pRight->Arrange(aTmpDev, rFormat);
// determine implicitly the values (incl. the margin) of the diagonal line
pOper->Arrange(aTmpDev, rFormat);
long nDelta = pOper->GetWidth() * 8 / 10;
// determine TopLeft position from the right argument
Point aPos;
aPos.X() = pLeft->GetItalicRight() + nDelta + pRight->GetItalicLeftSpace();
if (IsAscending())
aPos.Y() = pLeft->GetBottom() + nDelta;
else
aPos.Y() = pLeft->GetTop() - nDelta - pRight->GetHeight();
pRight->MoveTo(aPos);
// determine new baseline
long nTmpBaseline = IsAscending() ? (pLeft->GetBottom() + pRight->GetTop()) / 2
: (pLeft->GetTop() + pRight->GetBottom()) / 2;
Point aLogCenter ((pLeft->GetItalicRight() + pRight->GetItalicLeft()) / 2,
nTmpBaseline);
SmRect::operator = (*pLeft);
ExtendBy(*pRight, RCP_NONE);
// determine position and size of diagonal line
Size aTmpSize;
GetOperPosSize(aPos, aTmpSize, aLogCenter, IsAscending() ? 60.0 : -60.0);
// font specialist advised to change the width first
pOper->AdaptToY(aTmpDev, aTmpSize.Height());
pOper->AdaptToX(aTmpDev, aTmpSize.Width());
// and make it active
pOper->Arrange(aTmpDev, rFormat);
pOper->MoveTo(aPos);
ExtendBy(*pOper, RCP_NONE, nTmpBaseline);
}
/**************************************************************************/
void SmSubSupNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
OSL_ENSURE(GetNumSubNodes() == 1 + SUBSUP_NUM_ENTRIES,
"Sm: wrong number of subnodes");
SmNode *pBody = GetBody();
OSL_ENSURE(pBody, "Sm: NULL pointer");
long nOrigHeight = pBody->GetFont().GetSize().Height();
pBody->Arrange(rDev, rFormat);
const SmRect &rBodyRect = pBody->GetRect();
SmRect::operator = (rBodyRect);
// line that separates sub- and supscript rectangles
long nDelimLine = SmFromTo(GetAlignB(), GetAlignT(), 0.4);
Point aPos;
long nDelta, nDist;
// iterate over all possible sub-/supscripts
SmRect aTmpRect (rBodyRect);
for (int i = 0; i < SUBSUP_NUM_ENTRIES; i++)
{ SmSubSup eSubSup = (SmSubSup) i; // cast
SmNode *pSubSup = GetSubSup(eSubSup);
if (!pSubSup)
continue;
// switch position of limits if we are in textmode
if (rFormat.IsTextmode() && (GetToken().nGroup & TGLIMIT))
switch (eSubSup)
{ case CSUB: eSubSup = RSUB; break;
case CSUP: eSubSup = RSUP; break;
default:
break;
}
// prevent sub-/supscripts from diminishing in size
// (as would be in "a_{1_{2_{3_4}}}")
if (GetFont().GetSize().Height() > rFormat.GetBaseSize().Height() / 3)
{
sal_uInt16 nIndex = (eSubSup == CSUB || eSubSup == CSUP) ?
SIZ_LIMITS : SIZ_INDEX;
Fraction aFraction ( rFormat.GetRelSize(nIndex), 100 );
pSubSup->SetSize(aFraction);
}
pSubSup->Arrange(rDev, rFormat);
bool bIsTextmode = rFormat.IsTextmode();
nDist = 0;
//! be sure that CSUB, CSUP are handled before the other cases!
switch (eSubSup)
{ case RSUB :
case LSUB :
if (!bIsTextmode)
nDist = nOrigHeight
* rFormat.GetDistance(DIS_SUBSCRIPT) / 100L;
aPos = pSubSup->GetRect().AlignTo(aTmpRect,
eSubSup == LSUB ? RP_LEFT : RP_RIGHT,
RHA_CENTER, RVA_BOTTOM);
aPos.Y() += nDist;
nDelta = nDelimLine - aPos.Y();
if (nDelta > 0)
aPos.Y() += nDelta;
break;
case RSUP :
case LSUP :
if (!bIsTextmode)
nDist = nOrigHeight
* rFormat.GetDistance(DIS_SUPERSCRIPT) / 100L;
aPos = pSubSup->GetRect().AlignTo(aTmpRect,
eSubSup == LSUP ? RP_LEFT : RP_RIGHT,
RHA_CENTER, RVA_TOP);
aPos.Y() -= nDist;
nDelta = aPos.Y() + pSubSup->GetHeight() - nDelimLine;
if (nDelta > 0)
aPos.Y() -= nDelta;
break;
case CSUB :
if (!bIsTextmode)
nDist = nOrigHeight
* rFormat.GetDistance(DIS_LOWERLIMIT) / 100L;
aPos = pSubSup->GetRect().AlignTo(rBodyRect, RP_BOTTOM,
RHA_CENTER, RVA_BASELINE);
aPos.Y() += nDist;
break;
case CSUP :
if (!bIsTextmode)
nDist = nOrigHeight
* rFormat.GetDistance(DIS_UPPERLIMIT) / 100L;
aPos = pSubSup->GetRect().AlignTo(rBodyRect, RP_TOP,
RHA_CENTER, RVA_BASELINE);
aPos.Y() -= nDist;
break;
}
pSubSup->MoveTo(aPos);
ExtendBy(*pSubSup, RCP_THIS, true);
// update rectangle to which RSUB, RSUP, LSUB, LSUP
// will be aligned to
if (eSubSup == CSUB || eSubSup == CSUP)
aTmpRect = *this;
}
}
void SmSubSupNode::CreateTextFromNode(OUString &rText)
{
SmNode *pNode;
GetSubNode(0)->CreateTextFromNode(rText);
if (NULL != (pNode = GetSubNode(LSUB+1)))
{
rText += "lsub ";
pNode->CreateTextFromNode(rText);
}
if (NULL != (pNode = GetSubNode(LSUP+1)))
{
rText += "lsup ";
pNode->CreateTextFromNode(rText);
}
if (NULL != (pNode = GetSubNode(CSUB+1)))
{
rText += "csub ";
pNode->CreateTextFromNode(rText);
}
if (NULL != (pNode = GetSubNode(CSUP+1)))
{
rText += "csup ";
pNode->CreateTextFromNode(rText);
}
if (NULL != (pNode = GetSubNode(RSUB+1)))
{
rText = comphelper::string::stripEnd(rText, ' ');
rText += "_";
pNode->CreateTextFromNode(rText);
}
if (NULL != (pNode = GetSubNode(RSUP+1)))
{
rText = comphelper::string::stripEnd(rText, ' ');
rText += "^";
pNode->CreateTextFromNode(rText);
}
}
/**************************************************************************/
void SmBraceNode::CreateTextFromNode(OUString &rText)
{
if (GetScaleMode() == SCALE_HEIGHT)
rText += "left ";
{
OUString aStr;
GetSubNode(0)->CreateTextFromNode(aStr);
aStr = comphelper::string::strip(aStr, ' ');
aStr = comphelper::string::stripStart(aStr, '\\');
if (!aStr.isEmpty())
{
if (aStr.equalsAscii("divides"))
rText += "lline";
else if (aStr.equalsAscii("parallel"))
rText += "ldline";
else if (aStr.equalsAscii("<"))
rText += "langle";
else
rText += aStr;
rText += " ";
}
else
rText += "none ";
}
GetSubNode(1)->CreateTextFromNode(rText);
if (GetScaleMode() == SCALE_HEIGHT)
rText += "right ";
{
OUString aStr;
GetSubNode(2)->CreateTextFromNode(aStr);
aStr = comphelper::string::strip(aStr, ' ');
aStr = comphelper::string::stripStart(aStr, '\\');
if (!aStr.isEmpty())
{
if (aStr.equalsAscii("divides"))
rText += "rline";
else if (aStr.equalsAscii("parallel"))
rText += "rdline";
else if (aStr.equalsAscii(">"))
rText += "rangle";
else
rText += aStr;
rText += " ";
}
else
rText += "none ";
}
rText += " ";
}
void SmBraceNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
SmNode *pLeft = GetSubNode(0),
*pBody = GetSubNode(1),
*pRight = GetSubNode(2);
OSL_ENSURE(pLeft, "Sm: NULL pointer");
OSL_ENSURE(pBody, "Sm: NULL pointer");
OSL_ENSURE(pRight, "Sm: NULL pointer");
pBody->Arrange(rDev, rFormat);
bool bIsScaleNormal = rFormat.IsScaleNormalBrackets(),
bScale = pBody->GetHeight() > 0 &&
(GetScaleMode() == SCALE_HEIGHT || bIsScaleNormal),
bIsABS = GetToken().eType == TABS;
long nFaceHeight = GetFont().GetSize().Height();
// determine oversize in %
sal_uInt16 nPerc = 0;
if (!bIsABS && bScale)
{ // in case of oversize braces...
sal_uInt16 nIndex = GetScaleMode() == SCALE_HEIGHT ?
DIS_BRACKETSIZE : DIS_NORMALBRACKETSIZE;
nPerc = rFormat.GetDistance(nIndex);
}
// determine the height for the braces
long nBraceHeight;
if (bScale)
{
nBraceHeight = pBody->GetType() == NBRACEBODY ?
((SmBracebodyNode *) pBody)->GetBodyHeight()
: pBody->GetHeight();
nBraceHeight += 2 * (nBraceHeight * nPerc / 100L);
}
else
nBraceHeight = nFaceHeight;
// distance to the argument
nPerc = bIsABS ? 0 : rFormat.GetDistance(DIS_BRACKETSPACE);
long nDist = nFaceHeight * nPerc / 100L;
// if wanted, scale the braces to the wanted size
if (bScale)
{
Size aTmpSize (pLeft->GetFont().GetSize());
OSL_ENSURE(pRight->GetFont().GetSize() == aTmpSize,
"Sm : different font sizes");
aTmpSize.Width() = std::min((long) nBraceHeight * 60L / 100L,
rFormat.GetBaseSize().Height() * 3L / 2L);
// correction factor since change from StarMath to OpenSymbol font
// because of the different font width in the FontMetric
aTmpSize.Width() *= 182;
aTmpSize.Width() /= 267;
sal_Unicode cChar = pLeft->GetToken().cMathChar;
if (cChar != MS_LINE && cChar != MS_DLINE &&
cChar != MS_VERTLINE && cChar != MS_DVERTLINE)
pLeft ->GetFont().SetSize(aTmpSize);
cChar = pRight->GetToken().cMathChar;
if (cChar != MS_LINE && cChar != MS_DLINE &&
cChar != MS_VERTLINE && cChar != MS_DVERTLINE)
pRight->GetFont().SetSize(aTmpSize);
pLeft ->AdaptToY(rDev, nBraceHeight);
pRight->AdaptToY(rDev, nBraceHeight);
}
pLeft ->Arrange(rDev, rFormat);
pRight->Arrange(rDev, rFormat);
// required in order to make "\(a\) - (a) - left ( a right )" look alright
RectVerAlign eVerAlign = bScale ? RVA_CENTERY : RVA_BASELINE;
Point aPos;
aPos = pLeft->AlignTo(*pBody, RP_LEFT, RHA_CENTER, eVerAlign);
aPos.X() -= nDist;
pLeft->MoveTo(aPos);
aPos = pRight->AlignTo(*pBody, RP_RIGHT, RHA_CENTER, eVerAlign);
aPos.X() += nDist;
pRight->MoveTo(aPos);
SmRect::operator = (*pBody);
ExtendBy(*pLeft, RCP_THIS).ExtendBy(*pRight, RCP_THIS);
}
/**************************************************************************/
void SmBracebodyNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
sal_uInt16 nNumSubNodes = GetNumSubNodes();
if (nNumSubNodes == 0)
return;
// arrange arguments
sal_uInt16 i;
for (i = 0; i < nNumSubNodes; i += 2)
GetSubNode(i)->Arrange(rDev, rFormat);
// build reference rectangle with necessary info for vertical alignment
SmRect aRefRect (*GetSubNode(0));
for (i = 0; i < nNumSubNodes; i += 2)
{
SmRect aTmpRect (*GetSubNode(i));
Point aPos = aTmpRect.AlignTo(aRefRect, RP_RIGHT, RHA_CENTER, RVA_BASELINE);
aTmpRect.MoveTo(aPos);
aRefRect.ExtendBy(aTmpRect, RCP_XOR);
}
nBodyHeight = aRefRect.GetHeight();
// scale separators to required height and arrange them
bool bScale = GetScaleMode() == SCALE_HEIGHT || rFormat.IsScaleNormalBrackets();
long nHeight = bScale ? aRefRect.GetHeight() : GetFont().GetSize().Height();
sal_uInt16 nIndex = GetScaleMode() == SCALE_HEIGHT ?
DIS_BRACKETSIZE : DIS_NORMALBRACKETSIZE;
sal_uInt16 nPerc = rFormat.GetDistance(nIndex);
if (bScale)
nHeight += 2 * (nHeight * nPerc / 100L);
for (i = 1; i < nNumSubNodes; i += 2)
{
SmNode *pNode = GetSubNode(i);
pNode->AdaptToY(rDev, nHeight);
pNode->Arrange(rDev, rFormat);
}
// horizontal distance between argument and brackets or separators
long nDist = GetFont().GetSize().Height()
* rFormat.GetDistance(DIS_BRACKETSPACE) / 100L;
SmNode *pLeft = GetSubNode(0);
SmRect::operator = (*pLeft);
for (i = 1; i < nNumSubNodes; i++)
{
bool bIsSeparator = i % 2 != 0;
RectVerAlign eVerAlign = bIsSeparator ? RVA_CENTERY : RVA_BASELINE;
SmNode *pRight = GetSubNode(i);
Point aPosX = pRight->AlignTo(*pLeft, RP_RIGHT, RHA_CENTER, eVerAlign),
aPosY = pRight->AlignTo(aRefRect, RP_RIGHT, RHA_CENTER, eVerAlign);
aPosX.X() += nDist;
pRight->MoveTo(Point(aPosX.X(), aPosY.Y()));
ExtendBy(*pRight, bIsSeparator ? RCP_THIS : RCP_XOR);
pLeft = pRight;
}
}
/**************************************************************************/
void SmVerticalBraceNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
SmNode *pBody = GetSubNode(0),
*pBrace = GetSubNode(1),
*pScript = GetSubNode(2);
OSL_ENSURE(pBody, "Sm: NULL pointer!");
OSL_ENSURE(pBrace, "Sm: NULL pointer!");
OSL_ENSURE(pScript, "Sm: NULL pointer!");
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
pBody->Arrange(aTmpDev, rFormat);
// size is the same as for limits for this part
pScript->SetSize( Fraction( rFormat.GetRelSize(SIZ_LIMITS), 100 ) );
// braces are a bit taller than usually
pBrace ->SetSize( Fraction(3, 2) );
long nItalicWidth = pBody->GetItalicWidth();
if (nItalicWidth > 0)
pBrace->AdaptToX(aTmpDev, nItalicWidth);
pBrace ->Arrange(aTmpDev, rFormat);
pScript->Arrange(aTmpDev, rFormat);
// determine the relative position and the distances between each other
RectPos eRectPos;
long nFontHeight = pBody->GetFont().GetSize().Height();
long nDistBody = nFontHeight * rFormat.GetDistance(DIS_ORNAMENTSIZE),
nDistScript = nFontHeight;
if (GetToken().eType == TOVERBRACE)
{
eRectPos = RP_TOP;
nDistBody = - nDistBody;
nDistScript *= - rFormat.GetDistance(DIS_UPPERLIMIT);
}
else // TUNDERBRACE
{
eRectPos = RP_BOTTOM;
nDistScript *= + rFormat.GetDistance(DIS_LOWERLIMIT);
}
nDistBody /= 100L;
nDistScript /= 100L;
Point aPos = pBrace->AlignTo(*pBody, eRectPos, RHA_CENTER, RVA_BASELINE);
aPos.Y() += nDistBody;
pBrace->MoveTo(aPos);
aPos = pScript->AlignTo(*pBrace, eRectPos, RHA_CENTER, RVA_BASELINE);
aPos.Y() += nDistScript;
pScript->MoveTo(aPos);
SmRect::operator = (*pBody);
ExtendBy(*pBrace, RCP_THIS).ExtendBy(*pScript, RCP_THIS);
}
/**************************************************************************/
SmNode * SmOperNode::GetSymbol()
{
SmNode *pNode = GetSubNode(0);
OSL_ENSURE(pNode, "Sm: NULL pointer!");
if (pNode->GetType() == NSUBSUP)
pNode = ((SmSubSupNode *) pNode)->GetBody();
OSL_ENSURE(pNode, "Sm: NULL pointer!");
return pNode;
}
long SmOperNode::CalcSymbolHeight(const SmNode &rSymbol,
const SmFormat &rFormat) const
// returns the font height to be used for operator-symbol
{
long nHeight = GetFont().GetSize().Height();
SmTokenType eTmpType = GetToken().eType;
if (eTmpType == TLIM || eTmpType == TLIMINF || eTmpType == TLIMSUP)
return nHeight;
if (!rFormat.IsTextmode())
{
// set minimum size ()
nHeight += (nHeight * 20L) / 100L;
nHeight += nHeight
* rFormat.GetDistance(DIS_OPERATORSIZE) / 100L;
nHeight = nHeight * 686L / 845L;
}
// correct user-defined symbols to match height of sum from used font
if (rSymbol.GetToken().eType == TSPECIAL)
nHeight = nHeight * 845L / 686L;
return nHeight;
}
void SmOperNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
SmNode *pOper = GetSubNode(0);
SmNode *pBody = GetSubNode(1);
OSL_ENSURE(pOper, "Sm: missing subnode");
OSL_ENSURE(pBody, "Sm: missing subnode");
SmNode *pSymbol = GetSymbol();
pSymbol->SetSize(Fraction(CalcSymbolHeight(*pSymbol, rFormat),
pSymbol->GetFont().GetSize().Height()));
pBody->Arrange(rDev, rFormat);
pOper->Arrange(rDev, rFormat);
long nOrigHeight = GetFont().GetSize().Height(),
nDist = nOrigHeight
* rFormat.GetDistance(DIS_OPERATORSPACE) / 100L;
Point aPos = pOper->AlignTo(*pBody, RP_LEFT, RHA_CENTER, /*RVA_CENTERY*/RVA_MID);
aPos.X() -= nDist;
pOper->MoveTo(aPos);
SmRect::operator = (*pBody);
ExtendBy(*pOper, RCP_THIS);
}
/**************************************************************************/
void SmAlignNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
// set alignment within the entire subtree (including current node)
{
OSL_ENSURE(GetNumSubNodes() > 0, "Sm: missing subnode");
SmNode *pNode = GetSubNode(0);
RectHorAlign eHorAlign = RHA_CENTER;
switch (GetToken().eType)
{
case TALIGNL: eHorAlign = RHA_LEFT; break;
case TALIGNC: eHorAlign = RHA_CENTER; break;
case TALIGNR: eHorAlign = RHA_RIGHT; break;
default:
break;
}
SetRectHorAlign(eHorAlign);
pNode->Arrange(rDev, rFormat);
SmRect::operator = (pNode->GetRect());
}
/**************************************************************************/
void SmAttributNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
SmNode *pAttr = GetSubNode(0),
*pBody = GetSubNode(1);
OSL_ENSURE(pBody, "Sm: body missing");
OSL_ENSURE(pAttr, "Sm: attribute missing");
pBody->Arrange(rDev, rFormat);
if (GetScaleMode() == SCALE_WIDTH)
pAttr->AdaptToX(rDev, pBody->GetItalicWidth());
pAttr->Arrange(rDev, rFormat);
// get relative position of attribute
RectVerAlign eVerAlign;
long nDist = 0;
switch (GetToken().eType)
{ case TUNDERLINE :
eVerAlign = RVA_ATTRIBUT_LO;
break;
case TOVERSTRIKE :
eVerAlign = RVA_ATTRIBUT_MID;
break;
default :
eVerAlign = RVA_ATTRIBUT_HI;
if (pBody->GetType() == NATTRIBUT)
nDist = GetFont().GetSize().Height()
* rFormat.GetDistance(DIS_ORNAMENTSPACE) / 100L;
}
Point aPos = pAttr->AlignTo(*pBody, RP_ATTRIBUT, RHA_CENTER, eVerAlign);
aPos.Y() -= nDist;
pAttr->MoveTo(aPos);
SmRect::operator = (*pBody);
ExtendBy(*pAttr, RCP_THIS, true);
}
/**************************************************************************/
void SmFontNode::CreateTextFromNode(OUString &rText)
{
switch (GetToken().eType)
{
case TBOLD:
rText += "bold ";
break;
case TNBOLD:
rText += "nbold ";
break;
case TITALIC:
rText += "italic ";
break;
case TNITALIC:
rText += "nitalic ";
break;
case TPHANTOM:
rText += "phantom ";
break;
case TSIZE:
{
rText += "size ";
switch (nSizeType)
{
case FNTSIZ_PLUS:
rText += "+";
break;
case FNTSIZ_MINUS:
rText += "-";
break;
case FNTSIZ_MULTIPLY:
rText += "*'";
break;
case FNTSIZ_DIVIDE:
rText += "/";
break;
case FNTSIZ_ABSOLUT:
default:
break;
}
rText += ::rtl::math::doubleToUString(
static_cast<double>(aFontSize),
rtl_math_StringFormat_Automatic,
rtl_math_DecimalPlaces_Max, '.', true);
rText += " ";
}
break;
case TBLACK:
rText += "color black ";
break;
case TWHITE:
rText += "color white ";
break;
case TRED:
rText += "color red ";
break;
case TGREEN:
rText += "color green ";
break;
case TBLUE:
rText += "color blue ";
break;
case TCYAN:
rText += "color cyan ";
break;
case TMAGENTA:
rText += "color magenta ";
break;
case TYELLOW:
rText += "color yellow ";
break;
case TSANS:
rText += "font sans ";
break;
case TSERIF:
rText += "font serif ";
break;
case TFIXED:
rText += "font fixed ";
break;
default:
break;
}
GetSubNode(1)->CreateTextFromNode(rText);
}
void SmFontNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell)
{
//! prepare subnodes first
SmNode::Prepare(rFormat, rDocShell);
int nFnt = -1;
switch (GetToken().eType)
{
case TFIXED: nFnt = FNT_FIXED; break;
case TSANS: nFnt = FNT_SANS; break;
case TSERIF: nFnt = FNT_SERIF; break;
default:
break;
}
if (nFnt != -1)
{ GetFont() = rFormat.GetFont( sal::static_int_cast< sal_uInt16 >(nFnt) );
SetFont(GetFont());
}
//! prevent overwrites of this font by 'Arrange' or 'SetFont' calls of
//! other font nodes (those with lower depth in the tree)
Flags() |= FLG_FONT;
}
void SmFontNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
SmNode *pNode = GetSubNode(1);
OSL_ENSURE(pNode, "Sm: missing subnode");
switch (GetToken().eType)
{ case TSIZE :
pNode->SetFontSize(aFontSize, nSizeType);
break;
case TSANS :
case TSERIF :
case TFIXED :
pNode->SetFont(GetFont());
break;
case TUNKNOWN : break; // no assertion on "font <?> <?>"
case TPHANTOM : SetPhantom(true); break;
case TBOLD : SetAttribut(ATTR_BOLD); break;
case TITALIC : SetAttribut(ATTR_ITALIC); break;
case TNBOLD : ClearAttribut(ATTR_BOLD); break;
case TNITALIC : ClearAttribut(ATTR_ITALIC); break;
case TBLACK : SetColor(Color(COL_BLACK)); break;
case TWHITE : SetColor(Color(COL_WHITE)); break;
case TRED : SetColor(Color(COL_RED)); break;
case TGREEN : SetColor(Color(COL_GREEN)); break;
case TBLUE : SetColor(Color(COL_BLUE)); break;
case TCYAN : SetColor(Color(COL_CYAN)); break;
case TMAGENTA : SetColor(Color(COL_MAGENTA)); break;
case TYELLOW : SetColor(Color(COL_YELLOW)); break;
default:
SAL_WARN("starmath", "unknown case");
}
pNode->Arrange(rDev, rFormat);
SmRect::operator = (pNode->GetRect());
}
void SmFontNode::SetSizeParameter(const Fraction& rValue, sal_uInt16 Type)
{
nSizeType = Type;
aFontSize = rValue;
}
/**************************************************************************/
SmPolyLineNode::SmPolyLineNode(const SmToken &rNodeToken)
: SmGraphicNode(NPOLYLINE, rNodeToken)
{
aPoly.SetSize(2);
nWidth = 0;
}
void SmPolyLineNode::AdaptToX(const OutputDevice &/*rDev*/, sal_uLong nNewWidth)
{
aToSize.Width() = nNewWidth;
}
void SmPolyLineNode::AdaptToY(const OutputDevice &/*rDev*/, sal_uLong nNewHeight)
{
GetFont().FreezeBorderWidth();
aToSize.Height() = nNewHeight;
}
void SmPolyLineNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
//! some routines being called extract some info from the OutputDevice's
//! font (eg the space to be used for borders OR the font name(!!)).
//! Thus the font should reflect the needs and has to be set!
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
long nBorderwidth = GetFont().GetBorderWidth();
// create polygon using both endpoints
OSL_ENSURE(aPoly.GetSize() == 2, "Sm : wrong number of points");
Point aPointA, aPointB;
if (GetToken().eType == TWIDESLASH)
{
aPointA.X() = nBorderwidth;
aPointA.Y() = aToSize.Height() - nBorderwidth;
aPointB.X() = aToSize.Width() - nBorderwidth;
aPointB.Y() = nBorderwidth;
}
else
{
OSL_ENSURE(GetToken().eType == TWIDEBACKSLASH, "Sm : unexpected token");
aPointA.X() =
aPointA.Y() = nBorderwidth;
aPointB.X() = aToSize.Width() - nBorderwidth;
aPointB.Y() = aToSize.Height() - nBorderwidth;
}
aPoly.SetPoint(aPointA, 0);
aPoly.SetPoint(aPointB, 1);
long nThick = GetFont().GetSize().Height()
* rFormat.GetDistance(DIS_STROKEWIDTH) / 100L;
nWidth = nThick + 2 * nBorderwidth;
SmRect::operator = (SmRect(aToSize.Width(), aToSize.Height()));
}
/**************************************************************************/
void SmRootSymbolNode::AdaptToX(const OutputDevice &/*rDev*/, sal_uLong nWidth)
{
nBodyWidth = nWidth;
}
void SmRootSymbolNode::AdaptToY(const OutputDevice &rDev, sal_uLong nHeight)
{
// some additional length so that the horizontal
// bar will be positioned above the argument
SmMathSymbolNode::AdaptToY(rDev, nHeight + nHeight / 10L);
}
/**************************************************************************/
void SmDynIntegralSymbolNode::AdaptToY(const OutputDevice &rDev, sal_uLong nHeight)
{
long nFactor = 12L;
// The new height equals (1 + nFactor) * oldHeight
// nFactor was chosen for keeping the integral sign from becoming too "fat".
SmMathSymbolNode::AdaptToY(rDev, nHeight + nHeight / nFactor);
// keep the ratio
long nCurWidth = GetSize().Width();
SmMathSymbolNode::AdaptToX(rDev, nCurWidth + nCurWidth / nFactor);
}
/**************************************************************************/
void SmRectangleNode::AdaptToX(const OutputDevice &/*rDev*/, sal_uLong nWidth)
{
aToSize.Width() = nWidth;
}
void SmRectangleNode::AdaptToY(const OutputDevice &/*rDev*/, sal_uLong nHeight)
{
GetFont().FreezeBorderWidth();
aToSize.Height() = nHeight;
}
void SmRectangleNode::Arrange(const OutputDevice &rDev, const SmFormat &/*rFormat*/)
{
long nFontHeight = GetFont().GetSize().Height();
long nWidth = aToSize.Width(),
nHeight = aToSize.Height();
if (nHeight == 0)
nHeight = nFontHeight / 30;
if (nWidth == 0)
nWidth = nFontHeight / 3;
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
// add some borderspace
sal_uLong nTmpBorderWidth = GetFont().GetBorderWidth();
nHeight += 2 * nTmpBorderWidth;
//! use this method in order to have 'SmRect::HasAlignInfo() == true'
//! and thus having the attribute-fences updated in 'SmRect::ExtendBy'
SmRect::operator = (SmRect(nWidth, nHeight));
}
/**************************************************************************/
SmTextNode::SmTextNode( SmNodeType eNodeType, const SmToken &rNodeToken, sal_uInt16 nFontDescP )
: SmVisibleNode(eNodeType, rNodeToken)
, nFontDesc(nFontDescP)
, nSelectionStart(0)
, nSelectionEnd(0)
{
}
SmTextNode::SmTextNode( const SmToken &rNodeToken, sal_uInt16 nFontDescP )
: SmVisibleNode(NTEXT, rNodeToken)
, nFontDesc(nFontDescP)
, nSelectionStart(0)
, nSelectionEnd(0)
{
}
void SmTextNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell)
{
SmNode::Prepare(rFormat, rDocShell);
// default setting for horizontal alignment of nodes with TTEXT
// content is as alignl (cannot be done in Arrange since it would
// override the settings made by an SmAlignNode before)
if (TTEXT == GetToken().eType)
SetRectHorAlign( RHA_LEFT );
aText = GetToken().aText;
GetFont() = rFormat.GetFont(GetFontDesc());
if (IsItalic( GetFont() ))
Attributes() |= ATTR_ITALIC;
if (IsBold( GetFont() ))
Attributes() |= ATTR_BOLD;
// special handling for ':' where it is a token on it's own and is likely
// to be used for mathematical notations. (E.g. a:b = 2:3)
// In that case it should not be displayed in italic.
if (GetToken().aText.getLength() == 1 && GetToken().aText[0] == ':')
Attributes() &= ~ATTR_ITALIC;
};
void SmTextNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
PrepareAttributes();
sal_uInt16 nSizeDesc = GetFontDesc() == FNT_FUNCTION ?
SIZ_FUNCTION : SIZ_TEXT;
GetFont() *= Fraction (rFormat.GetRelSize(nSizeDesc), 100);
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
SmRect::operator = (SmRect(aTmpDev, &rFormat, aText, GetFont().GetBorderWidth()));
}
void SmTextNode::CreateTextFromNode(OUString &rText)
{
bool bQuoted=false;
if (GetToken().eType == TTEXT)
{
rText += "\"";
bQuoted=true;
}
else
{
SmParser aParseTest;
SmNode *pTable = aParseTest.Parse(GetToken().aText);
bQuoted=true;
if ( (pTable->GetType() == NTABLE) && (pTable->GetNumSubNodes() == 1) )
{
SmNode *pResult = pTable->GetSubNode(0);
if ( (pResult->GetType() == NLINE) &&
(pResult->GetNumSubNodes() == 1) )
{
pResult = pResult->GetSubNode(0);
if ( (pResult->GetType() == NEXPRESSION) &&
(pResult->GetNumSubNodes() == 1) )
{
pResult = pResult->GetSubNode(0);
if (pResult->GetType() == NTEXT)
bQuoted=false;
}
}
}
delete pTable;
if ((GetToken().eType == TIDENT) && (GetFontDesc() == FNT_FUNCTION))
{
//Search for existing functions and remove extraenous keyword
rText += "func ";
}
else if (bQuoted)
rText += "italic ";
if (bQuoted)
rText += "\"";
}
rText += GetToken().aText;
if (bQuoted)
rText += "\"";
rText += " ";
}
void SmTextNode::GetAccessibleText( OUStringBuffer &rText ) const
{
rText.append(aText);
}
void SmTextNode::AdjustFontDesc()
{
if (GetToken().eType == TTEXT)
nFontDesc = FNT_TEXT;
else if(GetToken().eType == TFUNC)
nFontDesc = FNT_FUNCTION;
else {
SmTokenType nTok;
const SmTokenTableEntry *pEntry = SmParser::GetTokenTableEntry( aText );
if (pEntry && pEntry->nGroup == TGFUNCTION) {
nTok = pEntry->eType;
nFontDesc = FNT_FUNCTION;
} else {
sal_Unicode firstChar = aText[0];
if( ('0' <= firstChar && firstChar <= '9') || firstChar == '.' || firstChar == ',') {
nFontDesc = FNT_NUMBER;
nTok = TNUMBER;
} else if (aText.getLength() > 1) {
nFontDesc = FNT_VARIABLE;
nTok = TIDENT;
} else {
nFontDesc = FNT_VARIABLE;
nTok = TCHARACTER;
}
}
SmToken tok = GetToken();
tok.eType = nTok;
SetToken(tok);
}
}
sal_Unicode SmTextNode::ConvertSymbolToUnicode(sal_Unicode nIn)
{
//Find the best match in accepted unicode for our private area symbols
static const sal_Unicode aStarMathPrivateToUnicode[] =
{
0x2030, 0xF613, 0xF612, 0x002B, 0x003C, 0x003E, 0xE425, 0xE421, 0xE088, 0x2208,
0x0192, 0x2026, 0x2192, 0x221A, 0x221A, 0x221A, 0xE090, 0x005E, 0x02C7, 0x02D8,
0x00B4, 0x0060, 0x02DC, 0x00AF, 0x0362, 0xE099, 0xE09A, 0x20DB, 0xE09C, 0xE09D,
0x0028, 0x0029, 0x2220, 0x22AF, 0xE0A2, 0xE0A3, 0xE0A4, 0xE0A5, 0xE0A6, 0xE0A7,
0x002F, 0x005C, 0x274F, 0xE0AB, 0x0393, 0x0394, 0x0398, 0x039b, 0x039e, 0x03A0,
0x03a3, 0x03a5, 0x03a6, 0x03a8, 0x03A9, 0x03B1, 0x03B2, 0x03b3, 0x03b4, 0x03b5,
0x03b6, 0x03b7, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf,
0x03c0, 0x03c1, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9, 0x03b5,
0x03d1, 0x03d6, 0xE0D2, 0x03db, 0x2118, 0x2202, 0x2129, 0xE0D7, 0xE0D8, 0x22A4,
0xE0DA, 0x2190, 0x2191, 0x2193
};
if ((nIn >= 0xE080) && (nIn <= 0xE0DD))
nIn = aStarMathPrivateToUnicode[nIn-0xE080];
//For whatever unicode glyph that equation editor doesn't ship with that
//we have a possible match we can munge it to.
switch (nIn)
{
case 0x2223:
nIn = '|';
break;
default:
break;
}
return nIn;
}
/**************************************************************************/
void SmMatrixNode::CreateTextFromNode(OUString &rText)
{
rText += "matrix {";
for (sal_uInt16 i = 0; i < nNumRows; i++)
{
for (sal_uInt16 j = 0; j < nNumCols; j++)
{
SmNode *pNode = GetSubNode(i * nNumCols + j);
if (pNode)
pNode->CreateTextFromNode(rText);
if (j != nNumCols-1)
rText += "# ";
}
if (i != nNumRows-1)
rText += "## ";
}
rText = comphelper::string::stripEnd(rText, ' ');
rText += "} ";
}
void SmMatrixNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
SmNode *pNode;
sal_uInt16 i, j;
// initialize array that is to hold the maximum widths of all
// elements (subnodes) in that column.
long *pColWidth = new long[nNumCols];
for (j = 0; j < nNumCols; j++)
pColWidth[j] = 0;
// arrange subnodes and calculate the aboves arrays contents
sal_uInt16 nNodes = GetNumSubNodes();
for (i = 0; i < nNodes; i++)
{
sal_uInt16 nIdx = nNodes - 1 - i;
if (NULL != (pNode = GetSubNode(nIdx)))
{
pNode->Arrange(rDev, rFormat);
int nCol = nIdx % nNumCols;
pColWidth[nCol] = std::max(pColWidth[nCol], pNode->GetItalicWidth());
}
}
// norm distance from which the following two are calcutated
const int nNormDist = 3 * GetFont().GetSize().Height();
// define horizontal and vertical minimal distances that separate
// the elements
long nHorDist = nNormDist * rFormat.GetDistance(DIS_MATRIXCOL) / 100L,
nVerDist = nNormDist * rFormat.GetDistance(DIS_MATRIXROW) / 100L;
// build array that holds the leftmost position for each column
long *pColLeft = new long[nNumCols];
long nX = 0;
for (j = 0; j < nNumCols; j++)
{ pColLeft[j] = nX;
nX += pColWidth[j] + nHorDist;
}
Point aPos, aDelta;
SmRect aLineRect;
SmRect::operator = (SmRect());
for (i = 0; i < nNumRows; i++)
{ aLineRect = SmRect();
for (j = 0; j < nNumCols; j++)
{ SmNode *pTmpNode = GetSubNode(i * nNumCols + j);
OSL_ENSURE(pTmpNode, "Sm: NULL pointer");
const SmRect &rNodeRect = pTmpNode->GetRect();
// align all baselines in that row if possible
aPos = rNodeRect.AlignTo(aLineRect, RP_RIGHT, RHA_CENTER, RVA_BASELINE);
aPos.X() += nHorDist;
// get horizontal alignment
const SmNode *pCoNode = pTmpNode->GetLeftMost();
RectHorAlign eHorAlign = pCoNode->GetRectHorAlign();
// caculate horizontal position of element depending on column
// and horizontal alignment
switch (eHorAlign)
{ case RHA_LEFT:
aPos.X() = rNodeRect.GetLeft() + pColLeft[j];
break;
case RHA_CENTER:
aPos.X() = rNodeRect.GetLeft() + pColLeft[j]
+ pColWidth[j] / 2
- rNodeRect.GetItalicCenterX();
break;
case RHA_RIGHT:
aPos.X() = rNodeRect.GetLeft() + pColLeft[j]
+ pColWidth[j] - rNodeRect.GetItalicWidth();
break;
}
pTmpNode->MoveTo(aPos);
aLineRect.ExtendBy(rNodeRect, RCP_XOR);
}
aPos = aLineRect.AlignTo(*this, RP_BOTTOM, RHA_CENTER, RVA_BASELINE);
aPos.Y() += nVerDist;
// move 'aLineRect' and rectangles in that line to final position
aDelta.X() = 0; // since horizontal alignment is already done
aDelta.Y() = aPos.Y() - aLineRect.GetTop();
aLineRect.Move(aDelta);
for (j = 0; j < nNumCols; j++)
if (NULL != (pNode = GetSubNode(i * nNumCols + j)))
pNode->Move(aDelta);
ExtendBy(aLineRect, RCP_NONE);
}
delete [] pColLeft;
delete [] pColWidth;
}
void SmMatrixNode::SetRowCol(sal_uInt16 nMatrixRows, sal_uInt16 nMatrixCols)
{
nNumRows = nMatrixRows;
nNumCols = nMatrixCols;
}
SmNode * SmMatrixNode::GetLeftMost()
{
return this;
}
/**************************************************************************/
SmMathSymbolNode::SmMathSymbolNode(const SmToken &rNodeToken)
: SmSpecialNode(NMATH, rNodeToken, FNT_MATH)
{
sal_Unicode cChar = GetToken().cMathChar;
if ((sal_Unicode) '\0' != cChar)
SetText(OUString(cChar));
}
void SmMathSymbolNode::AdaptToX(const OutputDevice &rDev, sal_uLong nWidth)
{
// Since there is no function to do this, we try to approximate it:
Size aFntSize (GetFont().GetSize());
//! however the result is a bit better with 'nWidth' as initial font width
aFntSize.Width() = nWidth;
GetFont().SetSize(aFntSize);
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
// get denominator of error factor for width
long nTmpBorderWidth = GetFont().GetBorderWidth();
long nDenom = SmRect(aTmpDev, NULL, GetText(), nTmpBorderWidth).GetItalicWidth();
// scale fontwidth with this error factor
aFntSize.Width() *= nWidth;
aFntSize.Width() /= nDenom ? nDenom : 1;
GetFont().SetSize(aFntSize);
}
void SmMathSymbolNode::AdaptToY(const OutputDevice &rDev, sal_uLong nHeight)
{
GetFont().FreezeBorderWidth();
Size aFntSize (GetFont().GetSize());
// Since we only want to scale the height, we might have
// to determine the font width in order to keep it
if (aFntSize.Width() == 0)
{
OutputDevice &rDevNC = (OutputDevice &) rDev;
rDevNC.Push(PUSH_FONT | PUSH_MAPMODE);
rDevNC.SetFont(GetFont());
aFntSize.Width() = rDev.GetFontMetric().GetSize().Width();
rDevNC.Pop();
}
OSL_ENSURE(aFntSize.Width() != 0, "Sm: ");
//! however the result is a bit better with 'nHeight' as initial
//! font height
aFntSize.Height() = nHeight;
GetFont().SetSize(aFntSize);
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
// get denominator of error factor for height
long nTmpBorderWidth = GetFont().GetBorderWidth();
long nDenom = SmRect(aTmpDev, NULL, GetText(), nTmpBorderWidth).GetHeight();
// scale fontwidth with this error factor
aFntSize.Height() *= nHeight;
aFntSize.Height() /= nDenom ? nDenom : 1;
GetFont().SetSize(aFntSize);
}
void SmMathSymbolNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell)
{
SmNode::Prepare(rFormat, rDocShell);
GetFont() = rFormat.GetFont(GetFontDesc());
// use same font size as is used for variables
GetFont().SetSize( rFormat.GetFont( FNT_VARIABLE ).GetSize() );
OSL_ENSURE(GetFont().GetCharSet() == RTL_TEXTENCODING_SYMBOL ||
GetFont().GetCharSet() == RTL_TEXTENCODING_UNICODE,
"wrong charset for character from StarMath/OpenSymbol font");
Flags() |= FLG_FONT | FLG_ITALIC;
};
void SmMathSymbolNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
const OUString &rText = GetText();
if (rText.isEmpty() || rText[0] == '\0')
{ SmRect::operator = (SmRect());
return;
}
PrepareAttributes();
GetFont() *= Fraction (rFormat.GetRelSize(SIZ_TEXT), 100);
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
SmRect::operator = (SmRect(aTmpDev, &rFormat, rText, GetFont().GetBorderWidth()));
}
void SmMathSymbolNode::CreateTextFromNode(OUString &rText)
{
OUString sStr;
MathType::LookupChar(GetToken().cMathChar, sStr);
rText += sStr;
}
void SmRectangleNode::CreateTextFromNode(OUString &rText)
{
switch (GetToken().eType)
{
case TUNDERLINE:
rText += "underline ";
break;
case TOVERLINE:
rText += "overline ";
break;
case TOVERSTRIKE:
rText += "overstrike ";
break;
default:
break;
}
}
void SmAttributNode::CreateTextFromNode(OUString &rText)
{
SmNode *pNode;
sal_uInt16 nSize = GetNumSubNodes();
OSL_ENSURE(nSize == 2, "Node missing members");
rText += "{";
sal_Unicode nLast=0;
if (NULL != (pNode = GetSubNode(0)))
{
OUString aStr;
pNode->CreateTextFromNode(aStr);
if (aStr.getLength() > 1)
rText += aStr;
else
{
nLast = aStr[0];
switch (nLast)
{
case MS_BAR: // MACRON
rText += "overline ";
break;
case MS_DOT: // DOT ABOVE
rText += "dot ";
break;
case 0x2dc: // SMALL TILDE
rText += "widetilde ";
break;
case MS_DDOT: // DIAERESIS
rText += "ddot ";
break;
case 0xE082:
break;
case 0xE09B:
case MS_DDDOT: // COMBINING THREE DOTS ABOVE
rText += "dddot ";
break;
case MS_ACUTE: // ACUTE ACCENT
case MS_COMBACUTE: // COMBINING ACUTE ACCENT
rText += "acute ";
break;
case MS_GRAVE: // GRAVE ACCENT
case MS_COMBGRAVE: // COMBINING GRAVE ACCENT
rText += "grave ";
break;
case MS_CHECK: // CARON
case MS_COMBCHECK: // COMBINING CARON
rText += "check ";
break;
case MS_BREVE: // BREVE
case MS_COMBBREVE: // COMBINING BREVE
rText += "breve ";
break;
case MS_CIRCLE: // RING ABOVE
case MS_COMBCIRCLE: // COMBINING RING ABOVE
rText += "circle ";
break;
case MS_RIGHTARROW: // RIGHTWARDS ARROW
case MS_VEC: // COMBINING RIGHT ARROW ABOVE
rText += "vec ";
break;
case MS_TILDE: // TILDE
case MS_COMBTILDE: // COMBINING TILDE
rText += "tilde ";
break;
case MS_HAT: // CIRCUMFLEX ACCENT
case MS_COMBHAT: // COMBINING CIRCUMFLEX ACCENT
rText += "hat ";
break;
case MS_COMBBAR: // COMBINING MACRON
rText += "bar ";
break;
default:
rText += OUString( nLast );
break;
}
}
}
if (nSize == 2)
if (NULL != (pNode = GetSubNode(1)))
pNode->CreateTextFromNode(rText);
rText = comphelper::string::stripEnd(rText, ' ');
if (nLast == 0xE082)
rText += " overbrace {}";
rText += "} ";
}
/**************************************************************************/
static bool lcl_IsFromGreekSymbolSet( const OUString &rTokenText )
{
bool bRes = false;
// valid symbol name needs to have a '%' at pos 0 and at least an additional char
if (rTokenText.getLength() > 2 && rTokenText[0] == (sal_Unicode)'%')
{
OUString aName( rTokenText.copy(1) );
SmSym *pSymbol = SM_MOD()->GetSymbolManager().GetSymbolByName( aName );
if (pSymbol && GetExportSymbolSetName(pSymbol->GetSymbolSetName()) == "Greek")
bRes = true;
}
return bRes;
}
SmSpecialNode::SmSpecialNode(SmNodeType eNodeType, const SmToken &rNodeToken, sal_uInt16 _nFontDesc) :
SmTextNode(eNodeType, rNodeToken, _nFontDesc)
{
bIsFromGreekSymbolSet = lcl_IsFromGreekSymbolSet( rNodeToken.aText );
}
SmSpecialNode::SmSpecialNode(const SmToken &rNodeToken) :
SmTextNode(NSPECIAL, rNodeToken, FNT_MATH) // default Font isn't always correct!
{
bIsFromGreekSymbolSet = lcl_IsFromGreekSymbolSet( rNodeToken.aText );
}
void SmSpecialNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell)
{
SmNode::Prepare(rFormat, rDocShell);
const SmSym *pSym;
SmModule *pp = SM_MOD();
OUString aName(GetToken().aText.copy(1));
if (NULL != (pSym = pp->GetSymbolManager().GetSymbolByName( aName )))
{
sal_UCS4 cChar = pSym->GetCharacter();
OUString aTmp( &cChar, 1 );
SetText( aTmp );
GetFont() = pSym->GetFace();
}
else
{
SetText( GetToken().aText );
GetFont() = rFormat.GetFont(FNT_VARIABLE);
}
// use same font size as is used for variables
GetFont().SetSize( rFormat.GetFont( FNT_VARIABLE ).GetSize() );
// Actually only WEIGHT_NORMAL and WEIGHT_BOLD should occur... However, the sms-file also
// contains e.g. 'WEIGHT_ULTRALIGHT'. Consequently, compare here with '>' instead of '!='.
// (In the long term the necessity for 'PrepareAttribut' and thus also for this here should be dropped)
//! see also SmFontStyles::GetStyleName
if (IsItalic( GetFont() ))
SetAttribut(ATTR_ITALIC);
if (IsBold( GetFont() ))
SetAttribut(ATTR_BOLD);
Flags() |= FLG_FONT;
if (bIsFromGreekSymbolSet)
{
OSL_ENSURE( GetText().getLength() == 1, "a symbol should only consist of 1 char!" );
bool bItalic = false;
sal_Int16 nStyle = rFormat.GetGreekCharStyle();
OSL_ENSURE( nStyle >= 0 && nStyle <= 2, "unexpected value for GreekCharStyle" );
if (nStyle == 1)
bItalic = true;
else if (nStyle == 2)
{
const OUString& rTmp(GetText());
if (rTmp.isEmpty())
{
const sal_Unicode cUppercaseAlpha = 0x0391;
const sal_Unicode cUppercaseOmega = 0x03A9;
sal_Unicode cChar = rTmp[0];
// uppercase letters should be straight and lowercase letters italic
bItalic = !(cUppercaseAlpha <= cChar && cChar <= cUppercaseOmega);
}
}
if (bItalic)
Attributes() |= ATTR_ITALIC;
else
Attributes() &= ~ATTR_ITALIC;;
}
};
void SmSpecialNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
PrepareAttributes();
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
SmRect::operator = (SmRect(aTmpDev, &rFormat, GetText(), GetFont().GetBorderWidth()));
}
/**************************************************************************/
void SmGlyphSpecialNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
PrepareAttributes();
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
SmRect::operator = (SmRect(aTmpDev, &rFormat, GetText(),
GetFont().GetBorderWidth()).AsGlyphRect());
}
/**************************************************************************/
void SmPlaceNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell)
{
SmNode::Prepare(rFormat, rDocShell);
GetFont().SetColor(COL_GRAY);
Flags() |= FLG_COLOR | FLG_FONT | FLG_ITALIC;
};
void SmPlaceNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
PrepareAttributes();
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
SmRect::operator = (SmRect(aTmpDev, &rFormat, GetText(), GetFont().GetBorderWidth()));
}
/**************************************************************************/
void SmErrorNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell)
{
SmNode::Prepare(rFormat, rDocShell);
GetFont().SetColor(COL_RED);
Flags() |= FLG_VISIBLE | FLG_BOLD | FLG_ITALIC
| FLG_COLOR | FLG_FONT | FLG_SIZE;
}
void SmErrorNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
PrepareAttributes();
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
const OUString &rText = GetText();
SmRect::operator = (SmRect(aTmpDev, &rFormat, rText, GetFont().GetBorderWidth()));
}
/**************************************************************************/
void SmBlankNode::IncreaseBy(const SmToken &rToken)
{
switch(rToken.eType)
{
case TBLANK: nNum += 4; break;
case TSBLANK: nNum += 1; break;
default:
break;
}
}
void SmBlankNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell)
{
SmNode::Prepare(rFormat, rDocShell);
// Here it need/should not be the StarMath font, so that for the character
// used in Arrange a normal (non-clipped) rectangle is generated
GetFont() = rFormat.GetFont(FNT_VARIABLE);
Flags() |= FLG_FONT | FLG_BOLD | FLG_ITALIC;
}
void SmBlankNode::Arrange(const OutputDevice &rDev, const SmFormat &rFormat)
{
SmTmpDevice aTmpDev ((OutputDevice &) rDev, true);
aTmpDev.SetFont(GetFont());
// make distance depend on the font height
// (so that it increases when scaling (e.g. size *2 {a ~ b})
long nDist = GetFont().GetSize().Height() / 10L,
nSpace = nNum * nDist;
// get a SmRect with Baseline and all the bells and whistles
SmRect::operator = (SmRect(aTmpDev, &rFormat, OUString(' '),
GetFont().GetBorderWidth()));
// and resize it to the requested size
SetItalicSpaces(0, 0);
SetWidth(nSpace);
}
/**************************************************************************/
//Implementation of all accept methods for SmVisitor
void SmNode::Accept(SmVisitor*){
//This method is only implemented to avoid making SmNode abstract because an
//obscure copy constructor is used... I can't find it's implementation, and
//don't want to figure out how to fix it... If you want to, just delete this
//method, making SmNode abstract, and see where you can an problem with that.
SAL_WARN("starmath", "SmNode should not be visitable!");
}
void SmTableNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmBraceNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmBracebodyNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmOperNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmAlignNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmAttributNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmFontNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmUnHorNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmBinHorNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmBinVerNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmBinDiagonalNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmSubSupNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmMatrixNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmPlaceNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmTextNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmSpecialNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmGlyphSpecialNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmMathSymbolNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmBlankNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmErrorNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmLineNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmExpressionNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmPolyLineNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmRootNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmRootSymbolNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmDynIntegralNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmDynIntegralSymbolNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmRectangleNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
void SmVerticalBraceNode::Accept(SmVisitor* pVisitor) {
pVisitor->Visit(this);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|