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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include <vcl/outdev.hxx>
#include <vcl/virdev.hxx>
#include "viewsh.hxx"
#include "pagefrm.hxx"
#include "rootfrm.hxx"
#include "viewimp.hxx" // SwViewImp
#include "pam.hxx" // SwPosition
#include "swregion.hxx" // SwRegionRects
#include "dcontact.hxx" // SwContact
#include "dflyobj.hxx" // SdrObject
#include "flyfrm.hxx" // SwFlyFrm
#include "frmtool.hxx" // ::DrawGraphic
#include "porfld.hxx" // SwGrfNumPortion
#include "txtfrm.hxx" // SwTxtFrm
#include "itrform2.hxx" // SwTxtFormatter
#include "porfly.hxx" // NewFlyCntPortion
#include "porfld.hxx" // SwGrfNumPortion
#include "txtfly.hxx" // SwTxtFly
#include "txtpaint.hxx" // SwSaveClip
#include "txtatr.hxx" // SwTxtFlyCnt
#include "notxtfrm.hxx"
#include "flyfrms.hxx"
#include "fmtcnct.hxx" // SwFmtChain
#include <pormulti.hxx> // SwMultiPortion
#include <svx/obj3d.hxx>
#include <editeng/txtrange.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/ulspitem.hxx>
// #i28701#
#include <editeng/lspcitem.hxx>
#include <txtflcnt.hxx>
#include <fmtsrnd.hxx>
#include <fmtanchr.hxx>
#include <fmtflcnt.hxx>
#include <frmfmt.hxx>
#include <pagedesc.hxx> // SwPageDesc
#include <tgrditem.hxx>
#include <sortedobjs.hxx>
#include <layouter.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <IDocumentSettingAccess.hxx>
#include <svx/svdoedge.hxx>
#include "doc.hxx"
#ifdef DBG_UTIL
#include "viewopt.hxx" // SwViewOptions, nur zum Testen (Test2)
#include "doc.hxx"
#endif
using namespace ::com::sun::star;
/*****************************************************************************
* Beschreibung:
* Die Klasse SwTxtFly soll die Universalschnittstelle zwischen der
* Formatierung/Textausgabe und den u.U. ueberlappenden freifliegenden
* Frames sein.
* Waehrend der Formatierung erkundigt sich der Formatierer beim SwTxtFly,
* ob ein bestimmter Bereich durch die Attribute eines ueberlappenden
* Frames vorliegt. Solche Bereiche werden in Form von Dummy-Portions
* abgebildet.
* Die gesamte Textausgabe und Retusche wird ebenfalls an ein SwTxtFly
* weitergeleitet. Dieser entscheidet, ob Textteile geclippt werden muessen
* und zerteilt z.B. die Bereiche bei einem DrawRect.
* Zu beachten ist, dass alle freifliegenden Frames in einem nach TopLeft
* sortiertem PtrArray an der Seite zu finden sind. Intern wird immer nur
* in dokumentglobalen Werten gerechnet. Die IN- und OUT-Parameter sind
* jedoch in den meisten Faellen an die Beduerfnisse des LineIters
* zugeschnitten, d.h. sie werden in frame- oder windowlokalen Koordinaten
* konvertiert.
* Wenn mehrere Frames mit Umlaufattributen in einer Zeile liegen,
* ergeben sich unterschiedliche Auswirkungen fuer den Textfluss:
*
* L/R P L R K
* P -P-P- -P-L -P R- -P K
* L -L P- -L L -L R- -L K
* R R-P- R-L R R- R K
* K K P- K L K R- K K
*
* (P=parallel, L=links, R=rechts, K=kein Umlauf)
*
* Das Verhalten so beschreiben:
* Jeder Rahmen kann Text verdraengen, wobei der Einfluss allerdings nur
* bis zum naechsten Rahmen reicht.
*****************************************************************************/
void SwTxtFormatter::CalcUnclipped( SwTwips& rTop, SwTwips& rBottom )
{
OSL_ENSURE( ! pFrm->IsVertical() || pFrm->IsSwapped(),
"SwTxtFormatter::CalcUnclipped with unswapped frame" );
long nFlyAsc, nFlyDesc;
// OD 08.01.2004 #i11859# - use new method <SwLineLayout::MaxAscentDescent(..)>
//lcl_MaxAscDescent( pCurr, rTop, rBottom, nFlyAsc, nFlyDesc );
pCurr->MaxAscentDescent( rTop, rBottom, nFlyAsc, nFlyDesc );
rTop = Y() + GetCurr()->GetAscent();
rBottom = rTop + nFlyDesc;
rTop -= nFlyAsc;
}
/*************************************************************************
* SwTxtFormatter::UpdatePos() aktualisiert die Referenzpunkte der zeichengeb.
* Objekte, z. B. nach Adjustierung ( rechtsbuendig, Blocksatz etc. )
* ( hauptsaechlich Korrrektur der X-Position )
*************************************************************************/
void SwTxtFormatter::UpdatePos( SwLineLayout *pCurrent, Point aStart,
xub_StrLen nStartIdx, sal_Bool bAllWays ) const
{
OSL_ENSURE( ! pFrm->IsVertical() || pFrm->IsSwapped(),
"SwTxtFormatter::UpdatePos with unswapped frame" );
if( GetInfo().IsTest() )
return;
SwLinePortion *pFirst = pCurrent->GetFirstPortion();
SwLinePortion *pPos = pFirst;
SwTxtPaintInfo aTmpInf( GetInfo() );
aTmpInf.SetpSpaceAdd( pCurrent->GetpLLSpaceAdd() );
aTmpInf.ResetSpaceIdx();
aTmpInf.SetKanaComp( pCurrent->GetpKanaComp() );
aTmpInf.ResetKanaIdx();
// Die Groesse des Frames
aTmpInf.SetIdx( nStartIdx );
aTmpInf.SetPos( aStart );
long nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc;
// OD 08.01.2004 #i11859# - use new method <SwLineLayout::MaxAscentDescent(..)>
//lcl_MaxAscDescent( pPos, nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc );
pCurrent->MaxAscentDescent( nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc );
KSHORT nTmpHeight = pCurrent->GetRealHeight();
KSHORT nAscent = pCurrent->GetAscent() + nTmpHeight - pCurrent->Height();
objectpositioning::AsCharFlags nFlags = AS_CHAR_ULSPACE;
if( GetMulti() )
{
aTmpInf.SetDirection( GetMulti()->GetDirection() );
if( GetMulti()->HasRotation() )
{
nFlags |= AS_CHAR_ROTATE;
if( GetMulti()->IsRevers() )
{
nFlags |= AS_CHAR_REVERSE;
aTmpInf.X( aTmpInf.X() - nAscent );
}
else
aTmpInf.X( aTmpInf.X() + nAscent );
}
else
{
if ( GetMulti()->IsBidi() )
nFlags |= AS_CHAR_BIDI;
aTmpInf.Y( aTmpInf.Y() + nAscent );
}
}
else
aTmpInf.Y( aTmpInf.Y() + nAscent );
while( pPos )
{
// bislang ist mir nur ein Fall bekannt, wo die Positionsaenderung
// (verursacht durch das Adjustment) fuer eine Portion wichtig
// sein koennte: Bei FlyCntPortions muss ein SetRefPoint erfolgen.
if( ( pPos->IsFlyCntPortion() || pPos->IsGrfNumPortion() )
&& ( bAllWays || !IsQuick() ) )
{
// OD 08.01.2004 #i11859# - use new method <SwLineLayout::MaxAscentDescent(..)>
//lcl_MaxAscDescent( pFirst, nTmpAscent, nTmpDescent,
// nFlyAsc, nFlyDesc, pPos );
pCurrent->MaxAscentDescent( nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc, pPos );
if( pPos->IsGrfNumPortion() )
{
if( !nFlyAsc && !nFlyDesc )
{
nTmpAscent = nAscent;
nFlyAsc = nAscent;
nTmpDescent = nTmpHeight - nAscent;
nFlyDesc = nTmpDescent;
}
((SwGrfNumPortion*)pPos)->SetBase( nTmpAscent, nTmpDescent,
nFlyAsc, nFlyDesc );
}
else
{
Point aBase( aTmpInf.GetPos() );
if ( GetInfo().GetTxtFrm()->IsVertical() )
GetInfo().GetTxtFrm()->SwitchHorizontalToVertical( aBase );
((SwFlyCntPortion*)pPos)->SetBase( *aTmpInf.GetTxtFrm(),
aBase, nTmpAscent, nTmpDescent, nFlyAsc,
nFlyDesc, nFlags );
}
}
if( pPos->IsMultiPortion() && ((SwMultiPortion*)pPos)->HasFlyInCntnt() )
{
OSL_ENSURE( !GetMulti(), "Too much multi" );
((SwTxtFormatter*)this)->pMulti = (SwMultiPortion*)pPos;
SwLineLayout *pLay = &GetMulti()->GetRoot();
Point aSt( aTmpInf.X(), aStart.Y() );
if ( GetMulti()->HasBrackets() )
{
OSL_ENSURE( GetMulti()->IsDouble(), "Brackets only for doubles");
aSt.X() += ((SwDoubleLinePortion*)GetMulti())->PreWidth();
}
else if( GetMulti()->HasRotation() )
{
aSt.Y() += pCurrent->GetAscent() - GetMulti()->GetAscent();
if( GetMulti()->IsRevers() )
aSt.X() += GetMulti()->Width();
else
aSt.Y() += GetMulti()->Height();
}
else if ( GetMulti()->IsBidi() )
// jump to end of the bidi portion
aSt.X() += pLay->Width();
xub_StrLen nStIdx = aTmpInf.GetIdx();
do
{
UpdatePos( pLay, aSt, nStIdx, bAllWays );
nStIdx = nStIdx + pLay->GetLen();
aSt.Y() += pLay->Height();
pLay = pLay->GetNext();
} while ( pLay );
((SwTxtFormatter*)this)->pMulti = NULL;
}
pPos->Move( aTmpInf );
pPos = pPos->GetPortion();
}
}
/*************************************************************************
* SwTxtFormatter::AlignFlyInCntBase()
* richtet die zeichengeb. Objekte in Y-Richtung ggf. neu aus.
*************************************************************************/
void SwTxtFormatter::AlignFlyInCntBase( long nBaseLine ) const
{
OSL_ENSURE( ! pFrm->IsVertical() || pFrm->IsSwapped(),
"SwTxtFormatter::AlignFlyInCntBase with unswapped frame" );
if( GetInfo().IsTest() )
return;
SwLinePortion *pFirst = pCurr->GetFirstPortion();
SwLinePortion *pPos = pFirst;
objectpositioning::AsCharFlags nFlags = AS_CHAR_NOFLAG;
if( GetMulti() && GetMulti()->HasRotation() )
{
nFlags |= AS_CHAR_ROTATE;
if( GetMulti()->IsRevers() )
nFlags |= AS_CHAR_REVERSE;
}
long nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc;
while( pPos )
{
if( pPos->IsFlyCntPortion() || pPos->IsGrfNumPortion() )
{
// OD 08.01.2004 #i11859# - use new method <SwLineLayout::MaxAscentDescent(..)>
//lcl_MaxAscDescent( pFirst, nTmpAscent, nTmpDescent,
// nFlyAsc, nFlyDesc, pPos );
pCurr->MaxAscentDescent( nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc, pPos );
if( pPos->IsGrfNumPortion() )
((SwGrfNumPortion*)pPos)->SetBase( nTmpAscent, nTmpDescent,
nFlyAsc, nFlyDesc );
else
{
Point aBase;
if ( GetInfo().GetTxtFrm()->IsVertical() )
{
nBaseLine = GetInfo().GetTxtFrm()->SwitchHorizontalToVertical( nBaseLine );
aBase = Point( nBaseLine, ((SwFlyCntPortion*)pPos)->GetRefPoint().Y() );
}
else
aBase = Point( ((SwFlyCntPortion*)pPos)->GetRefPoint().X(), nBaseLine );
((SwFlyCntPortion*)pPos)->SetBase( *GetInfo().GetTxtFrm(), aBase, nTmpAscent, nTmpDescent,
nFlyAsc, nFlyDesc, nFlags );
}
}
pPos = pPos->GetPortion();
}
}
/*************************************************************************
* SwTxtFly::ChkFlyUnderflow()
* This is called after the real height of the line has been calculated
* Therefore it is possible, that more flys from below intersect with the
* line, or that flys from above do not intersect with the line anymore
* We check this and return true if so, meaning that the line has to be
* formatted again
*************************************************************************/
sal_Bool SwTxtFormatter::ChkFlyUnderflow( SwTxtFormatInfo &rInf ) const
{
OSL_ENSURE( rInf.GetTxtFly()->IsOn(), "SwTxtFormatter::ChkFlyUnderflow: why?" );
if( GetCurr() )
{
// Erst pruefen wir, ob ueberhaupt ein Fly mit der Zeile ueberlappt.
// = GetLineHeight()
const long nHeight = GetCurr()->GetRealHeight();
SwRect aLine( GetLeftMargin(), Y(), rInf.RealWidth(), nHeight );
SwRect aLineVert( aLine );
if ( pFrm->IsVertical() )
pFrm->SwitchHorizontalToVertical( aLineVert );
SwRect aInter( rInf.GetTxtFly()->GetFrm( aLineVert ) );
if ( pFrm->IsVertical() )
pFrm->SwitchVerticalToHorizontal( aInter );
if( !aInter.HasArea() )
return sal_False;
// Nun ueberpruefen wir jede Portion, die sich haette senken koennen,
// ob sie mit dem Fly ueberlappt.
const SwLinePortion *pPos = GetCurr()->GetFirstPortion();
aLine.Pos().Y() = Y() + GetCurr()->GetRealHeight() - GetCurr()->Height();
aLine.Height( GetCurr()->Height() );
while( pPos )
{
aLine.Width( pPos->Width() );
aLineVert = aLine;
if ( pFrm->IsVertical() )
pFrm->SwitchHorizontalToVertical( aLineVert );
aInter = rInf.GetTxtFly()->GetFrm( aLineVert );
if ( pFrm->IsVertical() )
pFrm->SwitchVerticalToHorizontal( aInter );
// new flys from below?
if( !pPos->IsFlyPortion() )
{
if( aInter.IsOver( aLine ) )
{
aInter._Intersection( aLine );
if( aInter.HasArea() )
{
// to be evaluated during reformat of this line:
// RealHeight including spacing
rInf.SetLineHeight( KSHORT(nHeight) );
// Height without extra spacing
rInf.SetLineNettoHeight( KSHORT( pCurr->Height() ) );
return sal_True;
}
}
}
else
{
// the fly portion is not anylonger intersected by a fly
if ( ! aInter.IsOver( aLine ) )
{
rInf.SetLineHeight( KSHORT(nHeight) );
rInf.SetLineNettoHeight( KSHORT( pCurr->Height() ) );
return sal_True;
}
else
{
aInter._Intersection( aLine );
// no area means a fly has become invalid because of
// lowering the line => reformat the line
// we also have to reformat the line, if the fly size
// differs from the intersection intervals size
if( ! aInter.HasArea() ||
((SwFlyPortion*)pPos)->GetFixWidth() != aInter.Width() )
{
rInf.SetLineHeight( KSHORT(nHeight) );
rInf.SetLineNettoHeight( KSHORT( pCurr->Height() ) );
return sal_True;
}
}
}
aLine.Left( aLine.Left() + pPos->Width() );
pPos = pPos->GetPortion();
}
}
return sal_False;
}
/*************************************************************************
* SwTxtFormatter::CalcFlyWidth()
* ermittelt das naechste Objekt, das in die restliche Zeile ragt und
* konstruiert die zugehoerige FlyPortion.
* Dazu wird SwTxtFly.GetFrm(..) benutzt.
*************************************************************************/
// Durch Flys kann sich der rechte Rand verkuerzen.
void SwTxtFormatter::CalcFlyWidth( SwTxtFormatInfo &rInf )
{
if( GetMulti() || rInf.GetFly() )
return;
SwTxtFly *pTxtFly = rInf.GetTxtFly();
if( !pTxtFly->IsOn() || rInf.IsIgnoreFly() )
return;
const SwLinePortion *pLast = rInf.GetLast();
long nAscent;
long nTop = Y();
long nHeight;
if( rInf.GetLineHeight() )
{
// real line height has already been calculated, we only have to
// search for intersections in the lower part of the strip
nAscent = pCurr->GetAscent();
nHeight = rInf.GetLineNettoHeight();
nTop += rInf.GetLineHeight() - nHeight;
}
else
{
nAscent = pLast->GetAscent();
nHeight = pLast->Height();
// we make a first guess for the lines real height
if ( ! pCurr->GetRealHeight() )
CalcRealHeight();
if ( pCurr->GetRealHeight() > nHeight )
nTop += pCurr->GetRealHeight() - nHeight;
else
// important for fixed space between lines
nHeight = pCurr->GetRealHeight();
}
const long nLeftMar = GetLeftMargin();
const long nLeftMin = (rInf.X() || GetDropLeft()) ? nLeftMar : GetLeftMin();
SwRect aLine( rInf.X() + nLeftMin, nTop, rInf.RealWidth() - rInf.X()
+ nLeftMar - nLeftMin , nHeight );
SwRect aLineVert( aLine );
if ( pFrm->IsRightToLeft() )
pFrm->SwitchLTRtoRTL( aLineVert );
if ( pFrm->IsVertical() )
pFrm->SwitchHorizontalToVertical( aLineVert );
SwRect aInter( pTxtFly->GetFrm( aLineVert ) );
if ( pFrm->IsRightToLeft() )
pFrm->SwitchRTLtoLTR( aInter );
if ( pFrm->IsVertical() )
pFrm->SwitchVerticalToHorizontal( aInter );
if( aInter.IsOver( aLine ) )
{
aLine.Left( rInf.X() + nLeftMar );
sal_Bool bForced = sal_False;
if( aInter.Left() <= nLeftMin )
{
SwTwips nFrmLeft = GetTxtFrm()->Frm().Left();
if( GetTxtFrm()->Prt().Left() < 0 )
nFrmLeft += GetTxtFrm()->Prt().Left();
if( aInter.Left() < nFrmLeft )
aInter.Left( nFrmLeft );
long nAddMar = 0;
if ( pFrm->IsRightToLeft() )
{
nAddMar = pFrm->Frm().Right() - Right();
if ( nAddMar < 0 )
nAddMar = 0;
}
else
nAddMar = nLeftMar - nFrmLeft;
aInter.Width( aInter.Width() + nAddMar );
// Bei negativem Erstzeileneinzug setzen wir das Flag,
// um anzuzeigen, dass der Einzug/Rand verschoben wurde
// Dies muss beim DefaultTab an der Nullposition beruecksichtigt
// werden.
if( IsFirstTxtLine() && HasNegFirst() )
bForced = sal_True;
}
aInter.Intersection( aLine );
if( !aInter.HasArea() )
return;
const sal_Bool bFullLine = aLine.Left() == aInter.Left() &&
aLine.Right() == aInter.Right();
// Obwohl kein Text mehr da ist, muss eine weitere Zeile
// formatiert werden, weil auch leere Zeilen einem Fly
// ohne Umlauf ausweichen muessen.
if( bFullLine && rInf.GetIdx() == rInf.GetTxt().Len() )
{
rInf.SetNewLine( sal_True );
// 8221: Dummies erkennt man an Ascent == Height
pCurr->SetDummy(sal_True);
}
// aInter wird framelokal
aInter.Pos().X() -= nLeftMar;
SwFlyPortion *pFly = new SwFlyPortion( aInter );
if( bForced )
{
pCurr->SetForcedLeftMargin( sal_True );
rInf.ForcedLeftMargin( (sal_uInt16)aInter.Width() );
}
if( bFullLine )
{
// 8110: wir muessen um Einheiten von Zeilenhoehen anwachsen,
// um nebeneinanderliegende Flys mit unterschiedlichen
// Umlaufattributen angemessen zu umfliessen.
// Die letzte ausweichende Zeile, sollte in der Hoehe angepasst
// sein, damit nicht der Eindruck von "Rahmenabstaenden" aufkommt.
// 8221: Wichtig ist, dass Ascent == Height ist, weil die FlyPortionWerte
// im CalcLine in pCurr uebertragen werden und IsDummy() darauf
// angewiesen ist.
// Es gibt meines Wissens nur zwei Stellen, in denen DummyLines
// entstehen koennen: hier und in MakeFlyDummies.
// Ausgewertet wird IsDummy() in IsFirstTxtLine() und
// beim Zeilenwandern und im Zusammenhang mit DropCaps.
pFly->Height( KSHORT(aInter.Height()) );
// In nNextTop steckt jetzt die Unterkante des Rahmens, dem wir
// ausweichen oder die Oberkante des naechsten Rahmens, den wir
// beachten muessen. Wir koennen also jetzt getrost bis zu diesem
// Wert anwachsen, so sparen wir einige Leerzeilen.
long nNextTop = pTxtFly->GetNextTop();
if ( pFrm->IsVertical() )
nNextTop = pFrm->SwitchVerticalToHorizontal( nNextTop );
if( nNextTop > aInter.Bottom() )
{
SwTwips nH = nNextTop - aInter.Top();
if( nH < KSHRT_MAX )
pFly->Height( KSHORT( nH ) );
}
if( nAscent < pFly->Height() )
pFly->SetAscent( KSHORT(nAscent) );
else
pFly->SetAscent( pFly->Height() );
}
else
{
if( rInf.GetIdx() == rInf.GetTxt().Len() )
{
// Nicht nHeight nehmen, sonst haben wir einen Riesendescent
pFly->Height( pLast->Height() );
pFly->SetAscent( pLast->GetAscent() );
}
else
{
pFly->Height( KSHORT(aInter.Height()) );
if( nAscent < pFly->Height() )
pFly->SetAscent( KSHORT(nAscent) );
else
pFly->SetAscent( pFly->Height() );
}
}
rInf.SetFly( pFly );
if( pFly->Fix() < rInf.Width() )
rInf.Width( pFly->Fix() );
GETGRID( pFrm->FindPageFrm() )
if ( pGrid )
{
const SwPageFrm* pPageFrm = pFrm->FindPageFrm();
const SwLayoutFrm* pBody = pPageFrm->FindBodyCont();
SWRECTFN( pPageFrm )
const long nGridOrigin = pBody ?
(pBody->*fnRect->fnGetPrtLeft)() :
(pPageFrm->*fnRect->fnGetPrtLeft)();
const SwDoc *pDoc = rInf.GetTxtFrm()->GetNode()->GetDoc();
const sal_uInt16 nGridWidth = GETGRIDWIDTH( pGrid, pDoc); //for textgrid refactor
SwTwips nStartX = GetLeftMargin();
if ( bVert )
{
Point aPoint( nStartX, 0 );
pFrm->SwitchHorizontalToVertical( aPoint );
nStartX = aPoint.Y();
}
const SwTwips nOfst = nStartX - nGridOrigin;
const SwTwips nTmpWidth = rInf.Width() + nOfst;
const sal_uLong i = nTmpWidth / nGridWidth + 1;
const long nNewWidth = ( i - 1 ) * nGridWidth - nOfst;
if ( nNewWidth > 0 )
rInf.Width( (sal_uInt16)nNewWidth );
else
rInf.Width( 0 );
}
}
}
/*****************************************************************************
* SwTxtFormatter::NewFlyCntPortion
* legt eine neue Portion fuer ein zeichengebundenes Objekt an.
*****************************************************************************/
SwFlyCntPortion *SwTxtFormatter::NewFlyCntPortion( SwTxtFormatInfo &rInf,
SwTxtAttr *pHint ) const
{
SwFlyCntPortion *pRet = 0;
const SwFrm *pFrame = (SwFrm*)pFrm;
SwFlyInCntFrm *pFly;
SwFrmFmt* pFrmFmt = ((SwTxtFlyCnt*)pHint)->GetFlyCnt().GetFrmFmt();
if( RES_FLYFRMFMT == pFrmFmt->Which() )
pFly = ((SwTxtFlyCnt*)pHint)->GetFlyFrm(pFrame);
else
pFly = NULL;
// aBase bezeichnet die dokumentglobale Position,
// ab der die neue Extraportion plaziert wird.
// aBase.X() = Offset in der Zeile,
// hinter der aktuellen Portion
// aBase.Y() = LineIter.Y() + Ascent der aktuellen Portion
long nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc;
// OD 08.01.2004 #i11859# - use new method <SwLineLayout::MaxAscentDescent(..)>
//SwLinePortion *pPos = pCurr->GetFirstPortion();
//lcl_MaxAscDescent( pPos, nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc );
pCurr->MaxAscentDescent( nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc );
// Wenn der Ascent des Rahmens groesser als der Ascent der akt. Portion
// ist, wird dieser bei der Base-Berechnung verwendet, sonst wuerde
// der Rahmen zunaechst zu weit nach oben gesetzt, um dann doch wieder
// nach unten zu rutschen und dabei ein Repaint in einem Bereich ausloesen,
// indem er niemals wirklich war.
KSHORT nAscent = 0;
const bool bTxtFrmVertical = GetInfo().GetTxtFrm()->IsVertical();
const bool bUseFlyAscent = pFly && pFly->GetValidPosFlag() &&
0 != ( bTxtFrmVertical ?
pFly->GetRefPoint().X() :
pFly->GetRefPoint().Y() );
if ( bUseFlyAscent )
nAscent = static_cast<sal_uInt16>( Abs( int( bTxtFrmVertical ?
pFly->GetRelPos().X() :
pFly->GetRelPos().Y() ) ) );
// check if be prefer to use the ascent of the last portion:
if ( IsQuick() ||
!bUseFlyAscent ||
nAscent < rInf.GetLast()->GetAscent() )
{
nAscent = rInf.GetLast()->GetAscent();
}
else if( nAscent > nFlyAsc )
nFlyAsc = nAscent;
Point aBase( GetLeftMargin() + rInf.X(), Y() + nAscent );
objectpositioning::AsCharFlags nMode = IsQuick() ? AS_CHAR_QUICK : 0;
if( GetMulti() && GetMulti()->HasRotation() )
{
nMode |= AS_CHAR_ROTATE;
if( GetMulti()->IsRevers() )
nMode |= AS_CHAR_REVERSE;
}
Point aTmpBase( aBase );
if ( GetInfo().GetTxtFrm()->IsVertical() )
GetInfo().GetTxtFrm()->SwitchHorizontalToVertical( aTmpBase );
if( pFly )
{
pRet = new SwFlyCntPortion( *GetInfo().GetTxtFrm(), pFly, aTmpBase,
nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc, nMode );
// Wir muessen sicherstellen, dass unser Font wieder im OutputDevice
// steht. Es koennte sein, dass der FlyInCnt frisch eingefuegt wurde,
// dann hat GetFlyFrm dazu gefuehrt, dass er neu angelegt wird.
// Dessen Frames werden sofort formatiert, die verstellen den Font
// und schon haben wir den Salat (3322).
rInf.SelectFont();
if( pRet->GetAscent() > nAscent )
{
aBase.Y() = Y() + pRet->GetAscent();
nMode |= AS_CHAR_ULSPACE;
if( !rInf.IsTest() )
aTmpBase = aBase;
if ( GetInfo().GetTxtFrm()->IsVertical() )
GetInfo().GetTxtFrm()->SwitchHorizontalToVertical( aTmpBase );
pRet->SetBase( *rInf.GetTxtFrm(), aTmpBase, nTmpAscent,
nTmpDescent, nFlyAsc, nFlyDesc, nMode );
}
}
else
{
pRet = new SwFlyCntPortion( *rInf.GetTxtFrm(), (SwDrawContact*)pFrmFmt->FindContactObj(),
aTmpBase, nTmpAscent, nTmpDescent, nFlyAsc, nFlyDesc, nMode );
}
return pRet;
}
/*************************************************************************
* SwTxtFly::SwTxtFly()
*************************************************************************/
SwTxtFly::SwTxtFly( const SwTxtFly& rTxtFly )
{
pPage = rTxtFly.pPage;
mpCurrAnchoredObj = rTxtFly.mpCurrAnchoredObj;
pCurrFrm = rTxtFly.pCurrFrm;
pMaster = rTxtFly.pMaster;
if( rTxtFly.mpAnchoredObjList )
{
mpAnchoredObjList = new SwAnchoredObjList( *(rTxtFly.mpAnchoredObjList) );
}
else
{
mpAnchoredObjList = NULL;
}
bOn = rTxtFly.bOn;
bLeftSide = rTxtFly.bLeftSide;
bTopRule = rTxtFly.bTopRule;
nMinBottom = rTxtFly.nMinBottom;
nNextTop = rTxtFly.nNextTop;
nIndex = rTxtFly.nIndex;
mbIgnoreCurrentFrame = rTxtFly.mbIgnoreCurrentFrame;
mbIgnoreContour = rTxtFly.mbIgnoreContour;
mbIgnoreObjsInHeaderFooter = rTxtFly.mbIgnoreObjsInHeaderFooter;
}
void SwTxtFly::CtorInitTxtFly( const SwTxtFrm *pFrm )
{
mbIgnoreCurrentFrame = sal_False;
mbIgnoreContour = sal_False;
// #118809#
mbIgnoreObjsInHeaderFooter = sal_False;
pPage = pFrm->FindPageFrm();
const SwFlyFrm* pTmp = pFrm->FindFlyFrm();
// #i68520#
mpCurrAnchoredObj = pTmp;
pCurrFrm = pFrm;
pMaster = pCurrFrm->IsFollow() ? NULL : pCurrFrm;
// #i68520#
mpAnchoredObjList = NULL;
// Wenn wir nicht von einem Frame ueberlappt werden, oder wenn
// es gar keine FlyCollection gibt, dann schaltet wir uns fuer immer ab.
// Aber es koennte sein, dass waehrend der Formatierung eine Zeile
// hinzukommt, die in einen Frame hineinragt. Deswegen keine Optimierung
// per bOn = pSortedFlys && IsAnyFrm();
bOn = pPage->GetSortedObjs() != 0;
bTopRule = sal_True;
bLeftSide = sal_False;
nMinBottom = 0;
nIndex = ULONG_MAX;
}
/*************************************************************************
* SwTxtFly::_GetFrm()
*
* IN: dokumentglobal (rRect)
* OUT: framelokal (return-Wert)
* Diese Methode wird waehrend der Formatierung vom LineIter gerufen.
* 1. um die naechste FlyPortion vorzubereiten
* 2. um nach Aenderung der Zeilenhoehe neue Ueberlappungen festzustellen
*************************************************************************/
SwRect SwTxtFly::_GetFrm( const SwRect &rRect, sal_Bool bTop ) const
{
SwRect aRet;
if( ForEach( rRect, &aRet, sal_True ) )
{
SWRECTFN( pCurrFrm )
if( bTop )
(aRet.*fnRect->fnSetTop)( (rRect.*fnRect->fnGetTop)() );
// 8110: Bottom nicht immer anpassen.
const SwTwips nRetBottom = (aRet.*fnRect->fnGetBottom)();
const SwTwips nRectBottom = (rRect.*fnRect->fnGetBottom)();
if ( (*fnRect->fnYDiff)( nRetBottom, nRectBottom ) > 0 ||
(aRet.*fnRect->fnGetHeight)() < 0 )
(aRet.*fnRect->fnSetBottom)( nRectBottom );
}
return aRet;
}
/*************************************************************************
* SwTxtFly::IsAnyFrm()
*
* IN: dokumentglobal
* fuer die Printarea des aktuellen Frame
*
* dient zum Abschalten des SwTxtFly, wenn keine Objekte ueberlappen (Relax)
*
*************************************************************************/
sal_Bool SwTxtFly::IsAnyFrm() const
{
SWAP_IF_SWAPPED( pCurrFrm )
OSL_ENSURE( bOn, "IsAnyFrm: Why?" );
SwRect aRect( pCurrFrm->Frm().Pos() + pCurrFrm->Prt().Pos(),
pCurrFrm->Prt().SSize() );
const sal_Bool bRet = ForEach( aRect, NULL, sal_False );
UNDO_SWAP( pCurrFrm )
return bRet;
}
/*************************************************************************
* SwTxtFly::IsAnyObj()
*
* IN: dokumentglobal
* OUT: sal_True Wenn ein Rahmen oder DrawObj beruecksichtigt werden muss
* Nur wenn IsAnyObj sal_False liefert, koennen Optimierungen benutzt werden
* wie Paint/FormatEmpty fuer leere Absaetze
* und auch das virtuelle Outputdevice.
*************************************************************************/
sal_Bool SwTxtFly::IsAnyObj( const SwRect &rRect ) const
{
OSL_ENSURE( bOn, "SwTxtFly::IsAnyObj: Who's knocking?" );
SwRect aRect( rRect );
if ( aRect.IsEmpty() )
aRect = SwRect( pCurrFrm->Frm().Pos() + pCurrFrm->Prt().Pos(),
pCurrFrm->Prt().SSize() );
const SwSortedObjs *pSorted = pPage->GetSortedObjs();
if( pSorted ) // Eigentlich ist durch bOn sichergestellt, dass es an der
// Seite Objekte gibt, aber wer weiss, wer inzwischen etwas geloescht hat.
{
for ( MSHORT i = 0; i < pSorted->Count(); ++i )
{
const SwAnchoredObject* pObj = (*pSorted)[i];
const SwRect aBound( pObj->GetObjRectWithSpaces() );
// Optimierung
if( pObj->GetObjRect().Left() > aRect.Right() )
continue;
// #i68520#
if( mpCurrAnchoredObj != pObj && aBound.IsOver( aRect ) )
return sal_True;
}
}
return sal_False;
}
const SwCntntFrm* SwTxtFly::_GetMaster()
{
pMaster = pCurrFrm;
while( pMaster && pMaster->IsFollow() )
pMaster = (SwCntntFrm*)pMaster->FindMaster();
return pMaster;
}
/*************************************************************************
* SwTxtFly::DrawTextOpaque()
*
* IN: dokumentglobal
* DrawTextOpaque() wird von DrawText() gerufen.
* Die Clipregions werden so gesetzt, dass nur die Teile ausgegeben werden,
* die nicht in den Bereichen von FlyFrms liegen, die undurchsichtig und
* ueber dem aktuellen Frame liegen.
* Die On-Optimierung uebernimmt DrawText()!
*************************************************************************/
sal_Bool SwTxtFly::DrawTextOpaque( SwDrawTextInfo &rInf )
{
SwSaveClip aClipSave( rInf.GetpOut() );
SwRect aRect( rInf.GetPos(), rInf.GetSize() );
if( rInf.GetSpace() )
{
xub_StrLen nTmpLen = STRING_LEN == rInf.GetLen() ? rInf.GetText().Len() :
rInf.GetLen();
if( rInf.GetSpace() > 0 )
{
xub_StrLen nSpaceCnt = 0;
const xub_StrLen nEndPos = rInf.GetIdx() + nTmpLen;
for( xub_StrLen nPos = rInf.GetIdx(); nPos < nEndPos; ++nPos )
{
if( CH_BLANK == rInf.GetText().GetChar( nPos ) )
++nSpaceCnt;
}
if( nSpaceCnt )
aRect.Width( aRect.Width() + nSpaceCnt * rInf.GetSpace() );
}
else
aRect.Width( aRect.Width() - nTmpLen * rInf.GetSpace() );
}
if( aClipSave.IsOn() && rInf.GetOut().IsClipRegion() )
{
SwRect aClipRect( rInf.GetOut().GetClipRegion().GetBoundRect() );
aRect.Intersection( aClipRect );
}
SwRegionRects aRegion( aRect );
sal_Bool bOpaque = sal_False;
// #i68520#
const sal_uInt32 nCurrOrd = mpCurrAnchoredObj
? mpCurrAnchoredObj->GetDrawObj()->GetOrdNum()
: SAL_MAX_UINT32;
OSL_ENSURE( !bTopRule, "DrawTextOpaque: Wrong TopRule" );
// #i68520#
SwAnchoredObjList::size_type nCount( bOn ? GetAnchoredObjList()->size() : 0 );
if ( bOn && nCount > 0 )
{
MSHORT nHellId = pPage->getRootFrm()->GetCurrShell()->getIDocumentDrawModelAccess()->GetHellId();
for( MSHORT i = 0; i < nCount; ++i )
{
// #i68520#
const SwAnchoredObject* pTmpAnchoredObj = (*mpAnchoredObjList)[i];
if( dynamic_cast<const SwFlyFrm*>(pTmpAnchoredObj) &&
mpCurrAnchoredObj != pTmpAnchoredObj )
{
// #i68520#
const SwFlyFrm* pFly = dynamic_cast<const SwFlyFrm*>(pTmpAnchoredObj);
if( aRegion.GetOrigin().IsOver( pFly->Frm() ) )
{
const SwFrmFmt *pFmt = pFly->GetFmt();
const SwFmtSurround &rSur = pFmt->GetSurround();
const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
//Nur undurchsichtige und weiter oben liegende.
/// OD 08.10.2002 #103898# - add condition
/// <!(pFly->IsBackgroundTransparent() || pFly->IsShadowTransparent())>
if( !( pFly->IsBackgroundTransparent()
|| pFly->IsShadowTransparent() ) &&
SURROUND_THROUGHT == rSur.GetSurround() &&
( !rSur.IsAnchorOnly() ||
// #i68520#
GetMaster() == pFly->GetAnchorFrm() ||
((FLY_AT_PARA != rAnchor.GetAnchorId()) &&
(FLY_AT_CHAR != rAnchor.GetAnchorId())
)
) &&
// #i68520#
pTmpAnchoredObj->GetDrawObj()->GetLayer() != nHellId &&
nCurrOrd < pTmpAnchoredObj->GetDrawObj()->GetOrdNum()
)
{
//Ausser der Inhalt ist Transparent
const SwNoTxtFrm *pNoTxt =
pFly->Lower() && pFly->Lower()->IsNoTxtFrm()
? (SwNoTxtFrm*)pFly->Lower()
: 0;
if ( !pNoTxt ||
(!pNoTxt->IsTransparent() && !rSur.IsContour()) )
{
bOpaque = sal_True;
aRegion -= pFly->Frm();
}
}
}
}
}
}
Point aPos( rInf.GetPos().X(), rInf.GetPos().Y() + rInf.GetAscent() );
const Point &rOld = rInf.GetPos();
rInf.SetPos( aPos );
if( !bOpaque )
{
if( rInf.GetKern() )
rInf.GetFont()->_DrawStretchText( rInf );
else
rInf.GetFont()->_DrawText( rInf );
rInf.SetPos( rOld );
return sal_False;
}
else if( aRegion.Count() )
{
// Was fuer ein Aufwand ...
SwSaveClip aClipVout( rInf.GetpOut() );
for( MSHORT i = 0; i < aRegion.Count(); ++i )
{
SwRect &rRect = aRegion[i];
if( rRect != aRegion.GetOrigin() )
aClipVout.ChgClip( rRect );
if( rInf.GetKern() )
rInf.GetFont()->_DrawStretchText( rInf );
else
rInf.GetFont()->_DrawText( rInf );
}
}
rInf.SetPos( rOld );
return sal_True;
}
/*************************************************************************
* SwTxtFly::DrawFlyRect()
*
* IN: windowlokal
* Zwei Feinheiten gilt es zu beachten:
* 1) DrawRect() oberhalb des ClipRects sind erlaubt !
* 2) FlyToRect() liefert groessere Werte als die Framedaten !
*************************************************************************/
void SwTxtFly::DrawFlyRect( OutputDevice* pOut, const SwRect &rRect,
const SwTxtPaintInfo &rInf, sal_Bool bNoGraphic )
{
SwRegionRects aRegion( rRect );
OSL_ENSURE( !bTopRule, "DrawFlyRect: Wrong TopRule" );
// #i68520#
SwAnchoredObjList::size_type nCount( bOn ? GetAnchoredObjList()->size() : 0 );
if ( bOn && nCount > 0 )
{
MSHORT nHellId = pPage->getRootFrm()->GetCurrShell()->getIDocumentDrawModelAccess()->GetHellId();
for( MSHORT i = 0; i < nCount; ++i )
{
// #i68520#
const SwAnchoredObject* pAnchoredObjTmp = (*mpAnchoredObjList)[i];
if( mpCurrAnchoredObj != pAnchoredObjTmp &&
dynamic_cast<const SwFlyFrm*>(pAnchoredObjTmp) )
{
// #i68520#
const SwFmtSurround& rSur = pAnchoredObjTmp->GetFrmFmt().GetSurround();
// OD 24.01.2003 #106593# - correct clipping of fly frame area.
// Consider that fly frame background/shadow can be transparent
// and <SwAlignRect(..)> fly frame area
// #i68520#
const SwFlyFrm* pFly = dynamic_cast<const SwFlyFrm*>(pAnchoredObjTmp);
// #i47804# - consider transparent graphics
// and OLE objects.
bool bClipFlyArea =
( ( SURROUND_THROUGHT == rSur.GetSurround() )
// #i68520#
? (pAnchoredObjTmp->GetDrawObj()->GetLayer() != nHellId)
: !rSur.IsContour() ) &&
!pFly->IsBackgroundTransparent() &&
!pFly->IsShadowTransparent() &&
( !pFly->Lower() ||
!pFly->Lower()->IsNoTxtFrm() ||
!static_cast<const SwNoTxtFrm*>(pFly->Lower())->IsTransparent() );
if ( bClipFlyArea )
{
// #i68520#
SwRect aFly( pAnchoredObjTmp->GetObjRect() );
// OD 24.01.2003 #106593#
::SwAlignRect( aFly, pPage->getRootFrm()->GetCurrShell() );
if( aFly.Width() > 0 && aFly.Height() > 0 )
aRegion -= aFly;
}
}
}
}
for( MSHORT i = 0; i < aRegion.Count(); ++i )
{
if ( bNoGraphic )
pOut->DrawRect( aRegion[i].SVRect() );
else
{
OSL_ENSURE( ((SvxBrushItem*)-1) != rInf.GetBrushItem(),
"DrawRect: Uninitialized BrushItem!" );
::DrawGraphic( rInf.GetBrushItem(), pOut, rInf.GetBrushRect(),
aRegion[i] );
}
}
}
// #i26945# - change first parameter
// Now it's the <SwAnchoredObject> instance of the floating screen object
sal_Bool SwTxtFly::GetTop( const SwAnchoredObject* _pAnchoredObj,
const sal_Bool bInFtn,
const sal_Bool bInFooterOrHeader )
{
// #i68520#
// <mpCurrAnchoredObj> is set, if <pCurrFrm> is inside a fly frame
if( _pAnchoredObj != mpCurrAnchoredObj )
{
// #i26945#
const SdrObject* pNew = _pAnchoredObj->GetDrawObj();
// #102344# Ignore connectors which have one or more connections
if(pNew && pNew->ISA(SdrEdgeObj))
{
if(((SdrEdgeObj*)pNew)->GetConnectedNode(sal_True)
|| ((SdrEdgeObj*)pNew)->GetConnectedNode(sal_False))
{
return sal_False;
}
}
if( ( bInFtn || bInFooterOrHeader ) && bTopRule )
{
// #i26945#
const SwFrmFmt& rFrmFmt = _pAnchoredObj->GetFrmFmt();
const SwFmtAnchor& rNewA = rFrmFmt.GetAnchor();
if (FLY_AT_PAGE == rNewA.GetAnchorId())
{
if ( bInFtn )
return sal_False;
if ( bInFooterOrHeader )
{
SwFmtVertOrient aVert( rFrmFmt.GetVertOrient() );
sal_Bool bVertPrt = aVert.GetRelationOrient() == text::RelOrientation::PRINT_AREA ||
aVert.GetRelationOrient() == text::RelOrientation::PAGE_PRINT_AREA;
if( bVertPrt )
return sal_False;
}
}
}
// #i68520#
// bEvade: consider pNew, if we are not inside a fly
// consider pNew, if pNew is lower of <mpCurrAnchoredObj>
sal_Bool bEvade = !mpCurrAnchoredObj ||
Is_Lower_Of( dynamic_cast<const SwFlyFrm*>(mpCurrAnchoredObj), pNew);
if ( !bEvade )
{
// We are currently inside a fly frame and pNew is not
// inside this fly frame. We can do some more checks if
// we have to consider pNew.
// If bTopRule is not set, we ignore the frame types.
// We directly check the z-order
if ( !bTopRule )
bEvade = sal_True;
else
{
// innerhalb von verketteten Flys wird nur Lowern ausgewichen
// #i68520#
const SwFmtChain &rChain = mpCurrAnchoredObj->GetFrmFmt().GetChain();
if ( !rChain.GetPrev() && !rChain.GetNext() )
{
// #i26945#
const SwFmtAnchor& rNewA = _pAnchoredObj->GetFrmFmt().GetAnchor();
// #i68520#
const SwFmtAnchor& rCurrA = mpCurrAnchoredObj->GetFrmFmt().GetAnchor();
// If <mpCurrAnchoredObj> is anchored as character, its content
// does not wrap around pNew
if (FLY_AS_CHAR == rCurrA.GetAnchorId())
return sal_False;
// If pNew is anchored to page and <mpCurrAnchoredObj is not anchored
// to page, the content of <mpCurrAnchoredObj> does not wrap around pNew
// If both pNew and <mpCurrAnchoredObj> are anchored to page, we can do
// some more checks
if (FLY_AT_PAGE == rNewA.GetAnchorId())
{
if (FLY_AT_PAGE == rCurrA.GetAnchorId())
{
bEvade = sal_True;
}
else
return sal_False;
}
else if (FLY_AT_PAGE == rCurrA.GetAnchorId())
return sal_False; // Seitengebundene weichen nur seitengeb. aus
else if (FLY_AT_FLY == rNewA.GetAnchorId())
bEvade = sal_True; // Nicht seitengeb. weichen Rahmengeb. aus
else if( FLY_AT_FLY == rCurrA.GetAnchorId() )
return sal_False; // Rahmengebundene weichen abs.geb. nicht aus
// #i57062#
// In order to avoid loop situation, it's decided to adjust
// the wrapping behaviour of content of at-paragraph/at-character
// anchored objects to one in the page header/footer and
// the document body --> content of at-paragraph/at-character
// anchored objects doesn't wrap around each other.
// else if( bInFooterOrHeader )
// return sal_False; // In header or footer no wrapping
// // if both bounded at paragraph
// else // Zwei Flies mit (auto-)absatzgebunder Verankerung ...
// // ... entscheiden nach der Reihenfolge ihrer Anker im Dok.
// bEvade = rNewA.GetCntntAnchor()->nNode.GetIndex() <=
// rCurrA.GetCntntAnchor()->nNode.GetIndex();
else
return sal_False;
}
}
// aber: es wird niemals einem hierarchisch untergeordnetem
// ausgewichen und ausserdem braucht nur bei Ueberlappung
// ausgewichen werden.
// #i68520#
bEvade &= ( mpCurrAnchoredObj->GetDrawObj()->GetOrdNum() < pNew->GetOrdNum() );
if( bEvade )
{
// #i68520#
SwRect aTmp( _pAnchoredObj->GetObjRectWithSpaces() );
if ( !aTmp.IsOver( mpCurrAnchoredObj->GetObjRectWithSpaces() ) )
bEvade = sal_False;
}
}
if ( bEvade )
{
// #i26945#
const SwFmtAnchor& rNewA = _pAnchoredObj->GetFrmFmt().GetAnchor();
OSL_ENSURE( FLY_AS_CHAR != rNewA.GetAnchorId(),
"Don't call GetTop with a FlyInCntFrm" );
if (FLY_AT_PAGE == rNewA.GetAnchorId())
return sal_True; // Seitengebundenen wird immer ausgewichen.
// Wenn absatzgebundene Flys in einem FlyCnt gefangen sind, so
// endet deren Einflussbereich an den Grenzen des FlyCnt!
// Wenn wir aber gerade den Text des FlyCnt formatieren, dann
// muss er natuerlich dem absatzgebundenen Frm ausweichen!
// pCurrFrm ist der Anker von pNew?
// #i26945#
const SwFrm* pTmp = _pAnchoredObj->GetAnchorFrm();
if( pTmp == pCurrFrm )
return sal_True;
if( pTmp->IsTxtFrm() && ( pTmp->IsInFly() || pTmp->IsInFtn() ) )
{
// #i26945#
Point aPos = _pAnchoredObj->GetObjRect().Pos();
pTmp = GetVirtualUpper( pTmp, aPos );
}
// #i26945#
// #115759#
// If <pTmp> is a text frame inside a table, take the upper
// of the anchor frame, which contains the anchor position.
else if ( pTmp->IsTxtFrm() && pTmp->IsInTab() )
{
pTmp = const_cast<SwAnchoredObject*>(_pAnchoredObj)
->GetAnchorFrmContainingAnchPos()->GetUpper();
}
// #i28701# - consider all objects in same context,
// if wrapping style is considered on object positioning.
// Thus, text will wrap around negative positioned objects.
// #i3317# - remove condition on checking,
// if wrappings style is considered on object postioning.
// Thus, text is wrapping around negative positioned objects.
// #i35640# - no consideration of negative
// positioned objects, if wrapping style isn't considered on
// object position and former text wrapping is applied.
// This condition is typically for documents imported from the
// OpenOffice.org file format.
const IDocumentSettingAccess* pIDSA = pCurrFrm->GetTxtNode()->getIDocumentSettingAccess();
if ( ( pIDSA->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION) ||
!pIDSA->get(IDocumentSettingAccess::USE_FORMER_TEXT_WRAPPING) ) &&
::FindKontext( pTmp, 0 ) == ::FindKontext( pCurrFrm, 0 ) )
{
return sal_True;
}
const SwFrm* pHeader = 0;
if ( pCurrFrm->GetNext() != pTmp &&
( IsFrmInSameKontext( pTmp, pCurrFrm ) ||
// #i13832#, #i24135# wrap around objects in page header
( !pIDSA->get(IDocumentSettingAccess::USE_FORMER_TEXT_WRAPPING) &&
0 != ( pHeader = pTmp->FindFooterOrHeader() ) &&
!pHeader->IsFooterFrm() &&
pCurrFrm->IsInDocBody() ) ) )
{
if( pHeader || FLY_AT_FLY == rNewA.GetAnchorId() )
return sal_True;
// Compare indices:
// Den Index des anderen erhalten wir immer ueber das Ankerattr.
sal_uLong nTmpIndex = rNewA.GetCntntAnchor()->nNode.GetIndex();
// Jetzt wird noch ueberprueft, ob der aktuelle Absatz vor dem
// Anker des verdraengenden Objekts im Text steht, dann wird
// nicht ausgewichen.
// Der Index wird moeglichst ueber einen SwFmtAnchor ermittelt,
// da sonst recht teuer.
if( ULONG_MAX == nIndex )
nIndex = pCurrFrm->GetNode()->GetIndex();
if( nIndex >= nTmpIndex )
return sal_True;
}
}
}
return sal_False;
}
// #i68520#
struct AnchoredObjOrder
{
sal_Bool mbR2L;
SwRectFn mfnRect;
AnchoredObjOrder( const sal_Bool bR2L,
SwRectFn fnRect )
: mbR2L( bR2L ),
mfnRect( fnRect )
{}
bool operator()( const SwAnchoredObject* pListedAnchoredObj,
const SwAnchoredObject* pNewAnchoredObj )
{
const SwRect aBoundRectOfListedObj( pListedAnchoredObj->GetObjRectWithSpaces() );
const SwRect aBoundRectOfNewObj( pNewAnchoredObj->GetObjRectWithSpaces() );
if ( ( mbR2L &&
( (aBoundRectOfListedObj.*mfnRect->fnGetRight)() ==
(aBoundRectOfNewObj.*mfnRect->fnGetRight)() ) ) ||
( !mbR2L &&
( (aBoundRectOfListedObj.*mfnRect->fnGetLeft)() ==
(aBoundRectOfNewObj.*mfnRect->fnGetLeft)() ) ) )
{
SwTwips nTopDiff =
(*mfnRect->fnYDiff)( (aBoundRectOfNewObj.*mfnRect->fnGetTop)(),
(aBoundRectOfListedObj.*mfnRect->fnGetTop)() );
if ( nTopDiff == 0 &&
( ( mbR2L &&
( (aBoundRectOfNewObj.*mfnRect->fnGetLeft)() >
(aBoundRectOfListedObj.*mfnRect->fnGetLeft)() ) ) ||
( !mbR2L &&
( (aBoundRectOfNewObj.*mfnRect->fnGetRight)() <
(aBoundRectOfListedObj.*mfnRect->fnGetRight)() ) ) ) )
{
return true;
}
else if ( nTopDiff > 0 )
{
return true;
}
}
else if ( ( mbR2L &&
( (aBoundRectOfListedObj.*mfnRect->fnGetRight)() >
(aBoundRectOfNewObj.*mfnRect->fnGetRight)() ) ) ||
( !mbR2L &&
( (aBoundRectOfListedObj.*mfnRect->fnGetLeft)() <
(aBoundRectOfNewObj.*mfnRect->fnGetLeft)() ) ) )
{
return true;
}
return false;
}
};
// #i68520#
SwAnchoredObjList* SwTxtFly::InitAnchoredObjList()
{
OSL_ENSURE( pCurrFrm, "InitFlyList: No Frame, no FlyList" );
// #i68520#
OSL_ENSURE( !mpAnchoredObjList, "InitFlyList: FlyList already initialized" );
SWAP_IF_SWAPPED( pCurrFrm )
const SwSortedObjs *pSorted = pPage->GetSortedObjs();
const sal_uInt32 nCount = pSorted ? pSorted->Count() : 0;
// --> #108724# Page header/footer content doesn't have to wrap around
// floating screen objects
const bool bFooterHeader = 0 != pCurrFrm->FindFooterOrHeader();
const IDocumentSettingAccess* pIDSA = pCurrFrm->GetTxtNode()->getIDocumentSettingAccess();
// #i40155# - check, if frame is marked not to wrap
const sal_Bool bWrapAllowed = ( pIDSA->get(IDocumentSettingAccess::USE_FORMER_TEXT_WRAPPING) ||
( !pCurrFrm->IsInFtn() && !bFooterHeader ) );
bOn = sal_False;
if( nCount && bWrapAllowed )
{
// #i68520#
mpAnchoredObjList = new SwAnchoredObjList();
// #i28701# - consider complete frame area for new
// text wrapping
SwRect aRect;
if ( pIDSA->get(IDocumentSettingAccess::USE_FORMER_TEXT_WRAPPING) )
{
aRect = pCurrFrm->Prt();
aRect += pCurrFrm->Frm().Pos();
}
else
{
aRect = pCurrFrm->Frm();
}
// Wir machen uns etwas kleiner als wir sind,
// damit Ein-Twip-Ueberlappungen ignoriert werden. (#49532)
SWRECTFN( pCurrFrm )
const long nRight = (aRect.*fnRect->fnGetRight)() - 1;
const long nLeft = (aRect.*fnRect->fnGetLeft)() + 1;
const sal_Bool bR2L = pCurrFrm->IsRightToLeft();
const IDocumentDrawModelAccess* pIDDMA = pCurrFrm->GetTxtNode()->getIDocumentDrawModelAccess();
for( sal_uInt32 i = 0; i < nCount; i++ )
{
// #i68520#
// do not consider hidden objects
// check, if object has to be considered for text wrap
// #118809# - If requested, do not consider
// objects in page header|footer for text frames not in page
// header|footer. This is requested for the calculation of
// the base offset for objects <SwTxtFrm::CalcBaseOfstForFly()>
// #i20505# Do not consider oversized objects
SwAnchoredObject* pAnchoredObj = (*pSorted)[ i ];
if ( !pIDDMA->IsVisibleLayerId( pAnchoredObj->GetDrawObj()->GetLayer() ) ||
!pAnchoredObj->ConsiderForTextWrap() ||
( mbIgnoreObjsInHeaderFooter && !bFooterHeader &&
pAnchoredObj->GetAnchorFrm()->FindFooterOrHeader() ) )
{
continue;
}
const SwRect aBound( pAnchoredObj->GetObjRectWithSpaces() );
if ( nRight < (aBound.*fnRect->fnGetLeft)() ||
(*fnRect->fnYDiff)( (aRect.*fnRect->fnGetTop)(),
(aBound.*fnRect->fnGetBottom)() ) > 0 ||
nLeft > (aBound.*fnRect->fnGetRight)() ||
(aBound.*fnRect->fnGetHeight)() >
2 * (pPage->Frm().*fnRect->fnGetHeight)() )
{
continue;
}
// #i26945# - pass <pAnchoredObj> to method
// <GetTop(..)> instead of only the <SdrObject> instance of the
// anchored object
if ( GetTop( pAnchoredObj, pCurrFrm->IsInFtn(), bFooterHeader ) )
{
// OD 11.03.2003 #107862# - adjust insert position:
// overlapping objects should be sorted from left to right and
// inside left to right sorting from top to bottom.
// If objects on the same position are found, they are sorted
// on its width.
// #i68520#
// sal_uInt16 nPos = pFlyList->Count();
// while ( nPos )
// {
// SdrObject* pTmpObj = (*pFlyList)[ --nPos ];
// const SwRect aBoundRectOfTmpObj( GetBoundRect( pTmpObj ) );
// if ( ( bR2L &&
// ( (aBoundRectOfTmpObj.*fnRect->fnGetRight)() ==
// (aBound.*fnRect->fnGetRight)() ) ) ||
// ( !bR2L &&
// ( (aBoundRectOfTmpObj.*fnRect->fnGetLeft)() ==
// (aBound.*fnRect->fnGetLeft)() ) ) )
// {
// SwTwips nTopDiff =
// (*fnRect->fnYDiff)( (aBound.*fnRect->fnGetTop)(),
// (aBoundRectOfTmpObj.*fnRect->fnGetTop)() );
// if ( nTopDiff == 0 &&
// ( ( bR2L &&
// ( (aBound.*fnRect->fnGetLeft)() >
// (aBoundRectOfTmpObj.*fnRect->fnGetLeft)() ) ) ||
// ( !bR2L &&
// ( (aBound.*fnRect->fnGetRight)() <
// (aBoundRectOfTmpObj.*fnRect->fnGetRight)() ) ) ) )
// {
// ++nPos;
// break;
// }
// else if ( nTopDiff > 0 )
// {
// ++nPos;
// break;
// }
// }
// else if ( ( bR2L &&
// ( (aBoundRectOfTmpObj.*fnRect->fnGetRight)() >
// (aBound.*fnRect->fnGetRight)() ) ) ||
// ( !bR2L &&
// ( (aBoundRectOfTmpObj.*fnRect->fnGetLeft)() <
// (aBound.*fnRect->fnGetLeft)() ) ) )
// {
// ++nPos;
// break;
// }
// }
// SdrObject* pSdrObj = pAnchoredObj->DrawObj();
// pFlyList->C40_INSERT( SdrObject, pSdrObj, nPos );
{
SwAnchoredObjList::iterator aInsPosIter =
std::lower_bound( mpAnchoredObjList->begin(),
mpAnchoredObjList->end(),
pAnchoredObj,
AnchoredObjOrder( bR2L, fnRect ) );
mpAnchoredObjList->insert( aInsPosIter, pAnchoredObj );
}
const SwFmtSurround &rFlyFmt = pAnchoredObj->GetFrmFmt().GetSurround();
// #i68520#
if ( rFlyFmt.IsAnchorOnly() &&
pAnchoredObj->GetAnchorFrm() == GetMaster() )
{
const SwFmtVertOrient &rTmpFmt =
pAnchoredObj->GetFrmFmt().GetVertOrient();
if( text::VertOrientation::BOTTOM != rTmpFmt.GetVertOrient() )
nMinBottom = ( bVert && nMinBottom ) ?
Min( nMinBottom, aBound.Left() ) :
Max( nMinBottom, (aBound.*fnRect->fnGetBottom)() );
}
bOn = sal_True;
}
}
if( nMinBottom )
{
SwTwips nMax = (pCurrFrm->GetUpper()->*fnRect->fnGetPrtBottom)();
if( (*fnRect->fnYDiff)( nMinBottom, nMax ) > 0 )
nMinBottom = nMax;
}
}
else
{
// #i68520#
mpAnchoredObjList = new SwAnchoredObjList();
}
UNDO_SWAP( pCurrFrm )
// #i68520#
return mpAnchoredObjList;
}
SwTwips SwTxtFly::CalcMinBottom() const
{
SwTwips nRet = 0;
const SwCntntFrm *pLclMaster = GetMaster();
OSL_ENSURE(pLclMaster, "SwTxtFly without master");
const SwSortedObjs *pDrawObj = pLclMaster ? pLclMaster->GetDrawObjs() : NULL;
const sal_uInt32 nCount = pDrawObj ? pDrawObj->Count() : 0;
if( nCount )
{
SwTwips nEndOfFrm = pCurrFrm->Frm().Bottom();
for( sal_uInt32 i = 0; i < nCount; i++ )
{
SwAnchoredObject* pAnchoredObj = (*pDrawObj)[ i ];
const SwFmtSurround &rFlyFmt = pAnchoredObj->GetFrmFmt().GetSurround();
if( rFlyFmt.IsAnchorOnly() )
{
const SwFmtVertOrient &rTmpFmt =
pAnchoredObj->GetFrmFmt().GetVertOrient();
if( text::VertOrientation::BOTTOM != rTmpFmt.GetVertOrient() )
{
const SwRect aBound( pAnchoredObj->GetObjRectWithSpaces() );
if( aBound.Top() < nEndOfFrm )
nRet = Max( nRet, aBound.Bottom() );
}
}
}
SwTwips nMax = pCurrFrm->GetUpper()->Frm().Top() +
pCurrFrm->GetUpper()->Prt().Bottom();
if( nRet > nMax )
nRet = nMax;
}
return nRet;
}
/*************************************************************************
* Hier erfolgt die Berechnung der Kontur ...
* CalcBoundRect(..) und andere
*************************************************************************/
/*************************************************************************
* class SwContourCache
*************************************************************************/
SwContourCache::SwContourCache() :
nPntCnt( 0 ), nObjCnt( 0 )
{
memset( (SdrObject**)pSdrObj, 0, sizeof(pSdrObj) );
memset( pTextRanger, 0, sizeof(pTextRanger) );
}
SwContourCache::~SwContourCache()
{
for( MSHORT i = 0; i < nObjCnt; delete pTextRanger[ i++ ] )
;
}
void SwContourCache::ClrObject( MSHORT nPos )
{
OSL_ENSURE( pTextRanger[ nPos ], "ClrObject: Allready cleared. Good Bye!" );
nPntCnt -= pTextRanger[ nPos ]->GetPointCount();
delete pTextRanger[ nPos ];
--nObjCnt;
memmove( (SdrObject**)pSdrObj + nPos, pSdrObj + nPos + 1,
( nObjCnt - nPos ) * sizeof( SdrObject* ) );
memmove( pTextRanger + nPos, pTextRanger + nPos + 1,
( nObjCnt - nPos ) * sizeof( TextRanger* ) );
}
void ClrContourCache( const SdrObject *pObj )
{
if( pContourCache && pObj )
for( MSHORT i = 0; i < pContourCache->GetCount(); ++i )
if( pObj == pContourCache->GetObject( i ) )
{
pContourCache->ClrObject( i );
break;
}
}
void ClrContourCache()
{
if( pContourCache )
{
for( MSHORT i = 0; i < pContourCache->GetCount();
delete pContourCache->pTextRanger[ i++ ] )
;
pContourCache->nObjCnt = 0;
pContourCache->nPntCnt = 0;
}
}
/*************************************************************************
* SwContourCache::CalcBoundRect
* berechnet das Rechteck, welches vom Objekt in der angegebenen Zeile
* ueberdeckt wird.
* Bei _nicht_ konturumflossenen Objekten ist dies einfach die Ueber-
* lappung von BoundRect (inkl. Abstand!) und Zeile,
* bei Konturumfluss wird das Polypolygon des Objekts abgeklappert
*************************************************************************/
// #i68520#
const SwRect SwContourCache::CalcBoundRect( const SwAnchoredObject* pAnchoredObj,
const SwRect &rLine,
const SwTxtFrm* pFrm,
const long nXPos,
const sal_Bool bRight )
{
SwRect aRet;
const SwFrmFmt* pFmt = &(pAnchoredObj->GetFrmFmt());
if( pFmt->GetSurround().IsContour() &&
( !pAnchoredObj->ISA(SwFlyFrm) ||
( static_cast<const SwFlyFrm*>(pAnchoredObj)->Lower() &&
static_cast<const SwFlyFrm*>(pAnchoredObj)->Lower()->IsNoTxtFrm() ) ) )
{
aRet = pAnchoredObj->GetObjRectWithSpaces();
if( aRet.IsOver( rLine ) )
{
if( !pContourCache )
pContourCache = new SwContourCache;
aRet = pContourCache->ContourRect(
pFmt, pAnchoredObj->GetDrawObj(), pFrm, rLine, nXPos, bRight );
}
else
aRet.Width( 0 );
}
else
{
aRet = pAnchoredObj->GetObjRectWithSpaces();
}
return aRet;
}
const SwRect SwContourCache::ContourRect( const SwFmt* pFmt,
const SdrObject* pObj, const SwTxtFrm* pFrm, const SwRect &rLine,
const long nXPos, const sal_Bool bRight )
{
SwRect aRet;
MSHORT nPos = 0; // Suche im Cache ...
while( nPos < GetCount() && pObj != pSdrObj[ nPos ] )
++nPos;
if( GetCount() == nPos ) // nicht gefunden
{
if( nObjCnt == POLY_CNT )
{
nPntCnt -= pTextRanger[ --nObjCnt ]->GetPointCount();
delete pTextRanger[ nObjCnt ];
}
::basegfx::B2DPolyPolygon aPolyPolygon;
::basegfx::B2DPolyPolygon* pPolyPolygon = 0L;
if ( pObj->ISA(SwVirtFlyDrawObj) )
{
// Vorsicht #37347: Das GetContour() fuehrt zum Laden der Grafik,
// diese aendert dadurch ggf. ihre Groesse, ruft deshalb ein
// ClrObject() auf.
PolyPolygon aPoly;
if( !((SwVirtFlyDrawObj*)pObj)->GetFlyFrm()->GetContour( aPoly ) )
aPoly = PolyPolygon( ((SwVirtFlyDrawObj*)pObj)->
GetFlyFrm()->Frm().SVRect() );
aPolyPolygon.clear();
aPolyPolygon.append(aPoly.getB2DPolyPolygon());
}
else
{
if( !pObj->ISA( E3dObject ) )
{
aPolyPolygon = pObj->TakeXorPoly();
}
::basegfx::B2DPolyPolygon aContourPoly(pObj->TakeContour());
pPolyPolygon = new ::basegfx::B2DPolyPolygon(aContourPoly);
}
const SvxLRSpaceItem &rLRSpace = pFmt->GetLRSpace();
const SvxULSpaceItem &rULSpace = pFmt->GetULSpace();
memmove( pTextRanger + 1, pTextRanger, nObjCnt * sizeof( TextRanger* ) );
memmove( (SdrObject**)pSdrObj + 1, pSdrObj, nObjCnt++ * sizeof( SdrObject* ) );
pSdrObj[ 0 ] = pObj; // Wg. #37347 darf das Object erst nach dem
// GetContour() eingetragen werden.
pTextRanger[ 0 ] = new TextRanger( aPolyPolygon, pPolyPolygon, 20,
(sal_uInt16)rLRSpace.GetLeft(), (sal_uInt16)rLRSpace.GetRight(),
pFmt->GetSurround().IsOutside(), sal_False, pFrm->IsVertical() );
pTextRanger[ 0 ]->SetUpper( rULSpace.GetUpper() );
pTextRanger[ 0 ]->SetLower( rULSpace.GetLower() );
delete pPolyPolygon;
// UPPER_LOWER_TEST
#ifdef DBG_UTIL
const ViewShell* pTmpViewShell = pFmt->GetDoc()->GetCurrentViewShell();
if( pTmpViewShell )
{
sal_Bool bT2 = pTmpViewShell->GetViewOptions()->IsTest2();
sal_Bool bT6 = pTmpViewShell->GetViewOptions()->IsTest6();
if( bT2 || bT6 )
{
if( bT2 )
pTextRanger[ 0 ]->SetFlag7( sal_True );
else
pTextRanger[ 0 ]->SetFlag6( sal_True );
}
}
#endif
nPntCnt += pTextRanger[ 0 ]->GetPointCount();
while( nPntCnt > POLY_MAX && nObjCnt > POLY_MIN )
{
nPntCnt -= pTextRanger[ --nObjCnt ]->GetPointCount();
delete pTextRanger[ nObjCnt ];
}
}
else if( nPos )
{
const SdrObject* pTmpObj = pSdrObj[ nPos ];
TextRanger* pTmpRanger = pTextRanger[ nPos ];
memmove( (SdrObject**)pSdrObj + 1, pSdrObj, nPos * sizeof( SdrObject* ) );
memmove( pTextRanger + 1, pTextRanger, nPos * sizeof( TextRanger* ) );
pSdrObj[ 0 ] = pTmpObj;
pTextRanger[ 0 ] = pTmpRanger;
}
SWRECTFN( pFrm )
long nTmpTop = (rLine.*fnRect->fnGetTop)();
// fnGetBottom is top + height
long nTmpBottom = (rLine.*fnRect->fnGetBottom)();
Range aRange( Min( nTmpTop, nTmpBottom ), Max( nTmpTop, nTmpBottom ) );
LongDqPtr pTmp = pTextRanger[ 0 ]->GetTextRanges( aRange );
MSHORT nCount;
if( 0 != ( nCount = pTmp->size() ) )
{
MSHORT nIdx = 0;
while( nIdx < nCount && (*pTmp)[ nIdx ] < nXPos )
++nIdx;
sal_Bool bOdd = (nIdx % 2) ? sal_True : sal_False;
sal_Bool bSet = sal_True;
if( bOdd )
--nIdx; // innerhalb eines Intervalls
else if( ! bRight && ( nIdx >= nCount || (*pTmp)[ nIdx ] != nXPos ) )
{
if( nIdx )
nIdx -= 2; // ein Intervall nach links gehen
else
bSet = sal_False; // vor dem erstem Intervall
}
if( bSet && nIdx < nCount )
{
(aRet.*fnRect->fnSetTopAndHeight)( (rLine.*fnRect->fnGetTop)(),
(rLine.*fnRect->fnGetHeight)() );
(aRet.*fnRect->fnSetLeft)( (*pTmp)[ nIdx ] );
(aRet.*fnRect->fnSetRight)( (*pTmp)[ nIdx + 1 ] + 1 );
}
}
return aRet;
}
/*************************************************************************
* SwContourCache::ShowContour()
* zeichnet die PolyPolygone des Caches zu Debugzwecken.
*************************************************************************/
#ifdef DBG_UTIL
void SwContourCache::ShowContour( OutputDevice* pOut, const SdrObject* pObj,
const Color& rClosedColor, const Color& rOpenColor )
{
MSHORT nPos = 0; // Suche im Cache ...
while( nPos < POLY_CNT && pObj != pSdrObj[ nPos ] )
++nPos;
if( POLY_CNT != nPos )
{
const PolyPolygon* pPol = pTextRanger[ nPos ]->GetLinePolygon();
if( !pPol )
pPol = &(pTextRanger[ nPos ]->GetPolyPolygon());
for( MSHORT i = 0; i < pPol->Count(); ++i )
{
pOut->SetLineColor( rOpenColor );
const Polygon& rPol = (*pPol)[ i ];
MSHORT nCount = rPol.GetSize();
if( nCount > 1 && rPol[ 0 ] == rPol[ nCount - 1 ] )
pOut->SetLineColor( rClosedColor );
pOut->DrawPolygon( rPol );
}
static KSHORT nRadius = 0;
if( nRadius )
{
KSHORT nHalf = nRadius / 2;
Size aSz( nRadius, nRadius );
for( MSHORT i = 0; i < pPol->Count(); ++i )
{
const Polygon& rPol = (*pPol)[ i ];
MSHORT nCount = rPol.GetSize();
for( MSHORT k = 0; k < nCount; ++k )
{
Point aPt( rPol[ k ] );
aPt.X() -= nHalf;
aPt.Y() -= nHalf;
Rectangle aTmp( aPt, aSz );
pOut->DrawEllipse( aTmp );
}
}
}
}
}
#endif
/*************************************************************************
* SwTxtFly::ShowContour()
* zeichnet die PolyPolygone des Caches zu Debugzwecken.
*************************************************************************/
#ifdef DBG_UTIL
void SwTxtFly::ShowContour( OutputDevice* pOut )
{
MSHORT nFlyCount;
if( bOn && ( 0 != ( nFlyCount = static_cast<sal_uInt16>(GetAnchoredObjList()->size() ) ) ) )
{
Color aRedColor( COL_LIGHTRED );
Color aGreenColor( COL_LIGHTGREEN );
Color aSaveColor( pOut->GetLineColor() );
for( MSHORT j = 0; j < nFlyCount; ++j )
{
const SwAnchoredObject* pObj = (*mpAnchoredObjList)[ j ];
if( !pObj->GetFrmFmt().GetSurround().IsContour() )
{
Rectangle aRect = pObj->GetObjRectWithSpaces().SVRect();
pOut->DrawRect( aRect );
continue;
}
pContourCache->ShowContour( pOut, pObj->GetDrawObj(), aRedColor, aGreenColor );
}
pOut->SetLineColor( aSaveColor );
}
}
#endif
/*************************************************************************
* SwTxtFly::ForEach()
*
* sucht nach dem ersten Objekt, welches mit dem Rechteck ueberlappt
*
*************************************************************************/
sal_Bool SwTxtFly::ForEach( const SwRect &rRect, SwRect* pRect, sal_Bool bAvoid ) const
{
SWAP_IF_SWAPPED( pCurrFrm )
sal_Bool bRet = sal_False;
// #i68520#
SwAnchoredObjList::size_type nCount( bOn ? GetAnchoredObjList()->size() : 0 );
if ( bOn && nCount > 0 )
{
for( SwAnchoredObjList::size_type i = 0; i < nCount; ++i )
{
// #i68520#
const SwAnchoredObject* pAnchoredObj = (*mpAnchoredObjList)[i];
SwRect aRect( pAnchoredObj->GetObjRectWithSpaces() );
// Optimierung
SWRECTFN( pCurrFrm )
if( (aRect.*fnRect->fnGetLeft)() > (rRect.*fnRect->fnGetRight)() )
break;
// #i68520#
if ( mpCurrAnchoredObj != pAnchoredObj && aRect.IsOver( rRect ) )
{
// #i68520#
const SwFmt* pFmt( &(pAnchoredObj->GetFrmFmt()) );
const SwFmtSurround &rSur = pFmt->GetSurround();
if( bAvoid )
{
// Wenn der Text drunter durchlaeuft, bleibt die
// Formatierung unbeeinflusst. Im LineIter::DrawText()
// muessen "nur" geschickt die ClippingRegions gesetzt werden ...
const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
if( ( SURROUND_THROUGHT == rSur.GetSurround() &&
( !rSur.IsAnchorOnly() ||
// #i68520#
GetMaster() == pAnchoredObj->GetAnchorFrm() ||
((FLY_AT_PARA != rAnchor.GetAnchorId()) &&
(FLY_AT_CHAR != rAnchor.GetAnchorId())) ) )
|| aRect.Top() == WEIT_WECH )
continue;
}
// #i58642#
// Compare <GetMaster()> instead of <pCurrFrm> with the anchor
// frame of the anchored object, because a follow frame have
// to ignore the anchored objects of its master frame.
// Note: Anchored objects are always registered at the master
// frame, exception are as-character anchored objects,
// but these aren't handled here.
// #i68520#
if ( mbIgnoreCurrentFrame &&
GetMaster() == pAnchoredObj->GetAnchorFrm() )
continue;
if( pRect )
{
// #i68520#
SwRect aFly = AnchoredObjToRect( pAnchoredObj, rRect );
if( aFly.IsEmpty() || !aFly.IsOver( rRect ) )
continue;
if( !bRet || (
( !pCurrFrm->IsRightToLeft() &&
( (aFly.*fnRect->fnGetLeft)() <
(pRect->*fnRect->fnGetLeft)() ) ) ||
( pCurrFrm->IsRightToLeft() &&
( (aFly.*fnRect->fnGetRight)() >
(pRect->*fnRect->fnGetRight)() ) ) ) )
*pRect = aFly;
if( rSur.IsContour() )
{
bRet = sal_True;
continue;
}
}
bRet = sal_True;
break;
}
}
}
UNDO_SWAP( pCurrFrm )
return bRet;
}
/*************************************************************************
* SwTxtFly::GetPos()
*
* liefert die Position im sorted Array zurueck
*************************************************************************/
// #i68520#
SwAnchoredObjList::size_type SwTxtFly::GetPos( const SwAnchoredObject* pAnchoredObj ) const
{
SwAnchoredObjList::size_type nCount = GetAnchoredObjList()->size();
SwAnchoredObjList::size_type nRet = 0;
while ( nRet < nCount && pAnchoredObj != (*mpAnchoredObjList)[ nRet ] )
++nRet;
return nRet;
}
/*************************************************************************
* SwTxtFly::CalcRightMargin()
*
* pObj ist das Object, der uns gerade ueberlappt.
* pCurrFrm ist der aktuelle Textframe, der ueberlappt wird.
* Der rechte Rand ist der rechte Rand oder
* er wird durch das naechste Object, welches in die Zeile ragt, bestimmt.
*************************************************************************/
// #i68520#
void SwTxtFly::CalcRightMargin( SwRect &rFly,
SwAnchoredObjList::size_type nFlyPos,
const SwRect &rLine ) const
{
// Normalerweise ist der rechte Rand der rechte Rand der Printarea.
OSL_ENSURE( ! pCurrFrm->IsVertical() || ! pCurrFrm->IsSwapped(),
"SwTxtFly::CalcRightMargin with swapped frame" );
SWRECTFN( pCurrFrm )
// #118796# - correct determination of right of printing area
SwTwips nRight = (pCurrFrm->*fnRect->fnGetPrtRight)();
SwTwips nFlyRight = (rFly.*fnRect->fnGetRight)();
SwRect aLine( rLine );
(aLine.*fnRect->fnSetRight)( nRight );
(aLine.*fnRect->fnSetLeft)( (rFly.*fnRect->fnGetLeft)() );
// Es koennte aber sein, dass in die gleiche Zeile noch ein anderes
// Object hineinragt, welches _ueber_ uns liegt.
// Wunder der Technik: Flys mit Durchlauf sind fuer die darunterliegenden
// unsichtbar, das heisst, dass sie bei der Berechnung der Raender
// anderer Flys ebenfalls nicht auffallen.
// 3301: pNext->Frm().IsOver( rLine ) ist noetig
// #i68520#
SwSurround eSurroundForTextWrap;
sal_Bool bStop = sal_False;
// #i68520#
SwAnchoredObjList::size_type nPos = 0;
// #i68520#
while( nPos < mpAnchoredObjList->size() && !bStop )
{
if( nPos == nFlyPos )
{
++nPos;
continue;
}
// #i68520#
const SwAnchoredObject* pNext = (*mpAnchoredObjList)[ nPos++ ];
if ( pNext == mpCurrAnchoredObj )
continue;
eSurroundForTextWrap = _GetSurroundForTextWrap( pNext );
if( SURROUND_THROUGHT == eSurroundForTextWrap )
continue;
const SwRect aTmp( SwContourCache::CalcBoundRect
( pNext, aLine, pCurrFrm, nFlyRight, sal_True ) );
SwTwips nTmpRight = (aTmp.*fnRect->fnGetRight)();
// Optimierung:
// In nNextTop wird notiert, an welcher Y-Positon mit Aenderung der
// Rahmenverhaeltnisse gerechnet werden muss. Dies dient dazu, dass,
// obwohl nur die Rahmen in der aktuellen Zeilenhoehe betrachtet werden,
// bei Rahmen ohne Umlauf die Zeilenhoehe so erhoeht wird, dass mit einer
// einzigen Zeile die Unterkante das Rahmens oder ggf. die Oberkante des
// naechsten Rahmen erreicht wird.
// Insbesondere bei HTML-Dokumenten kommen oft (Dummy-)Absaetze in einer
// 2-Pt.-Schrift vor, bis diese einem groesseren Rahmen ausgewichen sind,
// erforderte es frueher Unmengen von Leerzeilen.
const long nTmpTop = (aTmp.*fnRect->fnGetTop)();
if( (*fnRect->fnYDiff)( nTmpTop, (aLine.*fnRect->fnGetTop)() ) > 0 )
{
if( (*fnRect->fnYDiff)( nNextTop, nTmpTop ) > 0 )
SetNextTop( nTmpTop ); // Die Oberkante des "naechsten" Rahmens
}
else if( ! (aTmp.*fnRect->fnGetWidth)() ) // Typisch fuer Objekte mit Konturumlauf
{ // Bei Objekten mit Konturumlauf, die vor der aktuellen Zeile beginnen
// und hinter ihr enden, trotzdem aber nicht mit ihr ueberlappen,
// muss die Optimierung ausgeschaltet werden, denn bereits in der
// naechsten Zeile kann sich dies aendern.
if( ! (aTmp.*fnRect->fnGetHeight)() ||
(*fnRect->fnYDiff)( (aTmp.*fnRect->fnGetBottom)(),
(aLine.*fnRect->fnGetTop)() ) > 0 )
SetNextTop( 0 );
}
if( aTmp.IsOver( aLine ) && nTmpRight > nFlyRight )
{
nFlyRight = nTmpRight;
if( SURROUND_RIGHT == eSurroundForTextWrap ||
SURROUND_PARALLEL == eSurroundForTextWrap )
{
// der FlyFrm wird ueberstimmt.
if( nRight > nFlyRight )
nRight = nFlyRight;
bStop = sal_True;
}
}
}
(rFly.*fnRect->fnSetRight)( nRight );
}
/*************************************************************************
* SwTxtFly::CalcLeftMargin()
*
* pFly ist der FlyFrm, der uns gerade ueberlappt.
* pCurrFrm ist der aktuelle Textframe, der ueberlappt wird.
* Der linke Rand ist der linke Rand der aktuellen PrintArea oder
* er wird durch den vorigen FlyFrm, der in die Zeile ragt, bestimmt.
*************************************************************************/
// #i68520#
void SwTxtFly::CalcLeftMargin( SwRect &rFly,
SwAnchoredObjList::size_type nFlyPos,
const SwRect &rLine ) const
{
OSL_ENSURE( ! pCurrFrm->IsVertical() || ! pCurrFrm->IsSwapped(),
"SwTxtFly::CalcLeftMargin with swapped frame" );
SWRECTFN( pCurrFrm )
// #118796# - correct determination of left of printing area
SwTwips nLeft = (pCurrFrm->*fnRect->fnGetPrtLeft)();
const SwTwips nFlyLeft = (rFly.*fnRect->fnGetLeft)();
if( nLeft > nFlyLeft )
nLeft = rFly.Left();
SwRect aLine( rLine );
(aLine.*fnRect->fnSetLeft)( nLeft );
// Es koennte aber sein, dass in die gleiche Zeile noch ein anderes
// Object hineinragt, welches _ueber_ uns liegt.
// Wunder der Technik: Flys mit Durchlauf sind fuer die darunterliegenden
// unsichtbar, das heisst, dass sie bei der Berechnung der Raender
// anderer Flys ebenfalls nicht auffallen.
// 3301: pNext->Frm().IsOver( rLine ) ist noetig
// #i68520#
SwAnchoredObjList::size_type nMyPos = nFlyPos;
while( ++nFlyPos < mpAnchoredObjList->size() )
{
// #i68520#
const SwAnchoredObject* pNext = (*mpAnchoredObjList)[ nFlyPos ];
const SwRect aTmp( pNext->GetObjRectWithSpaces() );
if( (aTmp.*fnRect->fnGetLeft)() >= nFlyLeft )
break;
}
while( nFlyPos )
{
if( --nFlyPos == nMyPos )
continue;
// #i68520#
const SwAnchoredObject* pNext = (*mpAnchoredObjList)[ nFlyPos ];
if( pNext == mpCurrAnchoredObj )
continue;
SwSurround eSurroundForTextWrap = _GetSurroundForTextWrap( pNext );
if( SURROUND_THROUGHT == eSurroundForTextWrap )
continue;
const SwRect aTmp( SwContourCache::CalcBoundRect
( pNext, aLine, pCurrFrm, nFlyLeft, sal_False ) );
if( (aTmp.*fnRect->fnGetLeft)() < nFlyLeft && aTmp.IsOver( aLine ) )
{
// #118796# - no '+1', because <..fnGetRight>
// returns the correct value.
SwTwips nTmpRight = (aTmp.*fnRect->fnGetRight)();
if ( nLeft <= nTmpRight )
nLeft = nTmpRight;
break;
}
}
(rFly.*fnRect->fnSetLeft)( nLeft );
}
/*************************************************************************
* SwTxtFly::FlyToRect()
*
* IN: dokumentglobal (rRect)
* OUT: dokumentglobal (return-Wert)
* Liefert zu einem SwFlyFrm das von ihm in Anspruch genommene Rechteck
* unter Beruecksichtigung der eingestellten Attribute fuer den Abstand
* zum Text zurueck.
*************************************************************************/
// #i68520#
SwRect SwTxtFly::AnchoredObjToRect( const SwAnchoredObject* pAnchoredObj,
const SwRect &rLine ) const
{
SWRECTFN( pCurrFrm )
const long nXPos = pCurrFrm->IsRightToLeft() ?
rLine.Right() :
(rLine.*fnRect->fnGetLeft)();
SwRect aFly = mbIgnoreContour ?
pAnchoredObj->GetObjRectWithSpaces() :
SwContourCache::CalcBoundRect( pAnchoredObj, rLine, pCurrFrm,
nXPos, ! pCurrFrm->IsRightToLeft() );
if( !aFly.Width() )
return aFly;
SetNextTop( (aFly.*fnRect->fnGetBottom)() ); // Damit die Zeile ggf. bis zur Unterkante
// des Rahmens waechst.
SwAnchoredObjList::size_type nFlyPos = GetPos( pAnchoredObj );
// Bei LEFT und RIGHT vergroessern wir das Rechteck.
// Hier gibt es einige Probleme, wenn mehrere Frames zu sehen sind.
// Zur Zeit wird nur der einfachste Fall angenommen:
// LEFT bedeutet, dass der Text links vom Frame fliessen soll,
// d.h. der Frame blaeht sich bis zum rechten Rand der Printarea
// oder bis zum naechsten Frame auf.
// Bei RIGHT ist es umgekehrt.
// Ansonsten wird immer der eingestellte Abstand zwischen Text
// und Frame aufaddiert.
switch( _GetSurroundForTextWrap( pAnchoredObj ) )
{
case SURROUND_LEFT :
{
CalcRightMargin( aFly, nFlyPos, rLine );
break;
}
case SURROUND_RIGHT :
{
CalcLeftMargin( aFly, nFlyPos, rLine );
break;
}
case SURROUND_NONE :
{
CalcRightMargin( aFly, nFlyPos, rLine );
CalcLeftMargin( aFly, nFlyPos, rLine );
break;
}
default:
break;
}
return aFly;
}
// #i68520#
// new method <_GetSurroundForTextWrap(..)> replaces methods
// <CalcSmart(..)> and <GetOrder(..)>
/*************************************************************************
* SwTxtFly::CalcSmart()
*
* CalcSmart() liefert die Umlaufform zurueck.
*
* Auf beiden Seiten ist weniger als 2 cm Platz fuer den Text
* => kein Umlauf ( SURROUND_NONE )
* Auf genau einer Seite ist mehr als 2 cm Platz
* => Umlauf auf dieser Seite ( SURROUND_LEFT / SURROUND_RIGHT )
* Auf beiden Seiten ist mehr als 2 cm Platz, das Objekt ist breiter als 1,5 cm
* => Umlauf auf der breiteren Seite ( SURROUND_LEFT / SURROUND_RIGHT )
* Auf beiden Seiten ist mehr als 2 cm Platz, das Objekt ist schmaler als 1,5 cm
* => beidseitiger Umlauf ( SURROUND_PARALLEL )
*
*************************************************************************/
// Umfluss nur auf Seiten mit mindestens 2 cm Platz fuer den Text
#define TEXT_MIN 1134
// Beidseitiger Umfluss bis zu einer Rahmenbreite von maximal 1,5 cm
#define FRAME_MAX 850
SwSurround SwTxtFly::_GetSurroundForTextWrap( const SwAnchoredObject* pAnchoredObj ) const
{
const SwFrmFmt* pFmt = &(pAnchoredObj->GetFrmFmt());
const SwFmtSurround &rFlyFmt = pFmt->GetSurround();
SwSurround eSurroundForTextWrap = rFlyFmt.GetSurround();
if( rFlyFmt.IsAnchorOnly() && pAnchoredObj->GetAnchorFrm() != GetMaster() )
{
const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
if ((FLY_AT_PARA == rAnchor.GetAnchorId()) ||
(FLY_AT_CHAR == rAnchor.GetAnchorId()))
{
return SURROUND_NONE;
}
}
// Beim Durchlauf und Nowrap wird smart ignoriert.
if( SURROUND_THROUGHT == eSurroundForTextWrap ||
SURROUND_NONE == eSurroundForTextWrap )
return eSurroundForTextWrap;
// left is left and right is right
if ( pCurrFrm->IsRightToLeft() )
{
if ( SURROUND_LEFT == eSurroundForTextWrap )
eSurroundForTextWrap = SURROUND_RIGHT;
else if ( SURROUND_RIGHT == eSurroundForTextWrap )
eSurroundForTextWrap = SURROUND_LEFT;
}
// "idealer Seitenumlauf":
if ( SURROUND_IDEAL == eSurroundForTextWrap )
{
SWRECTFN( pCurrFrm )
const long nCurrLeft = (pCurrFrm->*fnRect->fnGetPrtLeft)();
const long nCurrRight = (pCurrFrm->*fnRect->fnGetPrtRight)();
const SwRect aRect( pAnchoredObj->GetObjRectWithSpaces() );
long nFlyLeft = (aRect.*fnRect->fnGetLeft)();
long nFlyRight = (aRect.*fnRect->fnGetRight)();
if ( nFlyRight < nCurrLeft || nFlyLeft > nCurrRight )
eSurroundForTextWrap = SURROUND_PARALLEL;
else
{
long nLeft = nFlyLeft - nCurrLeft;
long nRight = nCurrRight - nFlyRight;
if( nFlyRight - nFlyLeft > FRAME_MAX )
{
if( nLeft < nRight )
nLeft = 0;
else
nRight = 0;
}
if( nLeft < TEXT_MIN )
nLeft = 0;
if( nRight < TEXT_MIN )
nRight = 0;
if( nLeft )
eSurroundForTextWrap = nRight ? SURROUND_PARALLEL : SURROUND_LEFT;
else
eSurroundForTextWrap = nRight ? SURROUND_RIGHT: SURROUND_NONE;
}
}
return eSurroundForTextWrap;
}
/*************************************************************************
* SwTxtFly::IsAnyFrm( SwRect )
*
* IN: dokumentglobal
*
* dient zum Abschalten des SwTxtFly, wenn keine Objekte ueberlappen (Relax)
*
*************************************************************************/
sal_Bool SwTxtFly::IsAnyFrm( const SwRect &rLine ) const
{
SWAP_IF_SWAPPED( pCurrFrm )
OSL_ENSURE( bOn, "IsAnyFrm: Why?" );
const sal_Bool bRet = ForEach( rLine, NULL, sal_False );
UNDO_SWAP( pCurrFrm )
return bRet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|