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
|
/* -*- 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/.
*/
#include <swmodeltestbase.hxx>
#include <comphelper/propertysequence.hxx>
#include <com/sun/star/linguistic2/XHyphenator.hpp>
#include <com/sun/star/text/WrapTextMode.hpp>
#include <com/sun/star/text/XTextSectionsSupplier.hpp>
#include <vcl/event.hxx>
#include <vcl/scheduler.hxx>
#include <editeng/fontitem.hxx>
#include <editeng/fhgtitem.hxx>
#include <editeng/postitem.hxx>
#include <editeng/unolingu.hxx>
#include <editeng/editobj.hxx>
#include <comphelper/sequence.hxx>
#include <fmtfsize.hxx>
#include <wrtsh.hxx>
#include <edtwin.hxx>
#include <view.hxx>
#include <txtfrm.hxx>
#include <pagefrm.hxx>
#include <bodyfrm.hxx>
#include <sortedobjs.hxx>
#include <ndtxt.hxx>
#include <frmatr.hxx>
#include <IDocumentSettingAccess.hxx>
#include <unotxdoc.hxx>
#include <rootfrm.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <unoframe.hxx>
#include <drawdoc.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdotext.hxx>
#include <dcontact.hxx>
#include <frameformats.hxx>
/// Test to assert layout / rendering result of Writer.
class SwLayoutWriter3 : public SwModelTestBase
{
public:
SwLayoutWriter3()
: SwModelTestBase("/sw/qa/extras/layout/data/")
{
}
};
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf134463)
{
createSwDoc("tdf134463.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// This was 621. The previous paragraph must have zero bottom border.
assertXPath(pXmlDoc, "/root/page/body/txt[3]/infos/prtBounds"_ostr, "top"_ostr, "21");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf117188)
{
createSwDoc("tdf117188.docx");
saveAndReload("writer8");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
OUString sWidth
= getXPath(pXmlDoc, "/root/page/body/txt/anchored/fly/infos/bounds"_ostr, "width"_ostr);
OUString sHeight
= getXPath(pXmlDoc, "/root/page/body/txt/anchored/fly/infos/bounds"_ostr, "height"_ostr);
// The text box must have zero border distances
assertXPath(pXmlDoc, "/root/page/body/txt/anchored/fly/infos/prtBounds"_ostr, "left"_ostr, "0");
assertXPath(pXmlDoc, "/root/page/body/txt/anchored/fly/infos/prtBounds"_ostr, "top"_ostr, "0");
assertXPath(pXmlDoc, "/root/page/body/txt/anchored/fly/infos/prtBounds"_ostr, "width"_ostr,
sWidth);
assertXPath(pXmlDoc, "/root/page/body/txt/anchored/fly/infos/prtBounds"_ostr, "height"_ostr,
sHeight);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf117187)
{
createSwDoc("tdf117187.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// there should be no fly portions
assertXPath(
pXmlDoc,
"/root/page/body/txt/SwParaPortion/SwLineLayout/child::*[@nType='PortionType::Fly']"_ostr,
0);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf119875)
{
createSwDoc("tdf119875.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "//page[2]/body/section[1]"_ostr, "formatName"_ostr, u"S10"_ustr);
assertXPath(pXmlDoc, "//page[2]/body/section[2]"_ostr, "formatName"_ostr, u"S11"_ustr);
assertXPath(pXmlDoc, "//page[2]/body/section[3]"_ostr, "formatName"_ostr, u"S13"_ustr);
assertXPath(pXmlDoc, "//page[2]/body/section[4]"_ostr, "formatName"_ostr, u"S14"_ustr);
// Sections "S10" and "S13" are hidden -> their frames are zero-height
assertXPath(pXmlDoc, "//page[2]/body/section[1]/infos/bounds"_ostr, "height"_ostr, u"0"_ustr);
assertXPath(pXmlDoc, "//page[2]/body/section[3]/infos/bounds"_ostr, "height"_ostr, u"0"_ustr);
OUString S10Top = getXPath(pXmlDoc, "//page[2]/body/section[1]/infos/bounds"_ostr, "top"_ostr);
OUString S11Top = getXPath(pXmlDoc, "//page[2]/body/section[2]/infos/bounds"_ostr, "top"_ostr);
OUString S13Top = getXPath(pXmlDoc, "//page[2]/body/section[3]/infos/bounds"_ostr, "top"_ostr);
OUString S14Top = getXPath(pXmlDoc, "//page[2]/body/section[4]/infos/bounds"_ostr, "top"_ostr);
CPPUNIT_ASSERT_EQUAL(S10Top, S11Top);
CPPUNIT_ASSERT_EQUAL(S13Top, S14Top);
// Section "S11" had the same top value as section "S14", so they overlapped.
CPPUNIT_ASSERT_LESS(S14Top.toInt32(), S11Top.toInt32());
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf137523)
{
createSwDoc("tdf137523-1-min.fodt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// the problem was that in the footer, the text frames below the table
// had wrong height and were not visible
assertXPath(pXmlDoc, "/root/page/footer/txt[1]/infos/bounds"_ostr, "height"_ostr, "304");
assertXPath(pXmlDoc, "/root/page/footer/txt[2]/infos/bounds"_ostr, "height"_ostr, "191");
assertXPath(pXmlDoc, "/root/page/footer/txt[3]/infos/bounds"_ostr, "height"_ostr, "219");
assertXPath(pXmlDoc, "/root/page/footer/tab/infos/bounds"_ostr, "height"_ostr, "1378");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf120287)
{
createSwDoc("tdf120287.fodt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// This was 2, TabOverMargin Word-specific compat flag did not imply
// default-in-Word printer-independent layout, resulting in an additional
// line break.
assertXPath(pXmlDoc, "/root/page/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 1);
}
static auto getXPathIntAttributeValue(xmlXPathContextPtr pXmlXpathCtx, char const* const pXPath)
-> sal_Int32
{
xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(pXPath), pXmlXpathCtx);
CPPUNIT_ASSERT(pXmlXpathObj->nodesetval);
CPPUNIT_ASSERT_EQUAL(1, xmlXPathNodeSetGetLength(pXmlXpathObj->nodesetval));
auto ret
= sal_Int32(xmlXPathCastNodeToNumber(xmlXPathNodeSetItem(pXmlXpathObj->nodesetval, 0)));
xmlXPathFreeObject(pXmlXpathObj);
return ret;
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf128966)
{
createSwDoc("tdf128966-2-min.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
xmlXPathObjectPtr pXmlObj
= getXPathNode(pXmlDoc, "/root/page/body/tab/row/cell[@rowspan > 0][child::txt]"_ostr);
xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
CPPUNIT_ASSERT(pXmlNodes);
CPPUNIT_ASSERT_GREATER(300, xmlXPathNodeSetGetLength(pXmlNodes)); // many...
xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc.get());
registerNamespaces(pXmlXpathCtx);
for (int i = 0; i < xmlXPathNodeSetGetLength(pXmlNodes); ++i)
{
xmlNodePtr pNode = xmlXPathNodeSetItem(pXmlNodes, i);
xmlXPathSetContextNode(pNode, pXmlXpathCtx);
OString msg("Cell nr.: " + OString::number(i)
+ " id=" + OString::number(getXPathIntAttributeValue(pXmlXpathCtx, "@id")));
auto nCellTop = getXPathIntAttributeValue(pXmlXpathCtx, "infos/bounds/@top");
auto nCellHeight = getXPathIntAttributeValue(pXmlXpathCtx, "infos/bounds/@height");
auto nCellCenter = nCellTop + (nCellHeight / 2);
auto nContentTop
= getXPathIntAttributeValue(pXmlXpathCtx, "txt[position()=1]/infos/bounds/@top");
auto nContentBottom = getXPathIntAttributeValue(
pXmlXpathCtx, "txt[position()=last()]/infos/bounds/@bottom");
CPPUNIT_ASSERT_MESSAGE(msg.getStr(), nContentTop < nCellCenter);
CPPUNIT_ASSERT_MESSAGE(msg.getStr(), nContentBottom > nCellCenter);
}
xmlXPathFreeContext(pXmlXpathCtx);
xmlXPathFreeObject(pXmlObj);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf161718)
{
createSwDoc("tdf161718.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// everything on one page
assertXPath(pXmlDoc, "/root/page/header"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/header/txt/anchored"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/footer"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/ftncont/ftn"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/ftncont/ftn/txt"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/txt"_ostr, 27);
assertXPath(pXmlDoc, "/root/page/body/txt/anchored"_ostr, 1);
assertXPath(pXmlDoc, "/root/page"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf119908)
{
createSwDoc("tdf130088.docx");
// Ensure that all text portions are calculated before testing.
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwViewShell* pViewShell
= pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
CPPUNIT_ASSERT(pViewShell);
pViewShell->Reformat();
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Keep real width of the exceeding line portions to calculate shrinking
sal_Int32 nPortionWidth
= getXPath(pXmlDoc,
"/root/page/body/txt[1]/SwParaPortion/SwLineLayout[2]/SwLinePortion[2]"_ostr,
"width"_ostr)
.toInt32();
// This was 5806 (not real portion width, but stripped to the line width)
CPPUNIT_ASSERT_GREATER(sal_Int32(5840), nPortionWidth);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf158333)
{
createSwDoc("tdf130088.docx");
// Ensure that all text portions are calculated before testing.
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwViewShell* pViewShell
= pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
CPPUNIT_ASSERT(pViewShell);
pViewShell->Reformat();
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// shrink line 2
assertXPath(
pXmlDoc, "/root/page/body/txt[1]/SwParaPortion/SwLineLayout[2]"_ostr, "portion"_ostr,
"viverra odio. Donec auctor molestie sem, sit amet tristique lectus hendrerit sed. ");
// shrink line 7
assertXPath(
pXmlDoc, "/root/page/body/txt[1]/SwParaPortion/SwLineLayout[7]"_ostr, "portion"_ostr,
// This was "...diam ", not "...diam tempor "
"laoreet vel leo nec, volutpat facilisis eros. Donec consequat arcu ut diam tempor ");
// shrink line 2 of paragraph 2
assertXPath(
pXmlDoc, "/root/page/body/txt[2]/SwParaPortion/SwLineLayout[2]"_ostr, "portion"_ostr,
// This was "...Cras ", not "...Cras sodales "
"Donec auctor molestie sem, sit amet tristique lectus hendrerit sed. Cras sodales ");
// shrink line 2 of paragraph 4
assertXPath(pXmlDoc, "/root/page/body/txt[4]/SwParaPortion/SwLineLayout[2]"_ostr,
"portion"_ostr,
// This was "...et ", not "...et magnis "
"consequat arcu ut diam tempor luctus. Cum sociis natoque penatibus et magnis ");
// tdf#158776 don't shrink line 11 of paragraph 4
assertXPath(pXmlDoc, "/root/page/body/txt[4]/SwParaPortion/SwLineLayout[11]"_ostr,
"portion"_ostr,
// This was "...quis curcus ", not "...quis "
"venenatis, quis commodo dolor posuere. Curabitur dignissim sapien quis ");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159085)
{
createSwDoc("tdf159085.fodt");
// Ensure that all text portions are calculated before testing.
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwViewShell* pViewShell
= pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
CPPUNIT_ASSERT(pViewShell);
pViewShell->Reformat();
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// This was "... cursus" instead of breaking the word at soft hyphen
assertXPath(
pXmlDoc, "/root/page/body/txt[1]/SwParaPortion/SwLineLayout[1]"_ostr, "portion"_ostr,
u"venenatis, quis commodo dolor posuere. Curabitur dignissim sapien quis curÂ"_ustr);
// This was "... cursus" instead of breaking the word at soft hyphen
assertXPath(
pXmlDoc, "/root/page/body/txt[2]/SwParaPortion/SwLineLayout[1]"_ostr, "portion"_ostr,
u"venenatis, quis commodo dolor posuere. Curabitur dignissim sapien quis curÂ"_ustr);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf158419)
{
createSwDoc("tdf130088.docx");
SwDoc* pDoc = getSwDoc();
SwDocShell* pShell = pDoc->GetDocShell();
// Ensure that all text portions are calculated before testing.
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwViewShell* pViewShell
= pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
CPPUNIT_ASSERT(pViewShell);
pViewShell->Reformat();
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// second paragraph.
SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
SwWrtShell* pWrtShell = pShell->GetWrtShell();
SwPosition aPosition(*pWrtShell->GetCursor()->Start());
SwTwips nSecondParaLeft
= getXPath(pXmlDoc, "/root/page/body/txt[2]/infos/bounds"_ostr, "left"_ostr).toInt32();
SwTwips nSecondParaWidth
= getXPath(pXmlDoc, "/root/page/body/txt[2]/infos/bounds"_ostr, "width"_ostr).toInt32();
SwTwips nSecondParaTop
= getXPath(pXmlDoc, "/root/page/body/txt[2]/infos/bounds"_ostr, "top"_ostr).toInt32();
SwTwips nSecondParaHeight
= getXPath(pXmlDoc, "/root/page/body/txt[2]/infos/bounds"_ostr, "height"_ostr).toInt32();
Point aPoint;
// click at the end of the second line of the second paragraph
// (a line shrunk by the new justification)
aPoint.setX(nSecondParaLeft + nSecondParaWidth);
aPoint.setY(nSecondParaTop + (nSecondParaHeight / 6) * 1.5);
SwCursorMoveState aState(CursorMoveState::NONE);
pLayout->GetModelPositionForViewPoint(&aPosition, aPoint, &aState);
// Without the accompanying fix in place, this test would have failed: character position was 155,
// i.e. cursor was before the end of the paragraph.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(156), aPosition.GetContentIndex());
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf106234)
{
createSwDoc("tdf106234.fodt");
// Ensure that all text portions are calculated before testing.
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwViewShell* pViewShell
= pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
CPPUNIT_ASSERT(pViewShell);
pViewShell->Reformat();
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// In justified paragraphs, there is justification between left tabulators and manual line breaks
assertXPath(pXmlDoc, "/root/page/body/txt[1]/SwParaPortion/SwLineLayout[1]/SwGluePortion"_ostr,
"type"_ostr, "PortionType::Margin");
assertXPath(pXmlDoc, "/root/page/body/txt[1]/SwParaPortion/SwLineLayout[1]/SwGluePortion"_ostr,
"width"_ostr, "0");
// but not after centered, right and decimal tabulators
assertXPath(pXmlDoc, "/root/page/body/txt[2]/SwParaPortion/SwLineLayout[1]/SwGluePortion"_ostr,
"type"_ostr, "PortionType::Margin");
// This was a justified line, without width
assertXPath(pXmlDoc, "/root/page/body/txt[2]/SwParaPortion/SwLineLayout[1]/SwGluePortion"_ostr,
"width"_ostr, "7882");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf155324)
{
createSwDoc("tox-update-wrong-pages.odt");
dispatchCommand(mxComponent, ".uno:UpdateAllIndexes", {});
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// the problem was that the first entry was on page 7, 2nd on page 9 etc.
assertXPath(
pXmlDoc,
"/root/page[1]/body/section[2]/txt[1]/SwParaPortion/SwLineLayout/SwLinePortion[1]"_ostr,
"portion"_ostr, "Foo");
assertXPath(
pXmlDoc,
"/root/page[1]/body/section[2]/txt[1]/SwParaPortion/SwLineLayout/SwLinePortion[2]"_ostr,
"portion"_ostr, "5");
assertXPath(
pXmlDoc,
"/root/page[1]/body/section[2]/txt[2]/SwParaPortion/SwLineLayout/SwLinePortion[1]"_ostr,
"portion"_ostr, "bar");
assertXPath(
pXmlDoc,
"/root/page[1]/body/section[2]/txt[2]/SwParaPortion/SwLineLayout/SwLinePortion[2]"_ostr,
"portion"_ostr, "7");
assertXPath(
pXmlDoc,
"/root/page[1]/body/section[2]/txt[3]/SwParaPortion/SwLineLayout/SwLinePortion[1]"_ostr,
"portion"_ostr, "Three");
assertXPath(
pXmlDoc,
"/root/page[1]/body/section[2]/txt[3]/SwParaPortion/SwLineLayout/SwLinePortion[2]"_ostr,
"portion"_ostr, "7");
// check first content page has the footnotes
assertXPath(pXmlDoc, "/root/page[5]/body/txt[1]/SwParaPortion/SwLineLayout"_ostr,
"portion"_ostr, "Foo");
assertXPath(pXmlDoc, "/root/page[4]/ftncont"_ostr, 0);
assertXPath(pXmlDoc, "/root/page[5]/ftncont/ftn"_ostr, 5);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf120287b)
{
createSwDoc("tdf120287b.fodt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// This was 1418, TabOverMargin did the right split of the paragraph to two
// lines, but then calculated a too large tab portion size on the first
// line.
assertXPath(
pXmlDoc,
"/root/page/body/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabRight']"_ostr,
"width"_ostr, "1");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf120287c)
{
createSwDoc("tdf120287c.fodt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// This was 3, the second line was broken into a 2nd and a 3rd one,
// not rendering text outside the paragraph frame like Word 2013 does.
assertXPath(pXmlDoc, "/root/page/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 2);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf158658a)
{
createSwDoc("tdf158658a.rtf");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Word 2013 puts all tabs into one line, the last 8 of them are off the page
assertXPath(pXmlDoc, "/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(
pXmlDoc,
"/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabCenter']"_ostr,
1);
assertXPath(
pXmlDoc,
"/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabRight']"_ostr,
1);
assertXPath(
pXmlDoc,
"/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabLeft']"_ostr,
9);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf158658b)
{
createSwDoc("tdf158658b.rtf");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Word 2013 puts all tabs and the field following into one line
// and also puts the field off the page
assertXPath(pXmlDoc, "/root/page[1]/footer/txt[1]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(
pXmlDoc,
"/root/page[1]/footer/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabCenter']"_ostr,
1);
assertXPath(
pXmlDoc,
"/root/page[1]/footer/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabRight']"_ostr,
1);
assertXPath(
pXmlDoc,
"/root/page[1]/footer/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabRight']"_ostr,
"width"_ostr, u"4446"_ustr); // was very small: 24
assertXPath(
pXmlDoc,
"/root/page[1]/footer/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabLeft']"_ostr,
0);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf158658c)
{
createSwDoc("tdf158658c.rtf");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Word 2013 puts all tabs into one line, the last 17 of them are off the page
assertXPath(pXmlDoc, "/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(
pXmlDoc,
"/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabCenter']"_ostr,
1);
// the right tab is exactly at the margin of the paragraph
assertXPath(
pXmlDoc,
"/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabRight']"_ostr,
1);
assertXPath(
pXmlDoc,
"/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabLeft']"_ostr,
20);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf155177)
{
createSwDoc("tdf155177-1-min.odt");
uno::Reference<beans::XPropertySet> xStyle(getStyles("ParagraphStyles")->getByName("Body Text"),
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(210), getProperty<sal_Int32>(xStyle, "ParaTopMargin"));
{
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "/root/page[2]/body/txt"_ostr, 6);
assertXPath(pXmlDoc, "/root/page[2]/body/txt[6]/SwParaPortion/SwLineLayout"_ostr, 2);
assertXPath(pXmlDoc, "/root/page[2]/body/txt[6]/SwParaPortion/SwLineLayout[2]"_ostr,
"portion"_ostr, "long as two lines.");
assertXPath(pXmlDoc, "/root/page[3]/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 3);
assertXPath(pXmlDoc, "/root/page[3]/body/txt[1]/SwParaPortion/SwLineLayout[1]"_ostr,
"portion"_ostr, "This paragraph is even longer so that ");
discardDumpedLayout();
}
// this should bring one line back
xStyle->setPropertyValue("ParaTopMargin", uno::Any(sal_Int32(200)));
Scheduler::ProcessEventsToIdle();
{
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "/root/page[2]/body/txt"_ostr, 7);
assertXPath(pXmlDoc, "/root/page[2]/body/txt[7]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[2]/body/txt[7]/SwParaPortion/SwLineLayout[1]"_ostr,
"portion"_ostr, "This paragraph is even longer so that ");
assertXPath(pXmlDoc, "/root/page[3]/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 2);
assertXPath(pXmlDoc, "/root/page[3]/body/txt[1]/SwParaPortion/SwLineLayout[1]"_ostr,
"portion"_ostr, "it is now three lines long though ");
discardDumpedLayout();
}
// this should bring second line back
xStyle->setPropertyValue("ParaTopMargin", uno::Any(sal_Int32(120)));
Scheduler::ProcessEventsToIdle();
{
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "/root/page[2]/body/txt"_ostr, 7);
assertXPath(pXmlDoc, "/root/page[2]/body/txt[7]/SwParaPortion/SwLineLayout"_ostr, 2);
assertXPath(pXmlDoc, "/root/page[2]/body/txt[7]/SwParaPortion/SwLineLayout[1]"_ostr,
"portion"_ostr, "This paragraph is even longer so that ");
assertXPath(pXmlDoc, "/root/page[2]/body/txt[7]/SwParaPortion/SwLineLayout[2]"_ostr,
"portion"_ostr, "it is now three lines long though ");
assertXPath(pXmlDoc, "/root/page[3]/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[3]/body/txt[1]/SwParaPortion/SwLineLayout[1]"_ostr,
"portion"_ostr, "containing a single sentence.");
discardDumpedLayout();
}
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf122878)
{
createSwDoc("tdf122878.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
const sal_Int32 nTblTop
= getXPath(pXmlDoc, "/root/page[1]/footer/txt/anchored/fly/tab/infos/bounds"_ostr,
"top"_ostr)
.toInt32();
SwDoc* pDoc = getSwDoc();
SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
auto pPage1 = dynamic_cast<SwPageFrame*>(pLayout->Lower());
CPPUNIT_ASSERT(pPage1);
SwFrame* pBody = pPage1->FindBodyCont();
for (SwFrame* pFrame = pBody->GetLower(); pFrame; pFrame = pFrame->GetNext())
{
const sal_Int32 nTxtBottom = pFrame->getFrameArea().Bottom();
// No body paragraphs should overlap the table in the footer
CPPUNIT_ASSERT_MESSAGE(
OString("testing paragraph #" + OString::number(pFrame->GetFrameId())).getStr(),
nTxtBottom <= nTblTop);
}
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf115094)
{
createSwDoc("tdf115094.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
sal_Int32 nTopOfD1
= getXPath(pXmlDoc, "/root/page/body/txt/anchored/fly/tab/row[1]/cell[4]/infos/bounds"_ostr,
"top"_ostr)
.toInt32();
sal_Int32 nTopOfD1Anchored = getXPath(pXmlDoc,
"/root/page/body/txt/anchored/fly/tab/row[1]/cell[4]/"
"txt[2]/anchored/fly/infos/bounds"_ostr,
"top"_ostr)
.toInt32();
CPPUNIT_ASSERT_LESS(nTopOfD1Anchored, nTopOfD1);
sal_Int32 nTopOfB2
= getXPath(pXmlDoc, "/root/page/body/txt/anchored/fly/tab/row[2]/cell[2]/infos/bounds"_ostr,
"top"_ostr)
.toInt32();
sal_Int32 nTopOfB2Anchored = getXPath(pXmlDoc,
"/root/page/body/txt/anchored/fly/tab/row[2]/cell[2]/"
"txt[1]/anchored/fly/infos/bounds"_ostr,
"top"_ostr)
.toInt32();
CPPUNIT_ASSERT_LESS(nTopOfB2Anchored, nTopOfB2);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf112290)
{
createSwDoc("tdf112290.docx");
SwDoc* pDoc = getSwDoc();
CPPUNIT_ASSERT(pDoc);
auto pXml = parseLayoutDump();
assertXPath(pXml, "/root/page/body/txt/SwParaPortion/SwLineLayout[2]"_ostr, "portion"_ostr,
"Xxxx Xxxx");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testKeepWithNextPlusFlyFollowTextFlow)
{
createSwDoc("keep-with-next-fly.fodt");
{
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// 3 text frames on page 1
assertXPath(pXmlDoc, "/root/page[1]/body/infos/bounds"_ostr, "bottom"_ostr, "7540");
assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/infos/bounds"_ostr, "height"_ostr, "276");
assertXPath(pXmlDoc, "/root/page[1]/body/txt[2]/infos/bounds"_ostr, "height"_ostr, "276");
assertXPath(pXmlDoc, "/root/page[1]/body/txt[2]/anchored/fly"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[1]/body/txt[2]/anchored/fly/infos/bounds"_ostr, "top"_ostr,
"1694");
assertXPath(pXmlDoc, "/root/page[1]/body/txt[3]/infos/bounds"_ostr, "height"_ostr, "276");
assertXPath(pXmlDoc, "/root/page"_ostr, 1);
discardDumpedLayout();
}
dispatchCommand(mxComponent, ".uno:Fieldnames", {});
{
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// 1 text frame on page 1, and some empty space
assertXPath(pXmlDoc, "/root/page[1]/body/infos/bounds"_ostr, "bottom"_ostr, "7540");
assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/infos/bounds"_ostr, "height"_ostr, "5796");
assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/infos/bounds"_ostr, "bottom"_ostr, "7213");
// 2 text frames on page 2
assertXPath(pXmlDoc, "/root/page[2]/body/txt[1]/infos/bounds"_ostr, "height"_ostr, "276");
assertXPath(pXmlDoc, "/root/page[2]/body/txt[1]/anchored/fly"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[2]/body/txt[1]/anchored/fly/infos/bounds"_ostr, "top"_ostr,
"10093");
assertXPath(pXmlDoc, "/root/page[2]/body/txt[2]/infos/bounds"_ostr, "height"_ostr, "276");
assertXPath(pXmlDoc, "/root/page"_ostr, 2);
discardDumpedLayout();
}
dispatchCommand(mxComponent, ".uno:Fieldnames", {});
{
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// 3 text frames on page 1
assertXPath(pXmlDoc, "/root/page[1]/body/infos/bounds"_ostr, "bottom"_ostr, "7540");
assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/infos/bounds"_ostr, "height"_ostr, "276");
assertXPath(pXmlDoc, "/root/page[1]/body/txt[2]/infos/bounds"_ostr, "height"_ostr, "276");
assertXPath(pXmlDoc, "/root/page[1]/body/txt[2]/anchored/fly"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[1]/body/txt[2]/anchored/fly/infos/bounds"_ostr, "top"_ostr,
"1694");
assertXPath(pXmlDoc, "/root/page[1]/body/txt[3]/infos/bounds"_ostr, "height"_ostr, "276");
assertXPath(pXmlDoc, "/root/page"_ostr, 1);
discardDumpedLayout();
}
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf122607)
{
createSwDoc("tdf122607.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc,
"/root/page[1]/anchored/fly/txt[1]/anchored/fly/tab/row[2]/cell/txt[7]/anchored/"
"fly/txt/SwParaPortion/SwLineLayout/child::*[1]"_ostr,
"height"_ostr, "253");
assertXPath(pXmlDoc,
"/root/page[1]/anchored/fly/txt[1]/anchored/fly/tab/row[2]/cell/txt[7]/anchored/"
"fly/txt/SwParaPortion/SwLineLayout/child::*[1]"_ostr,
"width"_ostr, "428");
assertXPath(pXmlDoc,
"/root/page[1]/anchored/fly/txt[1]/anchored/fly/tab/row[2]/cell/txt[7]/anchored/"
"fly/txt/SwParaPortion/SwLineLayout/child::*[1]"_ostr,
"portion"_ostr, "Fax:");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf122607_regression)
{
discardDumpedLayout();
if (mxComponent.is())
mxComponent->dispose();
OUString const url(createFileURL(u"tdf122607_leerzeile.odt"));
// note: must set Hidden property, so that SfxFrameViewWindow_Impl::Resize()
// does *not* forward initial VCL Window Resize and thereby triggers a
// layout which does not happen on soffice --convert-to pdf.
std::vector<beans::PropertyValue> aFilterOptions = {
{ beans::PropertyValue("Hidden", -1, uno::Any(true), beans::PropertyState_DIRECT_VALUE) },
};
// inline the loading because currently properties can't be passed...
mxComponent = loadFromDesktop(url, "com.sun.star.text.TextDocument",
comphelper::containerToSequence(aFilterOptions));
uno::Sequence<beans::PropertyValue> props(comphelper::InitPropertySequence({
{ "FilterName", uno::Any(OUString("writer_pdf_Export")) },
}));
utl::TempFileNamed aTempFile;
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
xStorable->storeToURL(aTempFile.GetURL(), props);
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// somehow these 2 rows overlapped in the PDF unless CalcLayout() runs
assertXPath(pXmlDoc, "/root/page[1]/anchored/fly/tab[1]/row[1]/infos/bounds"_ostr,
"mbFixSize"_ostr, "false");
assertXPath(pXmlDoc, "/root/page[1]/anchored/fly/tab[1]/row[1]/infos/bounds"_ostr, "top"_ostr,
"2977");
assertXPath(pXmlDoc, "/root/page[1]/anchored/fly/tab[1]/row[1]/infos/bounds"_ostr,
"height"_ostr, "241");
assertXPath(pXmlDoc, "/root/page[1]/anchored/fly/tab[1]/row[2]/infos/bounds"_ostr,
"mbFixSize"_ostr, "true");
// this was 3034, causing the overlap
assertXPath(pXmlDoc, "/root/page[1]/anchored/fly/tab[1]/row[2]/infos/bounds"_ostr, "top"_ostr,
"3218");
assertXPath(pXmlDoc, "/root/page[1]/anchored/fly/tab[1]/row[2]/infos/bounds"_ostr,
"height"_ostr, "164");
aTempFile.EnableKillingFile();
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, TestTdf150616)
{
discardDumpedLayout();
if (mxComponent.is())
mxComponent->dispose();
OUString const url(createFileURL(u"in_056132_mod.odt"));
// note: must set Hidden property, so that SfxFrameViewWindow_Impl::Resize()
// does *not* forward initial VCL Window Resize and thereby triggers a
// layout which does not happen on soffice --convert-to pdf.
std::vector<beans::PropertyValue> aFilterOptions = {
{ beans::PropertyValue("Hidden", -1, uno::Any(true), beans::PropertyState_DIRECT_VALUE) },
};
// inline the loading because currently properties can't be passed...
mxComponent = loadFromDesktop(url, "com.sun.star.text.TextDocument",
comphelper::containerToSequence(aFilterOptions));
uno::Sequence<beans::PropertyValue> props(comphelper::InitPropertySequence({
{ "FilterName", uno::Any(OUString("writer_pdf_Export")) },
}));
utl::TempFileNamed aTempFile;
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
xStorable->storeToURL(aTempFile.GetURL(), props);
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
CPPUNIT_ASSERT(pXmlDoc);
// this one was 0 height
assertXPath(pXmlDoc,
"/root/page[1]/body/tab[3]/row[2]/cell[2]/txt[2]/SwParaPortion/SwLineLayout"_ostr,
"portion"_ostr, "Important information here!");
assertXPath(pXmlDoc, "/root/page[1]/body/tab[3]/row[2]/cell[2]/txt[2]/infos/bounds"_ostr,
"height"_ostr, "253");
assertXPath(pXmlDoc, "/root/page[1]/body/tab[3]/row[2]/cell[2]/txt[2]/infos/bounds"_ostr,
"top"_ostr, "7925");
assertXPath(pXmlDoc,
"/root/page[1]/body/tab[3]/row[2]/cell[2]/txt[3]/SwParaPortion/SwLineLayout"_ostr,
"portion"_ostr, "xxx 111 ");
assertXPath(pXmlDoc, "/root/page[1]/body/tab[3]/row[2]/cell[2]/txt[3]/infos/bounds"_ostr,
"height"_ostr, "697");
assertXPath(pXmlDoc, "/root/page[1]/body/tab[3]/row[2]/cell[2]/txt[3]/infos/bounds"_ostr,
"top"_ostr, "8178");
aTempFile.EnableKillingFile();
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testBtlrCell)
{
createSwDoc("btlr-cell.odt");
SwDoc* pDoc = getSwDoc();
SwDocShell* pShell = pDoc->GetDocShell();
// Dump the rendering of the first page as an XML file.
std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
MetafileXmlDump dumper;
xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
CPPUNIT_ASSERT(pXmlDoc);
// Without the accompanying fix in place, this test would have failed, as
// the orientation was 0 (layout did not take btlr direction request from
// doc model).
assertXPath(pXmlDoc, "//font[1]"_ostr, "orientation"_ostr, "900");
#if !defined(MACOSX) && !defined(_WIN32) // macOS fails with x == 2662 for some reason.
// Without the accompanying fix in place, this test would have failed with 'Expected: 1915;
// Actual : 1756', i.e. the AAA1 text was too close to the left cell border due to an ascent vs
// descent mismatch when calculating the baseline offset of the text portion.
assertXPath(pXmlDoc, "//textarray[1]"_ostr, "x"_ostr, "1911");
assertXPath(pXmlDoc, "//textarray[1]"_ostr, "y"_ostr, "2707");
// Without the accompanying fix in place, this test would have failed with 'Expected: 1979;
// Actual : 2129', i.e. the gray background of the "AAA2." text was too close to the right edge
// of the text portion. Now it's exactly behind the text portion.
assertXPath(pXmlDoc, "(//rect)[2]"_ostr, "left"_ostr, "1979");
// Without the accompanying fix in place, this test would have failed with 'Expected: 269;
// Actual : 0', i.e. the AAA2 frame was not visible due to 0 width.
pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/txt[2]/infos/bounds"_ostr, "width"_ostr,
"269");
// Test the position of the cursor after doc load.
// We expect that it's inside the first text frame in the first cell.
// More precisely, this is a bottom to top vertical frame, so we expect it's at the start, which
// means it's at the lower half of the text frame rectangle (vertically).
SwWrtShell* pWrtShell = pShell->GetWrtShell();
CPPUNIT_ASSERT(pWrtShell);
const SwRect& rCharRect = pWrtShell->GetCharRect();
SwTwips nFirstParaTop
= getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/txt[1]/infos/bounds"_ostr, "top"_ostr)
.toInt32();
SwTwips nFirstParaHeight
= getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/txt[1]/infos/bounds"_ostr,
"height"_ostr)
.toInt32();
SwTwips nFirstParaMiddle = nFirstParaTop + nFirstParaHeight / 2;
SwTwips nFirstParaBottom = nFirstParaTop + nFirstParaHeight;
// Without the accompanying fix in place, this test would have failed: the lower half (vertical)
// range was 2273 -> 2835, the good vertical position is 2730, the bad one was 1830.
CPPUNIT_ASSERT_GREATER(nFirstParaMiddle, rCharRect.Top());
CPPUNIT_ASSERT_LESS(nFirstParaBottom, rCharRect.Top());
// Save initial cursor position.
SwPosition aCellStart = *pWrtShell->GetCursor()->Start();
// Test that pressing "up" at the start of the cell goes to the next character position.
SwNodeOffset nNodeIndex = pWrtShell->GetCursor()->Start()->GetNodeIndex();
sal_Int32 nIndex = pWrtShell->GetCursor()->Start()->GetContentIndex();
KeyEvent aKeyEvent(0, KEY_UP);
SwEditWin& rEditWin = pShell->GetView()->GetEditWin();
rEditWin.KeyInput(aKeyEvent);
Scheduler::ProcessEventsToIdle();
// Without the accompanying fix in place, this test would have failed: "up" was interpreted as
// logical "left", which does nothing if you're at the start of the text anyway.
CPPUNIT_ASSERT_EQUAL(nIndex + 1, pWrtShell->GetCursor()->Start()->GetContentIndex());
// Test that pressing "right" goes to the next paragraph (logical "down").
sal_Int32 nContentIndex = pWrtShell->GetCursor()->Start()->GetContentIndex();
aKeyEvent = KeyEvent(0, KEY_RIGHT);
rEditWin.KeyInput(aKeyEvent);
Scheduler::ProcessEventsToIdle();
// Without the accompanying fix in place, this test would have failed: the cursor went to the
// paragraph after the table.
CPPUNIT_ASSERT_EQUAL(nNodeIndex + 1, pWrtShell->GetCursor()->Start()->GetNodeIndex());
// Test that we have the correct character index after traveling to the next paragraph.
// Without the accompanying fix in place, this test would have failed: char position was 5, i.e.
// the cursor jumped to the end of the paragraph for no reason.
CPPUNIT_ASSERT_EQUAL(nContentIndex, pWrtShell->GetCursor()->Start()->GetContentIndex());
// Test that clicking "below" the second paragraph positions the cursor at the start of the
// second paragraph.
SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
SwPosition aPosition(aCellStart);
SwTwips nSecondParaLeft
= getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/txt[2]/infos/bounds"_ostr, "left"_ostr)
.toInt32();
SwTwips nSecondParaWidth
= getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/txt[2]/infos/bounds"_ostr,
"width"_ostr)
.toInt32();
SwTwips nSecondParaTop
= getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/txt[2]/infos/bounds"_ostr, "top"_ostr)
.toInt32();
SwTwips nSecondParaHeight
= getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/txt[2]/infos/bounds"_ostr,
"height"_ostr)
.toInt32();
Point aPoint;
aPoint.setX(nSecondParaLeft + nSecondParaWidth / 2);
aPoint.setY(nSecondParaTop + nSecondParaHeight - 100);
SwCursorMoveState aState(CursorMoveState::NONE);
pLayout->GetModelPositionForViewPoint(&aPosition, aPoint, &aState);
CPPUNIT_ASSERT_EQUAL(aCellStart.GetNodeIndex() + 1, aPosition.GetNodeIndex());
// Without the accompanying fix in place, this test would have failed: character position was 5,
// i.e. cursor was at the end of the paragraph.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aPosition.GetContentIndex());
// Test that the selection rectangles are inside the cell frame if we select all the cell
// content.
SwTwips nCellLeft
= getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/infos/bounds"_ostr, "left"_ostr)
.toInt32();
SwTwips nCellWidth
= getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/infos/bounds"_ostr, "width"_ostr)
.toInt32();
SwTwips nCellTop
= getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/infos/bounds"_ostr, "top"_ostr)
.toInt32();
SwTwips nCellHeight
= getXPath(pXmlDoc, "/root/page/body/tab/row/cell[1]/infos/bounds"_ostr, "height"_ostr)
.toInt32();
SwRect aCellRect(Point(nCellLeft, nCellTop), Size(nCellWidth, nCellHeight));
pWrtShell->SelAll();
SwShellCursor* pShellCursor = pWrtShell->getShellCursor(/*bBlock=*/false);
CPPUNIT_ASSERT(!pShellCursor->empty());
// Without the accompanying fix in place, this test would have failed with:
// selection rectangle 269x2573@(1970,2172) is not inside cell rectangle 3207x1134@(1593,1701)
// i.e. the selection went past the bottom border of the cell frame.
for (const auto& rRect : *pShellCursor)
{
std::stringstream ss;
ss << "selection rectangle " << rRect << " is not inside cell rectangle " << aCellRect;
CPPUNIT_ASSERT_MESSAGE(ss.str(), aCellRect.Contains(rRect));
}
// Make sure that the correct rectangle gets repainted on scroll.
SwFrame* pPageFrame = pLayout->GetLower();
CPPUNIT_ASSERT(pPageFrame->IsPageFrame());
SwFrame* pBodyFrame = pPageFrame->GetLower();
CPPUNIT_ASSERT(pBodyFrame->IsBodyFrame());
SwFrame* pTabFrame = pBodyFrame->GetLower();
CPPUNIT_ASSERT(pTabFrame->IsTabFrame());
SwFrame* pRowFrame = pTabFrame->GetLower();
CPPUNIT_ASSERT(pRowFrame->IsRowFrame());
SwFrame* pCellFrame = pRowFrame->GetLower();
CPPUNIT_ASSERT(pCellFrame->IsCellFrame());
SwFrame* pFrame = pCellFrame->GetLower();
CPPUNIT_ASSERT(pFrame->IsTextFrame());
SwTextFrame* pTextFrame = static_cast<SwTextFrame*>(pFrame);
pTextFrame->SwapWidthAndHeight();
// Mimic what normally SwTextFrame::PaintSwFrame() does:
SwRect aRect(4207, 2273, 269, 572);
pTextFrame->SwitchVerticalToHorizontal(aRect);
// Without the accompanying fix in place, this test would have failed with:
// Expected: 572x269@(1691,4217)
// Actual : 572x269@(2263,4217)
// i.e. the paint rectangle position was incorrect, text was not painted on scrolling up.
CPPUNIT_ASSERT_EQUAL(SwRect(1691, 4217, 572, 269), aRect);
#endif
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf123898)
{
createSwDoc("tdf123898.odt");
// Make sure spellchecker has done its job already
Scheduler::ProcessEventsToIdle();
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Make sure that the arrow on the left is not there (the first portion's type is
// PortionType::Arrow if it's there)
assertXPath(
pXmlDoc,
"/root/page/body/txt/anchored/fly/txt/SwParaPortion/SwLineLayout[1]/child::*[1]"_ostr,
"type"_ostr, "PortionType::Para");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf123651)
{
createSwDoc("tdf123651.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Without the accompanying fix in place, this test would have failed with 'Expected: 7639;
// Actual: 12926'. The shape was below the second "Lorem ipsum" text, not above it.
const sal_Int32 nTopValue
= getXPath(pXmlDoc, "//anchored/SwAnchoredDrawObject/bounds"_ostr, "top"_ostr).toInt32();
CPPUNIT_ASSERT_DOUBLES_EQUAL(7639, nTopValue, 10);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf116501)
{
//just care it doesn't freeze
createSwDoc("tdf116501.odt");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf123163)
{
//just care it doesn't assert
createSwDoc("tdf123163-1.docx");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testAbi11870)
{
//just care it doesn't assert
createSwDoc("abi11870-2.odt");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testOfz64109)
{
//just care it doesn't assert
createSwDoc("ofz64109-1.fodt");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf118719)
{
// Insert a page break.
createSwDoc();
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
// Enable hide whitespace mode.
SwViewOption aViewOptions(*pWrtShell->GetViewOptions());
aViewOptions.SetHideWhitespaceMode(true);
pWrtShell->ApplyViewOptions(aViewOptions);
pWrtShell->Insert("first");
pWrtShell->InsertPageBreak();
pWrtShell->Insert("second");
// Without the accompanying fix in place, this test would have failed, as the height of the
// first page was 15840 twips, instead of the much smaller 276.
sal_Int32 nOther = parseDump("/root/page[1]/infos/bounds"_ostr, "height"_ostr).toInt32();
sal_Int32 nLast = parseDump("/root/page[2]/infos/bounds"_ostr, "height"_ostr).toInt32();
CPPUNIT_ASSERT_GREATER(nOther, nLast);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTabOverMargin)
{
createSwDoc("tab-over-margin.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// 2nd paragraph has a tab over the right margin, and with the TabOverMargin compat option,
// there is enough space to have all content in a single line.
// Without the accompanying fix in place, this test would have failed, there were 2 lines.
assertXPath(pXmlDoc, "/root/page/body/txt[2]/SwParaPortion/SwLineLayout"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testImageComment)
{
// Load a document that has "aaa" in it, then a commented image (4th char is the as-char image,
// 5th char is the comment anchor).
createSwDoc("image-comment.odt");
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
// Look up a layout position which is on the right of the image.
SwRootFrame* pRoot = pWrtShell->GetLayout();
CPPUNIT_ASSERT(pRoot->GetLower()->IsPageFrame());
SwPageFrame* pPage = static_cast<SwPageFrame*>(pRoot->GetLower());
CPPUNIT_ASSERT(pPage->GetLower()->IsBodyFrame());
SwBodyFrame* pBody = static_cast<SwBodyFrame*>(pPage->GetLower());
CPPUNIT_ASSERT(pBody->GetLower()->IsTextFrame());
SwTextFrame* pTextFrame = static_cast<SwTextFrame*>(pBody->GetLower());
CPPUNIT_ASSERT(pTextFrame->GetDrawObjs());
SwSortedObjs& rDrawObjs = *pTextFrame->GetDrawObjs();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rDrawObjs.size());
SwAnchoredObject* pDrawObj = rDrawObjs[0];
const SwRect& rDrawObjRect = pDrawObj->GetObjRect();
Point aPoint = rDrawObjRect.Center();
aPoint.setX(aPoint.getX() + rDrawObjRect.Width() / 2);
// Ask for the doc model pos of this layout point.
SwPosition aPosition(*pTextFrame->GetTextNodeForFirstText());
pTextFrame->GetModelPositionForViewPoint(&aPosition, aPoint);
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 5
// - Actual : 4
// i.e. the cursor got positioned between the image and its comment, so typing extended the
// comment, instead of adding content after the commented image.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), aPosition.GetContentIndex());
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testScriptField)
{
// Test clicking script field inside table ( tdf#141079 )
createSwDoc("tdf141079.odt");
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
// Look up layout position which is the first cell in the table
SwRootFrame* pRoot = pWrtShell->GetLayout();
CPPUNIT_ASSERT(pRoot->GetLower()->IsPageFrame());
SwPageFrame* pPage = static_cast<SwPageFrame*>(pRoot->GetLower());
CPPUNIT_ASSERT(pPage->GetLower()->IsBodyFrame());
SwBodyFrame* pBody = static_cast<SwBodyFrame*>(pPage->GetLower());
CPPUNIT_ASSERT(pBody->GetLower()->IsTextFrame());
SwTextFrame* pTextFrame = static_cast<SwTextFrame*>(pBody->GetLower());
CPPUNIT_ASSERT(pTextFrame->GetNext()->IsTabFrame());
SwFrame* pTable = pTextFrame->GetNext();
SwFrame* pRow1 = pTable->GetLower();
CPPUNIT_ASSERT(pRow1->GetLower()->IsCellFrame());
SwFrame* pCell1 = pRow1->GetLower();
CPPUNIT_ASSERT(pCell1->GetLower()->IsTextFrame());
SwTextFrame* pCellTextFrame = static_cast<SwTextFrame*>(pCell1->GetLower());
const SwRect& rCellRect = pCell1->getFrameArea();
Point aPoint = rCellRect.Center();
aPoint.setX(aPoint.getX() - rCellRect.Width() / 2);
// Ask for the doc model pos of this layout point.
SwPosition aPosition(*pCellTextFrame->GetTextNodeForFirstText());
pCellTextFrame->GetModelPositionForViewPoint(&aPosition, aPoint);
// Position was 1 without the fix from tdf#141079
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aPosition.GetContentIndex());
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testCommentCursorPosition)
{
// Load a document that has "aaa" in it, followed by three comments.
createSwDoc("endOfLineComments.odt");
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
SwRootFrame* pRoot = pWrtShell->GetLayout();
CPPUNIT_ASSERT(pRoot->GetLower()->IsPageFrame());
SwPageFrame* pPage = static_cast<SwPageFrame*>(pRoot->GetLower());
CPPUNIT_ASSERT(pPage->GetLower()->IsBodyFrame());
SwBodyFrame* pBody = static_cast<SwBodyFrame*>(pPage->GetLower());
CPPUNIT_ASSERT(pBody->GetLower()->IsTextFrame());
SwTextFrame* pTextFrame = static_cast<SwTextFrame*>(pBody->GetLower());
// Set a point in the whitespace past the end of the first line.
Point aPoint = pWrtShell->getShellCursor(false)->GetSttPos();
aPoint.setX(aPoint.getX() + 10000);
// Ask for the doc model pos of this layout point.
SwPosition aPosition(*pTextFrame->GetTextNodeForFirstText());
pTextFrame->GetModelPositionForViewPoint(&aPosition, aPoint);
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 6
// - Actual : 3 or 4
// i.e. the cursor got positioned before the comments,
// so typing extended the first comment instead of adding content after the comments.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6), aPosition.GetContentIndex());
// The second line is also important, but can't be auto-tested
// since the failing situation depends on GetViewWidth which is zero in the headless tests.
// bb<comment>| - the cursor should move behind the |, not before it.
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testCombiningCharacterCursorPosition)
{
// Load a document that has "a" in it, followed by a combining acute in a separate rext span
createSwDoc("tdf138592-a-acute.fodt");
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
SwRootFrame* pRoot = pWrtShell->GetLayout();
CPPUNIT_ASSERT(pRoot->GetLower()->IsPageFrame());
SwPageFrame* pPage = static_cast<SwPageFrame*>(pRoot->GetLower());
CPPUNIT_ASSERT(pPage->GetLower()->IsBodyFrame());
SwBodyFrame* pBody = static_cast<SwBodyFrame*>(pPage->GetLower());
CPPUNIT_ASSERT(pBody->GetLower()->IsTextFrame());
SwTextFrame* pTextFrame = static_cast<SwTextFrame*>(pBody->GetLower());
// Set a point in the whitespace past the end of the first line.
Point aPoint = pWrtShell->getShellCursor(false)->GetSttPos();
aPoint.AdjustX(10000);
// Ask for the doc model pos of this layout point.
SwPosition aPosition(*pTextFrame->GetTextNodeForFirstText());
pTextFrame->GetModelPositionForViewPoint(&aPosition, aPoint);
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 2
// - Actual : 1
// i.e. the cursor got positioned before the acute, so typing shifted the acute (applying it
// to newly typed characters) instead of adding content after it.
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aPosition.GetContentIndex());
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf64222)
{
createSwDoc("tdf64222.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc,
"/root/page/body/txt[2]/SwParaPortion/SwLineLayout/"
"child::*[@type='PortionType::Number']/SwFont"_ostr,
"height"_ostr, "560");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf113014)
{
createSwDoc("tdf113014.fodt");
SwDoc* pDoc = getSwDoc();
SwDocShell* pShell = pDoc->GetDocShell();
// Dump the rendering of the first page as an XML file.
std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
MetafileXmlDump dumper;
xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
CPPUNIT_ASSERT(pXmlDoc);
// This failed, if numbering of cell A1 is missing
// (A1: left indent: 3 cm, first line indent: -3 cm
// A2: left indent: 0 cm, first line indent: 0 cm)
assertXPathContent(pXmlDoc, "/metafile/push[1]/push[1]/push[1]/textarray[1]/text"_ostr, "1.");
assertXPathContent(pXmlDoc, "/metafile/push[1]/push[1]/push[1]/textarray[3]/text"_ostr, "2.");
assertXPathContent(pXmlDoc, "/metafile/push[1]/push[1]/push[1]/textarray[5]/text"_ostr, "3.");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf130218)
{
createSwDoc("tdf130218.fodt");
SwDoc* pDoc = getSwDoc();
SwDocShell* pShell = pDoc->GetDocShell();
// Dump the rendering of the first page as an XML file.
std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
MetafileXmlDump dumper;
xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
CPPUNIT_ASSERT(pXmlDoc);
// This failed, if hanging first line was hidden
assertXPathContent(pXmlDoc, "/metafile/push[1]/push[1]/push[1]/textarray[1]/text"_ostr, "Text");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf127235)
{
createSwDoc("tdf127235.odt");
SwDoc* pDoc = getSwDoc();
// This resulted in a layout loop.
pDoc->getIDocumentLayoutAccess().GetCurrentViewShell()->CalcLayout();
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf138039)
{
createSwDoc("tdf138039.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// there are 3 pages
assertXPath(pXmlDoc, "/root/page"_ostr, 3);
// table on first page
assertXPath(pXmlDoc, "/root/page[1]/body/tab"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[1]/body/txt"_ostr, 0);
// paragraph with large fly on second page
assertXPath(pXmlDoc, "/root/page[2]/body/tab"_ostr, 0);
assertXPath(pXmlDoc, "/root/page[2]/body/txt"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[2]/body/txt[1]/anchored/fly"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[2]/body/txt[1]/anchored/fly[1]/infos/bounds"_ostr, "top"_ostr,
"17915");
assertXPath(pXmlDoc, "/root/page[2]/body/txt[1]/anchored/fly[1]/infos/bounds"_ostr,
"height"_ostr, "15819");
// paragraph on third page
assertXPath(pXmlDoc, "/root/page[3]/body/tab"_ostr, 0);
assertXPath(pXmlDoc, "/root/page[3]/body/txt"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[3]/body/txt[1]/anchored"_ostr, 0);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf134298)
{
createSwDoc("tdf134298.ott");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// there are 2 pages
assertXPath(pXmlDoc, "/root/page"_ostr, 2);
// table and first para on first page
assertXPath(pXmlDoc, "/root/page[1]/body/tab"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[1]/body/txt"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/anchored"_ostr, 0);
// paragraph with large fly on second page
assertXPath(pXmlDoc, "/root/page[2]/body/tab"_ostr, 0);
assertXPath(pXmlDoc, "/root/page[2]/body/txt"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[2]/body/txt[1]/anchored/fly"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[2]/body/txt[1]/anchored/fly[1]/infos/bounds"_ostr, "top"_ostr,
"17897");
assertXPath(pXmlDoc, "/root/page[2]/body/txt[1]/anchored/fly[1]/infos/bounds"_ostr,
"height"_ostr, "15819");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testShapeAllowOverlap)
{
// Need to find out why this fails on macOS and why this is unstable on Windows.
#if !defined(MACOSX) && !defined(_WIN32)
// Create an empty document with two, intentionally overlapping shapes.
// Set their AllowOverlap property to false.
createSwDoc();
uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY);
awt::Point aPoint(1000, 1000);
awt::Size aSize(2000, 2000);
uno::Reference<drawing::XShape> xShape(
xDocument->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY);
xShape->setPosition(aPoint);
xShape->setSize(aSize);
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xDocument, uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY);
xShapeProperties->setPropertyValue("AllowOverlap", uno::Any(false));
xShapeProperties->setPropertyValue("AnchorType",
uno::Any(text::TextContentAnchorType_AT_CHARACTER));
xDrawPageSupplier->getDrawPage()->add(xShape);
aPoint = awt::Point(2000, 2000);
xShape.set(xDocument->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY);
xShape->setPosition(aPoint);
xShape->setSize(aSize);
xShapeProperties.set(xShape, uno::UNO_QUERY);
xShapeProperties->setPropertyValue("AllowOverlap", uno::Any(false));
xShapeProperties->setPropertyValue("AnchorType",
uno::Any(text::TextContentAnchorType_AT_CHARACTER));
xDrawPageSupplier->getDrawPage()->add(xShape);
// Now verify that the rectangle of the anchored objects don't overlap.
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
SwFrame* pPageFrame = pLayout->GetLower();
SwFrame* pBodyFrame = pPageFrame->GetLower();
SwFrame* pTextFrame = pBodyFrame->GetLower();
CPPUNIT_ASSERT(pTextFrame->GetDrawObjs());
SwSortedObjs& rObjs = *pTextFrame->GetDrawObjs();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rObjs.size());
SwAnchoredObject* pFirst = rObjs[0];
SwAnchoredObject* pSecond = rObjs[1];
// Without the accompanying fix in place, this test would have failed: the layout dump was
// <bounds left="1984" top="1984" width="1137" height="1137"/>
// <bounds left="2551" top="2551" width="1137" height="1137"/>
// so there was a clear vertical overlap. (Allow for 1px tolerance.)
OString aMessage = "Unexpected overlap: first shape's bottom is "
+ OString::number(pFirst->GetObjRect().Bottom()) + ", second shape's top is "
+ OString::number(pSecond->GetObjRect().Top());
CPPUNIT_ASSERT_MESSAGE(aMessage.getStr(),
std::abs(pFirst->GetObjRect().Bottom() - pSecond->GetObjRect().Top())
< 15);
#endif
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testShapeAllowOverlapWrap)
{
// Create an empty document with two, intentionally overlapping shapes.
// Set their AllowOverlap property to false and their wrap to through.
createSwDoc();
uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY);
awt::Point aPoint(1000, 1000);
awt::Size aSize(2000, 2000);
uno::Reference<drawing::XShape> xShape(
xDocument->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY);
xShape->setPosition(aPoint);
xShape->setSize(aSize);
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xDocument, uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY);
xShapeProperties->setPropertyValue("AllowOverlap", uno::Any(false));
xShapeProperties->setPropertyValue("AnchorType",
uno::Any(text::TextContentAnchorType_AT_CHARACTER));
xShapeProperties->setPropertyValue("Surround", uno::Any(text::WrapTextMode_THROUGH));
xDrawPageSupplier->getDrawPage()->add(xShape);
aPoint = awt::Point(2000, 2000);
xShape.set(xDocument->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY);
xShape->setPosition(aPoint);
xShape->setSize(aSize);
xShapeProperties.set(xShape, uno::UNO_QUERY);
xShapeProperties->setPropertyValue("AllowOverlap", uno::Any(false));
xShapeProperties->setPropertyValue("AnchorType",
uno::Any(text::TextContentAnchorType_AT_CHARACTER));
xShapeProperties->setPropertyValue("Surround", uno::Any(text::WrapTextMode_THROUGH));
xDrawPageSupplier->getDrawPage()->add(xShape);
// Now verify that the rectangle of the anchored objects do overlap.
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
SwFrame* pPageFrame = pLayout->GetLower();
SwFrame* pBodyFrame = pPageFrame->GetLower();
SwFrame* pTextFrame = pBodyFrame->GetLower();
CPPUNIT_ASSERT(pTextFrame->GetDrawObjs());
SwSortedObjs& rObjs = *pTextFrame->GetDrawObjs();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rObjs.size());
SwAnchoredObject* pFirst = rObjs[0];
SwAnchoredObject* pSecond = rObjs[1];
// Without the accompanying fix in place, this test would have failed: AllowOverlap=no had
// priority over Surround=through (which is bad for Word compat).
CPPUNIT_ASSERT(pSecond->GetObjRect().Overlaps(pFirst->GetObjRect()));
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf124600)
{
createSwDoc("tdf124600.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 1
// - Actual : 2
// i.e. the last line in the body text had 2 lines, while it should have 1, as Word does (as the
// fly frame does not intersect with the print area of the paragraph.)
assertXPath(pXmlDoc, "/root/page/body/txt[2]/SwParaPortion/SwLineLayout"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf124601)
{
// This is a testcase for the ContinuousEndnotes compat flag.
// The document has 2 pages, the endnote anchor is on the first page.
// The endnote should be on the 2nd page together with the last page content.
createSwDoc("tdf124601.doc");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 2
// - Actual : 3
// i.e. there was a separate endnote page, even when the ContinuousEndnotes compat option was
// on.
assertXPath(pXmlDoc, "/root/page"_ostr, 2);
assertXPath(pXmlDoc, "/root/page[2]/ftncont"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf124601b)
{
// Table has an image, which is anchored in the first row, but its vertical position is large
// enough to be rendered in the second row.
// The shape has layoutInCell=1, so should match what Word does here.
// Also the horizontal position should be in the last column, even if the anchor is in the
// last-but-one column.
createSwDoc("tdf124601b.doc");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
sal_Int32 nFlyTop = getXPath(pXmlDoc, "//anchored/fly/infos/bounds"_ostr, "top"_ostr).toInt32();
sal_Int32 nFlyLeft
= getXPath(pXmlDoc, "//anchored/fly/infos/bounds"_ostr, "left"_ostr).toInt32();
sal_Int32 nFlyRight
= nFlyLeft + getXPath(pXmlDoc, "//anchored/fly/infos/bounds"_ostr, "width"_ostr).toInt32();
sal_Int32 nSecondRowTop
= getXPath(pXmlDoc, "//tab/row[2]/infos/bounds"_ostr, "top"_ostr).toInt32();
sal_Int32 nLastCellLeft
= getXPath(pXmlDoc, "//tab/row[1]/cell[5]/infos/bounds"_ostr, "left"_ostr).toInt32();
sal_Int32 nLastCellRight
= nLastCellLeft
+ getXPath(pXmlDoc, "//tab/row[1]/cell[5]/infos/bounds"_ostr, "width"_ostr).toInt32();
// Without the accompanying fix in place, this test would have failed with:
// - Expected greater than: 3736
// - Actual : 2852
// i.e. the image was still inside the first row.
CPPUNIT_ASSERT_GREATER(nSecondRowTop, nFlyTop);
// Without the accompanying fix in place, this test would have failed with:
// - Expected greater than: 9640
// - Actual : 9639
// i.e. the right edge of the image was not within the bounds of the last column, the right edge
// was in the last-but-one column.
CPPUNIT_ASSERT_GREATER(nLastCellLeft, nFlyRight);
CPPUNIT_ASSERT_LESS(nLastCellRight, nFlyRight);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf124770)
{
// Enable content over margin.
createSwDoc();
SwDoc* pDoc = getSwDoc();
pDoc->getIDocumentSettingAccess().set(DocumentSettingId::TAB_OVER_MARGIN, true);
// Set page width.
SwPageDesc& rPageDesc = pDoc->GetPageDesc(0);
SwFrameFormat& rPageFormat = rPageDesc.GetMaster();
const SwAttrSet& rPageSet = rPageFormat.GetAttrSet();
SwFormatFrameSize aPageSize = rPageSet.GetFrameSize();
aPageSize.SetWidth(3703);
rPageFormat.SetFormatAttr(aPageSize);
// Set left and right margin.
SvxLRSpaceItem aLRSpace = rPageSet.GetLRSpace();
aLRSpace.SetLeft(1418);
aLRSpace.SetRight(1418);
rPageFormat.SetFormatAttr(aLRSpace);
pDoc->ChgPageDesc(0, rPageDesc);
// Set font to italic 20pt Liberation Serif.
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
SfxItemSet aTextSet(pWrtShell->GetView().GetPool(),
svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END - 1>);
SvxFontItem aFont(RES_CHRATR_FONT);
aFont.SetFamilyName("Liberation Serif");
aTextSet.Put(aFont);
SvxFontHeightItem aHeight(400, 100, RES_CHRATR_FONTSIZE);
aTextSet.Put(aHeight);
SvxPostureItem aItalic(ITALIC_NORMAL, RES_CHRATR_POSTURE);
aTextSet.Put(aItalic);
pWrtShell->SetAttrSet(aTextSet);
// Insert the text.
pWrtShell->Insert2("HHH");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 1
// - Actual : 2
// i.e. the italic string was broken into 2 lines, while Word kept it in a single line.
assertXPath(pXmlDoc, "/root/page/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testContinuousEndnotesInsertPageAtStart)
{
// Create a new document with CONTINUOUS_ENDNOTES enabled.
createSwDoc();
SwDoc* pDoc = getSwDoc();
pDoc->getIDocumentSettingAccess().set(DocumentSettingId::CONTINUOUS_ENDNOTES, true);
// Insert a second page, and an endnote on the 2nd page (both the anchor and the endnote is on
// the 2nd page).
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
pWrtShell->InsertPageBreak();
pWrtShell->InsertFootnote("endnote", /*bEndNote=*/true, /*bEdit=*/false);
// Add a new page at the start of the document.
pWrtShell->SttEndDoc(/*bStart=*/true);
pWrtShell->InsertPageBreak();
// Make sure that the endnote is moved from the 2nd page to the 3rd one.
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "/root/page"_ostr, 3);
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 1
// - Actual : 0
// i.e. the footnote container remained on page 2.
assertXPath(pXmlDoc, "/root/page[3]/ftncont"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testContinuousEndnotesDeletePageAtStart)
{
// Create a new document with CONTINUOUS_ENDNOTES enabled.
createSwDoc();
SwDoc* pDoc = getSwDoc();
pDoc->getIDocumentSettingAccess().set(DocumentSettingId::CONTINUOUS_ENDNOTES, true);
// Insert a second page, and an endnote on the 2nd page (both the anchor and the endnote is on
// the 2nd page).
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
pWrtShell->InsertPageBreak();
pWrtShell->InsertFootnote("endnote", /*bEndNote=*/true, /*bEdit=*/false);
// Remove the empty page at the start of the document.
pWrtShell->SttEndDoc(/*bStart=*/true);
pWrtShell->DelRight();
// Make sure that the endnote is moved from the 2nd page to the 1st one.
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 1
// - Actual : 2
// i.e. the endnote remained on an (otherwise) empty 2nd page.
assertXPath(pXmlDoc, "/root/page"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[1]/ftncont"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf128399)
{
createSwDoc("tdf128399.docx");
SwDoc* pDoc = getSwDoc();
SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
SwFrame* pPage = pLayout->GetLower();
SwFrame* pBody = pPage->GetLower();
SwFrame* pTable = pBody->GetLower();
SwFrame* pRow1 = pTable->GetLower();
SwFrame* pRow2 = pRow1->GetNext();
const SwRect& rRow2Rect = pRow2->getFrameArea();
Point aPoint = rRow2Rect.Center();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
SwPosition aPosition = *pWrtShell->GetCursor()->Start();
SwPosition aFirstRow(aPosition);
SwCursorMoveState aState(CursorMoveState::NONE);
pLayout->GetModelPositionForViewPoint(&aPosition, aPoint, &aState);
// Second row is +3: end node, start node and the first text node in the 2nd row.
SwNodeOffset nExpected = aFirstRow.GetNodeIndex() + 3;
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 14
// - Actual : 11
// i.e. clicking on the center of the 2nd row placed the cursor in the 1st row.
CPPUNIT_ASSERT_EQUAL(nExpected, aPosition.GetNodeIndex());
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf156724)
{
discardDumpedLayout();
if (mxComponent.is())
mxComponent->dispose();
OUString const url(createFileURL(u"fdo56797-2-min.odt"));
// note: must set Hidden property, so that SfxFrameViewWindow_Impl::Resize()
// does *not* forward initial VCL Window Resize and thereby triggers a
// layout which does not happen on soffice --convert-to pdf.
std::vector<beans::PropertyValue> aFilterOptions = {
{ beans::PropertyValue("Hidden", -1, uno::Any(true), beans::PropertyState_DIRECT_VALUE) },
};
// inline the loading because currently properties can't be passed...
mxComponent = loadFromDesktop(url, "com.sun.star.text.TextDocument",
comphelper::containerToSequence(aFilterOptions));
save("writer_pdf_Export");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// both pages have a tab frame and one footnote
assertXPath(pXmlDoc, "/root/page[1]/body/tab"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[1]/ftncont"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[1]/ftncont/ftn"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[2]/body/tab"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[2]/ftncont"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[2]/ftncont/ftn"_ostr, 1);
assertXPath(pXmlDoc, "/root/page"_ostr, 2);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf156725)
{
createSwDoc("tdf156725.fodt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "/root/page"_ostr, 2);
// the fly has 2 columns, the section in it has 2 columns, and is split
// across the fly columns => 4 columns with 1 text frame each
assertXPath(pXmlDoc, "/root/page[2]/body/txt/anchored/fly/column"_ostr, 2);
assertXPath(pXmlDoc, "/root/page[2]/body/txt/anchored/fly/column[1]/body/section/column"_ostr,
2);
assertXPath(
pXmlDoc,
"/root/page[2]/body/txt/anchored/fly/column[1]/body/section/column[1]/body/txt"_ostr, 1);
assertXPath(
pXmlDoc,
"/root/page[2]/body/txt/anchored/fly/column[1]/body/section/column[2]/body/txt"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[2]/body/txt/anchored/fly/column[2]/body/section/column"_ostr,
2);
assertXPath(
pXmlDoc,
"/root/page[2]/body/txt/anchored/fly/column[2]/body/section/column[1]/body/txt"_ostr, 1);
assertXPath(
pXmlDoc,
"/root/page[2]/body/txt/anchored/fly/column[2]/body/section/column[2]/body/txt"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf156419)
{
createSwDoc("linked_frames_section_bug.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "/root/page"_ostr, 2);
// there are 2 flys on page 1, and 1 on page 2, all linked
assertXPath(pXmlDoc, "/root/page[1]/body/txt/anchored/fly[1]/section/column"_ostr, 2);
assertXPath(pXmlDoc, "/root/page[1]/body/txt/anchored/fly[1]/section/column[1]/body/txt"_ostr,
11);
assertXPath(pXmlDoc, "/root/page[1]/body/txt/anchored/fly[1]/section/column[2]/body/txt"_ostr,
11);
assertXPath(pXmlDoc, "/root/page[1]/body/txt/anchored/fly[2]/section/column"_ostr, 2);
assertXPath(pXmlDoc, "/root/page[1]/body/txt/anchored/fly[2]/section/column[1]/body/txt"_ostr,
12);
assertXPath(pXmlDoc, "/root/page[1]/body/txt/anchored/fly[2]/section/column[2]/body/txt"_ostr,
12);
assertXPath(pXmlDoc, "/root/page[2]/body/txt/anchored/fly[1]/section/column"_ostr, 2);
assertXPath(pXmlDoc, "/root/page[2]/body/txt/anchored/fly[1]/section/column[1]/body/txt"_ostr,
2);
assertXPath(pXmlDoc, "/root/page[2]/body/txt/anchored/fly[1]/section/column[2]/body/txt"_ostr,
1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf145826)
{
createSwDoc("tdf145826.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
CPPUNIT_ASSERT(pXmlDoc);
assertXPath(pXmlDoc, "/root/page/body/section/column"_ostr, 2);
// Without the fix in place, this test would have failed with
// - Expected: 1
// - Actual : 0
assertXPath(pXmlDoc, "/root/page/body/section/column[1]/ftncont"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/section/column[2]/ftncont"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/section/column[1]/ftncont/ftn"_ostr, 3);
assertXPath(pXmlDoc, "/root/page/body/section/column[2]/ftncont/ftn"_ostr, 3);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTable0HeightRows)
{
createSwDoc("table-0-height-rows.fodt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
CPPUNIT_ASSERT(pXmlDoc);
// the problem was that the table was erroneously split across 2 or 3 pages
assertXPath(pXmlDoc, "/root/page[1]/body/tab"_ostr, 1);
assertXPath(pXmlDoc, "/root/page[1]/body/tab/row"_ostr, 28);
assertXPath(pXmlDoc, "/root/page[1]/body/tab/row/infos/bounds[@height='0']"_ostr, 25);
assertXPath(pXmlDoc, "/root/page"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf105481)
{
createSwDoc("tdf105481.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
CPPUNIT_ASSERT(pXmlDoc);
// Without the accompanying fix in place, this test would have failed
// because the vertical position of the as-char shape object and the
// as-char math object will be wrong (below/beyond the text frame's bottom).
SwTwips nTxtTop = getXPath(pXmlDoc,
"/root/page/anchored/fly/txt[2]"
"/infos/bounds"_ostr,
"top"_ostr)
.toInt32();
SwTwips nTxtBottom = nTxtTop
+ getXPath(pXmlDoc,
"/root/page/anchored/fly/txt[2]"
"/infos/bounds"_ostr,
"height"_ostr)
.toInt32();
SwTwips nFormula1Top = getXPath(pXmlDoc,
"/root/page/anchored/fly/txt[2]"
"/anchored/fly[1]/infos/bounds"_ostr,
"top"_ostr)
.toInt32();
SwTwips nFormula1Bottom = nFormula1Top
+ getXPath(pXmlDoc,
"/root/page/anchored/fly/txt[2]"
"/anchored/fly[1]/infos/bounds"_ostr,
"height"_ostr)
.toInt32();
SwTwips nFormula2Top = getXPath(pXmlDoc,
"/root/page/anchored/fly/txt[2]"
"/anchored/fly[2]/infos/bounds"_ostr,
"top"_ostr)
.toInt32();
SwTwips nFormula2Bottom = nFormula2Top
+ getXPath(pXmlDoc,
"/root/page/anchored/fly/txt[2]"
"/anchored/fly[2]/infos/bounds"_ostr,
"height"_ostr)
.toInt32();
// Ensure that the two formula positions are at least between top and bottom of the text frame.
// The below two are satisfied even without the fix.
CPPUNIT_ASSERT_GREATEREQUAL(nTxtTop, nFormula1Top);
CPPUNIT_ASSERT_GREATEREQUAL(nTxtTop, nFormula2Top);
// Without the accompanying fix in place, this test would have failed with:
// - Expected less than or equal to : 14423
// - Actual : 14828
// that is, the formula is below the text-frame's y bound.
CPPUNIT_ASSERT_LESSEQUAL(nTxtBottom, nFormula1Bottom);
// Similarly for formula # 2 :
// - Expected less than or equal to : 14423
// - Actual : 15035
// that is, the formula is below the text-frame's y bound.
CPPUNIT_ASSERT_LESSEQUAL(nTxtBottom, nFormula2Bottom);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf117982)
{
createSwDoc("tdf117982.docx");
SwDoc* pDocument = getSwDoc();
SwDocShell* pShell = pDocument->GetDocShell();
std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
MetafileXmlDump dumper;
xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
assertXPathContent(pXmlDoc, "/metafile/push[1]/push[1]/push[1]/textarray[1]/text"_ostr,
"FOO AAA");
//The first cell must be "FOO AAA". If not, this means the first cell content not visible in
//the source document.
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf128959)
{
// no orphan/widow control in table cells
createSwDoc("tdf128959.docx");
SwDoc* pDocument = getSwDoc();
CPPUNIT_ASSERT(pDocument);
discardDumpedLayout();
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// first two lines of the paragraph in the split table cell on the first page
// (these lines were completely lost)
assertXPath(
pXmlDoc,
"/root/page[1]/body/tab[1]/row[1]/cell[1]/txt[1]/SwParaPortion/SwLineLayout[1]"_ostr,
"portion"_ostr,
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue ");
assertXPath(
pXmlDoc,
"/root/page[1]/body/tab[1]/row[1]/cell[1]/txt[1]/SwParaPortion/SwLineLayout[2]"_ostr,
"portion"_ostr,
"massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit ");
// last line of the paragraph in the split table cell on the second page
assertXPath(
pXmlDoc,
"/root/page[2]/body/tab[1]/row[1]/cell[1]/txt[1]/SwParaPortion/SwLineLayout[1]"_ostr,
"portion"_ostr, "amet commodo magna eros quis urna.");
// Also check that the widow control for the paragraph is not turned off:
sw::TableFrameFormats& rTableFormats = *pDocument->GetTableFrameFormats();
SwFrameFormat* pTableFormat = rTableFormats[0];
SwTable* pTable = SwTable::FindTable(pTableFormat);
const SwTableBox* pCell = pTable->GetTableBox("A1");
const SwStartNode* pStartNode = pCell->GetSttNd();
SwNodeIndex aNodeIndex(*pStartNode);
++aNodeIndex;
const SwTextNode* pTextNode = aNodeIndex.GetNode().GetTextNode();
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 2
// - Actual : 0
// i.e. the original fix only worked as the entire widow / orphan control was switched off.
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(pTextNode->GetSwAttrSet().GetWidows().GetValue()));
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf121658)
{
uno::Reference<linguistic2::XHyphenator> xHyphenator = LinguMgr::GetHyphenator();
if (!xHyphenator->hasLocale(lang::Locale("en", "US", OUString())))
return;
createSwDoc("tdf121658.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Only 2 hyphenated words should appear in the document (in the lowercase words).
// Uppercase words should not be hyphenated.
assertXPath(pXmlDoc, "//SwLineLayout/child::*[@type='PortionType::Hyphen']"_ostr, 2);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf149420)
{
uno::Reference<linguistic2::XHyphenator> xHyphenator = LinguMgr::GetHyphenator();
if (!xHyphenator->hasLocale(lang::Locale("en", "US", OUString())))
return;
createSwDoc("tdf149420.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Only 3 hyphenated words should appear in the document (last paragraph
// has got a 1 cm hyphenation zone, removing two hyphenations, which visible
// in the second paragraph).
assertXPath(pXmlDoc, "//SwLineLayout/child::*[@type='PortionType::Hyphen']"_ostr, 8);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf149324)
{
uno::Reference<linguistic2::XHyphenator> xHyphenator = LinguMgr::GetHyphenator();
if (!xHyphenator->hasLocale(lang::Locale("en", "US", OUString())))
return;
createSwDoc("tdf149324.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Only 3 hyphenated words should appear in the document (last paragraph
// has got a 7-character word limit for hyphenation, removing the
// hyphenation "ex-cept".
assertXPath(pXmlDoc, "//SwLineLayout/child::*[@type='PortionType::Hyphen']"_ostr, 3);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf149248)
{
uno::Reference<linguistic2::XHyphenator> xHyphenator = LinguMgr::GetHyphenator();
if (!xHyphenator->hasLocale(lang::Locale("en", "US", OUString())))
return;
createSwDoc("tdf149248.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Only 1 hyphenated word should appear in the document (last word of the second
// paragraph). Last word should not be hyphenated for the fourth paragraph
// (the same paragraph, but with forbidden hyphenation of the last word).
assertXPath(pXmlDoc, "//SwLineLayout/child::*[@type='PortionType::Hyphen']"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testWriterImageNoCapture)
{
createSwDoc("writer-image-no-capture.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
CPPUNIT_ASSERT(pXmlDoc);
sal_Int32 nPageLeft = getXPath(pXmlDoc, "//page/infos/bounds"_ostr, "left"_ostr).toInt32();
sal_Int32 nImageLeft
= getXPath(pXmlDoc, "//anchored/fly/infos/bounds"_ostr, "left"_ostr).toInt32();
// Without the accompanying fix in place, this test would have failed with:
// - Expected less than: 284
// - Actual : 284
// i.e. the image position was modified to be inside the page frame ("captured"), even if Word
// does not do that.
CPPUNIT_ASSERT_LESS(nPageLeft, nImageLeft);
}
static SwRect lcl_getVisibleFlyObjRect(SwWrtShell* pWrtShell)
{
SwRootFrame* pRoot = pWrtShell->GetLayout();
SwPageFrame* pPage = static_cast<SwPageFrame*>(pRoot->GetLower());
pPage = static_cast<SwPageFrame*>(pPage->GetNext());
pPage = static_cast<SwPageFrame*>(pPage->GetNext());
SwSortedObjs* pDrawObjs = pPage->GetDrawObjs();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pDrawObjs->size());
SwAnchoredObject* pDrawObj = (*pDrawObjs)[0];
CPPUNIT_ASSERT_EQUAL(OUString("Rahmen8"), pDrawObj->GetFrameFormat()->GetName());
pPage = static_cast<SwPageFrame*>(pPage->GetNext());
pDrawObjs = pPage->GetDrawObjs();
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pDrawObjs->size());
pDrawObj = (*pDrawObjs)[0];
CPPUNIT_ASSERT_EQUAL(OUString("Rahmen123"), pDrawObj->GetFrameFormat()->GetName());
SwRect aFlyRect = pDrawObj->GetObjRect();
CPPUNIT_ASSERT(pPage->getFrameArea().Contains(aFlyRect));
return aFlyRect;
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testStableAtPageAnchoredFlyPosition)
{
// this doc has two page-anchored frames: one tiny on page 3 and one large on page 4.
// it also has a style:master-page named "StandardEntwurf", which contains some fields.
// if you add a break to page 2, or append some text to page 4 (or just toggle display field names),
// the page anchored frame on page 4 vanishes, as it is incorrectly moved out of the page bounds.
createSwDoc("stable-at-page-anchored-fly-position.odt");
SwDoc* pDoc = getSwDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
// look up the layout position of the page-bound frame on page four
SwRect aOrigRect = lcl_getVisibleFlyObjRect(pWrtShell);
// append some text to the document to trigger bug / relayout
pWrtShell->SttEndDoc(false);
pWrtShell->Insert("foo");
// get the current position of the frame on page four
SwRect aRelayoutRect = lcl_getVisibleFlyObjRect(pWrtShell);
// the anchored frame should not have moved
CPPUNIT_ASSERT_EQUAL(aOrigRect, aRelayoutRect);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf134548)
{
createSwDoc("tdf134548.odt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Second paragraph has two non zero width tabs in beginning of line
{
OUString sNodeType = parseDump(
"/root/page/body/txt[2]/SwParaPortion/SwLineLayout/SwFixPortion[1]"_ostr, "type"_ostr);
CPPUNIT_ASSERT_EQUAL(OUString("PortionType::TabLeft"), sNodeType);
sal_Int32 nWidth
= parseDump("/root/page/body/txt[2]/SwParaPortion/SwLineLayout/SwFixPortion[1]"_ostr,
"width"_ostr)
.toInt32();
CPPUNIT_ASSERT_GREATER(sal_Int32(0), nWidth);
}
{
OUString sNodeType = parseDump(
"/root/page/body/txt[2]/SwParaPortion/SwLineLayout/SwFixPortion[2]"_ostr, "type"_ostr);
CPPUNIT_ASSERT_EQUAL(OUString("PortionType::TabLeft"), sNodeType);
sal_Int32 nWidth
= parseDump("/root/page/body/txt[2]/SwParaPortion/SwLineLayout/SwFixPortion[2]"_ostr,
"width"_ostr)
.toInt32();
CPPUNIT_ASSERT_GREATER(sal_Int32(0), nWidth);
}
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf124423)
{
createSwDoc("tdf124423.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
sal_Int32 nFly1Width
= getXPath(pXmlDoc, "(//anchored/fly)[1]/infos/prtBounds"_ostr, "width"_ostr).toInt32();
sal_Int32 nFly2Width
= getXPath(pXmlDoc, "(//anchored/fly)[2]/infos/prtBounds"_ostr, "width"_ostr).toInt32();
sal_Int32 nPageWidth = getXPath(pXmlDoc, "//page/infos/prtBounds"_ostr, "width"_ostr).toInt32();
CPPUNIT_ASSERT_EQUAL(nPageWidth, nFly2Width);
CPPUNIT_ASSERT_LESS(nPageWidth / 2, nFly1Width);
createSwDoc("tdf124423.odt");
pXmlDoc = parseLayoutDump();
nFly1Width
= getXPath(pXmlDoc, "(//anchored/fly)[1]/infos/prtBounds"_ostr, "width"_ostr).toInt32();
nFly2Width
= getXPath(pXmlDoc, "(//anchored/fly)[2]/infos/prtBounds"_ostr, "width"_ostr).toInt32();
nPageWidth = getXPath(pXmlDoc, "//page/infos/prtBounds"_ostr, "width"_ostr).toInt32();
CPPUNIT_ASSERT_LESS(nPageWidth / 2, nFly2Width);
CPPUNIT_ASSERT_LESS(nPageWidth / 2, nFly1Width);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf137185)
{
// First load the sample bugdoc
createSwDoc("tdf137185.odt");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
// Get the doc shell
SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
// Get the DrawObject from page
auto pModel = pDoc->getIDocumentDrawModelAccess().GetDrawModel();
CPPUNIT_ASSERT(pModel);
auto pPage = pModel->GetPage(0);
CPPUNIT_ASSERT(pPage);
auto pObj = pPage->GetObj(0);
CPPUNIT_ASSERT(pObj);
// Get the format of the draw object
auto pShape = FindFrameFormat(pObj);
CPPUNIT_ASSERT(pShape);
// Check the text of the shape
uno::Reference<text::XText> xTxt(getShape(1), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("Align me!"), xTxt->getText()->getString());
// Add a textbox to the shape
SwTextBoxHelper::create(pShape, pShape->FindRealSdrObject(), true);
// Check if the text moved from the shape to the frame
auto pFormat = SwTextBoxHelper::getOtherTextBoxFormat(getShape(1));
auto xTextFrame = SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), pFormat);
CPPUNIT_ASSERT_EQUAL(OUString("Align me!"), xTextFrame->getText()->getString());
SdrTextObj* pTextObj = DynCastSdrTextObj(pObj);
CPPUNIT_ASSERT(pTextObj);
const auto& aOutStr = pTextObj->GetOutlinerParaObject()->GetTextObject();
CPPUNIT_ASSERT(aOutStr.GetText(0).isEmpty());
// Before the patch it failed, because the text appeared 2 times on each other.
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf138782)
{
createSwDoc("tdf138782.docx");
auto pXml = parseLayoutDump();
CPPUNIT_ASSERT(pXml);
// Without the fix it failed because the 3rd shape was outside the page:
// - Expected less than: 13327
// - Actual : 14469
CPPUNIT_ASSERT_LESS(getXPath(pXml, "/root/page/infos/bounds"_ostr, "right"_ostr).toInt32(),
getXPath(pXml,
"/root/page/body/txt[8]/anchored/SwAnchoredDrawObject/bounds"_ostr,
"right"_ostr)
.toInt32());
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf135035)
{
createSwDoc("tdf135035.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
sal_Int32 nFly1Width
= getXPath(pXmlDoc, "(//anchored/fly)[1]/infos/prtBounds"_ostr, "width"_ostr).toInt32();
sal_Int32 nFly2Width
= getXPath(pXmlDoc, "(//anchored/fly)[2]/infos/prtBounds"_ostr, "width"_ostr).toInt32();
sal_Int32 nFly3Width
= getXPath(pXmlDoc, "(//anchored/fly)[3]/infos/prtBounds"_ostr, "width"_ostr).toInt32();
sal_Int32 nParentWidth
= getXPath(pXmlDoc, "(//txt)[1]/infos/prtBounds"_ostr, "width"_ostr).toInt32();
CPPUNIT_ASSERT_EQUAL(nParentWidth, nFly2Width);
CPPUNIT_ASSERT_EQUAL(nParentWidth, nFly3Width);
CPPUNIT_ASSERT_LESS(nParentWidth / 2, nFly1Width);
createSwDoc("tdf135035.odt");
pXmlDoc = parseLayoutDump();
nFly1Width
= getXPath(pXmlDoc, "(//anchored/fly)[1]/infos/prtBounds"_ostr, "width"_ostr).toInt32();
nFly2Width
= getXPath(pXmlDoc, "(//anchored/fly)[2]/infos/prtBounds"_ostr, "width"_ostr).toInt32();
nFly3Width
= getXPath(pXmlDoc, "(//anchored/fly)[3]/infos/prtBounds"_ostr, "width"_ostr).toInt32();
nParentWidth = getXPath(pXmlDoc, "(//txt)[1]/infos/prtBounds"_ostr, "width"_ostr).toInt32();
CPPUNIT_ASSERT_LESS(nParentWidth / 2, nFly2Width);
CPPUNIT_ASSERT_LESS(nParentWidth / 2, nFly1Width);
CPPUNIT_ASSERT_GREATER(nParentWidth, nFly3Width);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf146704_EndnoteInSection)
{
createSwDoc("tdf146704_EndnoteInSection.odt");
SwDoc* pDoc = getSwDoc();
CPPUNIT_ASSERT(pDoc);
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Without the fix, the endnote placed to 2. page
assertXPath(pXmlDoc, "/root/page"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf139336_ColumnsWithFootnoteDoNotOccupyEntirePage)
{
createSwDoc("tdf139336_ColumnsWithFootnoteDoNotOccupyEntirePage.docx");
SwDoc* pDoc = getSwDoc();
CPPUNIT_ASSERT(pDoc);
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Without the fix, it would be 5 pages, but with the fix the whole document
// would fit into 1 page, but it will be 2 pages right now, because
// when writer import (from docx) the last section with columns, then it does not set
// the evenly distributed settings, and this settings is required for the fix now, to
// avoid some regression.
assertXPath(pXmlDoc, "/root/page"_ostr, 2);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf54465_ColumnsWithFootnoteDoNotOccupyEntirePage)
{
// Old odt files should keep their original layout, as it was before Tdf139336 fix.
// The new odt file is only 1 page long, while the old odt file (with the same content)
// was more than 1 page long.
// Note: Somewhy this test miscalculates the layout of the old odt file.
// It will be 4 pages long, while opened in Writer it is 5 pages long.
createSwDoc("tdf54465_ColumnsWithFootnoteDoNotOccupyEntirePage_Old.odt");
SwDoc* pDoc = getSwDoc();
CPPUNIT_ASSERT(pDoc);
Scheduler::ProcessEventsToIdle();
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, "/root/page"_ostr);
xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
CPPUNIT_ASSERT_GREATER(1, xmlXPathNodeSetGetLength(pXmlNodes));
xmlXPathFreeObject(pXmlObj);
discardDumpedLayout();
createSwDoc("tdf54465_ColumnsWithFootnoteDoNotOccupyEntirePage_New.odt");
pDoc = getSwDoc();
CPPUNIT_ASSERT(pDoc);
pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "/root/page"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf138124)
{
// When the only portion after the footnote number is a FlyCnt, and it doesn't fit into
// the page width, it should be moved to the next line without the footnote number, and
// not loop, nor OOM, nor fail assertions.
createSwDoc("wideBoxInFootnote.fodt");
Scheduler::ProcessEventsToIdle();
// Without the fix in place, the layout would loop, creating new FootnoteNum portions
// indefinitely, until OOM.
// If the footnote paragraph had no orphan control, then the loop would finally end,
// but an assertion in SwTextPainter::DrawTextLine would fail during paint.
xmlDocUniquePtr pXml = parseLayoutDump();
assertXPath(pXml, "/root/page"_ostr, 1);
assertXPath(pXml, "/root/page/ftncont/ftn/txt/anchored"_ostr, 1);
// And finally, if there were no assertion in SwTextPainter::DrawTextLine, it would have
// produced multiple lines with FootnoteNum portions, failing the following check like
// - Expected: 1
// - Actual : 49
assertXPath(pXml,
"/root/page/ftncont/ftn/txt//SwFieldPortion[@type='PortionType::FootnoteNum']"_ostr,
1);
assertXPath(pXml, "/root/page/ftncont/ftn/txt//SwLinePortion[@type='PortionType::FlyCnt']"_ostr,
1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf154113)
{
createSwDoc("three_sections.fodt");
Scheduler::ProcessEventsToIdle();
dispatchCommand(mxComponent, ".uno:GoToStartOfDoc", {});
dispatchCommand(mxComponent, ".uno:GoToNextPara", {});
dispatchCommand(mxComponent, ".uno:EndOfDocumentSel", {}); // to the end of current section!
dispatchCommand(mxComponent, ".uno:EndOfDocumentSel", {}); // to the end of the document.
auto xModel = mxComponent.queryThrow<frame::XModel>();
auto xSelected = xModel->getCurrentSelection().queryThrow<container::XIndexAccess>();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSelected->getCount());
auto xRange = xSelected->getByIndex(0).queryThrow<text::XTextRange>();
CPPUNIT_ASSERT_EQUAL(OUString("<-- Start selection here. Section1" SAL_NEWLINE_STRING
"Section2" SAL_NEWLINE_STRING "Section3. End selection here -->"),
xRange->getString());
dispatchCommand(mxComponent, ".uno:Cut", {});
xSelected = xModel->getCurrentSelection().queryThrow<container::XIndexAccess>();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSelected->getCount());
xRange = xSelected->getByIndex(0).queryThrow<text::XTextRange>();
CPPUNIT_ASSERT_EQUAL(OUString(), xRange->getString());
dispatchCommand(mxComponent, ".uno:Paste", {});
xmlDocUniquePtr pXml = parseLayoutDump();
// Without the fix in place, this would fail with
// - Expected: 3
// - Actual : 2
assertXPath(pXml, "/root/page/body/section"_ostr, 3);
assertXPath(pXml, "/root/page/body/section[1]/txt/SwParaPortion/SwLineLayout"_ostr,
"portion"_ostr, "<-- Start selection here. Section1");
assertXPath(pXml, "/root/page/body/section[2]/txt/SwParaPortion/SwLineLayout"_ostr,
"portion"_ostr, "Section2");
assertXPath(pXml, "/root/page/body/section[3]/txt/SwParaPortion/SwLineLayout"_ostr,
"portion"_ostr, "Section3. End selection here -->");
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf155611)
{
createSwDoc("tdf155611_table_and_nested_section.fodt");
Scheduler::ProcessEventsToIdle();
xmlDocUniquePtr pXml = parseLayoutDump();
CPPUNIT_ASSERT(pXml);
// Check the layout: single page, two section frames (no section frames after the one for Inner
// section), correct table structure and content in the first section frame, including nested
// table in the last cell, and the last section text.
assertXPath(pXml, "/root/page"_ostr);
// Without the fix in place, this would fail with
// - Expected: 2
// - Actual : 3
assertXPath(pXml, "/root/page/body/section"_ostr, 2);
assertXPath(pXml, "/root/page/body/section[1]/tab"_ostr);
assertXPath(pXml, "/root/page/body/section[1]/tab/row"_ostr);
assertXPath(pXml, "/root/page/body/section[1]/tab/row/cell"_ostr, 2);
assertXPath(pXml, "/root/page/body/section[1]/tab/row/cell[1]/txt/SwParaPortion/SwLineLayout/"
"SwParaPortion[@portion='foo']"_ostr);
assertXPath(pXml, "/root/page/body/section[1]/tab/row/cell[2]/txt/SwParaPortion/SwLineLayout/"
"SwParaPortion[@portion='bar']"_ostr);
assertXPath(pXml, "/root/page/body/section[1]/tab/row/cell[2]/tab/row/cell/txt/SwParaPortion/"
"SwLineLayout/SwParaPortion[@portion='baz']"_ostr);
assertXPath(pXml, "/root/page/body/section[2]/txt[1]/SwParaPortion/SwLineLayout/"
"SwParaPortion[@portion='abc']"_ostr);
// Also must not crash on close because of a frame that accidentally fell off of the layout
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf152307)
{
// Problem: On a given Writer document a table layout changed
// after doing Tools -> Update -> Update All. The last table row on page 13
// was bigger than the page size allowed and thus was hidden behind the footer.
// load the document
createSwDoc("tdf152307.odt");
// do Tools -> Update -> Update All
dispatchCommand(mxComponent, ".uno:UpdateAllIndexes", {});
// XML dump and some basic assertions
sal_Int32 nPage = 7, nPages = 0;
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
nPages = countXPathNodes(pXmlDoc, "/root/page"_ostr);
CPPUNIT_ASSERT_MESSAGE("tdf152307.odt / testTdf152307: Not enough pages.", nPage < nPages);
assertXPath(pXmlDoc, "/root/page[" + OString::number(nPage) + "]/body/section", 1);
// Actual test procedure:
// On page 7, check:
// How much tables do we have? How much rows does the last table have?
int nTables
= countXPathNodes(pXmlDoc, "/root/page[" + OString::number(nPage) + "]/body/section/tab");
int nRowsLastTable
= countXPathNodes(pXmlDoc, "/root/page[" + OString::number(nPage) + "]/body/section/tab["
+ OString::number(nTables) + "]/row");
// What is the bottom value of the last table row?
sal_Int32 nTabBottom = getXPath(pXmlDoc,
"/root/page[" + OString::number(nPage) + "]/body/section/tab["
+ OString::number(nTables) + "]/row["
+ OString::number(nRowsLastTable) + "]/infos/bounds",
"bottom"_ostr)
.toInt32();
// Where does the footer start (footer/info/bounds/top)?
sal_Int32 nFooterTop
= getXPath(pXmlDoc, "/root/page[" + OString::number(nPage) + "]/footer/infos/bounds",
"top"_ostr)
.toInt32();
// Is the bottom value of the last row above the top value of the footer?
OString aMsg = "tdf152307.odt / testTdf152307: Bottom value of last table row on page "
+ OString::number(nPage) + " is below top value of footer: "
+ OString::number(nTabBottom) + " > " + OString::number(nFooterTop);
CPPUNIT_ASSERT_MESSAGE(aMsg.getStr(), nTabBottom < nFooterTop);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf57187_Tdf158900)
{
// Given a document with a single paragraph, having some long space runs and line breaks
createSwDoc("space+break.fodt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Make sure there is only one page, one paragraph, and five lines
assertXPath(pXmlDoc, "/root/page"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion"_ostr, 1);
// Without the fix in place, this would fail: there used to be 6 lines
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout"_ostr, 5);
// tdf#57187: Check that relatively short lines have spaces not participating in layout.
// First line has 11 spaces in the end, and then a manual line break. It is rather short:
// without block justification, it is narrower than the available space.
// It uses the "first check if everything fits to line" return path in SwTextGuess::Guess.
// Check that the spaces are put into a Hole portion, thus not participating in layout.
// Without the fix, this would fail: there were only 2 portions, no Hole nor Margin portions.
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*"_ostr, 4);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[1]"_ostr, "type"_ostr,
u"PortionType::Text"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[1]"_ostr,
"length"_ostr, u"11"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[2]"_ostr, "type"_ostr,
u"PortionType::Hole"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[2]"_ostr,
"length"_ostr, u"11"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[3]"_ostr, "type"_ostr,
u"PortionType::Break"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[4]"_ostr, "type"_ostr,
u"PortionType::Margin"_ustr);
// Second line has 101 spaces in the end, and then a manual line break.
// It uses the "second check if everything fits to line" return path in SwTextGuess::Guess.
// Check that the spaces are put into a Hole portion, thus not participating in layout.
// Without the fix, this would fail: there were only 2 portions, no Hole portion.
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[2]/*"_ostr, 3);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[2]/*[1]"_ostr, "type"_ostr,
u"PortionType::Text"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[2]/*[1]"_ostr,
"length"_ostr, u"11"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[2]/*[2]"_ostr, "type"_ostr,
u"PortionType::Hole"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[2]/*[2]"_ostr,
"length"_ostr, u"101"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[2]/*[3]"_ostr, "type"_ostr,
u"PortionType::Break"_ustr);
// tdf#158900: Check that the break after a long line with trailing spaces is kept on same line.
// Without the fix in place, this would fail: the line had only 2 portions (text + hole),
// and the break was on a separate third line
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[3]/*"_ostr, 3);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[3]/*[1]"_ostr, "type"_ostr,
u"PortionType::Text"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[3]/*[2]"_ostr, "type"_ostr,
u"PortionType::Hole"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[3]/*[3]"_ostr, "type"_ostr,
u"PortionType::Break"_ustr);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159050)
{
// Given a document with a justified paragraph and a box with optimal wrapping
createSwDoc("tdf159050-wrap-adjust.fodt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Make sure there is only one page, one anchored object, one paragraph, and two lines
assertXPath(pXmlDoc, "/root/page"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/txt/anchored/SwAnchoredDrawObject"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout"_ostr, 2);
// Without the fix, this would fail: there was an unexpected second fly portion.
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*"_ostr, 4);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[1]"_ostr, "type"_ostr,
u"PortionType::Text"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[1]"_ostr,
"length"_ostr, u"91"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[2]"_ostr, "type"_ostr,
u"PortionType::Hole"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[2]"_ostr,
"length"_ostr, u"1"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[3]"_ostr, "type"_ostr,
u"PortionType::Fly"_ustr);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[4]"_ostr, "type"_ostr,
u"PortionType::Margin"_ustr);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159271)
{
// Given a document with a field with several spaces in a field content
createSwDoc("fld-in-tbl.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Make sure there is only one page, one table with one row and two cells, and one paragraph
assertXPath(pXmlDoc, "/root/page"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/tab"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/tab/row"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/tab/row/cell"_ostr, 2);
assertXPath(pXmlDoc, "/root/page/body/txt"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/tab/row/cell[2]/txt/SwParaPortion"_ostr, 1);
// Without the fix, this would fail:
// - Expected: 1
// - Actual : 16
// - In <>, XPath '/root/page/body/tab/row/cell[2]/txt//SwLineLayout' number of nodes is incorrect
assertXPath(pXmlDoc, "/root/page/body/tab/row/cell[2]/txt//SwLineLayout"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/tab/row/cell[2]/txt//SwFieldPortion"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159259)
{
// Given a document with a block sdt with a single field, having framePr aligned to right
createSwDoc("sdt+framePr.docx");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Make sure there is only one page and one paragraph with one line and one anchored object
assertXPath(pXmlDoc, "/root/page"_ostr, 1);
// Without the fix, this would fail: there were two paragraphs
assertXPath(pXmlDoc, "/root/page/body/txt"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout"_ostr, 1);
// Without the fix, this would fail: there was a field portion in the line
assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr, 0);
// Without the fix, this would fail: there was no anchored objects
assertXPath(pXmlDoc, "/root/page/body/txt/anchored"_ostr, 1);
assertXPath(pXmlDoc, "/root/page/body/txt/anchored/fly"_ostr, 1);
const sal_Int32 paraRight
= getXPath(pXmlDoc, "/root/page/body/txt/infos/bounds"_ostr, "right"_ostr).toInt32();
const sal_Int32 paraHeight
= getXPath(pXmlDoc, "/root/page/body/txt/infos/bounds"_ostr, "height"_ostr).toInt32();
CPPUNIT_ASSERT_GREATER(sal_Int32(0), paraRight);
CPPUNIT_ASSERT_GREATER(sal_Int32(0), paraHeight);
const sal_Int32 flyRight
= getXPath(pXmlDoc, "/root/page/body/txt/anchored/fly/infos/bounds"_ostr, "right"_ostr)
.toInt32();
const sal_Int32 flyHeight
= getXPath(pXmlDoc, "/root/page/body/txt/anchored/fly/infos/bounds"_ostr, "height"_ostr)
.toInt32();
CPPUNIT_ASSERT_EQUAL(paraRight, flyRight); // The fly is right-aligned
CPPUNIT_ASSERT_EQUAL(paraHeight, flyHeight);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testLargeTopParaMarginAfterHiddenSection)
{
// Given a large top margin in Standard paragraph style, and the first section hidden
createSwDoc("largeTopMarginAndHiddenFirstSection.fodt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
// Make sure there is only one page and two sections, first hidden (zero-height)
assertXPath(pXmlDoc, "//page"_ostr, 1);
assertXPath(pXmlDoc, "//page/body/section"_ostr, 2);
assertXPath(pXmlDoc, "//page/body/section[1]/infos/bounds"_ostr, "height"_ostr, u"0"_ustr);
// Check that the top margin (1 in = 1440 twip) is added to line height (12 pt = 240 twip)
assertXPath(pXmlDoc, "//page/body/section[2]/infos/bounds"_ostr, "height"_ostr, u"1680"_ustr);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testPageBreakInHiddenSection)
{
// Given a paragraph with page-break-before with page style and page number
createSwDoc("pageBreakInHiddenSection.fodt");
xmlDocUniquePtr pXmlDoc = parseLayoutDump();
assertXPath(pXmlDoc, "//page"_ostr, 4);
assertXPath(pXmlDoc, "//section"_ostr, 4);
assertXPath(pXmlDoc, "//page[1]/body/txt"_ostr, 1);
// The page break inside the hidden section is ignored (otherwise, there would be one section
// on the first page)
assertXPath(pXmlDoc, "//page[1]/body/section"_ostr, 2);
// The first section is hidden
assertXPath(pXmlDoc, "//page[1]/body/section[1]/infos/bounds"_ostr, "height"_ostr, u"0"_ustr);
// Page 2 is empty even page (generated by the next page's section with page-break-before)
assertXPath(pXmlDoc, "//page[2]/body"_ostr, 0);
// The section on page 3 is not hidden, only text in it is, therefore its page break works
assertXPath(pXmlDoc, "//page[3]/body/section"_ostr, 1);
assertXPath(pXmlDoc, "//page[3]/body/section/infos/bounds"_ostr, "height"_ostr, u"0"_ustr);
// The section on page 4 is hidden, thus page break in it is ignored (no further pages, where
// the section would be moved to otherwise)
assertXPath(pXmlDoc, "//page[4]/body/section"_ostr, 1);
assertXPath(pXmlDoc, "//page[4]/body/section/infos/bounds"_ostr, "height"_ostr, u"0"_ustr);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf160549)
{
// Given a document with a large as-char object, alone in its paragraph, shifted down by a
// header object: it must not hang in a layout loop on import (similar to i84870, but not
// fixed by its fix)
createSwDoc("tdf160549.fodt");
// The object is the first in the document; it must not move to the next page
CPPUNIT_ASSERT_EQUAL(1, getPages());
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf160526)
{
// Given a document with a large as-char object, alone in its paragraph, shifted down by
// another body object
createSwDoc("tdf160526.fodt");
// It must move to the next page
CPPUNIT_ASSERT_EQUAL(2, getPages());
auto pExportDump = parseLayoutDump();
assertXPath(pExportDump, "//page[2]/body/txt/anchored/SwAnchoredDrawObject"_ostr);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf160958_page_break)
{
// Given a document with a section with the first paragraph having a page break
createSwDoc("tdf160958_page_break.fodt");
auto pExportDump = parseLayoutDump();
assertXPath(pExportDump, "//page"_ostr, 2);
// A single paragraph on the first page, with 6 lines
assertXPath(pExportDump, "//page[1]/body/txt"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt/SwParaPortion/SwLineLayout"_ostr, 6);
// A section with 7 paragraphs, and two more paragraphs after the section
assertXPath(pExportDump, "//page[2]/body/section"_ostr, 1);
assertXPath(pExportDump, "//page[2]/body/section/txt"_ostr, 7);
assertXPath(pExportDump, "//page[2]/body/section/txt[1]/SwParaPortion"_ostr, 0);
assertXPath(pExportDump, "//page[2]/body/section/txt[2]/SwParaPortion"_ostr, 0);
assertXPath(pExportDump, "//page[2]/body/section/txt[3]/SwParaPortion"_ostr, 0);
assertXPath(pExportDump, "//page[2]/body/section/txt[4]/SwParaPortion/SwLineLayout"_ostr, 5);
assertXPath(pExportDump, "//page[2]/body/section/txt[5]/SwParaPortion"_ostr, 0);
assertXPath(pExportDump, "//page[2]/body/section/txt[6]/SwParaPortion"_ostr, 0);
assertXPath(pExportDump, "//page[2]/body/section/txt[7]/SwParaPortion"_ostr, 0);
assertXPath(pExportDump, "//page[2]/body/txt"_ostr, 2);
assertXPath(pExportDump, "//page[2]/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 7);
assertXPath(pExportDump, "//page[2]/body/txt[2]/SwParaPortion"_ostr, 0);
// Hide the section
auto xTextSectionsSupplier = mxComponent.queryThrow<css::text::XTextSectionsSupplier>();
auto xSections = xTextSectionsSupplier->getTextSections();
CPPUNIT_ASSERT(xSections);
auto xSection = xSections->getByName(u"Section1"_ustr).queryThrow<css::beans::XPropertySet>();
xSection->setPropertyValue(u"IsVisible"_ustr, css::uno::Any(false));
discardDumpedLayout();
calcLayout();
pExportDump = parseLayoutDump();
assertXPath(pExportDump, "//page"_ostr, 1);
// Three paragraphs and a hidden section on the first page
assertXPath(pExportDump, "//page/body/txt"_ostr, 3);
assertXPath(pExportDump, "//page/body/section"_ostr, 1);
assertXPath(pExportDump, "//page/body/section/infos/bounds"_ostr, "height"_ostr, "0");
assertXPath(pExportDump, "//page/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 6);
assertXPath(pExportDump, "//page/body/section/txt"_ostr, 7);
assertXPath(pExportDump, "//page/body/txt[2]/SwParaPortion/SwLineLayout"_ostr, 7);
assertXPath(pExportDump, "//page/body/txt[3]/SwParaPortion"_ostr, 0);
// Show the section again
xSection->setPropertyValue(u"IsVisible"_ustr, css::uno::Any(true));
// Check that the layout has been restored
discardDumpedLayout();
calcLayout();
pExportDump = parseLayoutDump();
assertXPath(pExportDump, "//page"_ostr, 2);
assertXPath(pExportDump, "//page[1]/body/txt"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt/SwParaPortion/SwLineLayout"_ostr, 6);
assertXPath(pExportDump, "//page[2]/body/section"_ostr, 1);
assertXPath(pExportDump, "//page[2]/body/section/txt"_ostr, 7);
assertXPath(pExportDump, "//page[2]/body/section/txt[1]/SwParaPortion"_ostr, 0);
assertXPath(pExportDump, "//page[2]/body/section/txt[2]/SwParaPortion"_ostr, 0);
assertXPath(pExportDump, "//page[2]/body/section/txt[3]/SwParaPortion"_ostr, 0);
assertXPath(pExportDump, "//page[2]/body/section/txt[4]/SwParaPortion/SwLineLayout"_ostr, 5);
assertXPath(pExportDump, "//page[2]/body/section/txt[5]/SwParaPortion"_ostr, 0);
assertXPath(pExportDump, "//page[2]/body/section/txt[6]/SwParaPortion"_ostr, 0);
assertXPath(pExportDump, "//page[2]/body/section/txt[7]/SwParaPortion"_ostr, 0);
assertXPath(pExportDump, "//page[2]/body/txt"_ostr, 2);
assertXPath(pExportDump, "//page[2]/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 7);
assertXPath(pExportDump, "//page[2]/body/txt[2]/SwParaPortion"_ostr, 0);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf160958_orphans)
{
// Given a document with a section which moves to the next page as a whole, because of orphans
createSwDoc("tdf160958_orphans_move_section.fodt");
auto pExportDump = parseLayoutDump();
assertXPath(pExportDump, "//page"_ostr, 2);
// 21 paragraphs on the first page
assertXPath(pExportDump, "//page[1]/body/txt"_ostr, 21);
assertXPath(pExportDump, "//page[1]/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 6);
assertXPath(pExportDump, "//page[1]/body/txt[2]/SwParaPortion/SwLineLayout"_ostr, 5);
assertXPath(pExportDump, "//page[1]/body/txt[3]/SwParaPortion/SwLineLayout"_ostr, 7);
assertXPath(pExportDump, "//page[1]/body/txt[4]/SwParaPortion/SwLineLayout"_ostr, 16);
assertXPath(pExportDump, "//page[1]/body/txt[5]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[6]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[7]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[8]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[9]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[10]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[11]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[12]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[13]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[14]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[15]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[16]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[17]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[18]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[19]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[20]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[21]/SwParaPortion/SwLineLayout"_ostr, 1);
// A section and one more paragraph after the section
assertXPath(pExportDump, "//page[2]/body/section"_ostr, 1);
assertXPath(pExportDump, "//page[2]/body/section/txt"_ostr, 3);
assertXPath(pExportDump, "//page[2]/body/section/txt[1]/SwParaPortion/SwLineLayout"_ostr, 6);
assertXPath(pExportDump, "//page[2]/body/section/txt[2]/SwParaPortion/SwLineLayout"_ostr, 5);
assertXPath(pExportDump, "//page[2]/body/section/txt[3]/SwParaPortion/SwLineLayout"_ostr, 7);
assertXPath(pExportDump, "//page[2]/body/txt"_ostr, 1);
assertXPath(pExportDump, "//page[2]/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 1);
// Hide the section
auto xTextSectionsSupplier = mxComponent.queryThrow<css::text::XTextSectionsSupplier>();
auto xSections = xTextSectionsSupplier->getTextSections();
CPPUNIT_ASSERT(xSections);
auto xSection = xSections->getByName(u"Section1"_ustr).queryThrow<css::beans::XPropertySet>();
xSection->setPropertyValue(u"IsVisible"_ustr, css::uno::Any(false));
discardDumpedLayout();
calcLayout();
pExportDump = parseLayoutDump();
assertXPath(pExportDump, "//page"_ostr, 1);
assertXPath(pExportDump, "//page/body/txt"_ostr, 22);
assertXPath(pExportDump, "//page/body/section"_ostr, 1);
assertXPath(pExportDump, "//page/body/section/infos/bounds"_ostr, "height"_ostr, "0");
// Show the section again
xSection->setPropertyValue(u"IsVisible"_ustr, css::uno::Any(true));
// Check that the layout has been restored
discardDumpedLayout();
calcLayout();
pExportDump = parseLayoutDump();
assertXPath(pExportDump, "//page"_ostr, 2);
assertXPath(pExportDump, "//page[1]/body/txt"_ostr, 21);
assertXPath(pExportDump, "//page[1]/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 6);
assertXPath(pExportDump, "//page[1]/body/txt[2]/SwParaPortion/SwLineLayout"_ostr, 5);
assertXPath(pExportDump, "//page[1]/body/txt[3]/SwParaPortion/SwLineLayout"_ostr, 7);
assertXPath(pExportDump, "//page[1]/body/txt[4]/SwParaPortion/SwLineLayout"_ostr, 16);
assertXPath(pExportDump, "//page[1]/body/txt[5]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[6]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[7]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[8]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[9]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[10]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[11]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[12]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[13]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[14]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[15]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[16]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[17]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[18]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[19]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[20]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[1]/body/txt[21]/SwParaPortion/SwLineLayout"_ostr, 1);
assertXPath(pExportDump, "//page[2]/body/section"_ostr, 1);
assertXPath(pExportDump, "//page[2]/body/section/txt"_ostr, 3);
assertXPath(pExportDump, "//page[2]/body/section/txt[1]/SwParaPortion/SwLineLayout"_ostr, 6);
assertXPath(pExportDump, "//page[2]/body/section/txt[2]/SwParaPortion/SwLineLayout"_ostr, 5);
assertXPath(pExportDump, "//page[2]/body/section/txt[3]/SwParaPortion/SwLineLayout"_ostr, 7);
assertXPath(pExportDump, "//page[2]/body/txt"_ostr, 1);
assertXPath(pExportDump, "//page[2]/body/txt[1]/SwParaPortion/SwLineLayout"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, TestTdf161508)
{
// This document must not hang on load.
createSwDoc("tdf161508.fodt");
auto pExportDump = parseLayoutDump();
// The table must move completely to the second page
assertXPath(pExportDump, "//page[1]/body/tab"_ostr, 0);
assertXPath(pExportDump, "//page[2]/body/tab"_ostr, 1);
}
CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, TestCrashHyphenation)
{
//just care it doesn't crash/assert
createSwDoc("crashHyphen.fodt");
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|