1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309
|
/* -*- 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 <sal/config.h>
#include <o3tl/any.hxx>
#include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/types.h>
#include <sal/log.hxx>
#include <osl/diagnose.h>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/container/XEnumeration.hpp>
#include <com/sun/star/container/XIndexReplace.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XMultiPropertySet.hpp>
#include <com/sun/star/beans/XPropertyState.hpp>
#include <com/sun/star/beans/UnknownPropertyException.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/text/XTextSectionsSupplier.hpp>
#include <com/sun/star/text/XTextTablesSupplier.hpp>
#include <com/sun/star/text/XNumberingRulesSupplier.hpp>
#include <com/sun/star/text/XChapterNumberingSupplier.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/text/XText.hpp>
#include <com/sun/star/text/XTextContent.hpp>
#include <com/sun/star/text/XTextRange.hpp>
#include <com/sun/star/text/XTextField.hpp>
#include <com/sun/star/container/XNamed.hpp>
#include <com/sun/star/container/XContentEnumerationAccess.hpp>
#include <com/sun/star/text/XTextFrame.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/text/SizeType.hpp>
#include <com/sun/star/text/HoriOrientation.hpp>
#include <com/sun/star/text/VertOrientation.hpp>
#include <com/sun/star/text/TextContentAnchorType.hpp>
#include <com/sun/star/text/XTextFramesSupplier.hpp>
#include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
#include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
#include <com/sun/star/document/XEventsSupplier.hpp>
#include <com/sun/star/document/XRedlinesSupplier.hpp>
#include <com/sun/star/text/XFormField.hpp>
#include <com/sun/star/text/XTextSection.hpp>
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/style/XAutoStylesSupplier.hpp>
#include <com/sun/star/style/XAutoStyleFamily.hpp>
#include <com/sun/star/text/XTextFieldsSupplier.hpp>
#include <com/sun/star/drawing/XControlShape.hpp>
#include <sax/tools/converter.hxx>
#include <xmloff/xmlnamespace.hxx>
#include <xmloff/xmlaustp.hxx>
#include <xmloff/families.hxx>
#include "txtexppr.hxx"
#include <xmloff/xmluconv.hxx>
#include "XMLAnchorTypePropHdl.hxx"
#include <xexptran.hxx>
#include <xmloff/ProgressBarHelper.hxx>
#include <xmloff/namespacemap.hxx>
#include <xmloff/xmlexp.hxx>
#include <txtflde.hxx>
#include <xmloff/txtprmap.hxx>
#include <XMLImageMapExport.hxx>
#include "XMLTextNumRuleInfo.hxx"
#include <xmloff/XMLTextListAutoStylePool.hxx>
#include <xmloff/txtparae.hxx>
#include "XMLSectionExport.hxx"
#include "XMLIndexMarkExport.hxx"
#include <xmloff/XMLEventExport.hxx>
#include "XMLRedlineExport.hxx"
#include <MultiPropertySetHelper.hxx>
#include <xmloff/formlayerexport.hxx>
#include "XMLTextCharStyleNamesElementExport.hxx"
#include <xmloff/odffields.hxx>
#include <xmloff/maptype.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/document/XStorageBasedDocument.hpp>
#include <txtlists.hxx>
#include <com/sun/star/rdf/XMetadatable.hpp>
#include <list>
#include <unordered_map>
#include <memory>
#include <vector>
#include <algorithm>
#include <iterator>
#include <officecfg/Office/Common.hxx>
#include <o3tl/safeint.hxx>
#include <comphelper/scopeguard.hxx>
#include <comphelper/sequenceashashmap.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::text;
using namespace ::com::sun::star::style;
using namespace ::com::sun::star::drawing;
using namespace ::com::sun::star::document;
using namespace ::com::sun::star::graphic;
using namespace ::xmloff;
using namespace ::xmloff::token;
// Implement Title/Description Elements UI (#i73249#)
constexpr OUString gsTitle(u"Title"_ustr);
constexpr OUString gsDescription(u"Description"_ustr);
constexpr OUStringLiteral gsAnchorPageNo(u"AnchorPageNo");
constexpr OUStringLiteral gsAnchorType(u"AnchorType");
constexpr OUString gsBookmark(u"Bookmark"_ustr);
constexpr OUString gsChainNextName(u"ChainNextName"_ustr);
constexpr OUString gsContourPolyPolygon(u"ContourPolyPolygon"_ustr);
constexpr OUStringLiteral gsDocumentIndexMark(u"DocumentIndexMark");
constexpr OUStringLiteral gsFrame(u"Frame");
constexpr OUStringLiteral gsGraphicFilter(u"GraphicFilter");
constexpr OUStringLiteral gsGraphicRotation(u"GraphicRotation");
constexpr OUString gsHeight(u"Height"_ustr);
constexpr OUStringLiteral gsHoriOrient(u"HoriOrient");
constexpr OUStringLiteral gsHoriOrientPosition(u"HoriOrientPosition");
constexpr OUString gsHyperLinkName(u"HyperLinkName"_ustr);
constexpr OUString gsHyperLinkTarget(u"HyperLinkTarget"_ustr);
constexpr OUString gsHyperLinkURL(u"HyperLinkURL"_ustr);
constexpr OUString gsIsAutomaticContour(u"IsAutomaticContour"_ustr);
constexpr OUString gsIsCollapsed(u"IsCollapsed"_ustr);
constexpr OUString gsIsPixelContour(u"IsPixelContour"_ustr);
constexpr OUString gsIsStart(u"IsStart"_ustr);
constexpr OUString gsIsSyncHeightToWidth(u"IsSyncHeightToWidth"_ustr);
constexpr OUString gsIsSyncWidthToHeight(u"IsSyncWidthToHeight"_ustr);
constexpr OUString gsNumberingRules(u"NumberingRules"_ustr);
constexpr OUString gsParaConditionalStyleName(u"ParaConditionalStyleName"_ustr);
constexpr OUStringLiteral gsParagraphService(u"com.sun.star.text.Paragraph");
constexpr OUStringLiteral gsRedline(u"Redline");
constexpr OUString gsReferenceMark(u"ReferenceMark"_ustr);
constexpr OUString gsRelativeHeight(u"RelativeHeight"_ustr);
constexpr OUString gsRelativeWidth(u"RelativeWidth"_ustr);
constexpr OUStringLiteral gsRuby(u"Ruby");
constexpr OUStringLiteral gsRubyCharStyleName(u"RubyCharStyleName");
constexpr OUStringLiteral gsRubyText(u"RubyText");
constexpr OUString gsServerMap(u"ServerMap"_ustr);
constexpr OUString gsShapeService(u"com.sun.star.drawing.Shape"_ustr);
constexpr OUString gsSizeType(u"SizeType"_ustr);
constexpr OUStringLiteral gsSoftPageBreak( u"SoftPageBreak" );
constexpr OUStringLiteral gsTableService(u"com.sun.star.text.TextTable");
constexpr OUStringLiteral gsText(u"Text");
constexpr OUString gsTextContentService(u"com.sun.star.text.TextContent"_ustr);
constexpr OUStringLiteral gsTextEmbeddedService(u"com.sun.star.text.TextEmbeddedObject");
constexpr OUString gsTextField(u"TextField"_ustr);
constexpr OUStringLiteral gsTextFieldService(u"com.sun.star.text.TextField");
constexpr OUStringLiteral gsTextFrameService(u"com.sun.star.text.TextFrame");
constexpr OUStringLiteral gsTextGraphicService(u"com.sun.star.text.TextGraphicObject");
constexpr OUString gsTextPortionType(u"TextPortionType"_ustr);
constexpr OUString gsUnvisitedCharStyleName(u"UnvisitedCharStyleName"_ustr);
constexpr OUStringLiteral gsVertOrient(u"VertOrient");
constexpr OUStringLiteral gsVertOrientPosition(u"VertOrientPosition");
constexpr OUString gsVisitedCharStyleName(u"VisitedCharStyleName"_ustr);
constexpr OUString gsWidth(u"Width"_ustr);
constexpr OUString gsWidthType( u"WidthType"_ustr );
constexpr OUStringLiteral gsTextFieldStart( u"TextFieldStart" );
constexpr OUStringLiteral gsTextFieldSep(u"TextFieldSeparator");
constexpr OUStringLiteral gsTextFieldEnd( u"TextFieldEnd" );
constexpr OUStringLiteral gsTextFieldStartEnd( u"TextFieldStartEnd" );
constexpr OUStringLiteral gsPropertyCharStyleNames(u"CharStyleNames");
namespace
{
class TextContentSet
{
public:
typedef std::list<Reference<XTextContent>> contents_t;
typedef std::back_insert_iterator<contents_t> inserter_t;
typedef contents_t::const_iterator const_iterator_t;
inserter_t getInserter()
{ return std::back_insert_iterator<contents_t>(m_vTextContents); };
const_iterator_t getBegin() const
{ return m_vTextContents.begin(); };
const_iterator_t getEnd() const
{ return m_vTextContents.end(); };
private:
contents_t m_vTextContents;
};
struct FrameRefHash
{
size_t operator()(const Reference<XTextFrame>& rFrame) const
{ return sal::static_int_cast<size_t>(reinterpret_cast<sal_uIntPtr>(rFrame.get())); }
};
bool lcl_TextContentsUnfiltered(const Reference<XTextContent>&)
{ return true; };
bool lcl_ShapeFilter(const Reference<XTextContent>& xTxtContent)
{
Reference<XShape> xShape(xTxtContent, UNO_QUERY);
if(!xShape.is())
return false;
Reference<XServiceInfo> xServiceInfo(xTxtContent, UNO_QUERY);
return !xServiceInfo->supportsService(u"com.sun.star.text.TextFrame"_ustr) &&
!xServiceInfo->supportsService(u"com.sun.star.text.TextGraphicObject"_ustr) &&
!xServiceInfo->supportsService(u"com.sun.star.text.TextEmbeddedObject"_ustr);
};
class BoundFrames
{
public:
typedef bool (*filter_t)(const Reference<XTextContent>&);
BoundFrames(
const Reference<XEnumerationAccess>& rEnumAccess,
const filter_t& rFilter)
: m_xEnumAccess(rEnumAccess)
{
Fill(rFilter);
};
BoundFrames()
{};
const TextContentSet& GetPageBoundContents() const
{ return m_vPageBounds; };
const TextContentSet* GetFrameBoundContents(const Reference<XTextFrame>& rParentFrame) const
{
framebound_map_t::const_iterator it = m_vFrameBoundsOf.find(rParentFrame);
if(it == m_vFrameBoundsOf.end())
return nullptr;
return &(it->second);
};
Reference<XEnumeration> createEnumeration() const
{
if(!m_xEnumAccess.is())
return Reference<XEnumeration>();
return m_xEnumAccess->createEnumeration();
};
private:
typedef std::unordered_map<
Reference<XTextFrame>,
TextContentSet,
FrameRefHash> framebound_map_t;
TextContentSet m_vPageBounds;
framebound_map_t m_vFrameBoundsOf;
const Reference<XEnumerationAccess> m_xEnumAccess;
void Fill(const filter_t& rFilter);
};
class FieldParamExporter
{
public:
FieldParamExporter(SvXMLExport* const pExport, Reference<XNameContainer> const & xFieldParams)
: m_pExport(pExport)
, m_xFieldParams(xFieldParams)
{ };
void Export();
private:
SvXMLExport* const m_pExport;
const Reference<XNameContainer> m_xFieldParams;
void ExportParameter(const OUString& sKey, const OUString& sValue);
};
struct HyperlinkData
{
OUString href, name, targetFrame, ustyleName, vstyleName;
bool serverMap = false;
css::uno::Reference<css::container::XNameReplace> events;
HyperlinkData() = default;
HyperlinkData(const css::uno::Reference<css::beans::XPropertySet>& rPropSet);
bool operator==(const HyperlinkData&);
bool operator!=(const HyperlinkData& rOther) { return !operator==(rOther); }
bool addHyperlinkAttributes(SvXMLExport& rExport);
void exportEvents(SvXMLExport& rExport);
};
HyperlinkData::HyperlinkData(const css::uno::Reference<css::beans::XPropertySet>& rPropSet)
{
const css::uno::Reference<css::beans::XPropertyState> xPropState(rPropSet, UNO_QUERY);
const auto xPropSetInfo(rPropSet->getPropertySetInfo());
if (xPropSetInfo->hasPropertyByName(gsHyperLinkURL)
&& (!xPropState.is()
|| PropertyState_DIRECT_VALUE == xPropState->getPropertyState(gsHyperLinkURL)))
{
rPropSet->getPropertyValue(gsHyperLinkURL) >>= href;
}
if (href.isEmpty())
return;
if (xPropSetInfo->hasPropertyByName(gsHyperLinkName)
&& (!xPropState.is()
|| PropertyState_DIRECT_VALUE == xPropState->getPropertyState(gsHyperLinkName)))
{
rPropSet->getPropertyValue(gsHyperLinkName) >>= name;
}
if (xPropSetInfo->hasPropertyByName(gsHyperLinkTarget)
&& (!xPropState.is()
|| PropertyState_DIRECT_VALUE == xPropState->getPropertyState(gsHyperLinkTarget)))
{
rPropSet->getPropertyValue(gsHyperLinkTarget) >>= targetFrame;
}
if (xPropSetInfo->hasPropertyByName(gsServerMap)
&& (!xPropState.is()
|| PropertyState_DIRECT_VALUE == xPropState->getPropertyState(gsServerMap)))
{
serverMap = *o3tl::doAccess<bool>(rPropSet->getPropertyValue(gsServerMap));
}
if (xPropSetInfo->hasPropertyByName(gsUnvisitedCharStyleName)
&& (!xPropState.is()
|| PropertyState_DIRECT_VALUE
== xPropState->getPropertyState(gsUnvisitedCharStyleName)))
{
rPropSet->getPropertyValue(gsUnvisitedCharStyleName) >>= ustyleName;
}
if (xPropSetInfo->hasPropertyByName(gsVisitedCharStyleName)
&& (!xPropState.is()
|| PropertyState_DIRECT_VALUE
== xPropState->getPropertyState(gsVisitedCharStyleName)))
{
rPropSet->getPropertyValue(gsVisitedCharStyleName) >>= vstyleName;
}
static constexpr OUString sHyperLinkEvents(u"HyperLinkEvents"_ustr);
if (xPropSetInfo->hasPropertyByName(sHyperLinkEvents))
{
events.set(rPropSet->getPropertyValue(sHyperLinkEvents), uno::UNO_QUERY);
}
}
bool HyperlinkData::operator==(const HyperlinkData& rOther)
{
if (href != rOther.href || name != rOther.name || targetFrame != rOther.targetFrame
|| ustyleName != rOther.ustyleName || vstyleName != rOther.vstyleName
|| serverMap != rOther.serverMap)
return false;
if (events == rOther.events)
return true;
if (!events || !rOther.events)
return false;
const css::uno::Sequence<OUString> aNames = events->getElementNames();
if (aNames != rOther.events->getElementNames())
return false;
for (const auto& rName : aNames)
{
const css::uno::Any aAny = events->getByName(rName);
const css::uno::Any aOtherAny = rOther.events->getByName(rName);
if (aAny != aOtherAny)
return false;
}
return true;
}
bool HyperlinkData::addHyperlinkAttributes(SvXMLExport& rExport)
{
if (href.isEmpty())
{
// hyperlink without a URL does not make sense
OSL_ENSURE(false, "hyperlink without a URL --> no export to ODF");
return false;
}
rExport.AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE);
rExport.AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, rExport.GetRelativeReference(href));
if (!name.isEmpty())
rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_NAME, name);
if (!targetFrame.isEmpty())
{
rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_TARGET_FRAME_NAME, targetFrame);
enum XMLTokenEnum eTok = targetFrame == "_blank" ? XML_NEW : XML_REPLACE;
rExport.AddAttribute(XML_NAMESPACE_XLINK, XML_SHOW, eTok);
}
if (serverMap)
rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_SERVER_MAP, XML_TRUE);
if (!ustyleName.isEmpty())
rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
rExport.EncodeStyleName(ustyleName));
if (!vstyleName.isEmpty())
rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_VISITED_STYLE_NAME,
rExport.EncodeStyleName(vstyleName));
return true;
}
void HyperlinkData::exportEvents(SvXMLExport& rExport)
{
// export events (if supported)
if (events)
rExport.GetEventExport().Export(events, false);
}
}
namespace xmloff
{
class BoundFrameSets
{
public:
explicit BoundFrameSets(const Reference<XInterface>& rModel);
const BoundFrames* GetTexts() const
{ return m_pTexts.get(); };
const BoundFrames* GetGraphics() const
{ return m_pGraphics.get(); };
const BoundFrames* GetEmbeddeds() const
{ return m_pEmbeddeds.get(); };
const BoundFrames* GetShapes() const
{ return m_pShapes.get(); };
private:
std::unique_ptr<BoundFrames> m_pTexts;
std::unique_ptr<BoundFrames> m_pGraphics;
std::unique_ptr<BoundFrames> m_pEmbeddeds;
std::unique_ptr<BoundFrames> m_pShapes;
};
}
#ifdef DBG_UTIL
static bool txtparae_bContainsIllegalCharacters = false;
#endif
// The following map shows which property values are required:
// property auto style pass export
// ParaStyleName if style exists always
// ParaConditionalStyleName if style exists always
// NumberingRules if style exists always
// TextSection always always
// ParaChapterNumberingLevel never always
// NumberingIsNumber never always
// The conclusion is that for auto styles the first three properties
// should be queried using a multi property set if, and only if, an
// auto style needs to be exported. TextSection should be queried by
// an individual call to getPropertyvalue, because this seems to be
// less expensive than querying the first three properties if they aren't
// required.
// For the export pass all properties can be queried using a multi property
// set.
constexpr OUString aParagraphPropertyNamesAuto[] =
{
u"NumberingRules"_ustr,
u"ParaConditionalStyleName"_ustr,
u"ParaStyleName"_ustr
};
namespace {
enum eParagraphPropertyNamesEnumAuto
{
NUMBERING_RULES_AUTO = 0,
PARA_CONDITIONAL_STYLE_NAME_AUTO = 1,
PARA_STYLE_NAME_AUTO = 2
};
}
constexpr OUString aParagraphPropertyNames[] =
{
u"NumberingIsNumber"_ustr,
u"NumberingStyleName"_ustr,
u"OutlineLevel"_ustr,
u"ParaConditionalStyleName"_ustr,
u"ParaStyleName"_ustr,
u"TextSection"_ustr,
u"OutlineContentVisible"_ustr
};
namespace {
enum eParagraphPropertyNamesEnum
{
NUMBERING_IS_NUMBER = 0,
PARA_NUMBERING_STYLENAME = 1,
PARA_OUTLINE_LEVEL=2,
PARA_CONDITIONAL_STYLE_NAME = 3,
PARA_STYLE_NAME = 4,
TEXT_SECTION = 5,
PARA_OUTLINE_CONTENT_VISIBLE = 6
};
}
void BoundFrames::Fill(const filter_t& rFilter)
{
if(!m_xEnumAccess.is())
return;
const Reference< XEnumeration > xEnum = m_xEnumAccess->createEnumeration();
if(!xEnum.is())
return;
static constexpr OUStringLiteral our_sAnchorType(u"AnchorType");
static constexpr OUStringLiteral our_sAnchorFrame(u"AnchorFrame");
while(xEnum->hasMoreElements())
{
Reference<XPropertySet> xPropSet(xEnum->nextElement(), UNO_QUERY);
Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY);
if(!xPropSet.is() || !xTextContent.is())
continue;
TextContentAnchorType eAnchor;
xPropSet->getPropertyValue(our_sAnchorType) >>= eAnchor;
if(TextContentAnchorType_AT_PAGE != eAnchor && TextContentAnchorType_AT_FRAME != eAnchor)
continue;
if(!rFilter(xTextContent))
continue;
TextContentSet::inserter_t pInserter = m_vPageBounds.getInserter();
if(TextContentAnchorType_AT_FRAME == eAnchor)
{
Reference<XTextFrame> xAnchorTxtFrame(
xPropSet->getPropertyValue(our_sAnchorFrame),
uno::UNO_QUERY);
pInserter = m_vFrameBoundsOf[xAnchorTxtFrame].getInserter();
}
*pInserter++ = xTextContent;
}
}
BoundFrameSets::BoundFrameSets(const Reference<XInterface>& rModel)
: m_pTexts(new BoundFrames())
, m_pGraphics(new BoundFrames())
, m_pEmbeddeds(new BoundFrames())
, m_pShapes(new BoundFrames())
{
const Reference<XTextFramesSupplier> xTFS(rModel, UNO_QUERY);
const Reference<XTextGraphicObjectsSupplier> xGOS(rModel, UNO_QUERY);
const Reference<XTextEmbeddedObjectsSupplier> xEOS(rModel, UNO_QUERY);
const Reference<XDrawPageSupplier> xDPS(rModel, UNO_QUERY);
if(xTFS.is())
m_pTexts.reset(new BoundFrames(
Reference<XEnumerationAccess>(xTFS->getTextFrames(), UNO_QUERY),
&lcl_TextContentsUnfiltered));
if(xGOS.is())
m_pGraphics.reset(new BoundFrames(
Reference<XEnumerationAccess>(xGOS->getGraphicObjects(), UNO_QUERY),
&lcl_TextContentsUnfiltered));
if(xEOS.is())
m_pEmbeddeds.reset(new BoundFrames(
Reference<XEnumerationAccess>(xEOS->getEmbeddedObjects(), UNO_QUERY),
&lcl_TextContentsUnfiltered));
if(xDPS.is())
m_pShapes.reset(new BoundFrames(
Reference<XEnumerationAccess>(xDPS->getDrawPage(), UNO_QUERY),
&lcl_ShapeFilter));
};
void FieldParamExporter::Export()
{
const Type aStringType = ::cppu::UnoType<OUString>::get();
const Type aBoolType = cppu::UnoType<sal_Bool>::get();
const Type aSeqType = cppu::UnoType<Sequence<OUString>>::get();
const Type aIntType = ::cppu::UnoType<sal_Int32>::get();
const Sequence<OUString> vParameters(m_xFieldParams->getElementNames());
for(const auto & rParameter : vParameters)
{
const Any aValue = m_xFieldParams->getByName(rParameter);
const Type& aValueType = aValue.getValueType();
if(aValueType == aStringType)
{
OUString sValue;
aValue >>= sValue;
ExportParameter(rParameter,sValue);
if ( rParameter == ODF_OLE_PARAM )
{
// Save the OLE object
Reference< embed::XStorage > xTargetStg = m_pExport->GetTargetStorage();
if (xTargetStg.is()) {
Reference< embed::XStorage > xDstStg = xTargetStg->openStorageElement(
u"OLELinks"_ustr, embed::ElementModes::WRITE );
if ( !xDstStg->hasByName( sValue ) ) {
Reference< XStorageBasedDocument > xStgDoc (
m_pExport->GetModel( ), UNO_QUERY );
Reference< embed::XStorage > xDocStg = xStgDoc->getDocumentStorage();
Reference< embed::XStorage > xOleStg = xDocStg->openStorageElement(
u"OLELinks"_ustr, embed::ElementModes::READ );
xOleStg->copyElementTo( sValue, xDstStg, sValue );
Reference< embed::XTransactedObject > xTransact( xDstStg, UNO_QUERY );
if ( xTransact.is( ) )
xTransact->commit( );
}
} else {
SAL_WARN("xmloff", "no target storage");
}
}
}
else if(aValueType == aBoolType)
{
bool bValue = false;
aValue >>= bValue;
ExportParameter(rParameter, OUString::boolean(bValue) );
}
else if(aValueType == aSeqType)
{
Sequence<OUString> vValue;
aValue >>= vValue;
for (const OUString& i : vValue)
{
ExportParameter(rParameter, i);
}
}
else if(aValueType == aIntType)
{
sal_Int32 nValue = 0;
aValue >>= nValue;
ExportParameter(rParameter, OUString::number(nValue));
}
}
}
void FieldParamExporter::ExportParameter(const OUString& sKey, const OUString& sValue)
{
m_pExport->AddAttribute(XML_NAMESPACE_FIELD, XML_NAME, sKey);
m_pExport->AddAttribute(XML_NAMESPACE_FIELD, XML_VALUE, sValue);
m_pExport->StartElement(XML_NAMESPACE_FIELD, XML_PARAM, false);
m_pExport->EndElement(XML_NAMESPACE_FIELD, XML_PARAM, false);
}
void XMLTextParagraphExport::Add( XmlStyleFamily nFamily,
const Reference < XPropertySet > & rPropSet,
const std::span<const XMLPropertyState> aAddStates,
bool bCheckParent )
{
rtl::Reference < SvXMLExportPropertyMapper > xPropMapper;
switch( nFamily )
{
case XmlStyleFamily::TEXT_PARAGRAPH:
xPropMapper = GetParaPropMapper();
break;
case XmlStyleFamily::TEXT_TEXT:
xPropMapper = GetTextPropMapper();
break;
case XmlStyleFamily::TEXT_FRAME:
xPropMapper = GetAutoFramePropMapper();
break;
case XmlStyleFamily::TEXT_SECTION:
xPropMapper = GetSectionPropMapper();
break;
case XmlStyleFamily::TEXT_RUBY:
xPropMapper = GetRubyPropMapper();
break;
default: break;
}
SAL_WARN_IF( !xPropMapper.is(), "xmloff", "There is the property mapper?" );
std::vector< XMLPropertyState > aPropStates =
xPropMapper->Filter(GetExport(), rPropSet);
aPropStates.insert( aPropStates.end(), aAddStates.begin(), aAddStates.end() );
if( aPropStates.empty() )
return;
Reference< XPropertySetInfo > xPropSetInfo(rPropSet->getPropertySetInfo());
OUString sParent, sCondParent;
switch( nFamily )
{
case XmlStyleFamily::TEXT_PARAGRAPH:
if( xPropSetInfo->hasPropertyByName( gsParaStyleName ) )
{
rPropSet->getPropertyValue( gsParaStyleName ) >>= sParent;
}
if( xPropSetInfo->hasPropertyByName( gsParaConditionalStyleName ) )
{
rPropSet->getPropertyValue( gsParaConditionalStyleName ) >>= sCondParent;
}
if( xPropSetInfo->hasPropertyByName( gsNumberingRules ) )
{
Reference < XIndexReplace > xNumRule(rPropSet->getPropertyValue( gsNumberingRules ), uno::UNO_QUERY);
if( xNumRule.is() && xNumRule->getCount() )
{
Reference < XNamed > xNamed( xNumRule, UNO_QUERY );
OUString sName;
if( xNamed.is() )
sName = xNamed->getName();
bool bAdd = sName.isEmpty();
if( !bAdd )
{
Reference < XPropertySet > xNumPropSet( xNumRule,
UNO_QUERY );
if( xNumPropSet.is() &&
xNumPropSet->getPropertySetInfo()
->hasPropertyByName( u"IsAutomatic"_ustr ) )
{
bAdd = *o3tl::doAccess<bool>(xNumPropSet->getPropertyValue( u"IsAutomatic"_ustr ));
// Check on outline style (#i73361#)
if ( bAdd &&
xNumPropSet->getPropertySetInfo()
->hasPropertyByName( u"NumberingIsOutline"_ustr ) )
{
bAdd = !(*o3tl::doAccess<bool>(xNumPropSet->getPropertyValue( u"NumberingIsOutline"_ustr )));
}
}
else
{
bAdd = true;
}
}
if( bAdd )
maListAutoPool.Add( xNumRule );
}
}
break;
case XmlStyleFamily::TEXT_TEXT:
{
if (bCheckParent && xPropSetInfo->hasPropertyByName(gsCharStyleName))
{
rPropSet->getPropertyValue(gsCharStyleName) >>= sParent;
}
// Get parent and remove hyperlinks (they aren't of interest)
rtl::Reference< XMLPropertySetMapper > xPM(xPropMapper->getPropertySetMapper());
sal_uInt16 nIgnoreProps = 0;
for( ::std::vector< XMLPropertyState >::iterator i(aPropStates.begin());
nIgnoreProps < 2 && i != aPropStates.end(); )
{
if( i->mnIndex == -1 )
{
++i;
continue;
}
switch( xPM->GetEntryContextId(i->mnIndex) )
{
case CTF_CHAR_STYLE_NAME:
case CTF_HYPERLINK_URL:
i->mnIndex = -1;
nIgnoreProps++;
i = aPropStates.erase( i );
break;
default:
++i;
break;
}
}
}
break;
case XmlStyleFamily::TEXT_FRAME:
if( xPropSetInfo->hasPropertyByName( gsFrameStyleName ) )
{
rPropSet->getPropertyValue( gsFrameStyleName ) >>= sParent;
}
break;
case XmlStyleFamily::TEXT_SECTION:
case XmlStyleFamily::TEXT_RUBY:
; // section styles have no parents
break;
default: break;
}
if (aPropStates.size()) // could change after the previous check
{
GetAutoStylePool().Add( nFamily, sParent, std::vector(aPropStates), /*bDontSeek*/false );
if( !sCondParent.isEmpty() && sParent != sCondParent )
GetAutoStylePool().Add( nFamily, sCondParent, std::move(aPropStates) );
}
}
static bool lcl_validPropState( const XMLPropertyState& rState )
{
return rState.mnIndex != -1;
}
void XMLTextParagraphExport::Add( XmlStyleFamily nFamily,
MultiPropertySetHelper& rPropSetHelper,
const Reference < XPropertySet > & rPropSet)
{
rtl::Reference < SvXMLExportPropertyMapper > xPropMapper;
switch( nFamily )
{
case XmlStyleFamily::TEXT_PARAGRAPH:
xPropMapper = GetParaPropMapper();
break;
default: break;
}
SAL_WARN_IF( !xPropMapper.is(), "xmloff", "There is the property mapper?" );
std::vector<XMLPropertyState> aPropStates(xPropMapper->Filter(GetExport(), rPropSet));
if( rPropSetHelper.hasProperty( NUMBERING_RULES_AUTO ) )
{
Reference < XIndexReplace > xNumRule(rPropSetHelper.getValue( NUMBERING_RULES_AUTO,
rPropSet, true ), uno::UNO_QUERY);
if( xNumRule.is() && xNumRule->getCount() )
{
Reference < XNamed > xNamed( xNumRule, UNO_QUERY );
OUString sName;
if( xNamed.is() )
sName = xNamed->getName();
bool bAdd = sName.isEmpty();
if( !bAdd )
{
Reference < XPropertySet > xNumPropSet( xNumRule,
UNO_QUERY );
if( xNumPropSet.is() &&
xNumPropSet->getPropertySetInfo()
->hasPropertyByName( u"IsAutomatic"_ustr ) )
{
bAdd = *o3tl::doAccess<bool>(xNumPropSet->getPropertyValue( u"IsAutomatic"_ustr ));
// Check on outline style (#i73361#)
if ( bAdd &&
xNumPropSet->getPropertySetInfo()
->hasPropertyByName( u"NumberingIsOutline"_ustr ) )
{
bAdd = !(*o3tl::doAccess<bool>(xNumPropSet->getPropertyValue( u"NumberingIsOutline"_ustr )));
}
}
else
{
bAdd = true;
}
}
if( bAdd )
maListAutoPool.Add( xNumRule );
}
}
if( aPropStates.empty() )
return;
OUString sParent, sCondParent;
switch( nFamily )
{
case XmlStyleFamily::TEXT_PARAGRAPH:
if( rPropSetHelper.hasProperty( PARA_STYLE_NAME_AUTO ) )
{
rPropSetHelper.getValue( PARA_STYLE_NAME_AUTO, rPropSet,
true ) >>= sParent;
}
if( rPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME_AUTO ) )
{
rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME_AUTO,
rPropSet, true ) >>= sCondParent;
}
break;
default: break;
}
if( std::any_of( aPropStates.begin(), aPropStates.end(), lcl_validPropState ) )
{
GetAutoStylePool().Add( nFamily, sParent, std::vector(aPropStates) );
if( !sCondParent.isEmpty() && sParent != sCondParent )
GetAutoStylePool().Add( nFamily, sCondParent, std::move(aPropStates) );
}
}
OUString XMLTextParagraphExport::Find(
XmlStyleFamily nFamily,
const Reference < XPropertySet > & rPropSet,
const OUString& rParent,
const std::span<const XMLPropertyState> aAddStates) const
{
OUString sName( rParent );
rtl::Reference < SvXMLExportPropertyMapper > xPropMapper;
switch( nFamily )
{
case XmlStyleFamily::TEXT_PARAGRAPH:
xPropMapper = GetParaPropMapper();
break;
case XmlStyleFamily::TEXT_FRAME:
xPropMapper = GetAutoFramePropMapper();
break;
case XmlStyleFamily::TEXT_SECTION:
xPropMapper = GetSectionPropMapper();
break;
case XmlStyleFamily::TEXT_RUBY:
xPropMapper = GetRubyPropMapper();
break;
default: break;
}
SAL_WARN_IF( !xPropMapper.is(), "xmloff", "There is the property mapper?" );
if( !xPropMapper.is() )
return sName;
std::vector<XMLPropertyState> aPropStates(xPropMapper->Filter(GetExport(), rPropSet));
aPropStates.insert( aPropStates.end(), aAddStates.begin(), aAddStates.end() );
if( std::any_of( aPropStates.begin(), aPropStates.end(), lcl_validPropState ) )
sName = GetAutoStylePool().Find( nFamily, sName, aPropStates );
return sName;
}
OUString XMLTextParagraphExport::FindTextStyle(
const Reference < XPropertySet > & rPropSet,
bool& rbHasCharStyle,
bool& rbHasAutoStyle,
const XMLPropertyState** ppAddStates,
const OUString* pParentName) const
{
rtl::Reference < SvXMLExportPropertyMapper > xPropMapper(GetTextPropMapper());
std::vector<XMLPropertyState> aPropStates(xPropMapper->Filter(GetExport(), rPropSet));
// Get parent and remove hyperlinks (they aren't of interest)
OUString sName;
rbHasCharStyle = rbHasAutoStyle = false;
sal_uInt16 nIgnoreProps = 0;
rtl::Reference< XMLPropertySetMapper > xPM(xPropMapper->getPropertySetMapper());
::std::vector< XMLPropertyState >::iterator aFirstDel = aPropStates.end();
::std::vector< XMLPropertyState >::iterator aSecondDel = aPropStates.end();
for( ::std::vector< XMLPropertyState >::iterator
i = aPropStates.begin();
nIgnoreProps < 2 && i != aPropStates.end();
++i )
{
if( i->mnIndex == -1 )
continue;
switch( xPM->GetEntryContextId(i->mnIndex) )
{
case CTF_CHAR_STYLE_NAME:
i->maValue >>= sName;
i->mnIndex = -1;
rbHasCharStyle = !sName.isEmpty();
if( nIgnoreProps )
aSecondDel = i;
else
aFirstDel = i;
nIgnoreProps++;
break;
case CTF_HYPERLINK_URL:
i->mnIndex = -1;
if( nIgnoreProps )
aSecondDel = i;
else
aFirstDel = i;
nIgnoreProps++;
break;
}
}
if( ppAddStates )
{
while( *ppAddStates )
{
aPropStates.push_back( **ppAddStates );
ppAddStates++;
}
}
if (aPropStates.size() - nIgnoreProps)
{
// erase the character style, otherwise the autostyle cannot be found!
// erase the hyperlink, otherwise the autostyle cannot be found!
if ( nIgnoreProps )
{
// If two elements of a vector have to be deleted,
// we should delete the second one first.
if( --nIgnoreProps )
aPropStates.erase( aSecondDel );
aPropStates.erase( aFirstDel );
}
OUString aParentName;
if (pParentName)
{
// Format redlines can have an autostyle with a parent.
aParentName = *pParentName;
}
sName = GetAutoStylePool().Find(
XmlStyleFamily::TEXT_TEXT,
aParentName,
aPropStates );
rbHasAutoStyle = true;
}
return sName;
}
// adjustments to support lists independent from list style
void XMLTextParagraphExport::exportListChange(
const XMLTextNumRuleInfo& rPrevInfo,
const XMLTextNumRuleInfo& rNextInfo )
{
// end a list
if ( rPrevInfo.GetLevel() > 0 )
{
sal_uInt32 nListLevelsToBeClosed = 0; // unsigned larger type to safely multiply and compare
if ( !rNextInfo.BelongsToSameList( rPrevInfo ) ||
rNextInfo.GetLevel() <= 0 )
{
// close complete previous list
nListLevelsToBeClosed = rPrevInfo.GetLevel();
}
else if ( rPrevInfo.GetLevel() > rNextInfo.GetLevel() )
{
// close corresponding sub lists
nListLevelsToBeClosed = rPrevInfo.GetLevel() - rNextInfo.GetLevel();
}
if ( nListLevelsToBeClosed > 0 &&
maListElements.size() >= 2 * nListLevelsToBeClosed )
{
do {
for(size_t j = 0; j < 2; ++j)
{
OUString aElem(maListElements.back());
maListElements.pop_back();
GetExport().EndElement(aElem, true);
}
// remove closed list from list stack
mpTextListsHelper->PopListFromStack();
--nListLevelsToBeClosed;
} while ( nListLevelsToBeClosed > 0 );
}
}
// start a new list
if ( rNextInfo.GetLevel() > 0 )
{
bool bRootListToBeStarted = false;
sal_Int16 nListLevelsToBeOpened = 0;
if ( !rPrevInfo.BelongsToSameList( rNextInfo ) ||
rPrevInfo.GetLevel() <= 0 )
{
// new root list
bRootListToBeStarted = true;
nListLevelsToBeOpened = rNextInfo.GetLevel();
}
else if ( rNextInfo.GetLevel() > rPrevInfo.GetLevel() )
{
// open corresponding sub lists
nListLevelsToBeOpened = rNextInfo.GetLevel() - rPrevInfo.GetLevel();
}
if ( nListLevelsToBeOpened > 0 )
{
const OUString& sListStyleName( rNextInfo.GetNumRulesName() );
// Currently only the text documents support <ListId>.
// Thus, for other document types <sListId> is empty.
const OUString& sListId( rNextInfo.GetListId() );
bool bExportListStyle( true );
bool bRestartNumberingAtContinuedList( false );
sal_Int32 nRestartValueForContinuedList( -1 );
bool bContinueingPreviousSubList = !bRootListToBeStarted &&
rNextInfo.IsContinueingPreviousSubTree();
do {
GetExport().CheckAttrList();
if ( bRootListToBeStarted )
{
if ( !mpTextListsHelper->IsListProcessed( sListId ) )
{
if ( ExportListId() &&
!sListId.isEmpty() && !rNextInfo.IsListIdDefault() )
{
/* Property text:id at element <text:list> has to be
replaced by property xml:id (#i92221#)
*/
GetExport().AddAttribute( XML_NAMESPACE_XML,
XML_ID,
sListId );
}
mpTextListsHelper->KeepListAsProcessed( sListId,
sListStyleName,
OUString() );
}
else
{
const OUString sNewListId(
mpTextListsHelper->GenerateNewListId() );
if ( ExportListId() &&
!sListId.isEmpty() && !rNextInfo.IsListIdDefault() )
{
/* Property text:id at element <text:list> has to be
replaced by property xml:id (#i92221#)
*/
GetExport().AddAttribute( XML_NAMESPACE_XML,
XML_ID,
sNewListId );
}
const OUString sContinueListId =
mpTextListsHelper->GetLastContinuingListId( sListId );
// store that list with list id <sNewListId> is last list,
// which has continued list with list id <sListId>
mpTextListsHelper->StoreLastContinuingList( sListId,
sNewListId );
if ( sListStyleName ==
mpTextListsHelper->GetListStyleOfLastProcessedList() &&
// Inconsistent behavior regarding lists (#i92811#)
sContinueListId ==
mpTextListsHelper->GetLastProcessedListId() )
{
GetExport().AddAttribute( XML_NAMESPACE_TEXT,
XML_CONTINUE_NUMBERING,
XML_TRUE );
}
else
{
if ( ExportListId() &&
!sListId.isEmpty() )
{
GetExport().AddAttribute( XML_NAMESPACE_TEXT,
XML_CONTINUE_LIST,
sContinueListId );
}
}
if ( rNextInfo.IsRestart() &&
( nListLevelsToBeOpened != 1 ||
!rNextInfo.HasStartValue() ) )
{
bRestartNumberingAtContinuedList = true;
nRestartValueForContinuedList =
rNextInfo.GetListLevelStartValue();
}
mpTextListsHelper->KeepListAsProcessed( sNewListId,
sListStyleName,
sContinueListId );
}
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
GetExport().EncodeStyleName( sListStyleName ) );
bExportListStyle = false;
bRootListToBeStarted = false;
}
else if ( bExportListStyle &&
!mpTextListsHelper->EqualsToTopListStyleOnStack( sListStyleName ) )
{
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
GetExport().EncodeStyleName( sListStyleName ) );
bExportListStyle = false;
}
else
{
// rhbz#746174: also export list restart for non root list
if (rNextInfo.IsRestart() && !rNextInfo.HasStartValue())
{
bRestartNumberingAtContinuedList = true;
nRestartValueForContinuedList =
rNextInfo.GetListLevelStartValue();
}
}
if ( bContinueingPreviousSubList )
{
GetExport().AddAttribute( XML_NAMESPACE_TEXT,
XML_CONTINUE_NUMBERING, XML_TRUE );
bContinueingPreviousSubList = false;
}
enum XMLTokenEnum eLName = XML_LIST;
OUString aElem(GetExport().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_TEXT,
GetXMLToken(eLName) ) );
GetExport().IgnorableWhitespace();
GetExport().StartElement(aElem, false);
maListElements.push_back(aElem);
mpTextListsHelper->PushListOnStack( sListId,
sListStyleName );
// <text:list-header> or <text:list-item>
GetExport().CheckAttrList();
/* Export start value at correct list item (#i97309#) */
if ( nListLevelsToBeOpened == 1 )
{
if ( rNextInfo.HasStartValue() )
{
OUString aTmp = OUString::number( static_cast<sal_Int32>(rNextInfo.GetStartValue()) );
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
aTmp );
}
else if (bRestartNumberingAtContinuedList)
{
GetExport().AddAttribute( XML_NAMESPACE_TEXT,
XML_START_VALUE,
OUString::number(nRestartValueForContinuedList) );
bRestartNumberingAtContinuedList = false;
}
}
eLName = ( rNextInfo.IsNumbered() || nListLevelsToBeOpened > 1 )
? XML_LIST_ITEM
: XML_LIST_HEADER;
aElem = GetExport().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_TEXT,
GetXMLToken(eLName) );
GetExport().IgnorableWhitespace();
GetExport().StartElement(aElem, false);
maListElements.push_back(aElem);
// export of <text:number> element for last opened <text:list-item>, if requested
if ( GetExport().exportTextNumberElement() &&
eLName == XML_LIST_ITEM && nListLevelsToBeOpened == 1 && // last iteration --> last opened <text:list-item>
!rNextInfo.ListLabelString().isEmpty() )
{
const OUString aTextNumberElem =
GetExport().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_TEXT,
GetXMLToken(XML_NUMBER) );
GetExport().IgnorableWhitespace();
GetExport().StartElement( aTextNumberElem, false );
GetExport().Characters( rNextInfo.ListLabelString() );
GetExport().EndElement( aTextNumberElem, true );
}
--nListLevelsToBeOpened;
} while ( nListLevelsToBeOpened > 0 );
}
}
bool bEndElement = false;
if ( rNextInfo.GetLevel() > 0 &&
rNextInfo.IsNumbered() &&
rPrevInfo.BelongsToSameList( rNextInfo ) &&
rPrevInfo.GetLevel() >= rNextInfo.GetLevel() )
{
assert(maListElements.size() >= 2 && "list elements missing");
bEndElement = maListElements.size() >= 2;
}
if (!bEndElement)
return;
// close previous list-item
GetExport().EndElement(maListElements.back(), true );
maListElements.pop_back();
// Only for sub lists (#i103745#)
if ( rNextInfo.IsRestart() && !rNextInfo.HasStartValue() &&
rNextInfo.GetLevel() != 1 )
{
// start new sub list respectively list on same list level
GetExport().EndElement(maListElements.back(), true );
GetExport().IgnorableWhitespace();
GetExport().StartElement(maListElements.back(), false);
}
// open new list-item
GetExport().CheckAttrList();
if( rNextInfo.HasStartValue() )
{
OUString aTmp = OUString::number( static_cast<sal_Int32>(rNextInfo.GetStartValue()) );
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE, aTmp );
}
// Handle restart without start value on list level 1 (#i103745#)
else if ( rNextInfo.IsRestart() && /*!rNextInfo.HasStartValue() &&*/
rNextInfo.GetLevel() == 1 )
{
OUString aTmp = OUString::number( static_cast<sal_Int32>(rNextInfo.GetListLevelStartValue()) );
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE, aTmp );
}
if ( ( GetExport().getExportFlags() & SvXMLExportFlags::OASIS ) &&
GetExport().getSaneDefaultVersion() >= SvtSaveOptions::ODFSVER_012)
{
const OUString& sListStyleName( rNextInfo.GetNumRulesName() );
if ( !mpTextListsHelper->EqualsToTopListStyleOnStack( sListStyleName ) )
{
GetExport().AddAttribute( XML_NAMESPACE_TEXT,
XML_STYLE_OVERRIDE,
GetExport().EncodeStyleName( sListStyleName ) );
}
}
OUString aElem( GetExport().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_TEXT,
GetXMLToken(XML_LIST_ITEM) ) );
GetExport().IgnorableWhitespace();
GetExport().StartElement(aElem, false );
maListElements.push_back(aElem);
// export of <text:number> element for <text:list-item>, if requested
if ( GetExport().exportTextNumberElement() &&
!rNextInfo.ListLabelString().isEmpty() )
{
const OUString aTextNumberElem =
GetExport().GetNamespaceMap().GetQNameByKey(
XML_NAMESPACE_TEXT,
GetXMLToken(XML_NUMBER) );
GetExport().IgnorableWhitespace();
GetExport().StartElement( aTextNumberElem, false );
GetExport().Characters( rNextInfo.ListLabelString() );
GetExport().EndElement( aTextNumberElem, true );
}
}
struct XMLTextParagraphExport::Impl
{
typedef ::std::map<Reference<XFormField>, sal_Int32> FieldMarkMap_t;
FieldMarkMap_t m_FieldMarkMap;
explicit Impl() {}
sal_Int32 AddFieldMarkStart(Reference<XFormField> const& i_xFieldMark)
{
assert(m_FieldMarkMap.find(i_xFieldMark) == m_FieldMarkMap.end());
sal_Int32 const ret(m_FieldMarkMap.size());
m_FieldMarkMap.insert(::std::make_pair(i_xFieldMark, ret));
return ret;
}
sal_Int32 GetFieldMarkIndex(Reference<XFormField> const& i_xFieldMark)
{
FieldMarkMap_t::const_iterator const it(
m_FieldMarkMap.find(i_xFieldMark));
// rely on SwXFieldmark::CreateXFieldmark returning the same instance
// because the Reference in m_FieldMarkMap will keep it alive
assert(it != m_FieldMarkMap.end());
return it->second;
}
};
struct XMLTextParagraphExport::DocumentListNodes
{
struct NodeData
{
std::ptrdiff_t order;
sal_Int32 index; // see SwNode::GetIndex and SwNodeOffset
sal_uInt64 style_id; // actually a pointer to NumRule
OUString list_id;
};
std::vector<NodeData> docListNodes;
DocumentListNodes(const css::uno::Reference<css::frame::XModel>& xModel,
const std::vector<sal_Int32>& aDocumentNodeOrder)
{
// Sequence of nodes, each of them represented by three-element sequence,
// corresponding to NodeData members
css::uno::Sequence<css::uno::Sequence<css::uno::Any>> nodes;
if (auto xPropSet = xModel.query<css::beans::XPropertySet>())
{
try
{
// See SwXTextDocument::getPropertyValue
xPropSet->getPropertyValue(u"ODFExport_ListNodes"_ustr) >>= nodes;
}
catch (css::beans::UnknownPropertyException&)
{
// That's absolutely fine!
}
}
docListNodes.reserve(nodes.getLength());
for (const auto& node : nodes)
{
assert(node.getLength() == 3);
sal_Int32 nodeIndex = node[0].get<sal_Int32>();
auto nodeOrder = std::distance(
aDocumentNodeOrder.begin(),
std::find(aDocumentNodeOrder.begin(), aDocumentNodeOrder.end(), nodeIndex));
docListNodes.push_back({ .order = nodeOrder,
.index = nodeIndex,
.style_id = node[1].get<sal_uInt64>(),
.list_id = node[2].get<OUString>() });
}
std::sort(docListNodes.begin(), docListNodes.end(),
[](const NodeData& lhs, const NodeData& rhs) { return lhs.order < rhs.order; });
}
bool ShouldSkipListId(const Reference<XTextContent>& xTextContent) const
{
if (docListNodes.empty())
return false;
if (auto xPropSet = xTextContent.query<css::beans::XPropertySet>())
{
sal_Int32 index = 0;
try
{
// See SwXParagraph::Impl::GetPropertyValues_Impl
xPropSet->getPropertyValue(u"ODFExport_NodeIndex"_ustr) >>= index;
}
catch (css::beans::UnknownPropertyException&)
{
// That's absolutely fine!
return false;
}
auto it = std::find_if(docListNodes.begin(), docListNodes.end(),
[index](const NodeData& el) { return el.index == index; });
if (it == docListNodes.end())
return false;
// We need to write the id, when there will be continuation of the list either with
// a different list style, or after another list.
for (auto next = it + 1; next != docListNodes.end(); ++next)
{
if (it->list_id != next->list_id)
{
// List changed. We will have to refer to this id, only if there will
// appear a continuation of this list
return std::find_if(next + 1, docListNodes.end(),
[list_id = it->list_id](const NodeData& data)
{ return data.list_id == list_id; })
== docListNodes.end();
}
if (it->style_id != next->style_id)
{
// Same list, new style -> this "next" will refer to the id, no skipping
return false;
}
if (it->index + 1 != next->index)
{
// we have a gap before the next node with the same list and style,
// with no other lists in between. There will be a continuation with a
// simple 'text:continue-numbering="true"'.
return true;
}
it = next; // walk through adjacent nodes of the same list
}
// all nodes were adjacent and of the same list and style -> no continuation, skip id
return true;
}
return false;
}
};
XMLTextParagraphExport::XMLTextParagraphExport(
SvXMLExport& rExp,
SvXMLAutoStylePoolP & rASP
) :
XMLStyleExport( rExp, &rASP ),
m_xImpl(new Impl),
m_rAutoStylePool( rASP ),
m_pBoundFrameSets(new BoundFrameSets(GetExport().GetModel())),
maListAutoPool( GetExport() ),
m_bProgress( false ),
m_bBlock( false ),
m_bOpenRuby( false ),
mpTextListsHelper( nullptr ),
mbCollected(false),
m_aCharStyleNamesPropInfoCache( gsCharStyleNames )
{
rtl::Reference < XMLPropertySetMapper > xPropMapper(new XMLTextPropertySetMapper( TextPropMap::PARA, true ));
m_xParaPropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
GetExport() );
OUString sFamily( GetXMLToken(XML_PARAGRAPH) );
OUString aPrefix(u'P');
m_rAutoStylePool.AddFamily( XmlStyleFamily::TEXT_PARAGRAPH, sFamily,
m_xParaPropMapper, aPrefix );
xPropMapper = new XMLTextPropertySetMapper( TextPropMap::TEXT, true );
m_xTextPropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
GetExport() );
sFamily = GetXMLToken(XML_TEXT);
aPrefix = "T";
m_rAutoStylePool.AddFamily( XmlStyleFamily::TEXT_TEXT, sFamily,
m_xTextPropMapper, aPrefix );
xPropMapper = new XMLTextPropertySetMapper( TextPropMap::AUTO_FRAME, true );
m_xAutoFramePropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
GetExport() );
sFamily = XML_STYLE_FAMILY_SD_GRAPHICS_NAME;
aPrefix = "fr";
m_rAutoStylePool.AddFamily( XmlStyleFamily::TEXT_FRAME, sFamily,
m_xAutoFramePropMapper, aPrefix );
xPropMapper = new XMLTextPropertySetMapper( TextPropMap::SECTION, true );
m_xSectionPropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
GetExport() );
sFamily = GetXMLToken( XML_SECTION );
aPrefix = "Sect" ;
m_rAutoStylePool.AddFamily( XmlStyleFamily::TEXT_SECTION, sFamily,
m_xSectionPropMapper, aPrefix );
xPropMapper = new XMLTextPropertySetMapper( TextPropMap::RUBY, true );
m_xRubyPropMapper = new SvXMLExportPropertyMapper( xPropMapper );
sFamily = GetXMLToken( XML_RUBY );
aPrefix = "Ru";
m_rAutoStylePool.AddFamily( XmlStyleFamily::TEXT_RUBY, sFamily,
m_xRubyPropMapper, aPrefix );
xPropMapper = new XMLTextPropertySetMapper( TextPropMap::FRAME, true );
m_xFramePropMapper = new XMLTextExportPropertySetMapper( xPropMapper,
GetExport() );
m_pSectionExport.reset( new XMLSectionExport( rExp, *this ) );
m_pIndexMarkExport.reset( new XMLIndexMarkExport( rExp ) );
if( ! IsBlockMode() &&
Reference<XRedlinesSupplier>( GetExport().GetModel(), UNO_QUERY ).is())
m_pRedlineExport.reset( new XMLRedlineExport( rExp ) );
// The text field helper needs a pre-constructed XMLPropertyState
// to export the combined characters field. We construct that
// here, because we need the text property mapper to do it.
// construct Any value, then find index
sal_Int32 nIndex = m_xTextPropMapper->getPropertySetMapper()->FindEntryIndex(
"", XML_NAMESPACE_STYLE,
GetXMLToken(XML_TEXT_COMBINE));
m_pFieldExport.reset( new XMLTextFieldExport( rExp, std::make_unique<XMLPropertyState>( nIndex, uno::Any(true) ) ) );
PushNewTextListsHelper();
}
XMLTextParagraphExport::~XMLTextParagraphExport()
{
m_pRedlineExport.reset();
m_pIndexMarkExport.reset();
m_pSectionExport.reset();
m_pFieldExport.reset();
#ifdef DBG_UTIL
txtparae_bContainsIllegalCharacters = false;
#endif
PopTextListsHelper();
SAL_WARN_IF( !maTextListsHelperStack.empty(), "xmloff",
"misusage of text lists helper stack - it is not empty. Serious defect" );
}
SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateShapeExtPropMapper(
SvXMLExport& rExport )
{
rtl::Reference < XMLPropertySetMapper > xPropMapper =
new XMLTextPropertySetMapper( TextPropMap::SHAPE, true );
return new XMLTextExportPropertySetMapper( xPropMapper, rExport );
}
SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateCharExtPropMapper(
SvXMLExport& rExport)
{
XMLPropertySetMapper *pPropMapper =
new XMLTextPropertySetMapper( TextPropMap::TEXT, true );
return new XMLTextExportPropertySetMapper( pPropMapper, rExport );
}
SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateParaExtPropMapper(
SvXMLExport& rExport)
{
XMLPropertySetMapper *pPropMapper =
new XMLTextPropertySetMapper( TextPropMap::SHAPE_PARA, true );
return new XMLTextExportPropertySetMapper( pPropMapper, rExport );
}
SvXMLExportPropertyMapper *XMLTextParagraphExport::CreateParaDefaultExtPropMapper(
SvXMLExport& rExport)
{
XMLPropertySetMapper *pPropMapper =
new XMLTextPropertySetMapper( TextPropMap::TEXT_ADDITIONAL_DEFAULTS, true );
return new XMLTextExportPropertySetMapper( pPropMapper, rExport );
}
void XMLTextParagraphExport::exportPageFrames( bool bIsProgress )
{
const TextContentSet& rTexts = m_pBoundFrameSets->GetTexts()->GetPageBoundContents();
const TextContentSet& rGraphics = m_pBoundFrameSets->GetGraphics()->GetPageBoundContents();
const TextContentSet& rEmbeddeds = m_pBoundFrameSets->GetEmbeddeds()->GetPageBoundContents();
const TextContentSet& rShapes = m_pBoundFrameSets->GetShapes()->GetPageBoundContents();
for(TextContentSet::const_iterator_t it = rTexts.getBegin();
it != rTexts.getEnd();
++it)
exportTextFrame(*it, false/*bAutoStyles*/, bIsProgress, true);
for(TextContentSet::const_iterator_t it = rGraphics.getBegin();
it != rGraphics.getEnd();
++it)
exportTextGraphic(*it, false/*bAutoStyles*/);
for(TextContentSet::const_iterator_t it = rEmbeddeds.getBegin();
it != rEmbeddeds.getEnd();
++it)
exportTextEmbedded(*it, false/*bAutoStyles*/);
for(TextContentSet::const_iterator_t it = rShapes.getBegin();
it != rShapes.getEnd();
++it)
exportShape(*it, false/*bAutoStyles*/);
}
void XMLTextParagraphExport::exportFrameFrames(
bool bAutoStyles,
bool bIsProgress,
const Reference < XTextFrame >& rParentTxtFrame )
{
const TextContentSet* const pTexts = m_pBoundFrameSets->GetTexts()->GetFrameBoundContents(rParentTxtFrame);
if(pTexts)
for(TextContentSet::const_iterator_t it = pTexts->getBegin();
it != pTexts->getEnd();
++it)
exportTextFrame(*it, bAutoStyles, bIsProgress, true);
const TextContentSet* const pGraphics = m_pBoundFrameSets->GetGraphics()->GetFrameBoundContents(rParentTxtFrame);
if(pGraphics)
for(TextContentSet::const_iterator_t it = pGraphics->getBegin();
it != pGraphics->getEnd();
++it)
exportTextGraphic(*it, bAutoStyles);
const TextContentSet* const pEmbeddeds = m_pBoundFrameSets->GetEmbeddeds()->GetFrameBoundContents(rParentTxtFrame);
if(pEmbeddeds)
for(TextContentSet::const_iterator_t it = pEmbeddeds->getBegin();
it != pEmbeddeds->getEnd();
++it)
exportTextEmbedded(*it, bAutoStyles);
const TextContentSet* const pShapes = m_pBoundFrameSets->GetShapes()->GetFrameBoundContents(rParentTxtFrame);
if(pShapes)
for(TextContentSet::const_iterator_t it = pShapes->getBegin();
it != pShapes->getEnd();
++it)
exportShape(*it, bAutoStyles);
}
// bookmarks, reference marks (and TOC marks) are the same except for the
// element names. We use the same method for export and it an array with
// the proper element names
const enum XMLTokenEnum lcl_XmlReferenceElements[] = {
XML_REFERENCE_MARK, XML_REFERENCE_MARK_START, XML_REFERENCE_MARK_END };
const enum XMLTokenEnum lcl_XmlBookmarkElements[] = {
XML_BOOKMARK, XML_BOOKMARK_START, XML_BOOKMARK_END };
void XMLTextParagraphExport::collectTextAutoStylesAndNodeExportOrder(bool bIsProgress)
{
GetExport().GetShapeExport(); // make sure the graphics styles family is added
if (mbCollected)
return;
const bool bAutoStyles = true;
const bool bExportContent = true;
if (auto xTextDocument = GetExport().GetModel().query<XTextDocument>())
{
bInDocumentNodeOrderCollection = true;
collectTextAutoStyles(xTextDocument->getText(), bIsProgress);
bInDocumentNodeOrderCollection = false;
}
// Export text frames:
Reference<XEnumeration> xTextFramesEnum = m_pBoundFrameSets->GetTexts()->createEnumeration();
if(xTextFramesEnum.is())
while(xTextFramesEnum->hasMoreElements())
{
Reference<XTextContent> xTxtCntnt(xTextFramesEnum->nextElement(), UNO_QUERY);
if(xTxtCntnt.is())
exportTextFrame(xTxtCntnt, bAutoStyles, bIsProgress, bExportContent);
}
// Export graphic objects:
Reference<XEnumeration> xGraphicsEnum = m_pBoundFrameSets->GetGraphics()->createEnumeration();
if(xGraphicsEnum.is())
while(xGraphicsEnum->hasMoreElements())
{
Reference<XTextContent> xTxtCntnt(xGraphicsEnum->nextElement(), UNO_QUERY);
if(xTxtCntnt.is())
exportTextGraphic(xTxtCntnt, true);
}
// Export embedded objects:
Reference<XEnumeration> xEmbeddedsEnum = m_pBoundFrameSets->GetEmbeddeds()->createEnumeration();
if(xEmbeddedsEnum.is())
while(xEmbeddedsEnum->hasMoreElements())
{
Reference<XTextContent> xTxtCntnt(xEmbeddedsEnum->nextElement(), UNO_QUERY);
if(xTxtCntnt.is())
exportTextEmbedded(xTxtCntnt, true);
}
// Export shapes:
Reference<XEnumeration> xShapesEnum = m_pBoundFrameSets->GetShapes()->createEnumeration();
if(xShapesEnum.is())
while(xShapesEnum->hasMoreElements())
{
Reference<XTextContent> xTxtCntnt(xShapesEnum->nextElement(), UNO_QUERY);
if(xTxtCntnt.is())
{
Reference<XServiceInfo> xServiceInfo(xTxtCntnt, UNO_QUERY);
if( xServiceInfo->supportsService(gsShapeService))
exportShape(xTxtCntnt, true);
}
}
if (GetExport().getExportFlags() & SvXMLExportFlags::CONTENT)
exportTrackedChanges(true);
mbCollected = true;
}
void XMLTextParagraphExport::exportText(
const Reference < XText > & rText,
bool bAutoStyles,
bool bIsProgress,
bool bExportParagraph,
TextPNS eExtensionNS)
{
if( bAutoStyles )
GetExport().GetShapeExport(); // make sure the graphics styles family
// is added
Reference < XEnumerationAccess > xEA( rText, UNO_QUERY );
if( ! xEA.is() )
return;
Reference < XEnumeration > xParaEnum(xEA->createEnumeration());
Reference < XPropertySet > xPropertySet( rText, UNO_QUERY );
Reference < XTextSection > xBaseSection;
// #97718# footnotes don't supply paragraph enumerations in some cases
// This is always a bug, but at least we don't want to crash.
SAL_WARN_IF( !xParaEnum.is(), "xmloff", "We need a paragraph enumeration" );
if( ! xParaEnum.is() )
return;
if (xPropertySet.is())
{
Reference < XPropertySetInfo > xInfo ( xPropertySet->getPropertySetInfo() );
if( xInfo.is() )
{
if (xInfo->hasPropertyByName( gsTextSection ))
{
xPropertySet->getPropertyValue(gsTextSection) >>= xBaseSection ;
}
}
}
// #96530# Export redlines at start & end of XText before & after
// exporting the text content enumeration
if( !bAutoStyles && (m_pRedlineExport != nullptr) )
m_pRedlineExport->ExportStartOrEndRedline( xPropertySet, true );
exportTextContentEnumeration( xParaEnum, bAutoStyles, xBaseSection,
bIsProgress, bExportParagraph, nullptr, eExtensionNS );
if( !bAutoStyles && (m_pRedlineExport != nullptr) )
m_pRedlineExport->ExportStartOrEndRedline( xPropertySet, false );
}
void XMLTextParagraphExport::exportText(
const Reference < XText > & rText,
const Reference < XTextSection > & rBaseSection,
bool bAutoStyles,
bool bIsProgress,
bool bExportParagraph)
{
if( bAutoStyles )
GetExport().GetShapeExport(); // make sure the graphics styles family
// is added
Reference < XEnumerationAccess > xEA( rText, UNO_QUERY );
Reference < XEnumeration > xParaEnum(xEA->createEnumeration());
// #98165# don't continue without a paragraph enumeration
if( ! xParaEnum.is() )
return;
// #96530# Export redlines at start & end of XText before & after
// exporting the text content enumeration
Reference<XPropertySet> xPropertySet;
if( !bAutoStyles && (m_pRedlineExport != nullptr) )
{
xPropertySet.set(rText, uno::UNO_QUERY );
m_pRedlineExport->ExportStartOrEndRedline( xPropertySet, true );
}
exportTextContentEnumeration( xParaEnum, bAutoStyles, rBaseSection,
bIsProgress, bExportParagraph );
if( !bAutoStyles && (m_pRedlineExport != nullptr) )
m_pRedlineExport->ExportStartOrEndRedline( xPropertySet, false );
}
bool XMLTextParagraphExport::ExportListId() const
{
return (GetExport().getExportFlags() & SvXMLExportFlags::OASIS)
&& GetExport().getSaneDefaultVersion() >= SvtSaveOptions::ODFSVER_012;
}
void XMLTextParagraphExport::RecordNodeIndex(const css::uno::Reference<css::text::XTextContent>& xTextContent)
{
if (!bInDocumentNodeOrderCollection)
return;
if (auto xPropSet = xTextContent.query<css::beans::XPropertySet>())
{
try
{
sal_Int32 index = 0;
// See SwXParagraph::Impl::GetPropertyValues_Impl
xPropSet->getPropertyValue(u"ODFExport_NodeIndex"_ustr) >>= index;
assert(std::find(maDocumentNodeOrder.begin(), maDocumentNodeOrder.end(), index)
== maDocumentNodeOrder.end());
maDocumentNodeOrder.push_back(index);
}
catch (css::beans::UnknownPropertyException&)
{
// That's absolutely fine!
}
}
}
bool XMLTextParagraphExport::ShouldSkipListId(const Reference<XTextContent>& xTextContent)
{
if (!mpDocumentListNodes)
{
if (ExportListId())
mpDocumentListNodes.reset(new DocumentListNodes(GetExport().GetModel(), maDocumentNodeOrder));
else
mpDocumentListNodes.reset(new DocumentListNodes({}, {}));
}
return mpDocumentListNodes->ShouldSkipListId(xTextContent);
}
void XMLTextParagraphExport::exportTextContentEnumeration(
const Reference < XEnumeration > & rContEnum,
bool bAutoStyles,
const Reference < XTextSection > & rBaseSection,
bool bIsProgress,
bool bExportParagraph,
const Reference < XPropertySet > *pRangePropSet,
TextPNS eExtensionNS )
{
SAL_WARN_IF( !rContEnum.is(), "xmloff", "No enumeration to export!" );
bool bHasMoreElements = rContEnum->hasMoreElements();
if( !bHasMoreElements )
return;
XMLTextNumRuleInfo aPrevNumInfo;
XMLTextNumRuleInfo aNextNumInfo;
bool bHasContent = false;
Reference<XTextSection> xCurrentTextSection(rBaseSection);
MultiPropertySetHelper aPropSetHelper(
bAutoStyles ? std::span<const OUString>(aParagraphPropertyNamesAuto) :
std::span<const OUString>(aParagraphPropertyNames) );
bool bHoldElement = false;
Reference < XTextContent > xTxtCntnt;
while( bHoldElement || bHasMoreElements )
{
if (bHoldElement)
{
bHoldElement = false;
}
else
{
xTxtCntnt.set(rContEnum->nextElement(), uno::UNO_QUERY);
aPropSetHelper.resetValues();
}
Reference<XServiceInfo> xServiceInfo( xTxtCntnt, UNO_QUERY );
if( xServiceInfo->supportsService( gsParagraphService ) )
{
if( bAutoStyles )
{
RecordNodeIndex(xTxtCntnt);
exportListAndSectionChange( xCurrentTextSection, xTxtCntnt,
aPrevNumInfo, aNextNumInfo,
bAutoStyles );
}
else
{
/* Pass list auto style pool to <XMLTextNumRuleInfo> instance
Pass info about request to export <text:number> element
to <XMLTextNumRuleInfo> instance (#i69627#)
*/
aNextNumInfo.Set( xTxtCntnt,
GetExport().writeOutlineStyleAsNormalListStyle(),
GetListAutoStylePool(),
GetExport().exportTextNumberElement(),
ShouldSkipListId(xTxtCntnt) );
exportListAndSectionChange( xCurrentTextSection, aPropSetHelper,
TEXT_SECTION, xTxtCntnt,
aPrevNumInfo, aNextNumInfo,
bAutoStyles );
}
// if we found a mute section: skip all section content
if (m_pSectionExport->IsMuteSection(xCurrentTextSection))
{
// Make sure headings are exported anyway.
if( !bAutoStyles )
m_pSectionExport->ExportMasterDocHeadingDummies();
while (rContEnum->hasMoreElements() &&
XMLSectionExport::IsInSection( xCurrentTextSection,
xTxtCntnt, true ))
{
xTxtCntnt.set(rContEnum->nextElement(), uno::UNO_QUERY);
aPropSetHelper.resetValues();
aNextNumInfo.Reset();
}
// the first non-mute element still needs to be processed
bHoldElement =
! XMLSectionExport::IsInSection( xCurrentTextSection,
xTxtCntnt, false );
}
else
exportParagraph( xTxtCntnt, bAutoStyles, bIsProgress,
bExportParagraph, aPropSetHelper, eExtensionNS );
bHasContent = true;
}
else if( xServiceInfo->supportsService( gsTableService ) )
{
if( !bAutoStyles )
{
aNextNumInfo.Reset();
}
exportListAndSectionChange( xCurrentTextSection, xTxtCntnt,
aPrevNumInfo, aNextNumInfo,
bAutoStyles );
if (! m_pSectionExport->IsMuteSection(xCurrentTextSection))
{
// export start + end redlines (for wholly redlined tables)
if ((! bAutoStyles) && (nullptr != m_pRedlineExport))
m_pRedlineExport->ExportStartOrEndRedline(xTxtCntnt, true);
exportTable( xTxtCntnt, bAutoStyles, bIsProgress );
if ((! bAutoStyles) && (nullptr != m_pRedlineExport))
m_pRedlineExport->ExportStartOrEndRedline(xTxtCntnt, false);
}
else if( !bAutoStyles )
{
// Make sure headings are exported anyway.
m_pSectionExport->ExportMasterDocHeadingDummies();
}
bHasContent = true;
}
else if( xServiceInfo->supportsService( gsTextFrameService ) )
{
exportTextFrame( xTxtCntnt, bAutoStyles, bIsProgress, true, pRangePropSet );
}
else if( xServiceInfo->supportsService( gsTextGraphicService ) )
{
exportTextGraphic( xTxtCntnt, bAutoStyles, pRangePropSet );
}
else if( xServiceInfo->supportsService( gsTextEmbeddedService ) )
{
exportTextEmbedded( xTxtCntnt, bAutoStyles, pRangePropSet );
}
else if( xServiceInfo->supportsService( gsShapeService ) )
{
exportShape( xTxtCntnt, bAutoStyles, pRangePropSet );
}
else
{
SAL_WARN_IF( xTxtCntnt.is(), "xmloff", "unknown text content" );
}
if( !bAutoStyles )
{
aPrevNumInfo = aNextNumInfo;
}
bHasMoreElements = rContEnum->hasMoreElements();
}
if( bHasContent && !bAutoStyles )
{
aNextNumInfo.Reset();
// close open lists and sections; no new styles
exportListAndSectionChange( xCurrentTextSection, rBaseSection,
aPrevNumInfo, aNextNumInfo,
bAutoStyles );
}
}
void XMLTextParagraphExport::exportParagraph(
const Reference < XTextContent > & rTextContent,
bool bAutoStyles, bool bIsProgress, bool bExportParagraph,
MultiPropertySetHelper& rPropSetHelper, TextPNS eExtensionNS)
{
sal_Int16 nOutlineLevel = -1;
if( bIsProgress )
{
ProgressBarHelper *pProgress = GetExport().GetProgressBarHelper();
pProgress->SetValue( pProgress->GetValue()+1 );
}
// get property set or multi property set and initialize helper
Reference<XMultiPropertySet> xMultiPropSet( rTextContent, UNO_QUERY );
Reference<XPropertySet> xPropSet( rTextContent, UNO_QUERY );
// check for supported properties
if( !rPropSetHelper.checkedProperties() )
rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
// if( xMultiPropSet.is() )
// rPropSetHelper.getValues( xMultiPropSet );
// else
// rPropSetHelper.getValues( xPropSet );
if( bExportParagraph )
{
if( bAutoStyles )
{
Add( XmlStyleFamily::TEXT_PARAGRAPH, rPropSetHelper, xPropSet );
}
else
{
// xml:id for RDF metadata
GetExport().AddAttributeXmlId(rTextContent);
GetExport().AddAttributesRDFa(rTextContent);
OUString sStyle;
if( rPropSetHelper.hasProperty( PARA_STYLE_NAME ) )
{
if( xMultiPropSet.is() )
rPropSetHelper.getValue( PARA_STYLE_NAME,
xMultiPropSet ) >>= sStyle;
else
rPropSetHelper.getValue( PARA_STYLE_NAME,
xPropSet ) >>= sStyle;
}
if( rTextContent.is() )
{
const OUString& rIdentifier = GetExport().getInterfaceToIdentifierMapper().getIdentifier( rTextContent );
if( !rIdentifier.isEmpty() )
{
// FIXME: this is just temporary until EditEngine
// paragraphs implement XMetadatable.
// then that must be used and not the mapper, because
// when both can be used we get two xml:id!
uno::Reference<rdf::XMetadatable> const xMeta(rTextContent,
uno::UNO_QUERY);
OSL_ENSURE(!xMeta.is(), "paragraph that implements "
"XMetadatable used in interfaceToIdentifierMapper?");
GetExport().AddAttributeIdLegacy(XML_NAMESPACE_TEXT,
rIdentifier);
}
}
OUString sAutoStyle = Find( XmlStyleFamily::TEXT_PARAGRAPH, xPropSet, sStyle );
if ( sAutoStyle.isEmpty() )
sAutoStyle = sStyle;
if( !sAutoStyle.isEmpty() )
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
GetExport().EncodeStyleName( sAutoStyle ) );
if( rPropSetHelper.hasProperty( PARA_CONDITIONAL_STYLE_NAME ) )
{
OUString sCondStyle;
if( xMultiPropSet.is() )
rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME,
xMultiPropSet ) >>= sCondStyle;
else
rPropSetHelper.getValue( PARA_CONDITIONAL_STYLE_NAME,
xPropSet ) >>= sCondStyle;
if( sCondStyle != sStyle )
{
sCondStyle = Find( XmlStyleFamily::TEXT_PARAGRAPH, xPropSet,
sCondStyle );
if( !sCondStyle.isEmpty() )
GetExport().AddAttribute( XML_NAMESPACE_TEXT,
XML_COND_STYLE_NAME,
GetExport().EncodeStyleName( sCondStyle ) );
}
}
if( rPropSetHelper.hasProperty( PARA_OUTLINE_LEVEL ) )
{
if( xMultiPropSet.is() )
rPropSetHelper.getValue( PARA_OUTLINE_LEVEL,
xMultiPropSet ) >>= nOutlineLevel;
else
rPropSetHelper.getValue( PARA_OUTLINE_LEVEL,
xPropSet ) >>= nOutlineLevel;
if( 0 < nOutlineLevel )
{
GetExport().AddAttribute( XML_NAMESPACE_TEXT,
XML_OUTLINE_LEVEL,
OUString::number( sal_Int32( nOutlineLevel) ) );
if ( rPropSetHelper.hasProperty( PARA_OUTLINE_CONTENT_VISIBLE ) )
{
uno::Sequence<beans::PropertyValue> propList;
bool bIsOutlineContentVisible = true;
if( xMultiPropSet.is() )
rPropSetHelper.getValue(
PARA_OUTLINE_CONTENT_VISIBLE, xMultiPropSet ) >>= propList;
else
rPropSetHelper.getValue(
PARA_OUTLINE_CONTENT_VISIBLE, xPropSet ) >>= propList;
for (const auto& rProp : propList)
{
OUString propName = rProp.Name;
if (propName == "OutlineContentVisibleAttr")
{
rProp.Value >>= bIsOutlineContentVisible;
break;
}
}
if (!bIsOutlineContentVisible)
{
GetExport().AddAttribute( XML_NAMESPACE_LO_EXT,
XML_OUTLINE_CONTENT_VISIBLE,
XML_FALSE);
}
}
if( rPropSetHelper.hasProperty( NUMBERING_IS_NUMBER ) )
{
bool bIsNumber = false;
if( xMultiPropSet.is() )
rPropSetHelper.getValue(
NUMBERING_IS_NUMBER, xMultiPropSet ) >>= bIsNumber;
else
rPropSetHelper.getValue(
NUMBERING_IS_NUMBER, xPropSet ) >>= bIsNumber;
OUString sListStyleName;
if( xMultiPropSet.is() )
rPropSetHelper.getValue(
PARA_NUMBERING_STYLENAME, xMultiPropSet ) >>= sListStyleName;
else
rPropSetHelper.getValue(
PARA_NUMBERING_STYLENAME, xPropSet ) >>= sListStyleName;
bool bAssignedtoOutlineStyle = false;
{
Reference< XChapterNumberingSupplier > xCNSupplier( GetExport().GetModel(), UNO_QUERY );
if (xCNSupplier.is())
{
Reference< XIndexReplace > xNumRule ( xCNSupplier->getChapterNumberingRules() );
SAL_WARN_IF( !xNumRule.is(), "xmloff", "no chapter numbering rules" );
if (xNumRule.is())
{
Reference< XPropertySet > xNumRulePropSet( xNumRule, UNO_QUERY );
OUString sOutlineName;
xNumRulePropSet->getPropertyValue(
u"Name"_ustr ) >>= sOutlineName;
bAssignedtoOutlineStyle = ( sListStyleName == sOutlineName );
}
}
}
if( ! bIsNumber && bAssignedtoOutlineStyle )
GetExport().AddAttribute( XML_NAMESPACE_TEXT,
XML_IS_LIST_HEADER,
XML_TRUE );
}
{
bool bIsRestartNumbering = false;
Reference< XPropertySetInfo >
xPropSetInfo(xMultiPropSet.is() ?
xMultiPropSet->getPropertySetInfo():
xPropSet->getPropertySetInfo());
if (xPropSetInfo->
hasPropertyByName(u"ParaIsNumberingRestart"_ustr))
{
xPropSet->getPropertyValue(u"ParaIsNumberingRestart"_ustr)
>>= bIsRestartNumbering;
}
if (bIsRestartNumbering)
{
GetExport().AddAttribute(XML_NAMESPACE_TEXT,
XML_RESTART_NUMBERING,
XML_TRUE);
if (xPropSetInfo->
hasPropertyByName(u"NumberingStartValue"_ustr))
{
sal_Int32 nStartValue = 0;
xPropSet->getPropertyValue(u"NumberingStartValue"_ustr)
>>= nStartValue;
GetExport().
AddAttribute(XML_NAMESPACE_TEXT,
XML_START_VALUE,
OUString::number(nStartValue));
}
}
}
}
}
}
if (GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
{
try
{
// ParaMarkerAutoStyleSpan is a hidden property, just to pass the autostyle here
// See SwXParagraph::Impl::GetPropertyValues_Impl
css::uno::Any aVal = xPropSet->getPropertyValue(u"ParaMarkerAutoStyleSpan"_ustr);
if (auto xFakeSpan = aVal.query<css::beans::XPropertySet>())
{
if (bAutoStyles)
{
Add(XmlStyleFamily::TEXT_TEXT, xFakeSpan);
}
else
{
bool bIsUICharStyle, bHasAutoStyle;
OUString sStyle = FindTextStyle(xFakeSpan, bIsUICharStyle, bHasAutoStyle);
if (!sStyle.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_MARKER_STYLE_NAME,
sStyle);
}
}
}
}
catch (const css::beans::UnknownPropertyException&)
{
// No problem
}
}
}
Reference < XEnumerationAccess > xEA( rTextContent, UNO_QUERY );
Reference < XEnumeration > xTextEnum = xEA->createEnumeration();
Reference < XEnumeration> xContentEnum;
Reference < XContentEnumerationAccess > xCEA( rTextContent, UNO_QUERY );
if( xCEA.is() )
xContentEnum.set(xCEA->createContentEnumeration( gsTextContentService ));
const bool bHasContentEnum = xContentEnum.is() &&
xContentEnum->hasMoreElements();
Reference < XTextSection > xSection;
if( bHasContentEnum )
{
// For the auto styles, the multi property set helper is only used
// if hard attributes are existing. Therefore, it seems to be a better
// strategy to have the TextSection property separate, because otherwise
// we always retrieve the style names even if they are not required.
if( bAutoStyles )
{
if( xPropSet->getPropertySetInfo()->hasPropertyByName( gsTextSection ) )
{
xSection.set(xPropSet->getPropertyValue( gsTextSection ), uno::UNO_QUERY);
}
}
else
{
if( rPropSetHelper.hasProperty( TEXT_SECTION ) )
{
xSection.set(rPropSetHelper.getValue( TEXT_SECTION ), uno::UNO_QUERY);
}
}
}
bool bPrevCharIsSpace(true); // true because whitespace at start is ignored
{
enum XMLTokenEnum eElem =
0 < nOutlineLevel ? XML_H : XML_P;
SvXMLElementExport aElem( GetExport(), !bAutoStyles, eExtensionNS == TextPNS::EXTENSION ? XML_NAMESPACE_LO_EXT : XML_NAMESPACE_TEXT, eElem,
true, false );
if( bHasContentEnum )
{
exportTextContentEnumeration(
xContentEnum, bAutoStyles, xSection,
bIsProgress );
}
exportTextRangeEnumeration(xTextEnum, bAutoStyles, bIsProgress, bPrevCharIsSpace);
}
}
void XMLTextParagraphExport::exportTextRangeEnumeration(
const Reference < XEnumeration > & rTextEnum,
bool bAutoStyles, bool bIsProgress,
bool & rPrevCharIsSpace)
{
static const char sFieldMarkName[] = "__FieldMark_";
/* This is used for exporting to strict OpenDocument 1.2, in which case traditional
* bookmarks are used instead of fieldmarks. */
FieldmarkType openFieldMark = NONE;
std::optional<SvXMLElementExport> oTextA;
HyperlinkData aHyperlinkData;
while( rTextEnum->hasMoreElements() )
{
Reference<XPropertySet> xPropSet(rTextEnum->nextElement(), UNO_QUERY);
Reference < XTextRange > xTxtRange(xPropSet, uno::UNO_QUERY);
Reference<XPropertySetInfo> xPropInfo(xPropSet->getPropertySetInfo());
if (!bAutoStyles)
{
if (HyperlinkData aNewHyperlinkData(xPropSet); aNewHyperlinkData != aHyperlinkData)
{
aHyperlinkData = std::move(aNewHyperlinkData);
oTextA.reset();
if (aHyperlinkData.addHyperlinkAttributes(GetExport()))
{
oTextA.emplace(GetExport(), true, XML_NAMESPACE_TEXT, XML_A, false, false);
aHyperlinkData.exportEvents(GetExport());
}
}
}
if (xPropInfo->hasPropertyByName(gsTextPortionType))
{
OUString sType;
xPropSet->getPropertyValue(gsTextPortionType) >>= sType;
if( sType == gsText)
{
exportTextRange( xTxtRange, bAutoStyles,
rPrevCharIsSpace, openFieldMark);
}
else if( sType == gsTextField)
{
exportTextField(xTxtRange, bAutoStyles, bIsProgress, &rPrevCharIsSpace);
}
else if ( sType == "Annotation" )
{
exportTextField(xTxtRange, bAutoStyles, bIsProgress, &rPrevCharIsSpace);
}
else if ( sType == "AnnotationEnd" )
{
if (!bAutoStyles)
{
Reference<XNamed> xBookmark(xPropSet->getPropertyValue(gsBookmark), UNO_QUERY);
const OUString aName = xBookmark->getName();
if (!aName.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_NAME, aName);
}
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_OFFICE, XML_ANNOTATION_END, false, false );
}
}
else if( sType == gsFrame )
{
Reference < XEnumeration> xContentEnum;
Reference < XContentEnumerationAccess > xCEA( xTxtRange,
UNO_QUERY );
if( xCEA.is() )
xContentEnum.set(xCEA->createContentEnumeration(
gsTextContentService ));
// frames are never in sections
Reference<XTextSection> xSection;
if( xContentEnum.is() )
exportTextContentEnumeration( xContentEnum,
bAutoStyles,
xSection, bIsProgress, true,
&xPropSet );
}
else if (sType == gsFootnote)
{
exportTextFootnote(xPropSet,
xTxtRange->getString(),
bAutoStyles, bIsProgress );
}
else if (sType == gsBookmark)
{
exportTextMark(xPropSet,
gsBookmark,
lcl_XmlBookmarkElements,
bAutoStyles);
}
else if (sType == gsReferenceMark)
{
exportTextMark(xPropSet,
gsReferenceMark,
lcl_XmlReferenceElements,
bAutoStyles);
}
else if (sType == gsDocumentIndexMark)
{
m_pIndexMarkExport->ExportIndexMark(xPropSet, bAutoStyles);
}
else if (sType == gsRedline)
{
if (nullptr != m_pRedlineExport)
m_pRedlineExport->ExportChange(xPropSet, bAutoStyles);
}
else if (sType == gsRuby)
{
exportRuby(xPropSet, bAutoStyles);
}
else if (sType == "InContentMetadata")
{
exportMeta(xPropSet, bAutoStyles, bIsProgress, rPrevCharIsSpace);
}
else if (sType == "ContentControl")
{
ExportContentControl(xPropSet, bAutoStyles, bIsProgress, rPrevCharIsSpace);
}
else if (sType == gsTextFieldStart)
{
Reference< css::text::XFormField > xFormField(xPropSet->getPropertyValue(gsBookmark), UNO_QUERY);
/* As of now, textmarks are a proposed extension to the OpenDocument standard. */
if (!bAutoStyles)
{
if (GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
{
Reference<XNamed> xBookmark(xPropSet->getPropertyValue(gsBookmark), UNO_QUERY);
if (xBookmark.is())
{
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
}
if (xFormField.is())
{
GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType());
}
GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, false);
if (xFormField.is())
{
FieldParamExporter(&GetExport(), xFormField->getParameters()).Export();
}
GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, false);
}
/* The OpenDocument standard does not include support for TextMarks for now, so use bookmarks instead. */
else
{
if (xFormField.is())
{
OUString sName;
Reference< css::container::XNameAccess > xParameters = xFormField->getParameters();
if (xParameters.is() && xParameters->hasByName(u"Name"_ustr))
{
const Any aValue = xParameters->getByName(u"Name"_ustr);
aValue >>= sName;
}
if (sName.isEmpty())
{ // name attribute is mandatory, so have to pull a
// rabbit out of the hat here
sName = sFieldMarkName + OUString::number(
m_xImpl->AddFieldMarkStart(xFormField));
}
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME,
sName);
SvXMLElementExport aElem( GetExport(), !bAutoStyles,
XML_NAMESPACE_TEXT, XML_BOOKMARK_START,
false, false );
const OUString sFieldType = xFormField->getFieldType();
if (sFieldType == ODF_FORMTEXT)
{
openFieldMark = TEXT;
}
else if (sFieldType == ODF_FORMCHECKBOX)
{
openFieldMark = CHECK;
}
else
{
openFieldMark = NONE;
}
}
}
}
}
else if (sType == gsTextFieldSep)
{
if (!bAutoStyles)
{
if (GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
{
SvXMLElementExport aElem( GetExport(), !bAutoStyles,
XML_NAMESPACE_FIELD, XML_FIELDMARK_SEPARATOR,
false, false );
}
}
}
else if (sType == gsTextFieldEnd)
{
if (!bAutoStyles)
{
Reference< css::text::XFormField > xFormField(xPropSet->getPropertyValue(gsBookmark), UNO_QUERY);
if (GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
{
SvXMLElementExport aElem( GetExport(), !bAutoStyles,
XML_NAMESPACE_FIELD, XML_FIELDMARK_END,
false, false );
}
else
{
if (xFormField.is())
{
OUString sName;
Reference< css::container::XNameAccess > xParameters = xFormField->getParameters();
if (xParameters.is() && xParameters->hasByName(u"Name"_ustr))
{
const Any aValue = xParameters->getByName(u"Name"_ustr);
aValue >>= sName;
}
if (sName.isEmpty())
{ // name attribute is mandatory, so have to pull a
// rabbit out of the hat here
sName = sFieldMarkName + OUString::number(
m_xImpl->GetFieldMarkIndex(xFormField));
}
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME,
sName);
SvXMLElementExport aElem( GetExport(), !bAutoStyles,
XML_NAMESPACE_TEXT, XML_BOOKMARK_END,
false, false );
}
}
}
}
else if (sType == gsTextFieldStartEnd)
{
exportTextFieldStartEnd(xPropSet, bAutoStyles);
}
else if (sType == gsSoftPageBreak)
{
if (!bAutoStyles)
exportSoftPageBreak();
}
else if (sType == "LineBreak")
{
if (!bAutoStyles)
exportTextLineBreak(xPropSet);
}
else {
OSL_FAIL("unknown text portion type");
}
}
else
{
Reference<XServiceInfo> xServiceInfo( xTxtRange, UNO_QUERY );
if( xServiceInfo->supportsService( gsTextFieldService ) )
{
exportTextField(xTxtRange, bAutoStyles, bIsProgress, &rPrevCharIsSpace);
}
else
{
// no TextPortionType property -> non-Writer app -> text
exportTextRange(xTxtRange, bAutoStyles, rPrevCharIsSpace, openFieldMark);
}
}
}
// now that there are nested enumerations for meta(-field), this may be valid!
// SAL_WARN_IF( bOpenRuby, "xmloff", "Red Alert: Ruby still open!" );
}
void XMLTextParagraphExport::exportTable(
const Reference < XTextContent > &,
bool /*bAutoStyles*/, bool /*bIsProgress*/ )
{
}
void XMLTextParagraphExport::exportTextField(
const Reference < XTextRange > & rTextRange,
bool bAutoStyles, bool bIsProgress, bool *const pPrevCharIsSpace)
{
Reference < XPropertySet > xPropSet( rTextRange, UNO_QUERY );
// non-Writer apps need not support Property TextField, so test first
if (!xPropSet->getPropertySetInfo()->hasPropertyByName( gsTextField ))
return;
Reference < XTextField > xTxtFld(xPropSet->getPropertyValue( gsTextField ), uno::UNO_QUERY);
SAL_WARN_IF( !xTxtFld.is(), "xmloff", "text field missing" );
if( xTxtFld.is() )
{
exportTextField(xTxtFld, bAutoStyles, bIsProgress, pPrevCharIsSpace);
}
else
{
// write only characters
GetExport().Characters(rTextRange->getString());
}
}
void XMLTextParagraphExport::exportTextField(
const Reference < XTextField > & xTextField,
const bool bAutoStyles, const bool bIsProgress,
bool *const pPrevCharIsSpace)
{
if ( bAutoStyles )
{
m_pFieldExport->ExportFieldAutoStyle( xTextField, bIsProgress );
}
else
{
assert(pPrevCharIsSpace);
m_pFieldExport->ExportField(xTextField, bIsProgress, *pPrevCharIsSpace);
}
}
void XMLTextParagraphExport::exportTextFieldStartEnd(const Reference < XPropertySet >& xPropSet, const bool bAutoStyles)
{
if (!bAutoStyles)
{
if (GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
{
bool bHasStyle = false;
Reference<XNamed> xBookmark(xPropSet->getPropertyValue(gsBookmark), UNO_QUERY);
if (xBookmark.is())
{
Reference<XTextContent> xBookmarkContent(xPropSet->getPropertyValue(gsBookmark), UNO_QUERY);
Reference<XPropertySet> xRangePropSet(xBookmarkContent->getAnchor(), UNO_QUERY);
const XMLPropertyState **pStates = nullptr;
// find out whether we need to set the style
bool bIsUICharStyle;
bool bHasAutoStyle;
OUString sStyle = GetExport().GetTextParagraphExport()->
FindTextStyle( xRangePropSet, bIsUICharStyle, bHasAutoStyle, pStates );
bHasStyle = !sStyle.isEmpty();
Reference<XPropertySetInfo> xRangePropSetInfo;
XMLTextCharStyleNamesElementExport aCharStylesExport(
GetExport(), bIsUICharStyle &&
GetExport().GetTextParagraphExport()
->GetCharStyleNamesPropInfoCache().hasProperty(
xRangePropSet, xRangePropSetInfo ), bHasAutoStyle,
xRangePropSet, gsPropertyCharStyleNames );
if( bHasStyle )
{
// export <text:span> element
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
GetExport().EncodeStyleName( sStyle ) );
}
}
SvXMLElementExport aSpan( GetExport(), bHasStyle,
XML_NAMESPACE_TEXT, XML_SPAN,
false, false);
if (xBookmark.is())
{
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
}
Reference< css::text::XFormField > xFormField(xPropSet->getPropertyValue(gsBookmark), UNO_QUERY);
if (xFormField.is())
{
GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType());
}
GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, false);
if (xFormField.is())
{
FieldParamExporter(&GetExport(), xFormField->getParameters()).Export();
}
GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, false);
}
else
{
Reference<XNamed> xBookmark(xPropSet->getPropertyValue(gsBookmark), UNO_QUERY);
if (xBookmark.is())
{
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
SvXMLElementExport aElem( GetExport(), !bAutoStyles,
XML_NAMESPACE_TEXT, XML_BOOKMARK,
false, false );
}
}
}
else
{
Reference<XTextContent> xBookmark(xPropSet->getPropertyValue(gsBookmark), UNO_QUERY);
if (xBookmark.is())
{
Reference<XPropertySet> xRangePropSet(xBookmark->getAnchor(), UNO_QUERY);
GetExport().GetTextParagraphExport()->Add(XmlStyleFamily::TEXT_TEXT,
xRangePropSet);
}
}
}
void XMLTextParagraphExport::exportSoftPageBreak()
{
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
XML_SOFT_PAGE_BREAK, false,
false );
}
void XMLTextParagraphExport::exportTextLineBreak(
const uno::Reference<beans::XPropertySet>& xPropSet)
{
static const XMLTokenEnum aLineBreakClears[] = {
XML_NONE,
XML_LEFT,
XML_RIGHT,
XML_ALL,
};
uno::Reference<text::XTextContent> xLineBreak;
xPropSet->getPropertyValue(u"LineBreak"_ustr) >>= xLineBreak;
if (!xLineBreak.is())
{
return;
}
uno::Reference<beans::XPropertySet> xLineBreakProps(xLineBreak, uno::UNO_QUERY);
if (!xLineBreakProps.is())
{
return;
}
sal_Int16 eClear{};
xLineBreakProps->getPropertyValue(u"Clear"_ustr) >>= eClear;
if (eClear >= 0 && o3tl::make_unsigned(eClear) < SAL_N_ELEMENTS(aLineBreakClears))
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_CLEAR,
GetXMLToken(aLineBreakClears[eClear]));
}
SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT, XML_LINE_BREAK,
/*bIgnWSOutside=*/false, /*bIgnWSInside=*/false);
}
void XMLTextParagraphExport::exportTextMark(
const Reference<XPropertySet> & rPropSet,
const OUString& rProperty,
const ::xmloff::token::XMLTokenEnum pElements[],
bool bAutoStyles)
{
// mib said: "Hau wech!"
// (Originally, I'd export a span element in case the (book|reference)mark
// was formatted. This actually makes a difference in case some pervert
// sets a point reference mark in the document and, say, formats it bold.
// This basically meaningless formatting will now been thrown away
// (aka cleaned up), since mib said: ... dvo
if (bAutoStyles)
return;
// name element
Reference<XNamed> xName(rPropSet->getPropertyValue(rProperty), UNO_QUERY);
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME,
xName->getName());
// start, end, or point-reference?
sal_Int8 nElement;
if( *o3tl::doAccess<bool>(rPropSet->getPropertyValue(gsIsCollapsed)) )
{
nElement = 0;
}
else
{
nElement = *o3tl::doAccess<bool>(rPropSet->getPropertyValue(gsIsStart)) ? 1 : 2;
}
// bookmark, bookmark-start: xml:id and RDFa for RDF metadata
if( nElement < 2 ) {
GetExport().AddAttributeXmlId(xName);
const uno::Reference<text::XTextContent> xTextContent(
xName, uno::UNO_QUERY_THROW);
GetExport().AddAttributesRDFa(xTextContent);
}
// bookmark-start: add attributes hidden and condition
if (nElement == 1)
{
Reference<XPropertySet> bkmkProps(rPropSet->getPropertyValue(rProperty), UNO_QUERY);
Reference<XPropertySetInfo> bkmkPropInfo = bkmkProps->getPropertySetInfo();
OUString sHidden(u"BookmarkHidden"_ustr);
if (bkmkPropInfo->hasPropertyByName(sHidden))
{
bool bHidden = false;
bkmkProps->getPropertyValue(sHidden) >>= bHidden;
if (bHidden)
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, u"hidden"_ustr, u"true"_ustr);
OUString sCondition(u"BookmarkCondition"_ustr);
if (bkmkPropInfo->hasPropertyByName(sCondition))
{
OUString sBookmarkCondition;
bkmkProps->getPropertyValue(sCondition) >>= sBookmarkCondition;
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, u"condition"_ustr, sBookmarkCondition);
}
}
}
}
// export element
assert(pElements != nullptr);
assert(0 <= nElement && nElement <= 2);
SvXMLElementExport aElem(GetExport(),
XML_NAMESPACE_TEXT, pElements[nElement],
false, false);
// else: no styles. (see above)
}
static bool lcl_txtpara_isBoundAsChar(
const Reference < XPropertySet > & rPropSet,
const Reference < XPropertySetInfo > & rPropSetInfo )
{
bool bIsBoundAsChar = false;
OUString sAnchorType( u"AnchorType"_ustr );
if( rPropSetInfo->hasPropertyByName( sAnchorType ) )
{
TextContentAnchorType eAnchor;
rPropSet->getPropertyValue( sAnchorType ) >>= eAnchor;
bIsBoundAsChar = TextContentAnchorType_AS_CHARACTER == eAnchor;
}
return bIsBoundAsChar;
}
XMLShapeExportFlags XMLTextParagraphExport::addTextFrameAttributes(
const Reference < XPropertySet >& rPropSet,
bool bShape,
basegfx::B2DPoint* pCenter,
OUString* pMinHeightValue,
OUString* pMinWidthValue)
{
XMLShapeExportFlags nShapeFeatures = SEF_DEFAULT;
// draw:name (#97662#: not for shapes, since those names will be
// treated in the shape export)
if( !bShape )
{
Reference < XNamed > xNamed( rPropSet, UNO_QUERY );
if( xNamed.is() )
{
OUString sName( xNamed->getName() );
if( !sName.isEmpty() )
GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
xNamed->getName() );
}
}
OUStringBuffer sValue;
// text:anchor-type
TextContentAnchorType eAnchor = TextContentAnchorType_AT_PARAGRAPH;
rPropSet->getPropertyValue( gsAnchorType ) >>= eAnchor;
{
XMLAnchorTypePropHdl aAnchorTypeHdl;
OUString sTmp;
aAnchorTypeHdl.exportXML( sTmp, uno::Any(eAnchor),
GetExport().GetMM100UnitConverter() );
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_ANCHOR_TYPE, sTmp );
}
// text:anchor-page-number
if( TextContentAnchorType_AT_PAGE == eAnchor )
{
sal_Int16 nPage = 0;
rPropSet->getPropertyValue( gsAnchorPageNo ) >>= nPage;
SAL_WARN_IF(nPage <= 0, "xmloff",
"ERROR: writing invalid anchor-page-number 0");
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_ANCHOR_PAGE_NUMBER,
OUString::number( nPage ) );
}
else
{
nShapeFeatures |= XMLShapeExportFlags::NO_WS;
}
// OD 2004-06-01 #i27691# - correction: no export of svg:x, if object
// is anchored as-character.
if ( !bShape &&
eAnchor != TextContentAnchorType_AS_CHARACTER )
{
// svg:x
sal_Int16 nHoriOrient = HoriOrientation::NONE;
rPropSet->getPropertyValue( gsHoriOrient ) >>= nHoriOrient;
if( HoriOrientation::NONE == nHoriOrient )
{
sal_Int32 nPos = 0;
rPropSet->getPropertyValue( gsHoriOrientPosition ) >>= nPos;
GetExport().GetMM100UnitConverter().convertMeasureToXML(
sValue, nPos );
GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_X,
sValue.makeStringAndClear() );
if(nullptr != pCenter)
{
// add left edge to Center
pCenter->setX(pCenter->getX() + nPos);
}
}
}
else if( TextContentAnchorType_AS_CHARACTER == eAnchor )
nShapeFeatures = (nShapeFeatures & ~XMLShapeExportFlags::X);
if( !bShape || TextContentAnchorType_AS_CHARACTER == eAnchor )
{
// svg:y
sal_Int16 nVertOrient = VertOrientation::NONE;
rPropSet->getPropertyValue( gsVertOrient ) >>= nVertOrient;
if( VertOrientation::NONE == nVertOrient )
{
sal_Int32 nPos = 0;
rPropSet->getPropertyValue( gsVertOrientPosition ) >>= nPos;
GetExport().GetMM100UnitConverter().convertMeasureToXML(
sValue, nPos );
GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_Y,
sValue.makeStringAndClear() );
if(nullptr != pCenter)
{
// add top edge to Center
pCenter->setY(pCenter->getY() + nPos);
}
}
if( bShape )
nShapeFeatures = (nShapeFeatures & ~XMLShapeExportFlags::Y);
}
Reference< XPropertySetInfo > xPropSetInfo(rPropSet->getPropertySetInfo());
bool bSyncWidth = false;
if (xPropSetInfo->hasPropertyByName(gsIsSyncWidthToHeight))
{
bSyncWidth = *o3tl::doAccess<bool>(rPropSet->getPropertyValue(gsIsSyncWidthToHeight));
}
sal_Int16 nRelWidth = 0;
if (!bSyncWidth && xPropSetInfo->hasPropertyByName(gsRelativeWidth))
{
rPropSet->getPropertyValue(gsRelativeWidth) >>= nRelWidth;
}
bool bSyncHeight = false;
if (xPropSetInfo->hasPropertyByName(gsIsSyncHeightToWidth))
{
bSyncHeight = *o3tl::doAccess<bool>(rPropSet->getPropertyValue(gsIsSyncHeightToWidth));
}
sal_Int16 nRelHeight = 0;
if (!bSyncHeight && xPropSetInfo->hasPropertyByName(gsRelativeHeight))
{
rPropSet->getPropertyValue(gsRelativeHeight) >>= nRelHeight;
}
awt::Size aLayoutSize;
if ((nRelWidth > 0 || nRelHeight > 0) && xPropSetInfo->hasPropertyByName(u"LayoutSize"_ustr))
{
rPropSet->getPropertyValue(u"LayoutSize"_ustr) >>= aLayoutSize;
}
bool bUseLayoutSize = true;
if (bSyncWidth && bSyncHeight)
{
// This is broken, width depends on height and height depends on width. Don't use the
// invalid layout size we got.
bUseLayoutSize = false;
}
if (aLayoutSize.Width <= 0 || aLayoutSize.Height <= 0)
{
// This is broken, Writer frames have a minimal size, see MINFLY.
bUseLayoutSize = false;
}
// svg:width
sal_Int16 nWidthType = SizeType::FIX;
if( xPropSetInfo->hasPropertyByName( gsWidthType ) )
{
rPropSet->getPropertyValue( gsWidthType ) >>= nWidthType;
}
if( xPropSetInfo->hasPropertyByName( gsWidth ) )
{
sal_Int32 nWidth = 0;
// VAR size will be written as zero min-size
if( SizeType::VARIABLE != nWidthType )
{
rPropSet->getPropertyValue( gsWidth ) >>= nWidth;
}
GetExport().GetMM100UnitConverter().convertMeasureToXML(sValue, nWidth);
if( SizeType::FIX != nWidthType )
{
assert(pMinWidthValue);
if (pMinWidthValue)
{
*pMinWidthValue = sValue.makeStringAndClear();
}
}
else
{
if ((nRelWidth > 0 || bSyncWidth) && bUseLayoutSize)
{
// Relative width: write the layout size for the fallback width.
sValue.setLength(0);
GetExport().GetMM100UnitConverter().convertMeasureToXML(sValue, aLayoutSize.Width);
}
GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_WIDTH,
sValue.makeStringAndClear() );
if(nullptr != pCenter)
{
// add half width to Center
pCenter->setX(pCenter->getX() + (0.5 * nWidth));
}
}
}
if( xPropSetInfo->hasPropertyByName( gsIsSyncWidthToHeight ) )
{
if( bSyncWidth )
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
XML_SCALE );
}
if( !bSyncWidth && xPropSetInfo->hasPropertyByName( gsRelativeWidth ) )
{
SAL_WARN_IF( nRelWidth < 0 || nRelWidth > 254, "xmloff",
"Got illegal relative width from API" );
if( nRelWidth > 0 )
{
::sax::Converter::convertPercent( sValue, nRelWidth );
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH,
sValue.makeStringAndClear() );
}
}
// svg:height, fo:min-height or style:rel-height
sal_Int16 nSizeType = SizeType::FIX;
if( xPropSetInfo->hasPropertyByName( gsSizeType ) )
{
rPropSet->getPropertyValue( gsSizeType ) >>= nSizeType;
}
if( xPropSetInfo->hasPropertyByName( gsHeight ) )
{
sal_Int32 nHeight = 0;
if( SizeType::VARIABLE != nSizeType )
{
rPropSet->getPropertyValue( gsHeight ) >>= nHeight;
}
GetExport().GetMM100UnitConverter().convertMeasureToXML( sValue,
nHeight );
if( SizeType::FIX != nSizeType && 0==nRelHeight && !bSyncHeight &&
pMinHeightValue )
{
*pMinHeightValue = sValue.makeStringAndClear();
}
else
{
if ((nRelHeight > 0 || bSyncHeight) && bUseLayoutSize)
{
// Relative height: write the layout size for the fallback height.
sValue.setLength(0);
GetExport().GetMM100UnitConverter().convertMeasureToXML(sValue, aLayoutSize.Height);
}
GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_HEIGHT,
sValue.makeStringAndClear() );
if(nullptr != pCenter)
{
// add half height to Center
pCenter->setY(pCenter->getY() + (0.5 * nHeight));
}
}
}
if( bSyncHeight )
{
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_HEIGHT,
SizeType::MIN == nSizeType ? XML_SCALE_MIN : XML_SCALE );
}
else if( nRelHeight > 0 )
{
::sax::Converter::convertPercent( sValue, nRelHeight );
if( SizeType::MIN == nSizeType )
{
assert(pMinHeightValue);
if (pMinHeightValue)
{
*pMinHeightValue = sValue.makeStringAndClear();
}
}
else
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_HEIGHT,
sValue.makeStringAndClear() );
}
OUString sZOrder( u"ZOrder"_ustr );
if( xPropSetInfo->hasPropertyByName( sZOrder ) )
{
sal_Int32 nZIndex = 0;
rPropSet->getPropertyValue( sZOrder ) >>= nZIndex;
if( -1 != nZIndex )
{
GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_ZINDEX,
OUString::number( nZIndex ) );
}
}
if (xPropSetInfo->hasPropertyByName(u"IsSplitAllowed"_ustr)
&& rPropSet->getPropertyValue(u"IsSplitAllowed"_ustr).get<bool>())
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_MAY_BREAK_BETWEEN_PAGES, XML_TRUE);
}
return nShapeFeatures;
}
void XMLTextParagraphExport::exportAnyTextFrame(
const Reference < XTextContent > & rTxtCntnt,
FrameType eType,
bool bAutoStyles,
bool bIsProgress,
bool bExportContent,
const Reference < XPropertySet > *pRangePropSet)
{
Reference < XPropertySet > xPropSet( rTxtCntnt, UNO_QUERY );
if( bAutoStyles )
{
if( FrameType::Embedded == eType )
_collectTextEmbeddedAutoStyles( xPropSet );
// No text frame style for shapes (#i28745#)
else if ( FrameType::Shape != eType )
Add( XmlStyleFamily::TEXT_FRAME, xPropSet );
if( pRangePropSet && lcl_txtpara_isBoundAsChar( xPropSet,
xPropSet->getPropertySetInfo() ) )
Add( XmlStyleFamily::TEXT_TEXT, *pRangePropSet );
switch( eType )
{
case FrameType::Text:
{
// frame bound frames
if ( bExportContent )
{
Reference < XTextFrame > xTxtFrame( rTxtCntnt, UNO_QUERY );
bool bAlreadySeen = !maFrameRecurseGuard.insert(xTxtFrame).second;
if (bAlreadySeen)
{
SAL_WARN("xmloff", "loop in frame export, ditching");
}
else
{
comphelper::ScopeGuard const g([this, xTxtFrame]() {
maFrameRecurseGuard.erase(xTxtFrame);
});
Reference < XText > xTxt(xTxtFrame->getText());
exportFrameFrames( true, bIsProgress, xTxtFrame );
exportText( xTxt, bAutoStyles, bIsProgress, true );
}
}
}
break;
case FrameType::Shape:
{
Reference < XShape > xShape( rTxtCntnt, UNO_QUERY );
bool bAlreadySeen = !maShapeRecurseGuard.insert(xShape).second;
if (bAlreadySeen)
{
SAL_WARN("xmloff", "loop in shape export, ditching");
}
else
{
comphelper::ScopeGuard const g([this, xShape]() {
maShapeRecurseGuard.erase(xShape);
});
GetExport().GetShapeExport()->collectShapeAutoStyles( xShape );
}
}
break;
default:
break;
}
}
else
{
Reference< XPropertySetInfo > xPropSetInfo(xPropSet->getPropertySetInfo());
{
bool bAddCharStyles = pRangePropSet &&
lcl_txtpara_isBoundAsChar( xPropSet, xPropSetInfo );
bool bIsUICharStyle;
bool bHasAutoStyle = false;
OUString sStyle;
if( bAddCharStyles )
sStyle = FindTextStyle( *pRangePropSet, bIsUICharStyle, bHasAutoStyle );
else
bIsUICharStyle = false;
bool bDoSomething = bIsUICharStyle
&& m_aCharStyleNamesPropInfoCache.hasProperty( *pRangePropSet );
XMLTextCharStyleNamesElementExport aCharStylesExport(
GetExport(), bDoSomething, bHasAutoStyle,
bDoSomething ? *pRangePropSet : Reference<XPropertySet>(),
gsCharStyleNames );
if( !sStyle.isEmpty() )
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
GetExport().EncodeStyleName( sStyle ) );
{
SvXMLElementExport aElem( GetExport(), !sStyle.isEmpty(),
XML_NAMESPACE_TEXT, XML_SPAN, false, false );
{
SvXMLElementExport aElement( GetExport(),
FrameType::Shape != eType &&
HyperlinkData(xPropSet).addHyperlinkAttributes(GetExport()),
XML_NAMESPACE_DRAW, XML_A, false, false );
switch( eType )
{
case FrameType::Text:
_exportTextFrame( xPropSet, xPropSetInfo, bIsProgress );
break;
case FrameType::Graphic:
_exportTextGraphic( xPropSet, xPropSetInfo );
break;
case FrameType::Embedded:
_exportTextEmbedded( xPropSet, xPropSetInfo );
break;
case FrameType::Shape:
{
Reference < XShape > xShape( rTxtCntnt, UNO_QUERY );
XMLShapeExportFlags nFeatures =
addTextFrameAttributes( xPropSet, true );
GetExport().GetShapeExport()
->exportShape( xShape, nFeatures );
}
break;
}
}
}
}
}
}
void XMLTextParagraphExport::_exportTextFrame(
const Reference < XPropertySet > & rPropSet,
const Reference < XPropertySetInfo > & rPropSetInfo,
bool bIsProgress )
{
Reference < XTextFrame > xTxtFrame( rPropSet, UNO_QUERY );
Reference < XText > xTxt(xTxtFrame->getText());
OUString sStyle;
if( rPropSetInfo->hasPropertyByName( gsFrameStyleName ) )
{
rPropSet->getPropertyValue( gsFrameStyleName ) >>= sStyle;
}
OUString aMinHeightValue;
OUString sMinWidthValue;
OUString sAutoStyle = Find( XmlStyleFamily::TEXT_FRAME, rPropSet, sStyle );
if ( sAutoStyle.isEmpty() )
sAutoStyle = sStyle;
if( !sAutoStyle.isEmpty() )
GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE_NAME,
GetExport().EncodeStyleName( sAutoStyle ) );
addTextFrameAttributes(rPropSet, false, nullptr, &aMinHeightValue, &sMinWidthValue);
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW,
XML_FRAME, false, true );
if( !aMinHeightValue.isEmpty() )
GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MIN_HEIGHT,
aMinHeightValue );
if (!sMinWidthValue.isEmpty())
{
GetExport().AddAttribute( XML_NAMESPACE_FO, XML_MIN_WIDTH,
sMinWidthValue );
}
// draw:chain-next-name
if( rPropSetInfo->hasPropertyByName( gsChainNextName ) )
{
OUString sNext;
if( (rPropSet->getPropertyValue( gsChainNextName ) >>= sNext) && !sNext.isEmpty() )
GetExport().AddAttribute( XML_NAMESPACE_DRAW,
XML_CHAIN_NEXT_NAME,
sNext );
}
{
SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_DRAW,
XML_TEXT_BOX, true, true );
// frames bound to frame
exportFrameFrames( false, bIsProgress, xTxtFrame );
exportText( xTxt, false, bIsProgress, true );
}
// script:events
Reference<XEventsSupplier> xEventsSupp( xTxtFrame, UNO_QUERY );
GetExport().GetEventExport().Export(xEventsSupp);
// image map
GetExport().GetImageMapExport().Export( rPropSet );
// svg:title and svg:desc (#i73249#)
exportTitleAndDescription( rPropSet, rPropSetInfo );
}
void XMLTextParagraphExport::exportContour(
const Reference < XPropertySet > & rPropSet,
const Reference < XPropertySetInfo > & rPropSetInfo )
{
if( !rPropSetInfo->hasPropertyByName( gsContourPolyPolygon ) )
{
return;
}
PointSequenceSequence aSourcePolyPolygon;
rPropSet->getPropertyValue( gsContourPolyPolygon ) >>= aSourcePolyPolygon;
const basegfx::B2DPolyPolygon aPolyPolygon(
basegfx::utils::UnoPointSequenceSequenceToB2DPolyPolygon(
aSourcePolyPolygon));
const sal_uInt32 nPolygonCount(aPolyPolygon.count());
if(!nPolygonCount)
{
return;
}
const basegfx::B2DRange aPolyPolygonRange(aPolyPolygon.getB2DRange());
bool bPixel(false);
if( rPropSetInfo->hasPropertyByName( gsIsPixelContour ) )
{
bPixel = *o3tl::doAccess<bool>(rPropSet->getPropertyValue( gsIsPixelContour ));
}
// svg: width
OUStringBuffer aStringBuffer( 10 );
if(bPixel)
{
::sax::Converter::convertMeasurePx(aStringBuffer, basegfx::fround(aPolyPolygonRange.getWidth()));
}
else
{
GetExport().GetMM100UnitConverter().convertMeasureToXML(aStringBuffer, basegfx::fround(aPolyPolygonRange.getWidth()));
}
GetExport().AddAttribute(XML_NAMESPACE_SVG, XML_WIDTH, aStringBuffer.makeStringAndClear());
// svg: height
if(bPixel)
{
::sax::Converter::convertMeasurePx(aStringBuffer, basegfx::fround(aPolyPolygonRange.getHeight()));
}
else
{
GetExport().GetMM100UnitConverter().convertMeasureToXML(aStringBuffer, basegfx::fround(aPolyPolygonRange.getHeight()));
}
GetExport().AddAttribute(XML_NAMESPACE_SVG, XML_HEIGHT, aStringBuffer.makeStringAndClear());
// svg:viewbox
SdXMLImExViewBox aViewBox(0.0, 0.0, aPolyPolygonRange.getWidth(), aPolyPolygonRange.getHeight());
GetExport().AddAttribute(XML_NAMESPACE_SVG, XML_VIEWBOX, aViewBox.GetExportString());
enum XMLTokenEnum eElem = XML_TOKEN_INVALID;
if(1 == nPolygonCount )
{
// simple polygon shape, can be written as svg:points sequence
const OUString aPointString(
basegfx::utils::exportToSvgPoints(
aPolyPolygon.getB2DPolygon(0)));
// write point array
GetExport().AddAttribute(XML_NAMESPACE_DRAW, XML_POINTS, aPointString);
eElem = XML_CONTOUR_POLYGON;
}
else
{
// polypolygon, needs to be written as a svg:path sequence
const OUString aPolygonString(
basegfx::utils::exportToSvgD(
aPolyPolygon,
true, // bUseRelativeCoordinates
false, // bDetectQuadraticBeziers: not used in old, but maybe activated now
true)); // bHandleRelativeNextPointCompatible
// write point array
GetExport().AddAttribute( XML_NAMESPACE_SVG, XML_D, aPolygonString);
eElem = XML_CONTOUR_PATH;
}
if( rPropSetInfo->hasPropertyByName( gsIsAutomaticContour ) )
{
bool bTmp = *o3tl::doAccess<bool>(rPropSet->getPropertyValue(
gsIsAutomaticContour ));
GetExport().AddAttribute( XML_NAMESPACE_DRAW,
XML_RECREATE_ON_EDIT, bTmp ? XML_TRUE : XML_FALSE );
}
// write object now
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW, eElem,
true, true );
}
void XMLTextParagraphExport::_exportTextGraphic(
const Reference < XPropertySet > & rPropSet,
const Reference < XPropertySetInfo > & rPropSetInfo )
{
// skip objects anchored at page in master documents,
// if they are imported from the subdocuments
TextContentAnchorType eAnchor;
rPropSet->getPropertyValue(u"AnchorType"_ustr) >>= eAnchor;
if( TextContentAnchorType_AT_PAGE == eAnchor )
{
Reference<XServiceInfo> xServiceInfo(GetExport().GetModel(), UNO_QUERY);
if( xServiceInfo->supportsService(u"com.sun.star.text.GlobalDocument"_ustr) )
{
Reference<XNamed> xNamed( rPropSet, UNO_QUERY );
if( xNamed.is() && xNamed->getName().indexOf(" (file://") > -1 )
return;
}
}
OUString sStyle;
if( rPropSetInfo->hasPropertyByName( gsFrameStyleName ) )
{
rPropSet->getPropertyValue( gsFrameStyleName ) >>= sStyle;
}
OUString sAutoStyle = Find( XmlStyleFamily::TEXT_FRAME, rPropSet, sStyle );
if ( sAutoStyle.isEmpty() )
sAutoStyle = sStyle;
if( !sAutoStyle.isEmpty() )
GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE_NAME,
GetExport().EncodeStyleName( sAutoStyle ) );
// check if we need to use svg:transform
sal_Int16 nRotation(0);
rPropSet->getPropertyValue( gsGraphicRotation ) >>= nRotation;
const bool bUseRotation(0 != nRotation);
basegfx::B2DPoint aCenter(0.0, 0.0);
// add TextFrame attributes like svg:x/y/width/height, also get back
// object's center point if rotation is used and has to be exported
addTextFrameAttributes(rPropSet, false, bUseRotation ? &aCenter : nullptr);
// svg:transform
if(bUseRotation)
{
// RotateFlyFrameFix: im/export full 'draw:transform' using existing tooling.
// Currently only rotation is used, but combinations with 'draw:transform'
// may be necessary in the future, so that svg:x/svg:y/svg:width/svg:height
// may be extended/replaced with 'draw:transform' (see draw objects)
SdXMLImExTransform2D aSdXMLImExTransform2D;
// Convert from 10th degree integer to deg.
// CAUTION: internal rotation is classically mathematically 'wrong' defined by ignoring that
// we have a right-handed coordinate system, so need to correct this by mirroring
// the rotation to get the correct transformation. See also case XML_TOK_TEXT_FRAME_TRANSFORM
// in XMLTextFrameContext_Impl::XMLTextFrameContext_Impl and #i78696#
// CAUTION-II: due to tdf#115782 it is better for current ODF to indeed write it with the wrong
// orientation as in all other cases - ARGH! We will need to correct this in future ODF ASAP!
const double fRotate(basegfx::deg2rad<10>(nRotation));
// transform to rotation center which is the object's center
aSdXMLImExTransform2D.AddTranslate(-aCenter);
// add rotation itself
// tdf#115529 but correct value modulo 2PI to have it positive and in the range of [0.0 .. 2PI[
aSdXMLImExTransform2D.AddRotate(basegfx::normalizeToRange(fRotate, 2 * M_PI));
// back-transform after rotation
aSdXMLImExTransform2D.AddTranslate(aCenter);
// Note: using GetTwipUnitConverter instead of GetMM100UnitConverter may be needed,
// but is not generally available (as it should be, a 'current' UnitConverter should
// be available at GetExport() - and maybe was once). May have to be addressed as soon
// as translate transformations are used here.
GetExport().AddAttribute(
XML_NAMESPACE_DRAW,
XML_TRANSFORM,
aSdXMLImExTransform2D.GetExportString(GetExport().GetMM100UnitConverter()));
}
// original content
SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_DRAW, XML_FRAME, false, true);
{
// xlink:href
uno::Reference<graphic::XGraphic> xGraphic;
rPropSet->getPropertyValue(u"Graphic"_ustr) >>= xGraphic;
OUString sInternalURL;
OUString sOutMimeType;
if (xGraphic.is())
{
sInternalURL = GetExport().AddEmbeddedXGraphic(xGraphic, sOutMimeType);
}
// If there still is no url, then graphic is empty
if (!sInternalURL.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sInternalURL);
GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE);
GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED);
GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD);
}
// draw:filter-name
OUString sGrfFilter;
rPropSet->getPropertyValue( gsGraphicFilter ) >>= sGrfFilter;
if( !sGrfFilter.isEmpty() )
GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_FILTER_NAME,
sGrfFilter );
if (GetExport().getSaneDefaultVersion() > SvtSaveOptions::ODFSVER_012)
{
if (sOutMimeType.isEmpty())
{
GetExport().GetGraphicMimeTypeFromStream(xGraphic, sOutMimeType);
}
if (!sOutMimeType.isEmpty())
{ // ODF 1.3 OFFICE-3943
GetExport().AddAttribute(
SvtSaveOptions::ODFSVER_013 <= GetExport().getSaneDefaultVersion()
? XML_NAMESPACE_DRAW
: XML_NAMESPACE_LO_EXT,
u"mime-type"_ustr, sOutMimeType);
}
}
// optional office:binary-data
if (xGraphic.is())
{
SvXMLElementExport aElement(GetExport(), XML_NAMESPACE_DRAW, XML_IMAGE, false, true );
GetExport().AddEmbeddedXGraphicAsBase64(xGraphic);
}
}
const bool bAddReplacementImages = officecfg::Office::Common::Save::Graphic::AddReplacementImages::get();
if (bAddReplacementImages)
{
// replacement graphic for backwards compatibility, but
// only for SVG and metafiles currently
uno::Reference<graphic::XGraphic> xReplacementGraphic;
rPropSet->getPropertyValue(u"ReplacementGraphic"_ustr) >>= xReplacementGraphic;
OUString sInternalURL;
OUString sOutMimeType;
//Resolves: fdo#62461 put preferred image first above, followed by
//fallback here
if (xReplacementGraphic.is())
{
sInternalURL = GetExport().AddEmbeddedXGraphic(xReplacementGraphic, sOutMimeType);
}
// If there is no url, then graphic is empty
if (!sInternalURL.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sInternalURL);
GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE);
GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED);
GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD);
}
if (GetExport().getSaneDefaultVersion() > SvtSaveOptions::ODFSVER_012)
{
if (sOutMimeType.isEmpty())
{
GetExport().GetGraphicMimeTypeFromStream(xReplacementGraphic, sOutMimeType);
}
if (!sOutMimeType.isEmpty())
{ // ODF 1.3 OFFICE-3943
GetExport().AddAttribute(
SvtSaveOptions::ODFSVER_013 <= GetExport().getSaneDefaultVersion()
? XML_NAMESPACE_DRAW
: XML_NAMESPACE_LO_EXT,
u"mime-type"_ustr, sOutMimeType);
}
}
// optional office:binary-data
if (xReplacementGraphic.is())
{
SvXMLElementExport aElement(GetExport(), XML_NAMESPACE_DRAW, XML_IMAGE, true, true);
GetExport().AddEmbeddedXGraphicAsBase64(xReplacementGraphic);
}
}
// script:events
Reference<XEventsSupplier> xEventsSupp( rPropSet, UNO_QUERY );
GetExport().GetEventExport().Export(xEventsSupp);
// image map
GetExport().GetImageMapExport().Export( rPropSet );
// svg:title and svg:desc (#i73249#)
exportTitleAndDescription( rPropSet, rPropSetInfo );
// draw:contour
exportContour( rPropSet, rPropSetInfo );
}
void XMLTextParagraphExport::_collectTextEmbeddedAutoStyles(const Reference < XPropertySet > & )
{
SAL_WARN( "xmloff", "no API implementation available" );
}
void XMLTextParagraphExport::_exportTextEmbedded(
const Reference < XPropertySet > &,
const Reference < XPropertySetInfo > & )
{
SAL_WARN( "xmloff", "no API implementation available" );
}
void XMLTextParagraphExport::exportEvents( const Reference < XPropertySet > & rPropSet )
{
// script:events
Reference<XEventsSupplier> xEventsSupp( rPropSet, UNO_QUERY );
GetExport().GetEventExport().Export(xEventsSupp);
// image map
if (rPropSet->getPropertySetInfo()->hasPropertyByName(u"ImageMap"_ustr))
GetExport().GetImageMapExport().Export( rPropSet );
}
// Implement Title/Description Elements UI (#i73249#)
void XMLTextParagraphExport::exportTitleAndDescription(
const Reference < XPropertySet > & rPropSet,
const Reference < XPropertySetInfo > & rPropSetInfo )
{
// svg:title
if( rPropSetInfo->hasPropertyByName( gsTitle ) )
{
OUString sObjTitle;
rPropSet->getPropertyValue( gsTitle ) >>= sObjTitle;
if( !sObjTitle.isEmpty() )
{
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_SVG,
XML_TITLE, true, false );
GetExport().Characters( sObjTitle );
}
}
// svg:description
if( rPropSetInfo->hasPropertyByName( gsDescription ) )
{
OUString sObjDesc;
rPropSet->getPropertyValue( gsDescription ) >>= sObjDesc;
if( !sObjDesc.isEmpty() )
{
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_SVG,
XML_DESC, true, false );
GetExport().Characters( sObjDesc );
}
}
}
void XMLTextParagraphExport::exportTextRangeSpan(
const css::uno::Reference< css::text::XTextRange > & rTextRange,
Reference< XPropertySet > const & xPropSet,
Reference < XPropertySetInfo > & xPropSetInfo,
const bool bIsUICharStyle,
const bool bHasAutoStyle,
const OUString& sStyle,
bool& rPrevCharIsSpace,
FieldmarkType& openFieldMark )
{
XMLTextCharStyleNamesElementExport aCharStylesExport(
GetExport(),
bIsUICharStyle && m_aCharStyleNamesPropInfoCache.hasProperty( xPropSet, xPropSetInfo ),
bHasAutoStyle,
xPropSet,
gsCharStyleNames );
if ( !sStyle.isEmpty() )
{
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, GetExport().EncodeStyleName( sStyle ) );
}
{
SvXMLElementExport aElement( GetExport(), !sStyle.isEmpty(), XML_NAMESPACE_TEXT, XML_SPAN, false, false );
const OUString aText( rTextRange->getString() );
SvXMLElementExport aElem2( GetExport(), TEXT == openFieldMark,
XML_NAMESPACE_TEXT, XML_TEXT_INPUT,
false, false );
exportCharacterData(aText, rPrevCharIsSpace);
openFieldMark = NONE;
}
}
void XMLTextParagraphExport::exportTextRange(
const Reference< XTextRange > & rTextRange,
bool bAutoStyles,
bool& rPrevCharIsSpace,
FieldmarkType& openFieldMark )
{
Reference< XPropertySet > xPropSet( rTextRange, UNO_QUERY );
if ( bAutoStyles )
{
Add( XmlStyleFamily::TEXT_TEXT, xPropSet );
}
else
{
bool bIsUICharStyle = false;
bool bHasAutoStyle = false;
const OUString sStyle(
FindTextStyle( xPropSet, bIsUICharStyle, bHasAutoStyle ) );
Reference < XPropertySetInfo > xPropSetInfo;
exportTextRangeSpan( rTextRange, xPropSet, xPropSetInfo, bIsUICharStyle, bHasAutoStyle, sStyle, rPrevCharIsSpace, openFieldMark );
}
}
void XMLTextParagraphExport::exportCharacterData(const OUString& rText,
bool& rPrevCharIsSpace )
{
sal_Int32 nExpStartPos = 0;
sal_Int32 nEndPos = rText.getLength();
sal_Int32 nSpaceChars = 0;
for( sal_Int32 nPos = 0; nPos < nEndPos; nPos++ )
{
sal_Unicode cChar = rText[nPos];
bool bExpCharAsText = true;
bool bExpCharAsElement = false;
bool bCurrCharIsSpace = false;
switch( cChar )
{
case 0x0009: // Tab
case 0x000A: // LF
// These characters are exported as text.
bExpCharAsElement = true;
bExpCharAsText = false;
break;
case 0x000D:
break; // legal character
case 0x0020: // Blank
if( rPrevCharIsSpace )
{
// If the previous character is a space character,
// too, export a special space element.
bExpCharAsText = false;
}
bCurrCharIsSpace = true;
break;
default:
if( cChar < 0x0020 )
{
#ifdef DBG_UTIL
OSL_ENSURE( txtparae_bContainsIllegalCharacters ||
cChar >= 0x0020,
"illegal character in text content" );
txtparae_bContainsIllegalCharacters = true;
#endif
bExpCharAsText = false;
}
break;
}
// If the current character is not exported as text
// the text that has not been exported by now has to be exported now.
if( nPos > nExpStartPos && !bExpCharAsText )
{
SAL_WARN_IF( 0 != nSpaceChars, "xmloff", "pending spaces" );
OUString sExp( rText.copy( nExpStartPos, nPos - nExpStartPos ) );
GetExport().Characters( sExp );
nExpStartPos = nPos;
}
// If there are spaces left that have not been exported and the
// current character is not a space , the pending spaces have to be
// exported now.
if( nSpaceChars > 0 && !bCurrCharIsSpace )
{
SAL_WARN_IF( nExpStartPos != nPos, "xmloff", " pending characters" );
if( nSpaceChars > 1 )
{
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_C,
OUString::number(nSpaceChars) );
}
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
XML_S, false, false );
nSpaceChars = 0;
}
// If the current character has to be exported as a special
// element, the element will be exported now.
if( bExpCharAsElement )
{
switch( cChar )
{
case 0x0009: // Tab
{
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
XML_TAB, false,
false );
}
break;
case 0x000A: // LF
{
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
XML_LINE_BREAK, false,
false );
}
break;
}
}
// If the current character is a space, and the previous one
// is a space, too, the number of pending spaces is incremented
// only.
if( bCurrCharIsSpace && rPrevCharIsSpace )
nSpaceChars++;
rPrevCharIsSpace = bCurrCharIsSpace;
// If the current character is not exported as text, the start
// position for text is the position behind the current position.
if( !bExpCharAsText )
{
SAL_WARN_IF( nExpStartPos != nPos, "xmloff", "wrong export start pos" );
nExpStartPos = nPos+1;
}
}
if( nExpStartPos < nEndPos )
{
SAL_WARN_IF( 0 != nSpaceChars, "xmloff", " pending spaces " );
OUString sExp( rText.copy( nExpStartPos, nEndPos - nExpStartPos ) );
GetExport().Characters( sExp );
}
// If there are some spaces left, they have to be exported now.
if( nSpaceChars > 0 )
{
if( nSpaceChars > 1 )
{
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_C,
OUString::number(nSpaceChars) );
}
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_S,
false, false );
}
}
void XMLTextParagraphExport::exportTextDeclarations()
{
m_pFieldExport->ExportFieldDeclarations();
// get XPropertySet from the document and ask for AutoMarkFileURL.
// If it exists, export the auto-mark-file element.
Reference<XPropertySet> xPropertySet( GetExport().GetModel(), UNO_QUERY );
if (!xPropertySet.is())
return;
OUString sUrl;
OUString sIndexAutoMarkFileURL(
u"IndexAutoMarkFileURL"_ustr);
if (!xPropertySet->getPropertySetInfo()->hasPropertyByName(
sIndexAutoMarkFileURL))
return;
xPropertySet->getPropertyValue(sIndexAutoMarkFileURL) >>= sUrl;
if (!sUrl.isEmpty())
{
GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF,
GetExport().GetRelativeReference(sUrl) );
SvXMLElementExport aAutoMarkElement(
GetExport(), XML_NAMESPACE_TEXT,
XML_ALPHABETICAL_INDEX_AUTO_MARK_FILE,
true, true );
}
}
void XMLTextParagraphExport::exportTextDeclarations(
const Reference<XText> & rText )
{
m_pFieldExport->ExportFieldDeclarations(rText);
}
void XMLTextParagraphExport::exportUsedDeclarations()
{
m_pFieldExport->SetExportOnlyUsedFieldDeclarations( false/*bOnlyUsed*/ );
}
void XMLTextParagraphExport::exportTrackedChanges(bool bAutoStyles)
{
if (nullptr != m_pRedlineExport)
m_pRedlineExport->ExportChangesList( bAutoStyles );
}
void XMLTextParagraphExport::exportTrackedChanges(
const Reference<XText> & rText,
bool bAutoStyle)
{
if (nullptr != m_pRedlineExport)
m_pRedlineExport->ExportChangesList(rText, bAutoStyle);
}
void XMLTextParagraphExport::recordTrackedChangesForXText(
const Reference<XText> & rText )
{
if (nullptr != m_pRedlineExport)
m_pRedlineExport->SetCurrentXText(rText);
}
void XMLTextParagraphExport::recordTrackedChangesNoXText()
{
if (nullptr != m_pRedlineExport)
m_pRedlineExport->SetCurrentXText();
}
void XMLTextParagraphExport::exportTableAutoStyles() {}
void XMLTextParagraphExport::exportTextAutoStyles()
{
// tdf#135942: do not collect styles during their export: this may modify iterated containers
mbCollected = true;
exportTableAutoStyles();
GetAutoStylePool().exportXML( XmlStyleFamily::TEXT_PARAGRAPH );
GetAutoStylePool().exportXML( XmlStyleFamily::TEXT_TEXT );
GetAutoStylePool().exportXML( XmlStyleFamily::TEXT_FRAME );
GetAutoStylePool().exportXML( XmlStyleFamily::TEXT_SECTION );
GetAutoStylePool().exportXML( XmlStyleFamily::TEXT_RUBY );
maListAutoPool.exportXML();
}
void XMLTextParagraphExport::exportRuby(
const Reference<XPropertySet> & rPropSet,
bool bAutoStyles )
{
// early out: a collapsed ruby makes no sense
if (*o3tl::doAccess<bool>(rPropSet->getPropertyValue(gsIsCollapsed)))
return;
// start value ?
bool bStart = *o3tl::doAccess<bool>(rPropSet->getPropertyValue(gsIsStart));
if (bAutoStyles)
{
// ruby auto styles
if (bStart)
Add( XmlStyleFamily::TEXT_RUBY, rPropSet );
}
else
{
if (bStart)
{
// ruby start
// we can only start a ruby if none is open
assert(!m_bOpenRuby && "Can't open a ruby inside of ruby!");
if( m_bOpenRuby )
return;
// save ruby text + ruby char style
rPropSet->getPropertyValue(gsRubyText) >>= m_sOpenRubyText;
rPropSet->getPropertyValue(gsRubyCharStyleName) >>= m_sOpenRubyCharStyle;
// ruby style
GetExport().CheckAttrList();
OUString sStyleName(Find(XmlStyleFamily::TEXT_RUBY, rPropSet, u""_ustr));
SAL_WARN_IF(sStyleName.isEmpty(), "xmloff", "Can't find ruby style!");
GetExport().AddAttribute(XML_NAMESPACE_TEXT,
XML_STYLE_NAME, sStyleName);
// export <text:ruby> and <text:ruby-base> start elements
GetExport().StartElement( XML_NAMESPACE_TEXT, XML_RUBY, false);
GetExport().ClearAttrList();
GetExport().StartElement( XML_NAMESPACE_TEXT, XML_RUBY_BASE,
false );
m_bOpenRuby = true;
}
else
{
// ruby end
// check for an open ruby
assert(m_bOpenRuby && "Can't close a ruby if none is open!");
if( !m_bOpenRuby )
return;
// close <text:ruby-base>
GetExport().EndElement(XML_NAMESPACE_TEXT, XML_RUBY_BASE,
false);
// write the ruby text (with char style)
{
if (!m_sOpenRubyCharStyle.isEmpty())
GetExport().AddAttribute(
XML_NAMESPACE_TEXT, XML_STYLE_NAME,
GetExport().EncodeStyleName( m_sOpenRubyCharStyle) );
SvXMLElementExport aRubyElement(
GetExport(), XML_NAMESPACE_TEXT, XML_RUBY_TEXT,
false, false);
GetExport().Characters(m_sOpenRubyText);
}
// and finally, close the ruby
GetExport().EndElement(XML_NAMESPACE_TEXT, XML_RUBY, false);
m_bOpenRuby = false;
}
}
}
void XMLTextParagraphExport::exportMeta(
const Reference<XPropertySet> & i_xPortion,
bool i_bAutoStyles, bool i_isProgress, bool & rPrevCharIsSpace)
{
bool doExport(!i_bAutoStyles); // do not export element if autostyles
// check version >= 1.2
switch (GetExport().getSaneDefaultVersion()) {
case SvtSaveOptions::ODFSVER_011: // fall through
case SvtSaveOptions::ODFSVER_010: doExport = false; break;
default: break;
}
const Reference< XTextContent > xTextContent(
i_xPortion->getPropertyValue(u"InContentMetadata"_ustr), UNO_QUERY_THROW);
const Reference< XEnumerationAccess > xEA( xTextContent, UNO_QUERY_THROW );
const Reference< XEnumeration > xTextEnum( xEA->createEnumeration() );
if (doExport)
{
const Reference<rdf::XMetadatable> xMeta(xTextContent, UNO_QUERY_THROW);
// text:meta with neither xml:id nor RDFa is invalid
xMeta->ensureMetadataReference();
// xml:id and RDFa for RDF metadata
GetExport().AddAttributeXmlId(xMeta);
GetExport().AddAttributesRDFa(xTextContent);
}
SvXMLElementExport aElem( GetExport(), doExport,
XML_NAMESPACE_TEXT, XML_META, false, false );
// recurse to export content
exportTextRangeEnumeration(xTextEnum, i_bAutoStyles, i_isProgress, rPrevCharIsSpace);
}
void XMLTextParagraphExport::ExportContentControl(
const uno::Reference<beans::XPropertySet>& xPortion, bool bAutoStyles, bool isProgress,
bool& rPrevCharIsSpace)
{
// Do not export the element in the autostyle case.
bool bExport = !bAutoStyles;
if (!(GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED))
{
bExport = false;
}
uno::Reference<text::XTextContent> xTextContent(xPortion->getPropertyValue(u"ContentControl"_ustr),
uno::UNO_QUERY_THROW);
uno::Reference<container::XEnumerationAccess> xEA(xTextContent, uno::UNO_QUERY_THROW);
uno::Reference<container::XEnumeration> xTextEnum = xEA->createEnumeration();
uno::Reference<beans::XPropertySet> xPropertySet(xTextContent, uno::UNO_QUERY_THROW);
if (bExport)
{
bool bShowingPlaceHolder = false;
xPropertySet->getPropertyValue(u"ShowingPlaceHolder"_ustr) >>= bShowingPlaceHolder;
if (bShowingPlaceHolder)
{
OUStringBuffer aBuffer;
sax::Converter::convertBool(aBuffer, bShowingPlaceHolder);
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_SHOWING_PLACE_HOLDER,
aBuffer.makeStringAndClear());
}
bool bCheckbox = false;
xPropertySet->getPropertyValue(u"Checkbox"_ustr) >>= bCheckbox;
if (bCheckbox)
{
OUStringBuffer aBuffer;
sax::Converter::convertBool(aBuffer, bCheckbox);
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_CHECKBOX, aBuffer.makeStringAndClear());
}
bool bChecked = false;
xPropertySet->getPropertyValue(u"Checked"_ustr) >>= bChecked;
if (bChecked)
{
OUStringBuffer aBuffer;
sax::Converter::convertBool(aBuffer, bChecked);
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_CHECKED, aBuffer.makeStringAndClear());
}
OUString aCheckedState;
xPropertySet->getPropertyValue(u"CheckedState"_ustr) >>= aCheckedState;
if (!aCheckedState.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_CHECKED_STATE, aCheckedState);
}
OUString aUncheckedState;
xPropertySet->getPropertyValue(u"UncheckedState"_ustr) >>= aUncheckedState;
if (!aUncheckedState.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_UNCHECKED_STATE, aUncheckedState);
}
bool bPicture = false;
xPropertySet->getPropertyValue(u"Picture"_ustr) >>= bPicture;
if (bPicture)
{
OUStringBuffer aBuffer;
sax::Converter::convertBool(aBuffer, bPicture);
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_PICTURE,
aBuffer.makeStringAndClear());
}
bool bDate = false;
xPropertySet->getPropertyValue(u"Date"_ustr) >>= bDate;
if (bDate)
{
OUStringBuffer aBuffer;
sax::Converter::convertBool(aBuffer, bDate);
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_DATE, aBuffer.makeStringAndClear());
}
OUString aDateFormat;
xPropertySet->getPropertyValue(u"DateFormat"_ustr) >>= aDateFormat;
if (!aDateFormat.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_DATE_FORMAT, aDateFormat);
}
OUString aDateLanguage;
xPropertySet->getPropertyValue(u"DateLanguage"_ustr) >>= aDateLanguage;
if (!aDateLanguage.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_DATE_RFC_LANGUAGE_TAG, aDateLanguage);
}
OUString aCurrentDate;
xPropertySet->getPropertyValue(u"CurrentDate"_ustr) >>= aCurrentDate;
if (!aCurrentDate.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_CURRENT_DATE, aCurrentDate);
}
bool bPlainText = false;
xPropertySet->getPropertyValue(u"PlainText"_ustr) >>= bPlainText;
if (bPlainText)
{
OUStringBuffer aBuffer;
sax::Converter::convertBool(aBuffer, bPlainText);
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_PLAIN_TEXT, aBuffer.makeStringAndClear());
}
bool bComboBox = false;
xPropertySet->getPropertyValue(u"ComboBox"_ustr) >>= bComboBox;
if (bComboBox)
{
OUStringBuffer aBuffer;
sax::Converter::convertBool(aBuffer, bComboBox);
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_COMBOBOX, aBuffer.makeStringAndClear());
}
bool bDropDown = false;
xPropertySet->getPropertyValue(u"DropDown"_ustr) >>= bDropDown;
if (bDropDown)
{
OUStringBuffer aBuffer;
sax::Converter::convertBool(aBuffer, bDropDown);
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_DROPDOWN, aBuffer.makeStringAndClear());
}
OUString aAlias;
xPropertySet->getPropertyValue(u"Alias"_ustr) >>= aAlias;
if (!aAlias.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_ALIAS, aAlias);
}
OUString aTag;
xPropertySet->getPropertyValue(u"Tag"_ustr) >>= aTag;
if (!aTag.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_TAG, aTag);
}
sal_Int32 nId = 0;
xPropertySet->getPropertyValue(u"Id"_ustr) >>= nId;
if (nId)
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_ID, OUString::number(nId));
}
sal_uInt32 nTabIndex = 0;
if ((xPropertySet->getPropertyValue(u"TabIndex"_ustr) >>= nTabIndex) && nTabIndex)
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_TAB_INDEX,
OUString::number(nTabIndex));
}
OUString aLock;
xPropertySet->getPropertyValue(u"Lock"_ustr) >>= aLock;
if (!aLock.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_LOCK, aLock);
}
}
SvXMLElementExport aElem(GetExport(), bExport, XML_NAMESPACE_LO_EXT, XML_CONTENT_CONTROL, false,
false);
if (bExport)
{
// Export list items of dropdowns.
uno::Sequence<beans::PropertyValues> aListItems;
xPropertySet->getPropertyValue(u"ListItems"_ustr) >>= aListItems;
for (const auto& rListItem : aListItems)
{
comphelper::SequenceAsHashMap aMap(rListItem);
auto it = aMap.find(u"DisplayText"_ustr);
OUString aValue;
if (it != aMap.end() && (it->second >>= aValue) && !aValue.isEmpty())
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_DISPLAY_TEXT, aValue);
}
it = aMap.find(u"Value"_ustr);
if (it != aMap.end() && (it->second >>= aValue))
{
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_VALUE, aValue);
}
SvXMLElementExport aItem(GetExport(), bExport, XML_NAMESPACE_LO_EXT, XML_LIST_ITEM, false,
false);
}
}
// Recurse to export content.
exportTextRangeEnumeration(xTextEnum, bAutoStyles, isProgress, rPrevCharIsSpace);
}
void XMLTextParagraphExport::PreventExportOfControlsInMuteSections(
const Reference<XIndexAccess> & rShapes,
const rtl::Reference<xmloff::OFormLayerXMLExport>& xFormExport )
{
// check parameters ad pre-conditions
if( ( ! rShapes.is() ) || ( ! xFormExport.is() ) )
{
// if we don't have shapes or a form export, there's nothing to do
return;
}
SAL_WARN_IF( m_pSectionExport == nullptr, "xmloff", "We need the section export." );
Reference<XEnumeration> xShapesEnum = m_pBoundFrameSets->GetShapes()->createEnumeration();
if(!xShapesEnum.is())
return;
while( xShapesEnum->hasMoreElements() )
{
// now we need to check
// 1) if this is a control shape, and
// 2) if it's in a mute section
// if both answers are 'yes', notify the form layer export
// we join accessing the shape and testing for control
Reference<XControlShape> xControlShape(xShapesEnum->nextElement(), UNO_QUERY);
if( xControlShape.is() )
{
// Reference<XPropertySet> xPropSet( xControlShape, UNO_QUERY );
// Reference<XTextContent> xTextContent;
// xPropSet->getPropertyValue("TextRange") >>= xTextContent;
Reference<XTextContent> xTextContent( xControlShape, UNO_QUERY );
if( xTextContent.is() )
{
if( m_pSectionExport->IsMuteSection( xTextContent, false ) )
{
// Ah, we've found a shape that
// 1) is a control shape
// 2) is anchored in a mute section
// so: don't export it!
xFormExport->excludeFromExport(
xControlShape->getControl() );
}
// else: not in mute section -> should be exported -> nothing
// to do
}
// else: no anchor -> ignore
}
// else: no control shape -> nothing to do
}
}
void XMLTextParagraphExport::PushNewTextListsHelper()
{
maTextListsHelperStack.emplace_back( new XMLTextListsHelper() );
mpTextListsHelper = maTextListsHelperStack.back().get();
}
void XMLTextParagraphExport::PopTextListsHelper()
{
mpTextListsHelper = nullptr;
maTextListsHelperStack.pop_back();
if ( !maTextListsHelperStack.empty() )
{
mpTextListsHelper = maTextListsHelperStack.back().get();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|