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
|
/* -*- 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 "hintids.hxx"
#include <svl/itemiter.hxx>
#include <svl/whiter.hxx>
#include <svl/urihelper.hxx>
#include <i18npool/mslangid.hxx>
#include <sfx2/docfile.hxx>
#include <vcl/svapp.hxx>
#include <editeng/fhgtitem.hxx>
#include <editeng/brshitem.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/ulspitem.hxx>
#include <editeng/boxitem.hxx>
#include <editeng/flstitem.hxx>
#include <editeng/brkitem.hxx>
#include <editeng/keepitem.hxx>
#include <editeng/fontitem.hxx>
#include <editeng/langitem.hxx>
#include <editeng/frmdiritem.hxx>
#include <svtools/htmltokn.h>
#include <svtools/htmlkywd.hxx>
#include <fmtpdsc.hxx>
#include <fmtanchr.hxx>
#include <fmtornt.hxx>
#include <fmtsrnd.hxx>
#include <fmtfsize.hxx>
#include "frmatr.hxx"
#include <charfmt.hxx>
#include <docary.hxx>
#include <svx/svxids.hrc>
#include "doc.hxx"
#include "pam.hxx"
#include "ndtxt.hxx"
#include "poolfmt.hxx"
#include "docsh.hxx"
#include "paratr.hxx"
#include "pagedesc.hxx"
#include "css1kywd.hxx"
#include "swcss1.hxx"
#include "htmlnum.hxx"
#include "swhtml.hxx"
#include <numrule.hxx>
using namespace ::com::sun::star;
// Wie viele Zeilen/Zeichen sind fuer DropCaps erlaubt?
// (Gibt es vielleicht woanders entsprechende Werte?)
#define MAX_DROPCAP_LINES 9
#define MAX_DROPCAP_CHARS 9
void lcl_swcss1_setEncoding( SwFmt& rFmt, rtl_TextEncoding eEnc );
// Implementierung des SwCSS1Parsers (eigentlich swcss1.cxx)
static struct SwCSS1ItemIds
{
sal_uInt16 nFmtBreak;
sal_uInt16 nFmtPageDesc;
sal_uInt16 nFmtKeep;
SwCSS1ItemIds() :
nFmtBreak( RES_BREAK ),
nFmtPageDesc( RES_PAGEDESC ),
nFmtKeep( RES_KEEP )
{}
} aItemIds;
void SwCSS1Parser::ChgPageDesc( const SwPageDesc *pPageDesc,
const SwPageDesc& rNewPageDesc )
{
sal_uInt16 nPageDescs = pDoc->GetPageDescCnt();
sal_uInt16 i;
for( i=0; i<nPageDescs; i++ )
if( pPageDesc == &(const_cast<const SwDoc *>(pDoc)->GetPageDesc(i)) )
{
pDoc->ChgPageDesc( i, rNewPageDesc );
return;
}
OSL_ENSURE( i<nPageDescs, "Seitenvorlage nicht gefunden" );
}
SwCSS1Parser::SwCSS1Parser( SwDoc *pD, sal_uInt32 aFHeights[7], const String& rBaseURL, sal_Bool bNewDoc ) :
SvxCSS1Parser( pD->GetAttrPool(), rBaseURL, MM50/2,
(sal_uInt16*)&aItemIds, sizeof(aItemIds) / sizeof(sal_uInt16) ),
pDoc( pD ),
nDropCapCnt( 0 ),
bIsNewDoc( bNewDoc ),
bBodyBGColorSet( sal_False ),
bBodyBackgroundSet( sal_False ),
bBodyTextSet( sal_False ),
bBodyLinkSet( sal_False ),
bBodyVLinkSet( sal_False ),
bSetFirstPageDesc( sal_False ),
bSetRightPageDesc( sal_False ),
bTableHeaderTxtCollSet( sal_False ),
bTableTxtCollSet( sal_False ),
bLinkCharFmtsSet( sal_False )
{
aFontHeights[0] = aFHeights[0];
aFontHeights[1] = aFHeights[1];
aFontHeights[2] = aFHeights[2];
aFontHeights[3] = aFHeights[3];
aFontHeights[4] = aFHeights[4];
aFontHeights[5] = aFHeights[5];
aFontHeights[6] = aFHeights[6];
}
SwCSS1Parser::~SwCSS1Parser()
{
}
// Feature: PrintExt
sal_Bool SwCSS1Parser::SetFmtBreak( SfxItemSet& rItemSet,
const SvxCSS1PropertyInfo& rPropInfo )
{
SvxBreak eBreak = SVX_BREAK_NONE;
sal_Bool bKeep = sal_False;
sal_Bool bSetKeep = sal_False, bSetBreak = sal_False, bSetPageDesc = sal_False;
const SwPageDesc *pPageDesc = 0;
switch( rPropInfo.ePageBreakBefore )
{
case SVX_CSS1_PBREAK_ALWAYS:
eBreak = SVX_BREAK_PAGE_BEFORE;
bSetBreak = sal_True;
break;
case SVX_CSS1_PBREAK_LEFT:
pPageDesc = GetLeftPageDesc( sal_True );
bSetPageDesc = sal_True;
break;
case SVX_CSS1_PBREAK_RIGHT:
pPageDesc = GetRightPageDesc( sal_True );
bSetPageDesc = sal_True;
break;
case SVX_CSS1_PBREAK_AUTO:
bSetBreak = bSetPageDesc = sal_True;
break;
default:
;
}
switch( rPropInfo.ePageBreakAfter )
{
case SVX_CSS1_PBREAK_ALWAYS:
case SVX_CSS1_PBREAK_LEFT:
case SVX_CSS1_PBREAK_RIGHT:
// LEFT/RIGHT koennte man auch am Absatz davor setzen
eBreak = SVX_BREAK_PAGE_AFTER;
bSetBreak = sal_True;
break;
case SVX_CSS1_PBREAK_AUTO:
bSetBreak = bSetKeep = bSetPageDesc = sal_True;
break;
case SVX_CSS1_PBREAK_AVOID:
bKeep = bSetKeep = sal_True;
break;
default:
;
}
if( bSetBreak )
rItemSet.Put( SvxFmtBreakItem( eBreak, RES_BREAK ) );
if( bSetPageDesc )
rItemSet.Put( SwFmtPageDesc( pPageDesc ) );
if( bSetKeep )
rItemSet.Put( SvxFmtKeepItem( bKeep, RES_KEEP ) );
return bSetBreak;
}
// /Feature: PrintExt
static void SetCharFmtAttrs( SwCharFmt *pCharFmt, SfxItemSet& rItemSet )
{
const SfxPoolItem *pItem;
static sal_uInt16 aWhichIds[3] = { RES_CHRATR_FONTSIZE,RES_CHRATR_CJK_FONTSIZE,
RES_CHRATR_CTL_FONTSIZE };
for( sal_uInt16 i=0; i<3; i++ )
{
if( SFX_ITEM_SET == rItemSet.GetItemState( aWhichIds[i], sal_False,
&pItem ) &&
((const SvxFontHeightItem *)pItem)->GetProp() != 100)
{
// %-Angaben beim FontHeight-Item werden nicht unterstuetzt
rItemSet.ClearItem( aWhichIds[i] );
}
}
pCharFmt->SetFmtAttr( rItemSet );
if( SFX_ITEM_SET == rItemSet.GetItemState( RES_BACKGROUND, sal_False, &pItem ) )
{
// Ein Brush-Item mit RES_BACKGROUND muss noch in eines mit
// RES_CHRATR_BACKGROUND gewandelt werden
SvxBrushItem aBrushItem( *(const SvxBrushItem *)pItem );
aBrushItem.SetWhich( RES_CHRATR_BACKGROUND );
pCharFmt->SetFmtAttr( aBrushItem );
}
}
void SwCSS1Parser::SetLinkCharFmts()
{
OSL_ENSURE( !bLinkCharFmtsSet, "Aufruf von SetLinkCharFmts unnoetig" );
SvxCSS1MapEntry *pStyleEntry =
GetTag( String::CreateFromAscii(OOO_STRING_SVTOOLS_HTML_anchor) );
SwCharFmt *pUnvisited = 0, *pVisited = 0;
if( pStyleEntry )
{
SfxItemSet& rItemSet = pStyleEntry->GetItemSet();
sal_Bool bColorSet = (SFX_ITEM_SET==rItemSet.GetItemState(RES_CHRATR_COLOR,
sal_False));
pUnvisited = GetCharFmtFromPool( RES_POOLCHR_INET_NORMAL );
SetCharFmtAttrs( pUnvisited, rItemSet );
bBodyLinkSet |= bColorSet;
pVisited = GetCharFmtFromPool( RES_POOLCHR_INET_VISIT );
SetCharFmtAttrs( pVisited, rItemSet );
bBodyVLinkSet |= bColorSet;
}
String sTmp( String::CreateFromAscii(OOO_STRING_SVTOOLS_HTML_anchor) );
sTmp.Append( ':' );
sTmp.AppendAscii( sCSS1_link );
pStyleEntry = GetTag( sTmp );
if( pStyleEntry )
{
SfxItemSet& rItemSet = pStyleEntry->GetItemSet();
sal_Bool bColorSet = (SFX_ITEM_SET==rItemSet.GetItemState(RES_CHRATR_COLOR,
sal_False));
if( !pUnvisited )
pUnvisited = GetCharFmtFromPool( RES_POOLCHR_INET_NORMAL );
SetCharFmtAttrs( pUnvisited, rItemSet );
bBodyLinkSet |= bColorSet;
}
sTmp.AssignAscii( OOO_STRING_SVTOOLS_HTML_anchor );
sTmp.Assign( ':' );
sTmp.AppendAscii( sCSS1_visited );
pStyleEntry = GetTag( sTmp );
if( pStyleEntry )
{
SfxItemSet& rItemSet = pStyleEntry->GetItemSet();
sal_Bool bColorSet = (SFX_ITEM_SET==rItemSet.GetItemState(RES_CHRATR_COLOR,
sal_False));
if( !pVisited )
pVisited = GetCharFmtFromPool( RES_POOLCHR_INET_VISIT );
SetCharFmtAttrs( pVisited, rItemSet );
bBodyVLinkSet |= bColorSet;
}
bLinkCharFmtsSet = sal_True;
}
static void SetTxtCollAttrs( SwTxtFmtColl *pColl, SfxItemSet& rItemSet,
SvxCSS1PropertyInfo& rPropInfo,
SwCSS1Parser *pCSS1Parser )
{
const SfxItemSet& rCollItemSet = pColl->GetAttrSet();
const SfxPoolItem *pCollItem, *pItem;
// linker, rechter Rand und Erstzeilen-Einzug
if( (rPropInfo.bLeftMargin || rPropInfo.bRightMargin ||
rPropInfo.bTextIndent) &&
(!rPropInfo.bLeftMargin || !rPropInfo.bRightMargin ||
!rPropInfo.bTextIndent) &&
SFX_ITEM_SET == rCollItemSet.GetItemState(RES_LR_SPACE,sal_True,&pCollItem) &&
SFX_ITEM_SET == rItemSet.GetItemState(RES_LR_SPACE,sal_False,&pItem) )
{
const SvxLRSpaceItem *pLRItem = (const SvxLRSpaceItem *)pItem;
SvxLRSpaceItem aLRItem( *((const SvxLRSpaceItem *)pCollItem) );
if( rPropInfo.bLeftMargin )
aLRItem.SetTxtLeft( pLRItem->GetTxtLeft() );
if( rPropInfo.bRightMargin )
aLRItem.SetRight( pLRItem->GetRight() );
if( rPropInfo.bTextIndent )
aLRItem.SetTxtFirstLineOfst( pLRItem->GetTxtFirstLineOfst() );
rItemSet.Put( aLRItem );
}
// oberer und unterer Rand
if( (rPropInfo.bTopMargin || rPropInfo.bBottomMargin) &&
(!rPropInfo.bTopMargin || !rPropInfo.bBottomMargin) &&
SFX_ITEM_SET == rCollItemSet.GetItemState(RES_UL_SPACE,sal_True,
&pCollItem) &&
SFX_ITEM_SET == rItemSet.GetItemState(RES_UL_SPACE,sal_False,&pItem) )
{
const SvxULSpaceItem *pULItem = (const SvxULSpaceItem *)pItem;
SvxULSpaceItem aULItem( *((const SvxULSpaceItem *)pCollItem) );
if( rPropInfo.bTopMargin )
aULItem.SetUpper( pULItem->GetUpper() );
if( rPropInfo.bBottomMargin )
aULItem.SetLower( pULItem->GetLower() );
rItemSet.Put( aULItem );
}
static sal_uInt16 aWhichIds[3] = { RES_CHRATR_FONTSIZE,RES_CHRATR_CJK_FONTSIZE,
RES_CHRATR_CTL_FONTSIZE };
for( sal_uInt16 i=0; i<3; i++ )
{
if( SFX_ITEM_SET == rItemSet.GetItemState( aWhichIds[i], sal_False,
&pItem ) &&
((const SvxFontHeightItem *)pItem)->GetProp() != 100)
{
// %-Angaben beim FontHeight-Item werden nicht unterstuetzt
rItemSet.ClearItem( aWhichIds[i] );
}
}
// Feature: PrintExt
pCSS1Parser->SetFmtBreak( rItemSet, rPropInfo );
// /Feature: PrintExt
pColl->SetFmtAttr( rItemSet );
}
void SwCSS1Parser::SetTableTxtColl( sal_Bool bHeader )
{
OSL_ENSURE( !(bHeader ? bTableHeaderTxtCollSet : bTableTxtCollSet),
"Aufruf von SetTableTxtColl unnoetig" );
sal_uInt16 nPoolId;
String sTag;
if( bHeader )
{
nPoolId = RES_POOLCOLL_TABLE_HDLN;
sTag.AssignAscii( OOO_STRING_SVTOOLS_HTML_tableheader );
}
else
{
nPoolId = RES_POOLCOLL_TABLE;
sTag.AssignAscii( OOO_STRING_SVTOOLS_HTML_tabledata );
}
SwTxtFmtColl *pColl = 0;
// The following entries will never be used again and may be changed.
SvxCSS1MapEntry *pStyleEntry = GetTag( sTag );
if( pStyleEntry )
{
pColl = GetTxtFmtColl( nPoolId, aEmptyStr );
SetTxtCollAttrs( pColl, pStyleEntry->GetItemSet(),
pStyleEntry->GetPropertyInfo(), this );
}
String sTmp( sTag );
sTmp.Append( ' ' );
sTmp.AppendAscii( OOO_STRING_SVTOOLS_HTML_parabreak );
pStyleEntry = GetTag( sTmp );
if( pStyleEntry )
{
if( !pColl )
pColl = GetTxtFmtColl( nPoolId, aEmptyStr );
SetTxtCollAttrs( pColl, pStyleEntry->GetItemSet(),
pStyleEntry->GetPropertyInfo(), this );
}
if( bHeader )
bTableHeaderTxtCollSet = sal_True;
else
bTableTxtCollSet = sal_True;
}
void SwCSS1Parser::SetPageDescAttrs( const SvxBrushItem *pBrush,
SfxItemSet *pItemSet2 )
{
SvxBrushItem aBrushItem( RES_BACKGROUND );
SvxBoxItem aBoxItem( RES_BOX );
SvxFrameDirectionItem aFrmDirItem(FRMDIR_ENVIRONMENT, RES_FRAMEDIR);
sal_Bool bSetBrush = pBrush!=0, bSetBox = sal_False, bSetFrmDir = sal_False;
if( pBrush )
aBrushItem = *pBrush;
if( pItemSet2 )
{
const SfxPoolItem *pItem = 0;
if( SFX_ITEM_SET == pItemSet2->GetItemState( RES_BACKGROUND, sal_False,
&pItem ) )
{
// ein Hintergrund wird gesetzt
aBrushItem = *((const SvxBrushItem *)pItem);
pItemSet2->ClearItem( RES_BACKGROUND );
bSetBrush = sal_True;
}
if( SFX_ITEM_SET == pItemSet2->GetItemState( RES_BOX, sal_False, &pItem ) )
{
// eine Umrandung wird gesetzt
aBoxItem = *((const SvxBoxItem *)pItem);
pItemSet2->ClearItem( RES_BOX );
bSetBox = sal_True;
}
if( SFX_ITEM_SET == pItemSet2->GetItemState( RES_BOX, sal_False, &pItem ) )
{
// eine Umrandung wird gesetzt
aBoxItem = *((const SvxBoxItem *)pItem);
pItemSet2->ClearItem( RES_BOX );
bSetBox = sal_True;
}
if( SFX_ITEM_SET == pItemSet2->GetItemState( RES_FRAMEDIR, sal_False, &pItem ) )
{
// eine Umrandung wird gesetzt
aFrmDirItem = *static_cast< const SvxFrameDirectionItem *>( pItem );
pItemSet2->ClearItem( RES_FRAMEDIR );
bSetFrmDir = sal_True;
}
}
if( bSetBrush || bSetBox || bSetFrmDir )
{
static sal_uInt16 aPoolIds[] = { RES_POOLPAGE_HTML, RES_POOLPAGE_FIRST,
RES_POOLPAGE_LEFT, RES_POOLPAGE_RIGHT };
for( sal_uInt16 i=0; i<4; i++ )
{
const SwPageDesc *pPageDesc = GetPageDesc( aPoolIds[i], sal_False );
if( pPageDesc )
{
SwPageDesc aNewPageDesc( *pPageDesc );
SwFrmFmt &rMaster = aNewPageDesc.GetMaster();
if( bSetBrush )
rMaster.SetFmtAttr( aBrushItem );
if( bSetBox )
rMaster.SetFmtAttr( aBoxItem );
if( bSetFrmDir )
rMaster.SetFmtAttr( aFrmDirItem );
ChgPageDesc( pPageDesc, aNewPageDesc );
}
}
}
}
// Feature: PrintExt
void SwCSS1Parser::SetPageDescAttrs( const SwPageDesc *pPageDesc,
SfxItemSet& rItemSet,
const SvxCSS1PropertyInfo& rPropInfo )
{
if( !pPageDesc )
return;
SwPageDesc aNewPageDesc( *pPageDesc );
SwFrmFmt &rMaster = aNewPageDesc.GetMaster();
const SfxItemSet& rPageItemSet = rMaster.GetAttrSet();
const SfxPoolItem *pPageItem, *pItem;
sal_Bool bChanged = sal_False;
// linker, rechter Rand und Erstzeilen-Einzug
if( (rPropInfo.bLeftMargin || rPropInfo.bRightMargin) &&
SFX_ITEM_SET == rItemSet.GetItemState(RES_LR_SPACE,sal_False,&pItem) )
{
if( (!rPropInfo.bLeftMargin || !rPropInfo.bRightMargin) &&
SFX_ITEM_SET == rPageItemSet.GetItemState(RES_LR_SPACE,
sal_True,&pPageItem) )
{
const SvxLRSpaceItem *pLRItem = (const SvxLRSpaceItem *)pItem;
SvxLRSpaceItem aLRItem( *((const SvxLRSpaceItem *)pPageItem) );
if( rPropInfo.bLeftMargin )
aLRItem.SetLeft( pLRItem->GetLeft() );
if( rPropInfo.bRightMargin )
aLRItem.SetRight( pLRItem->GetRight() );
rMaster.SetFmtAttr( aLRItem );
}
else
{
rMaster.SetFmtAttr( *pItem );
}
bChanged = sal_True;
}
// oberer und unterer Rand
if( (rPropInfo.bTopMargin || rPropInfo.bBottomMargin) &&
SFX_ITEM_SET == rItemSet.GetItemState(RES_UL_SPACE,sal_False,&pItem) )
{
if( (!rPropInfo.bTopMargin || !rPropInfo.bBottomMargin) &&
SFX_ITEM_SET == rPageItemSet.GetItemState(RES_UL_SPACE,
sal_True,&pPageItem) )
{
const SvxULSpaceItem *pULItem = (const SvxULSpaceItem *)pItem;
SvxULSpaceItem aULItem( *((const SvxULSpaceItem *)pPageItem) );
if( rPropInfo.bTopMargin )
aULItem.SetUpper( pULItem->GetUpper() );
if( rPropInfo.bBottomMargin )
aULItem.SetLower( pULItem->GetLower() );
rMaster.SetFmtAttr( aULItem );
}
else
{
rMaster.SetFmtAttr( *pItem );
}
bChanged = sal_True;
}
// die Groesse
if( rPropInfo.eSizeType != SVX_CSS1_STYPE_NONE )
{
if( rPropInfo.eSizeType == SVX_CSS1_STYPE_TWIP )
{
rMaster.SetFmtAttr( SwFmtFrmSize( ATT_FIX_SIZE, rPropInfo.nWidth,
rPropInfo.nHeight ) );
bChanged = sal_True;
}
else
{
// Bei "size: auto|portrait|landscape" bleibt die bisherige
// Groesse der Vorlage erhalten. Bei "landscape" und "portrait"
// wird das Landscape-Flag gesetzt und evtl. die Breite/Hoehe
// vertauscht.
SwFmtFrmSize aFrmSz( rMaster.GetFrmSize() );
sal_Bool bLandscape = aNewPageDesc.GetLandscape();
if( ( bLandscape &&
rPropInfo.eSizeType == SVX_CSS1_STYPE_PORTRAIT ) ||
( !bLandscape &&
rPropInfo.eSizeType == SVX_CSS1_STYPE_LANDSCAPE ) )
{
SwTwips nTmp = aFrmSz.GetHeight();
aFrmSz.SetHeight( aFrmSz.GetWidth() );
aFrmSz.SetWidth( nTmp );
rMaster.SetFmtAttr( aFrmSz );
aNewPageDesc.SetLandscape( !bLandscape );
bChanged = sal_True;
}
}
}
// Geht das wirklich?
if( SFX_ITEM_SET == rItemSet.GetItemState( RES_BACKGROUND, sal_False, &pItem ) )
{
// eine Umrandung wird gesetzt
rMaster.SetFmtAttr( *pItem );
rItemSet.ClearItem( RES_BACKGROUND );
bChanged = sal_True;
}
if( bChanged )
ChgPageDesc( pPageDesc, aNewPageDesc );
}
// /Feature: PrintExt
const SvxBrushItem& SwCSS1Parser::GetPageDescBackground() const
{
return pDoc->GetPageDescFromPool( RES_POOLPAGE_HTML, false )
->GetMaster().GetBackground();
}
sal_uInt16 SwCSS1Parser::GetScriptFromClass( String& rClass,
sal_Bool bSubClassOnly )
{
sal_uInt16 nScriptFlags = CSS1_SCRIPT_ALL;
xub_StrLen nLen = rClass.Len();
xub_StrLen nPos = nLen > 4 ? rClass.SearchBackward( '-' ) : STRING_NOTFOUND;
if( STRING_NOTFOUND == nPos )
{
if( bSubClassOnly )
return nScriptFlags;
nPos = 0;
}
else
{
nPos++;
nLen = nLen - nPos;
}
switch( nLen )
{
case 3:
if( rClass.EqualsIgnoreCaseAscii( "cjk", nPos, 3 ) )
{
nScriptFlags = CSS1_SCRIPT_CJK;
}
else if( rClass.EqualsIgnoreCaseAscii( "ctl", nPos, 3 ) )
{
nScriptFlags = CSS1_SCRIPT_CTL;
}
break;
case 7:
if( rClass.EqualsIgnoreCaseAscii( "western", nPos, 7 ) )
{
nScriptFlags = CSS1_SCRIPT_WESTERN;
}
break;
}
if( CSS1_SCRIPT_ALL != nScriptFlags )
{
if( nPos )
{
rClass.Erase( nPos-1 );
}
else
{
rClass.Erase();
}
}
return nScriptFlags;
}
static CSS1SelectorType GetTokenAndClass( const CSS1Selector *pSelector,
String& rToken, String& rClass,
sal_uInt16& rScriptFlags )
{
rToken = pSelector->GetString();
rClass.Erase();
rScriptFlags = CSS1_SCRIPT_ALL;
CSS1SelectorType eType = pSelector->GetType();
if( CSS1_SELTYPE_ELEM_CLASS==eType )
{
xub_StrLen nPos = rToken.Search( '.' );
OSL_ENSURE( nPos != STRING_NOTFOUND, "kein Punkt in Class-Selektor???" );
if( nPos != STRING_NOTFOUND )
{
rClass = rToken.Copy( nPos+1 );
rToken.Erase( nPos );
rScriptFlags = SwCSS1Parser::GetScriptFromClass( rClass, sal_False );
if( !rClass.Len() )
eType = CSS1_SELTYPE_ELEMENT;
}
}
rToken.ToUpperAscii();
return eType;
}
extern sal_Bool lcl_css1atr_equalFontItems( const SfxPoolItem& r1, const SfxPoolItem& r2 );
static void RemoveScriptItems( SfxItemSet& rItemSet, sal_uInt16 nScript,
const SfxItemSet *pParentItemSet = 0 )
{
static sal_uInt16 aWhichIds[3][5] =
{
{ RES_CHRATR_FONT, RES_CHRATR_FONTSIZE, RES_CHRATR_LANGUAGE,
RES_CHRATR_POSTURE, RES_CHRATR_WEIGHT },
{ RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_FONTSIZE, RES_CHRATR_CJK_LANGUAGE,
RES_CHRATR_CJK_POSTURE, RES_CHRATR_CJK_WEIGHT },
{ RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_FONTSIZE, RES_CHRATR_CTL_LANGUAGE,
RES_CHRATR_CTL_POSTURE, RES_CHRATR_CTL_WEIGHT }
};
sal_uInt16 aClearItems[3] = { sal_False, sal_False, sal_False };
switch( nScript )
{
case CSS1_SCRIPT_WESTERN:
aClearItems[1] = aClearItems[2] = sal_True;
break;
case CSS1_SCRIPT_CJK:
aClearItems[0] = aClearItems[2] = sal_True;
break;
case CSS1_SCRIPT_CTL:
aClearItems[0] = aClearItems[1] = sal_True;
break;
case CSS1_SCRIPT_ALL:
break;
default:
OSL_ENSURE( aClearItems[0], "unknown script type" );
break;
}
for( sal_uInt16 j=0; j < 3; j++ )
{
for( sal_uInt16 i=0; i < 5; i++ )
{
sal_uInt16 nWhich = aWhichIds[j][i];
const SfxPoolItem *pItem;
if( aClearItems[j] ||
(pParentItemSet &&
SFX_ITEM_SET == rItemSet.GetItemState( nWhich, sal_False, &pItem ) &&
(0==i ? lcl_css1atr_equalFontItems( *pItem, pParentItemSet->Get(nWhich, sal_True ) )
: *pItem == pParentItemSet->Get(nWhich, sal_True ) ) ) )
{
rItemSet.ClearItem( nWhich );
}
}
}
}
sal_Bool SwCSS1Parser::StyleParsed( const CSS1Selector *pSelector,
SfxItemSet& rItemSet,
SvxCSS1PropertyInfo& rPropInfo )
{
if( !bIsNewDoc )
return sal_True;
CSS1SelectorType eSelType = pSelector->GetType();
const CSS1Selector *pNext = pSelector->GetNext();
if( CSS1_SELTYPE_ID==eSelType && !pNext )
{
InsertId( pSelector->GetString(), rItemSet, rPropInfo );
}
else if( CSS1_SELTYPE_CLASS==eSelType && !pNext )
{
String aClass( pSelector->GetString() );
sal_uInt16 nScript = GetScriptFromClass( aClass );
if( CSS1_SCRIPT_ALL != nScript )
{
SfxItemSet aScriptItemSet( rItemSet );
RemoveScriptItems( aScriptItemSet, nScript );
InsertClass( aClass, aScriptItemSet, rPropInfo );
}
else
{
InsertClass( aClass, rItemSet, rPropInfo );
}
}
else if( CSS1_SELTYPE_PAGE==eSelType )
{
if( !pNext ||
(CSS1_SELTYPE_PSEUDO == pNext->GetType() &&
(pNext->GetString().EqualsIgnoreCaseAscii(sCSS1_left) ||
pNext->GetString().EqualsIgnoreCaseAscii(sCSS1_right) ||
pNext->GetString().EqualsIgnoreCaseAscii(sCSS1_first)) ) )
{
String aName;
if( pNext )
aName = pNext->GetString();
InsertPage( aName,
pNext != 0,
rItemSet, rPropInfo );
}
}
if( CSS1_SELTYPE_ELEMENT != eSelType &&
CSS1_SELTYPE_ELEM_CLASS != eSelType)
return sal_True;
// Token und Class zu dem Selektor holen
String aToken2, aClass;
sal_uInt16 nScript;
eSelType = GetTokenAndClass( pSelector, aToken2, aClass, nScript );
int nToken2 = GetHTMLToken( aToken2 );
// und noch ein ganz par Infos zum naechsten Element
CSS1SelectorType eNextType = pNext ? pNext->GetType()
: CSS1_SELTYPE_ELEMENT;
// Erstmal ein par Spezialfaelle
if( CSS1_SELTYPE_ELEMENT==eSelType )
{
switch( nToken2 )
{
case HTML_ANCHOR_ON:
if( !pNext )
{
InsertTag( aToken2, rItemSet, rPropInfo );
return sal_False;
}
else if( pNext && CSS1_SELTYPE_PSEUDO == eNextType )
{
// vielleicht A:visited oder A:link
String aPseudo( pNext->GetString() );
aPseudo.ToLowerAscii();
sal_Bool bInsert = sal_False;
switch( aPseudo.GetChar( 0 ))
{
case 'l':
if( aPseudo.EqualsAscii(sCSS1_link) )
{
bInsert = sal_True;
}
break;
case 'v':
if( aPseudo.EqualsAscii(sCSS1_visited) )
{
bInsert = sal_True;
}
break;
}
if( bInsert )
{
String sTmp( aToken2 );
(sTmp += ':') += aPseudo;
if( CSS1_SCRIPT_ALL != nScript )
{
SfxItemSet aScriptItemSet( rItemSet );
RemoveScriptItems( aScriptItemSet, nScript );
InsertTag( sTmp, aScriptItemSet, rPropInfo );
}
else
{
InsertTag( sTmp, rItemSet, rPropInfo );
}
return sal_False;
}
}
break;
case HTML_BODY_ON:
if( !pNext )
{
// BODY
// Den Hintergrund muessen wir vor dem Setzen abfragen,
// denn in SetPageDescAttrs wird er geloescht.
const SfxPoolItem *pItem;
if( SFX_ITEM_SET==rItemSet.GetItemState(RES_BACKGROUND,sal_False,&pItem) )
{
const SvxBrushItem *pBrushItem =
(const SvxBrushItem *)pItem;
/// Body has a background color, if it is not "no fill"/"auto fill"
if( pBrushItem->GetColor() != COL_TRANSPARENT )
bBodyBGColorSet = sal_True;
if( GPOS_NONE != pBrushItem->GetGraphicPos() )
bBodyBackgroundSet = sal_True;
}
// Border and Padding
rPropInfo.SetBoxItem( rItemSet, MIN_BORDER_DIST );
// Ein par Attribute muessen an der Seitenvorlage gesetzt werden,
// und zwar die, die nicht vererbt werden
SetPageDescAttrs( 0, &rItemSet );
// alle noch uebrigen Optionen koennen an der Standard-Vorlage
// gesetzt werden und gelten dann automatisch als defaults
if( SFX_ITEM_SET==rItemSet.GetItemState(RES_CHRATR_COLOR,sal_False) )
bBodyTextSet = sal_True;
SetTxtCollAttrs(
GetTxtCollFromPool( RES_POOLCOLL_STANDARD ),
rItemSet, rPropInfo, this );
return sal_False;
}
break;
}
}
else if( CSS1_SELTYPE_ELEM_CLASS==eSelType && HTML_ANCHOR_ON==nToken2 &&
!pNext && aClass.Len() >= 9 &&
('s' == aClass.GetChar(0) || 'S' == aClass.GetChar(0)) )
{
sal_uInt16 nPoolFmtId = 0;
if( aClass.EqualsIgnoreCaseAscii(OOO_STRING_SVTOOLS_HTML_sdendnote_sym) )
nPoolFmtId = RES_POOLCHR_ENDNOTE;
else if( aClass.EqualsIgnoreCaseAscii(OOO_STRING_SVTOOLS_HTML_sdfootnote_sym) )
nPoolFmtId = RES_POOLCHR_FOOTNOTE;
if( nPoolFmtId )
{
if( CSS1_SCRIPT_ALL == nScript )
{
SetCharFmtAttrs( GetCharFmtFromPool(nPoolFmtId), rItemSet );
}
else
{
SfxItemSet aScriptItemSet( rItemSet );
RemoveScriptItems( aScriptItemSet, nScript );
SetCharFmtAttrs( GetCharFmtFromPool(nPoolFmtId),
aScriptItemSet);
}
return sal_False;
}
}
// Jetzt werden die Selektoren verarbeitet, die zu einer Absatz-Vorlage
// gehoehren
sal_uInt16 nPoolCollId = 0;
switch( nToken2 )
{
case HTML_HEAD1_ON:
nPoolCollId = RES_POOLCOLL_HEADLINE1;
break;
case HTML_HEAD2_ON:
nPoolCollId = RES_POOLCOLL_HEADLINE2;
break;
case HTML_HEAD3_ON:
nPoolCollId = RES_POOLCOLL_HEADLINE3;
break;
case HTML_HEAD4_ON:
nPoolCollId = RES_POOLCOLL_HEADLINE4;
break;
case HTML_HEAD5_ON:
nPoolCollId = RES_POOLCOLL_HEADLINE5;
break;
case HTML_HEAD6_ON:
nPoolCollId = RES_POOLCOLL_HEADLINE6;
break;
case HTML_PARABREAK_ON:
if( aClass.Len() >= 9 &&
('s' == aClass.GetChar(0) || 'S' == aClass.GetChar(0)) )
{
if( aClass.EqualsIgnoreCaseAscii(OOO_STRING_SVTOOLS_HTML_sdendnote) )
nPoolCollId = RES_POOLCOLL_ENDNOTE;
else if( aClass.EqualsIgnoreCaseAscii(OOO_STRING_SVTOOLS_HTML_sdfootnote) )
nPoolCollId = RES_POOLCOLL_FOOTNOTE;
if( nPoolCollId )
aClass = aEmptyStr;
else
nPoolCollId = RES_POOLCOLL_TEXT;
}
else
{
nPoolCollId = RES_POOLCOLL_TEXT;
}
break;
case HTML_ADDRESS_ON:
nPoolCollId = RES_POOLCOLL_SENDADRESS;
break;
case HTML_BLOCKQUOTE_ON:
nPoolCollId = RES_POOLCOLL_HTML_BLOCKQUOTE;
break;
case HTML_DT_ON:
nPoolCollId = RES_POOLCOLL_HTML_DT;
break;
case HTML_DD_ON:
nPoolCollId = RES_POOLCOLL_HTML_DD;
break;
case HTML_PREFORMTXT_ON:
nPoolCollId = RES_POOLCOLL_HTML_PRE;
break;
case HTML_TABLEHEADER_ON:
case HTML_TABLEDATA_ON:
if( CSS1_SELTYPE_ELEMENT==eSelType && !pNext )
{
InsertTag( aToken2, rItemSet, rPropInfo );
return sal_False;
}
else if( CSS1_SELTYPE_ELEMENT==eSelType && pNext &&
(CSS1_SELTYPE_ELEMENT==eNextType ||
CSS1_SELTYPE_ELEM_CLASS==eNextType) )
{
// nicht TH und TD, aber TH P und TD P
String aSubToken, aSubClass;
GetTokenAndClass( pNext, aSubToken, aSubClass, nScript );
if( HTML_PARABREAK_ON == GetHTMLToken( aSubToken ) )
{
aClass = aSubClass;
pNext = pNext->GetNext();
eNextType = pNext ? pNext->GetType() : CSS1_SELTYPE_ELEMENT;
if( aClass.Len() || pNext )
{
nPoolCollId = static_cast< sal_uInt16 >(
HTML_TABLEHEADER_ON == nToken2 ? RES_POOLCOLL_TABLE_HDLN
: RES_POOLCOLL_TABLE );
}
else
{
String sTmp( aToken2 );
sTmp += ' ';
sTmp.AppendAscii( OOO_STRING_SVTOOLS_HTML_parabreak );
if( CSS1_SCRIPT_ALL == nScript )
{
InsertTag( sTmp, rItemSet, rPropInfo );
}
else
{
SfxItemSet aScriptItemSet( rItemSet );
RemoveScriptItems( aScriptItemSet, nScript );
InsertTag( sTmp, aScriptItemSet, rPropInfo );
}
return sal_False;
}
}
}
break;
default:
;
}
if( nPoolCollId )
{
if( !pNext ||
(CSS1_SELTYPE_PSEUDO==eNextType &&
pNext->GetString().EqualsIgnoreCaseAscii(sCSS1_first_letter) &&
SVX_ADJUST_LEFT == rPropInfo.eFloat) )
{
// Entweder kein zusammengesetzter Selektor oder
// ein X:first-line { float: left; ... }
// Die Vorlage Suchen bzw. Anlegen
SwTxtFmtColl *pColl = GetTxtFmtColl( nPoolCollId, aEmptyStr );
SwTxtFmtColl* pParentColl = 0;
if( aClass.Len() )
{
String aName( pColl->GetName() );
AddClassName( aName, aClass );
pParentColl = pColl;
pColl = pDoc->FindTxtFmtCollByName( aName );
if( !pColl )
pColl = pDoc->MakeTxtFmtColl( aName, pParentColl );
}
if( !pNext )
{
// nur die Attribute an der Vorlage setzen
const SfxPoolItem *pItem;
const SvxBoxItem *pBoxItem = 0;
if( SFX_ITEM_SET ==
pColl->GetAttrSet().GetItemState(RES_BOX,sal_True,&pItem) )
pBoxItem = (const SvxBoxItem *)pItem;
rPropInfo.SetBoxItem( rItemSet, MIN_BORDER_DIST, pBoxItem );
if( CSS1_SCRIPT_ALL == nScript && !pParentColl )
{
SetTxtCollAttrs( pColl, rItemSet, rPropInfo, this );
}
else
{
SfxItemSet aScriptItemSet( rItemSet );
RemoveScriptItems( aScriptItemSet, nScript,
pParentColl ? &pParentColl->GetAttrSet() : 0 );
SetTxtCollAttrs( pColl, aScriptItemSet, rPropInfo, this );
}
}
else
{
// ein Drop-Cap-Attribut basteln
SwFmtDrop aDrop( pColl->GetDrop() );
aDrop.GetChars() = 1;
// die Attribute in das DropCap-Attribut einfuegen
if( CSS1_SCRIPT_ALL == nScript )
{
FillDropCap( aDrop, rItemSet, &pColl->GetName() );
}
else
{
SfxItemSet aScriptItemSet( rItemSet );
if( CSS1_SCRIPT_WESTERN != nScript )
{
aScriptItemSet.ClearItem( RES_CHRATR_FONT );
aScriptItemSet.ClearItem( RES_CHRATR_LANGUAGE );
aScriptItemSet.ClearItem( RES_CHRATR_POSTURE );
aScriptItemSet.ClearItem( RES_CHRATR_WEIGHT );
}
if( CSS1_SCRIPT_CJK != nScript )
{
aScriptItemSet.ClearItem( RES_CHRATR_CJK_FONT );
aScriptItemSet.ClearItem( RES_CHRATR_CJK_LANGUAGE );
aScriptItemSet.ClearItem( RES_CHRATR_CJK_POSTURE );
aScriptItemSet.ClearItem( RES_CHRATR_CJK_WEIGHT );
}
if( CSS1_SCRIPT_CTL != nScript )
{
aScriptItemSet.ClearItem( RES_CHRATR_CTL_FONT );
aScriptItemSet.ClearItem( RES_CHRATR_CTL_LANGUAGE );
aScriptItemSet.ClearItem( RES_CHRATR_CTL_POSTURE );
aScriptItemSet.ClearItem( RES_CHRATR_CTL_WEIGHT );
}
FillDropCap( aDrop, aScriptItemSet, &pColl->GetName() );
}
// Das Attribut nur setzen, wenn float: left angegeben wurde
// und das Initial ueber mehrere Zeilen geht. Sonst wird die
// ggf. angelegte Zeichen-Vorlage spaeter ueber den Namen
// gesucht und gesetzt.
if( aDrop.GetLines() > 1 &&
(SVX_ADJUST_LEFT == rPropInfo.eFloat ||
CSS1_SCRIPT_ALL == nScript) )
{
pColl->SetFmtAttr( aDrop );
}
}
return sal_False;
}
return sal_True;
}
// Jetzt werden die Selektoten verarbeitet, die zu einer Zechenvorlage
// gehoehren. Zusammengesetzte gibt es hier allerdings nich nicht.
if( pNext )
return sal_True;
SwCharFmt *pCFmt = GetChrFmt( static_cast< sal_uInt16 >(nToken2), aEmptyStr );
if( pCFmt )
{
SwCharFmt *pParentCFmt = 0;
if( aClass.Len() )
{
String aName( pCFmt->GetName() );
AddClassName( aName, aClass );
pParentCFmt = pCFmt;
pCFmt = pDoc->FindCharFmtByName( aName );
if( !pCFmt )
{
pCFmt = pDoc->MakeCharFmt( aName, pParentCFmt );
pCFmt->SetAuto( sal_False );
}
}
if( CSS1_SCRIPT_ALL == nScript && !pParentCFmt )
{
SetCharFmtAttrs( pCFmt, rItemSet );
}
else
{
SfxItemSet aScriptItemSet( rItemSet );
RemoveScriptItems( aScriptItemSet, nScript,
pParentCFmt ? &pParentCFmt->GetAttrSet() : 0 );
SetCharFmtAttrs( pCFmt, aScriptItemSet );
}
return sal_False;
}
return sal_True;
}
sal_uInt32 SwCSS1Parser::GetFontHeight( sal_uInt16 nSize ) const
{
return aFontHeights[ nSize>6 ? 6 : nSize ];
}
const FontList *SwCSS1Parser::GetFontList() const
{
const FontList *pFList = 0;
SwDocShell *pDocSh = pDoc->GetDocShell();
if( pDocSh )
{
const SvxFontListItem *pFListItem =
(const SvxFontListItem *)pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST);
if( pFListItem )
pFList = pFListItem->GetFontList();
}
return pFList;
}
SwCharFmt* SwCSS1Parser::GetChrFmt( sal_uInt16 nToken2, const String& rClass ) const
{
// die entsprechende Vorlage suchen
sal_uInt16 nPoolId = 0;
const sal_Char* sName = 0;
switch( nToken2 )
{
case HTML_EMPHASIS_ON: nPoolId = RES_POOLCHR_HTML_EMPHASIS; break;
case HTML_CITIATION_ON: nPoolId = RES_POOLCHR_HTML_CITIATION; break;
case HTML_STRONG_ON: nPoolId = RES_POOLCHR_HTML_STRONG; break;
case HTML_CODE_ON: nPoolId = RES_POOLCHR_HTML_CODE; break;
case HTML_SAMPLE_ON: nPoolId = RES_POOLCHR_HTML_SAMPLE; break;
case HTML_KEYBOARD_ON: nPoolId = RES_POOLCHR_HTML_KEYBOARD; break;
case HTML_VARIABLE_ON: nPoolId = RES_POOLCHR_HTML_VARIABLE; break;
case HTML_DEFINSTANCE_ON: nPoolId = RES_POOLCHR_HTML_DEFINSTANCE; break;
case HTML_TELETYPE_ON: nPoolId = RES_POOLCHR_HTML_TELETYPE; break;
case HTML_SHORTQUOTE_ON: sName = OOO_STRING_SVTOOLS_HTML_shortquote; break;
case HTML_LANGUAGE_ON: sName = OOO_STRING_SVTOOLS_HTML_language; break;
case HTML_AUTHOR_ON: sName = OOO_STRING_SVTOOLS_HTML_author; break;
case HTML_PERSON_ON: sName = OOO_STRING_SVTOOLS_HTML_person; break;
case HTML_ACRONYM_ON: sName = OOO_STRING_SVTOOLS_HTML_acronym; break;
case HTML_ABBREVIATION_ON: sName = OOO_STRING_SVTOOLS_HTML_abbreviation; break;
case HTML_INSERTEDTEXT_ON: sName = OOO_STRING_SVTOOLS_HTML_insertedtext; break;
case HTML_DELETEDTEXT_ON: sName = OOO_STRING_SVTOOLS_HTML_deletedtext; break;
}
// die Vorlage suchen oder anlegen (geht nur mit Namen)
if( !nPoolId && !sName )
return 0;
// Die Vorlage (ohne Class) suchen oder anlegen
SwCharFmt *pCFmt = 0;
if( nPoolId )
{
pCFmt = GetCharFmtFromPool( nPoolId );
}
else
{
String sCName( String::CreateFromAscii(sName) );
pCFmt = pDoc->FindCharFmtByName( sCName );
if( !pCFmt )
{
pCFmt = pDoc->MakeCharFmt( sCName, pDoc->GetDfltCharFmt() );
pCFmt->SetAuto( sal_False );
}
}
OSL_ENSURE( pCFmt, "Keine Zeichen-Vorlage???" );
// Wenn es eine Klasse gibt, die Klassen-Vorlage suchen aber nicht
// neu anlegen.
String aClass( rClass );
GetScriptFromClass( aClass, sal_False );
if( aClass.Len() )
{
String aTmp( pCFmt->GetName() );
AddClassName( aTmp, aClass );
SwCharFmt *pClassCFmt = pDoc->FindCharFmtByName( aTmp );
if( pClassCFmt )
{
pCFmt = pClassCFmt;
}
else
{
const SvxCSS1MapEntry *pClass = GetClass( aClass );
if( pClass )
{
pCFmt = pDoc->MakeCharFmt( aTmp, pCFmt );
pCFmt->SetAuto( sal_False );
SfxItemSet aItemSet( pClass->GetItemSet() );
SetCharFmtAttrs( pCFmt, aItemSet );
}
}
}
return pCFmt;
}
SwTxtFmtColl *SwCSS1Parser::GetTxtCollFromPool( sal_uInt16 nPoolId ) const
{
sal_uInt16 nOldArrLen = pDoc->GetTxtFmtColls()->Count();
SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool( nPoolId, false );
if( bIsNewDoc )
{
sal_uInt16 nArrLen = pDoc->GetTxtFmtColls()->Count();
for( sal_uInt16 i=nOldArrLen; i<nArrLen; i++ )
lcl_swcss1_setEncoding( *(*pDoc->GetTxtFmtColls())[i],
GetDfltEncoding() );
}
return pColl;
}
SwCharFmt *SwCSS1Parser::GetCharFmtFromPool( sal_uInt16 nPoolId ) const
{
sal_uInt16 nOldArrLen = pDoc->GetCharFmts()->Count();
SwCharFmt *pCharFmt = pDoc->GetCharFmtFromPool( nPoolId );
if( bIsNewDoc )
{
sal_uInt16 nArrLen = pDoc->GetCharFmts()->Count();
for( sal_uInt16 i=nOldArrLen; i<nArrLen; i++ )
lcl_swcss1_setEncoding( *(*pDoc->GetCharFmts())[i],
GetDfltEncoding() );
}
return pCharFmt;
}
SwTxtFmtColl *SwCSS1Parser::GetTxtFmtColl( sal_uInt16 nTxtColl,
const String& rClass )
{
SwTxtFmtColl* pColl = 0;
String aClass( rClass );
GetScriptFromClass( aClass, sal_False );
if( RES_POOLCOLL_TEXT == nTxtColl && aClass.Len() >= 9 &&
('s' == aClass.GetChar(0) || 'S' == aClass.GetChar(0) ) )
{
if( aClass.EqualsIgnoreCaseAscii(OOO_STRING_SVTOOLS_HTML_sdendnote) )
{
nTxtColl = RES_POOLCOLL_ENDNOTE;
aClass = aEmptyStr;
}
else if( aClass.EqualsIgnoreCaseAscii(OOO_STRING_SVTOOLS_HTML_sdfootnote) )
{
nTxtColl = RES_POOLCOLL_FOOTNOTE;
aClass = aEmptyStr;
}
}
String sName;
if( USER_FMT & nTxtColl ) // eine vom Reader angelegte
{
OSL_ENSURE( !this, "Wo kommt die Benutzer-Vorlage her?" );
pColl = GetTxtCollFromPool( RES_POOLCOLL_STANDARD );
}
else
{
pColl = GetTxtCollFromPool( nTxtColl );
}
OSL_ENSURE( pColl, "Keine Absatz-Vorlage???" );
if( aClass.Len() )
{
String aTmp( pColl->GetName() );
AddClassName( aTmp, aClass );
SwTxtFmtColl* pClassColl = pDoc->FindTxtFmtCollByName( aTmp );
if( !pClassColl &&
(nTxtColl==RES_POOLCOLL_TABLE ||
nTxtColl==RES_POOLCOLL_TABLE_HDLN) )
{
// Wenn dieser Fall eintritt, dann wurde ein <TD><P CLASS=foo>
// gelesen, aber die TD.foo Vorlage nicht gefunden. Dann muessen
// wir P.foo nehmen, wenn es sie gibt.
SwTxtFmtColl* pCollText =
GetTxtCollFromPool( RES_POOLCOLL_TEXT );
aTmp = pCollText->GetName();
AddClassName( aTmp, aClass );
pClassColl = pDoc->FindTxtFmtCollByName( aTmp );
}
if( pClassColl )
{
pColl = pClassColl;
}
else
{
const SvxCSS1MapEntry *pClass = GetClass( aClass );
if( pClass )
{
pColl = pDoc->MakeTxtFmtColl( aTmp, pColl );
SfxItemSet aItemSet( pClass->GetItemSet() );
SvxCSS1PropertyInfo aPropInfo( pClass->GetPropertyInfo() );
aPropInfo.SetBoxItem( aItemSet, MIN_BORDER_DIST );
sal_Bool bPositioned = MayBePositioned( pClass->GetPropertyInfo() );
if( bPositioned )
aItemSet.ClearItem( RES_BACKGROUND );
SetTxtCollAttrs( pColl, aItemSet, aPropInfo,
this );
}
}
}
if( pColl )
lcl_swcss1_setEncoding( *pColl, GetDfltEncoding() );
return pColl;
}
SwPageDesc *SwCSS1Parser::GetMasterPageDesc()
{
return pDoc->GetPageDescFromPool( RES_POOLPAGE_HTML, false );
}
static SwPageDesc *FindPageDesc( SwDoc *pDoc, sal_uInt16 nPoolId, sal_uInt16& rPage )
{
sal_uInt16 nPageDescs = pDoc->GetPageDescCnt();
for( rPage=0; rPage < nPageDescs &&
const_cast<const SwDoc *>(pDoc)->
GetPageDesc(rPage).GetPoolFmtId() != nPoolId; rPage++ )
;
return rPage < nPageDescs ? &pDoc->_GetPageDesc( rPage ) : 0;
}
const SwPageDesc *SwCSS1Parser::GetPageDesc( sal_uInt16 nPoolId, sal_Bool bCreate )
{
if( RES_POOLPAGE_HTML == nPoolId )
return pDoc->GetPageDescFromPool( RES_POOLPAGE_HTML, false );
sal_uInt16 nPage;
const SwPageDesc *pPageDesc = FindPageDesc( pDoc, nPoolId, nPage );
if( !pPageDesc && bCreate )
{
// Die erste Seite wird aus der rechten Seite erzeugt, wenn es die
// gibt.
SwPageDesc *pMasterPageDesc = 0;
if( RES_POOLPAGE_FIRST == nPoolId )
pMasterPageDesc = FindPageDesc( pDoc, RES_POOLPAGE_RIGHT, nPage );
if( !pMasterPageDesc )
pMasterPageDesc = pDoc->GetPageDescFromPool( RES_POOLPAGE_HTML, false );
// Die neue Seitenvorlage entsteht aus dem Master durch kopieren.
SwPageDesc *pNewPageDesc = pDoc->
GetPageDescFromPool( nPoolId, false );
// dazu brauchen wir auch die Nummer der neuen Vorlage
pPageDesc = FindPageDesc( pDoc, nPoolId, nPage );
OSL_ENSURE( pPageDesc==pNewPageDesc, "Seitenvorlage nicht gefunden" );
pDoc->CopyPageDesc( *pMasterPageDesc, *pNewPageDesc, sal_False );
// Die Vorlagen an ihren neuen Zweck anpassen.
const SwPageDesc *pFollow = 0;
sal_Bool bSetFollowFollow = sal_False;
switch( nPoolId )
{
case RES_POOLPAGE_FIRST:
// Wenn es schon eine linke Seite gibt, dann ist das die
// Folge-Vorlage, sonst ist es die HTML-Vorlage.
pFollow = GetLeftPageDesc();
if( !pFollow )
pFollow = pMasterPageDesc;
break;
case RES_POOLPAGE_RIGHT:
// Wenn die linke Vorlage schon angelegt ist, passiert hier gar
// nichts. Sonst wird die linke Vorlage angelegt und sorgt auch
// fuer die richtige Verkettung mit der rechten Voralge.
GetLeftPageDesc( sal_True );
break;
case RES_POOLPAGE_LEFT:
// Die rechte Vorlage wird angelegt, wenn sie noch nicht existiert.
// Es findet aber keine Verkettung statt.
// Wenn schon eine erste Seitenvorlage existiert, wird die linke
// Vorlage die Folge-Vorlage der ersten Seite.
pFollow = GetRightPageDesc( sal_True );
bSetFollowFollow = sal_True;
{
const SwPageDesc *pFirstPageDesc = GetFirstPageDesc();
if( pFirstPageDesc )
{
SwPageDesc aNewFirstPageDesc( *pFirstPageDesc );
aNewFirstPageDesc.SetFollow( pNewPageDesc );
ChgPageDesc( pFirstPageDesc, aNewFirstPageDesc );
}
}
break;
}
if( pFollow )
{
SwPageDesc aNewPageDesc( *pNewPageDesc );
aNewPageDesc.SetFollow( pFollow );
ChgPageDesc( pNewPageDesc, aNewPageDesc );
if( bSetFollowFollow )
{
SwPageDesc aNewFollowPageDesc( *pFollow );
aNewFollowPageDesc.SetFollow( pNewPageDesc );
ChgPageDesc( pFollow, aNewFollowPageDesc );
}
}
pPageDesc = pNewPageDesc;
}
return pPageDesc;
}
sal_Bool SwCSS1Parser::MayBePositioned( const SvxCSS1PropertyInfo& rPropInfo,
sal_Bool bAutoWidth )
{
// abs-pos
// left/top none auto twip perc
//
// none Z Z - -
// auto Z Z - -
// twip Z Z S/R -
// perc - - - -
//
// - das Tag wird absolut positioniert und left/top sind beide
// gegeben und enthalten auch keine %-Angabe, oder
// - das Tag soll fliessen, und
// - es wurde eine Breite angegeben (in beiden Faellen noetig)
return ( ( SVX_CSS1_POS_ABSOLUTE == rPropInfo.ePosition &&
SVX_CSS1_LTYPE_PERCENTAGE != rPropInfo.eLeftType &&
SVX_CSS1_LTYPE_PERCENTAGE != rPropInfo.eTopType &&
(SVX_CSS1_LTYPE_TWIP == rPropInfo.eLeftType ||
SVX_CSS1_LTYPE_TWIP != rPropInfo.eTopType) ) ||
( SVX_ADJUST_END != rPropInfo.eFloat ) ) &&
( bAutoWidth ||
SVX_CSS1_LTYPE_TWIP == rPropInfo.eWidthType ||
SVX_CSS1_LTYPE_PERCENTAGE == rPropInfo.eWidthType );
}
void SwCSS1Parser::AddClassName( String& rFmtName, const String& rClass )
{
OSL_ENSURE( rClass.Len(), "Style-Klasse ohne Laenge?" );
(rFmtName += '.') += rClass;
}
void SwCSS1Parser::FillDropCap( SwFmtDrop& rDrop,
SfxItemSet& rItemSet,
const String *pName )
{
// die Anzahl der Zeilen entspricht in etwa einer %-Angabe
// fuer die Hoehe (was passiert mit absoluten Hoehen???)
sal_uInt8 nLines = rDrop.GetLines();
const SfxPoolItem *pItem;
if( SFX_ITEM_SET == rItemSet.GetItemState( RES_CHRATR_FONTSIZE, sal_False, &pItem ) )
{
sal_uInt16 nProp = ((const SvxFontHeightItem *)pItem)->GetProp();
nLines = (sal_uInt8)((nProp + 50) / 100);
if( nLines < 1 )
nLines = 1;
else if( nLines > MAX_DROPCAP_LINES )
nLines = MAX_DROPCAP_LINES;
// Nur wenn nLines>1 ist, wird das Attribut auch gesetzt. Dann
// brauchen wir die Font-Hoehe aber auch nicht in der Zeichen-Vorlage.
if( nLines > 1 )
{
rItemSet.ClearItem( RES_CHRATR_FONTSIZE );
rItemSet.ClearItem( RES_CHRATR_CJK_FONTSIZE );
rItemSet.ClearItem( RES_CHRATR_CTL_FONTSIZE );
}
}
// Bei harter Attributierung (pName==0) koennen wir aufhoehren, wenn
// das Initial nur ueber eine Zeile geht.
if( nLines<=1 )
return;
rDrop.GetLines() = nLines;
// ein rechter Rand wird der Abstand zum Text!
if( SFX_ITEM_SET == rItemSet.GetItemState( RES_LR_SPACE, sal_False, &pItem ) )
{
rDrop.GetDistance() = static_cast< sal_uInt16 >(
((const SvxLRSpaceItem *)pItem)->GetRight() );
rItemSet.ClearItem( RES_LR_SPACE );
}
// Fuer alle anderen Attribute eine Zeichen-Vorlage anlegen
if( rItemSet.Count() )
{
SwCharFmt *pCFmt = 0;
String aName;
if( pName )
{
aName = *pName;
AddFirstLetterExt( aName );
pCFmt = pDoc->FindCharFmtByName( aName );
}
else
{
do
{
aName.AssignAscii( sCSS1_first_letter );
aName.Append( ' ' );
aName.Append(
String::CreateFromInt32( (sal_Int32)(++nDropCapCnt) ) );
}
while( pDoc->FindCharFmtByName(aName) );
}
if( !pCFmt )
{
pCFmt = pDoc->MakeCharFmt( aName, pDoc->GetDfltCharFmt() );
pCFmt->SetAuto( sal_False );
}
SetCharFmtAttrs( pCFmt, rItemSet );
// Die Zeichenvorlage braucht nur im Attribut gesetzt werden, wenn
// auch das Attribut gesetzt wird.
if( nLines > 1 )
rDrop.SetCharFmt( pCFmt );
}
}
// CSS1-sezifisches des SwHTMLParsers
_HTMLAttr **SwHTMLParser::GetAttrTabEntry( sal_uInt16 nWhich )
{
// den zu dem Item gehoehrenden Tabellen-Eintrag ermitteln ...
_HTMLAttr **ppAttr = 0;
switch( nWhich )
{
case RES_CHRATR_BLINK:
ppAttr = &aAttrTab.pBlink;
break;
case RES_CHRATR_CASEMAP:
ppAttr = &aAttrTab.pCaseMap;
break;
case RES_CHRATR_COLOR:
ppAttr = &aAttrTab.pFontColor;
break;
case RES_CHRATR_CROSSEDOUT:
ppAttr = &aAttrTab.pStrike;
break;
case RES_CHRATR_ESCAPEMENT:
ppAttr = &aAttrTab.pEscapement;
break;
case RES_CHRATR_FONT:
ppAttr = &aAttrTab.pFont;
break;
case RES_CHRATR_CJK_FONT:
ppAttr = &aAttrTab.pFontCJK;
break;
case RES_CHRATR_CTL_FONT:
ppAttr = &aAttrTab.pFontCTL;
break;
case RES_CHRATR_FONTSIZE:
ppAttr = &aAttrTab.pFontHeight;
break;
case RES_CHRATR_CJK_FONTSIZE:
ppAttr = &aAttrTab.pFontHeightCJK;
break;
case RES_CHRATR_CTL_FONTSIZE:
ppAttr = &aAttrTab.pFontHeightCTL;
break;
case RES_CHRATR_KERNING:
ppAttr = &aAttrTab.pKerning;
break;
case RES_CHRATR_POSTURE:
ppAttr = &aAttrTab.pItalic;
break;
case RES_CHRATR_CJK_POSTURE:
ppAttr = &aAttrTab.pItalicCJK;
break;
case RES_CHRATR_CTL_POSTURE:
ppAttr = &aAttrTab.pItalicCTL;
break;
case RES_CHRATR_UNDERLINE:
ppAttr = &aAttrTab.pUnderline;
break;
case RES_CHRATR_WEIGHT:
ppAttr = &aAttrTab.pBold;
break;
case RES_CHRATR_CJK_WEIGHT:
ppAttr = &aAttrTab.pBoldCJK;
break;
case RES_CHRATR_CTL_WEIGHT:
ppAttr = &aAttrTab.pBoldCTL;
break;
case RES_CHRATR_BACKGROUND:
ppAttr = &aAttrTab.pCharBrush;
break;
case RES_PARATR_LINESPACING:
ppAttr = &aAttrTab.pLineSpacing;
break;
case RES_PARATR_ADJUST:
ppAttr = &aAttrTab.pAdjust;
break;
case RES_LR_SPACE:
ppAttr = &aAttrTab.pLRSpace;
break;
case RES_UL_SPACE:
ppAttr = &aAttrTab.pULSpace;
break;
case RES_BOX:
ppAttr = &aAttrTab.pBox;
break;
case RES_BACKGROUND:
ppAttr = &aAttrTab.pBrush;
break;
case RES_BREAK:
ppAttr = &aAttrTab.pBreak;
break;
case RES_PAGEDESC:
ppAttr = &aAttrTab.pPageDesc;
break;
case RES_PARATR_SPLIT:
ppAttr = &aAttrTab.pSplit;
break;
case RES_PARATR_WIDOWS:
ppAttr = &aAttrTab.pWidows;
break;
case RES_PARATR_ORPHANS:
ppAttr = &aAttrTab.pOrphans;
break;
case RES_KEEP:
ppAttr = &aAttrTab.pKeep;
break;
case RES_CHRATR_LANGUAGE:
ppAttr = &aAttrTab.pLanguage;
break;
case RES_CHRATR_CJK_LANGUAGE:
ppAttr = &aAttrTab.pLanguageCJK;
break;
case RES_CHRATR_CTL_LANGUAGE:
ppAttr = &aAttrTab.pLanguageCTL;
break;
case RES_FRAMEDIR:
ppAttr = &aAttrTab.pDirection;
break;
}
return ppAttr;
}
void SwHTMLParser::NewStyle()
{
String sType;
const HTMLOptions& rOptions2 = GetOptions();
for (size_t i = rOptions2.size(); i; )
{
const HTMLOption& rOption = rOptions2[--i];
if( HTML_O_TYPE == rOption.GetToken() )
sType = rOption.GetString();
}
bIgnoreRawData = sType.Len() &&
!sType.GetToken(0,';').EqualsAscii(sCSS_mimetype);
}
void SwHTMLParser::EndStyle()
{
bIgnoreRawData = sal_False;
if( aStyleSource.Len() )
{
pCSS1Parser->ParseStyleSheet( aStyleSource );
aStyleSource.Erase();
}
}
sal_Bool SwHTMLParser::FileDownload( const String& rURL,
String& rStr )
{
// View wegschmeissen (wegen Reschedule)
ViewShell *pOldVSh = CallEndAction();
// Ein Medium anlegen
SfxMedium aDLMedium( rURL, STREAM_READ | STREAM_SHARE_DENYWRITE, sal_False );
// Medium registrieren, damit abgebrochen werden kann
if( pDoc->GetDocShell() )
pDoc->GetDocShell()->RegisterTransfer( aDLMedium );
SvStream* pStream = aDLMedium.GetInStream();
if( pStream )
{
SvMemoryStream aStream;
aStream << *pStream;
aStream.Seek( STREAM_SEEK_TO_END );
OSL_ENSURE( aStream.Tell() < STRING_MAXLEN,
"File zu lang fuer einen String, Ende abgeschnitten" );
xub_StrLen nLen = aStream.Tell() < STRING_MAXLEN
? (xub_StrLen)aStream.Tell()
: STRING_MAXLEN;
rStr = String( (const sal_Char *)aStream.GetData(), nLen,
GetSrcEncoding() );
}
// wurde abgebrochen?
if( ( pDoc->GetDocShell() && pDoc->GetDocShell()->IsAbortingImport() )
|| 1 == pDoc->getReferenceCount() )
{
// wurde der Import vom SFX abgebrochen?
eState = SVPAR_ERROR;
pStream = 0;
}
// recreate View
ViewShell *const pVSh = CallStartAction( pOldVSh );
OSL_ENSURE( pOldVSh == pVSh, "FileDownload: ViewShell changed on us" );
(void) pVSh;
return pStream!=0;
}
void SwHTMLParser::InsertLink()
{
sal_Bool bFinishDownload = sal_False;
if( pPendStack )
{
OSL_ENSURE( ShouldFinishFileDownload(),
"Pending-Stack ohne File-Download?" );
SwPendingStack* pTmp = pPendStack->pNext;
delete pPendStack;
pPendStack = pTmp;
OSL_ENSURE( !pPendStack, "Wo kommt der Pending-Stack her?" );
bFinishDownload = sal_True;
}
else
{
String sRel, sHRef, sType;
const HTMLOptions& rOptions2 = GetOptions();
for (size_t i = rOptions2.size(); i; )
{
const HTMLOption& rOption = rOptions2[--i];
switch( rOption.GetToken() )
{
case HTML_O_REL:
sRel = rOption.GetString();
break;
case HTML_O_HREF:
sHRef = URIHelper::SmartRel2Abs( INetURLObject( sBaseURL ), rOption.GetString(), Link(), false );
break;
case HTML_O_TYPE:
sType = rOption.GetString();
break;
}
}
if( sHRef.Len() && sRel.EqualsIgnoreCaseAscii( "STYLESHEET" ) &&
( !sType.Len() ||
sType.GetToken(0,';').EqualsAscii(sCSS_mimetype) ) )
{
if( GetMedium() )
{
// Download des Style-Source starten
StartFileDownload(sHRef, pDoc->GetDocShell());
if( IsParserWorking() )
{
// Der Style wurde synchron geladen und wir koennen
// es direkt aufrufen.
bFinishDownload = sal_True;
}
else
{
// Der Style wird asynchron geladen und ist erst beim
// naechsten Continue-Aufruf da. Wir muessen deshalb einen
// Pending-Stack anlegen, damit wir hierher zurueckkehren
pPendStack = new SwPendingStack( HTML_LINK, pPendStack );
}
}
else
{
// File synchron holen
String sSource;
if( FileDownload( sHRef, sSource ) )
pCSS1Parser->ParseStyleSheet( sSource );
}
}
}
if( bFinishDownload )
{
String sSource;
if( FinishFileDownload(sSource) && sSource.Len() )
pCSS1Parser->ParseStyleSheet( sSource );
}
}
sal_Bool SwCSS1Parser::ParseStyleSheet( const String& rIn )
{
if( !SvxCSS1Parser::ParseStyleSheet( rIn ) )
return sal_False;
SwPageDesc *pMasterPageDesc =
pDoc->GetPageDescFromPool( RES_POOLPAGE_HTML, false );
SvxCSS1MapEntry *pPageEntry = GetPage( aEmptyStr, false );
if( pPageEntry )
{
// @page (wirkt auf alle Seiten, die es schon gibt
SetPageDescAttrs( pMasterPageDesc, pPageEntry->GetItemSet(),
pPageEntry->GetPropertyInfo() );
// Fuer alle anderen Seiten-Vorlagen, die es schon gibt,
// muessen die Attribute auch noch gesetzt werden
SetPageDescAttrs( GetFirstPageDesc(), pPageEntry->GetItemSet(),
pPageEntry->GetPropertyInfo() );
SetPageDescAttrs( GetLeftPageDesc(), pPageEntry->GetItemSet(),
pPageEntry->GetPropertyInfo() );
SetPageDescAttrs( GetRightPageDesc(), pPageEntry->GetItemSet(),
pPageEntry->GetPropertyInfo() );
}
pPageEntry = GetPage( String::CreateFromAscii(sCSS1_first), sal_True );
if( pPageEntry )
{
SetPageDescAttrs( GetFirstPageDesc(sal_True), pPageEntry->GetItemSet(),
pPageEntry->GetPropertyInfo() );
bSetFirstPageDesc = sal_True;
}
pPageEntry = GetPage( String::CreateFromAscii(sCSS1_right), sal_True );
if( pPageEntry )
{
SetPageDescAttrs( GetRightPageDesc(sal_True), pPageEntry->GetItemSet(),
pPageEntry->GetPropertyInfo() );
bSetRightPageDesc = sal_True;
}
pPageEntry = GetPage( String::CreateFromAscii(sCSS1_left), sal_True );
if( pPageEntry )
SetPageDescAttrs( GetLeftPageDesc(sal_True), pPageEntry->GetItemSet(),
pPageEntry->GetPropertyInfo() );
return sal_True;
}
sal_Bool SwHTMLParser::ParseStyleOptions( const String &rStyle,
const String &rId,
const String &rClass,
SfxItemSet &rItemSet,
SvxCSS1PropertyInfo &rPropInfo,
const String *pLang,
const String *pDir )
{
sal_Bool bRet = sal_False;
if( rClass.Len() )
{
String aClass( rClass );
SwCSS1Parser::GetScriptFromClass( aClass );
const SvxCSS1MapEntry *pClass = pCSS1Parser->GetClass( aClass );
if( pClass )
{
pCSS1Parser->MergeStyles( pClass->GetItemSet(),
pClass->GetPropertyInfo(),
rItemSet, rPropInfo, sal_False );
bRet = sal_True;
}
}
if( rId.Len() )
{
const SvxCSS1MapEntry *pId = pCSS1Parser->GetId( rId );
if( pId )
pCSS1Parser->MergeStyles( pId->GetItemSet(),
pId->GetPropertyInfo(),
rItemSet, rPropInfo, rClass.Len()!=0 );
rPropInfo.aId = rId;
bRet = sal_True;
}
if( rStyle.Len() )
{
pCSS1Parser->ParseStyleOption( rStyle, rItemSet, rPropInfo );
bRet = sal_True;
}
if( bRet )
rPropInfo.SetBoxItem( rItemSet, MIN_BORDER_DIST );
if( pLang && pLang->Len() )
{
LanguageType eLang = MsLangId::convertIsoStringToLanguage( *pLang );
if( LANGUAGE_DONTKNOW != eLang )
{
SvxLanguageItem aLang( eLang, RES_CHRATR_LANGUAGE );
rItemSet.Put( aLang );
aLang.SetWhich( RES_CHRATR_CJK_LANGUAGE );
rItemSet.Put( aLang );
aLang.SetWhich( RES_CHRATR_CTL_LANGUAGE );
rItemSet.Put( aLang );
bRet = sal_True;
}
}
if( pDir && pDir->Len() )
{
String aValue( *pDir );
aValue.ToUpperAscii();
SvxFrameDirection eDir = FRMDIR_ENVIRONMENT;
if( aValue.EqualsAscii( "LTR" ) )
eDir = FRMDIR_HORI_LEFT_TOP;
else if( aValue.EqualsAscii( "RTL" ) )
eDir = FRMDIR_HORI_RIGHT_TOP;
if( FRMDIR_ENVIRONMENT != eDir )
{
SvxFrameDirectionItem aDir( eDir, RES_FRAMEDIR );
rItemSet.Put( aDir );
bRet = sal_True;
}
}
return bRet;
}
void SwHTMLParser::SetAnchorAndAdjustment( const SfxItemSet & /*rItemSet*/,
const SvxCSS1PropertyInfo &rPropInfo,
SfxItemSet &rFrmItemSet )
{
SwFmtAnchor aAnchor;
sal_Int16 eHoriOri = text::HoriOrientation::NONE;
sal_Int16 eVertOri = text::VertOrientation::NONE;
sal_Int16 eHoriRel = text::RelOrientation::FRAME;
sal_Int16 eVertRel = text::RelOrientation::FRAME;
SwTwips nHoriPos = 0, nVertPos = 0;
SwSurround eSurround = SURROUND_THROUGHT;
if( SVX_CSS1_POS_ABSOLUTE == rPropInfo.ePosition )
{
if( SVX_CSS1_LTYPE_TWIP == rPropInfo.eLeftType &&
SVX_CSS1_LTYPE_TWIP == rPropInfo.eTopType )
{
// Absolut positionierte Objekte sind seitengebunden, wenn
// sie nicht schon in einem Rahmen stehen und sonst
// Rahmengebunden.
const SwStartNode *pFlySttNd =
pPam->GetPoint()->nNode.GetNode().FindFlyStartNode();
if( pFlySttNd )
{
aAnchor.SetType( FLY_AT_FLY );
SwPosition aPos( *pFlySttNd );
aAnchor.SetAnchor( &aPos );
}
else
{
aAnchor.SetType( FLY_AT_PAGE );
aAnchor.SetPageNum( 1 );
}
nHoriPos = rPropInfo.nLeft;
nVertPos = rPropInfo.nTop;
}
else
{
aAnchor.SetType( FLY_AT_PARA );
aAnchor.SetAnchor( pPam->GetPoint() );
eVertOri = text::VertOrientation::TOP;
eVertRel = text::RelOrientation::CHAR;
if( SVX_CSS1_LTYPE_TWIP == rPropInfo.eLeftType )
{
eHoriOri = text::HoriOrientation::NONE;
eHoriRel = text::RelOrientation::PAGE_FRAME;
nHoriPos = rPropInfo.nLeft;
}
else
{
eHoriOri = text::HoriOrientation::LEFT;
eHoriRel = text::RelOrientation::FRAME; // wird noch umgeschossen
}
}
}
else
{
// fliessende Objekte werden Absatzgebunden eingefuegt, wenn
// der Absatz noch leer ist und sonst auto-gebunden.
// Auto-gebundene Rahmen werden zunaechst an der Position davor
// eingefuegt und erst spaeter verschoben.
xub_StrLen nCntnt = pPam->GetPoint()->nContent.GetIndex();
if( nCntnt )
{
aAnchor.SetType( FLY_AT_CHAR );
pPam->Move( fnMoveBackward );
eVertOri = text::VertOrientation::CHAR_BOTTOM;
eVertRel = text::RelOrientation::CHAR;
}
else
{
aAnchor.SetType( FLY_AT_PARA );
eVertOri = text::VertOrientation::TOP;
eVertRel = text::RelOrientation::PRINT_AREA;
}
aAnchor.SetAnchor( pPam->GetPoint() );
if( nCntnt )
pPam->Move( fnMoveForward );
sal_uInt16 nLeftSpace = 0, nRightSpace = 0;
short nIndent = 0;
GetMarginsFromContextWithNumBul( nLeftSpace, nRightSpace, nIndent );
if( SVX_ADJUST_RIGHT==rPropInfo.eFloat )
{
eHoriOri = text::HoriOrientation::RIGHT;
eHoriRel = nRightSpace ? text::RelOrientation::PRINT_AREA : text::RelOrientation::FRAME;
eSurround = SURROUND_LEFT;
}
else
{
eHoriOri = text::HoriOrientation::LEFT;
eHoriRel = nLeftSpace ? text::RelOrientation::PRINT_AREA : text::RelOrientation::FRAME;
eSurround = SURROUND_RIGHT;
}
}
rFrmItemSet.Put( aAnchor );
// Absolut Positioniert mit Durchlauf
rFrmItemSet.Put( SwFmtHoriOrient( nHoriPos, eHoriOri, eHoriRel ) );
rFrmItemSet.Put( SwFmtVertOrient( nVertPos, eVertOri, eVertRel ) );
rFrmItemSet.Put( SwFmtSurround( eSurround ) );
}
void SwHTMLParser::SetVarSize( SfxItemSet & /*rItemSet*/,
SvxCSS1PropertyInfo &rPropInfo,
SfxItemSet &rFrmItemSet,
SwTwips nDfltWidth, sal_uInt8 nDfltPrcWidth )
{
SwFrmSize eSize = ATT_MIN_SIZE;
SwTwips nWidth = nDfltWidth, nHeight = MINFLY;
sal_uInt8 nPrcWidth = nDfltPrcWidth, nPrcHeight = 0;
switch( rPropInfo.eWidthType )
{
case SVX_CSS1_LTYPE_PERCENTAGE:
nPrcWidth = rPropInfo.nWidth > 0 ? (sal_uInt8)rPropInfo.nWidth : 1;
nWidth = MINFLY;
break;
case SVX_CSS1_LTYPE_TWIP:
nWidth = rPropInfo.nWidth > MINFLY ? rPropInfo.nWidth : MINFLY;
nPrcWidth = 0;
break;
default:
;
}
switch( rPropInfo.eHeightType )
{
case SVX_CSS1_LTYPE_PERCENTAGE:
nPrcHeight = rPropInfo.nHeight > 0 ? (sal_uInt8)rPropInfo.nHeight : 1;
break;
case SVX_CSS1_LTYPE_TWIP:
// Netscape und MS-IE interpretieren die Hoehe regelwiedrig
// als Mindest-Hoehe, also machwn wir das auch so.
nHeight = rPropInfo.nHeight > MINFLY ? rPropInfo.nHeight : MINFLY;
break;
default:
;
}
SwFmtFrmSize aFrmSize( eSize, nWidth, nHeight );
aFrmSize.SetWidthPercent( nPrcWidth );
aFrmSize.SetHeightPercent( nPrcHeight );
rFrmItemSet.Put( aFrmSize );
}
void SwHTMLParser::SetFrmFmtAttrs( SfxItemSet &rItemSet,
SvxCSS1PropertyInfo & /*rPropInfo*/,
sal_uInt16 nFlags,
SfxItemSet &rFrmItemSet )
{
const SfxPoolItem *pItem;
if( (nFlags & HTML_FF_BOX) != 0 &&
SFX_ITEM_SET==rItemSet.GetItemState( RES_BOX, sal_True, &pItem ) )
{
if( (nFlags & HTML_FF_PADDING) == 0 )
{
SvxBoxItem aBoxItem( *(const SvxBoxItem *)pItem );
// Alle 4 Seiten gleichzeitig auf 0 setzen
aBoxItem.SetDistance( 0 );
rFrmItemSet.Put( aBoxItem );
}
else
{
rFrmItemSet.Put( *pItem );
}
rItemSet.ClearItem( RES_BOX );
}
if( (nFlags & HTML_FF_BACKGROUND) != 0 &&
SFX_ITEM_SET==rItemSet.GetItemState( RES_BACKGROUND, sal_True, &pItem ) )
{
rFrmItemSet.Put( *pItem );
rItemSet.ClearItem( RES_BACKGROUND );
}
if( (nFlags & HTML_FF_DIRECTION) != 0 &&
SFX_ITEM_SET==rItemSet.GetItemState( RES_FRAMEDIR, sal_True, &pItem ) )
{
rFrmItemSet.Put( *pItem );
rItemSet.ClearItem( RES_FRAMEDIR );
}
}
_HTMLAttrContext *SwHTMLParser::PopContext( sal_uInt16 nToken, sal_uInt16 nLimit,
sal_Bool bRemove )
{
sal_uInt16 nPos = aContexts.Count();
if( nPos <= nContextStMin )
return 0;
sal_Bool bFound = 0==nToken;
if( nToken )
{
// Stack-Eintrag zu dem Token suchen
while( nPos > nContextStMin )
{
sal_uInt16 nCntxtToken = aContexts[--nPos]->GetToken();
if( nCntxtToken == nToken )
{
bFound = sal_True;
break;
}
else if( nCntxtToken == nLimit ) // 0 als Token kommt nicht vor
{
break;
}
}
}
else
{
nPos--;
}
_HTMLAttrContext *pCntxt = 0;
if( bFound )
{
pCntxt = aContexts[nPos];
if( bRemove )
aContexts.Remove( nPos, 1 );
}
return pCntxt;
}
sal_Bool SwHTMLParser::GetMarginsFromContext( sal_uInt16& nLeft,
sal_uInt16& nRight,
short& nIndent,
sal_Bool bIgnoreTopContext ) const
{
sal_uInt16 nPos = aContexts.Count();
if( bIgnoreTopContext )
{
if( !nPos )
return sal_False;
else
nPos--;
}
while( nPos > nContextStAttrMin )
{
const _HTMLAttrContext *pCntxt = aContexts[--nPos];
if( pCntxt->IsLRSpaceChanged() )
{
pCntxt->GetMargins( nLeft, nRight, nIndent );
return sal_True;
}
}
return sal_False;
}
sal_Bool SwHTMLParser::GetMarginsFromContextWithNumBul( sal_uInt16& nLeft,
sal_uInt16& nRight,
short& nIndent ) const
{
sal_Bool bRet = GetMarginsFromContext( nLeft, nRight, nIndent );
const SwHTMLNumRuleInfo& rInfo = ((SwHTMLParser*)this)->GetNumInfo();
if( rInfo.GetDepth() )
{
sal_uInt8 nLevel = (sal_uInt8)( (rInfo.GetDepth() <= MAXLEVEL ? rInfo.GetDepth()
: MAXLEVEL) - 1 );
const SwNumFmt& rNumFmt = rInfo.GetNumRule()->Get(nLevel);
nLeft = nLeft + rNumFmt.GetAbsLSpace();
nIndent = rNumFmt.GetFirstLineOffset();
}
return bRet;
}
void SwHTMLParser::GetULSpaceFromContext( sal_uInt16& nUpper,
sal_uInt16& nLower ) const
{
sal_uInt16 nDfltColl = 0;
String aDfltClass;
sal_uInt16 nPos = aContexts.Count();
while( nPos > nContextStAttrMin )
{
const _HTMLAttrContext *pCntxt = aContexts[--nPos];
if( pCntxt->IsULSpaceChanged() )
{
pCntxt->GetULSpace( nUpper, nLower );
return;
}
else if( !nDfltColl )
{
nDfltColl = pCntxt->GetDfltTxtFmtColl();
if( nDfltColl )
aDfltClass = pCntxt->GetClass();
}
}
if( !nDfltColl )
nDfltColl = RES_POOLCOLL_TEXT;
const SwTxtFmtColl *pColl =
pCSS1Parser->GetTxtFmtColl( nDfltColl, aDfltClass );
const SvxULSpaceItem& rULSpace = pColl->GetULSpace();
nUpper = rULSpace.GetUpper();
nLower = rULSpace.GetLower();
}
void SwHTMLParser::EndContextAttrs( _HTMLAttrContext *pContext, sal_Bool bRemove )
{
_HTMLAttrs &rAttrs = pContext->GetAttrs();
for( sal_uInt16 i=0; i<rAttrs.Count(); i++ )
{
_HTMLAttr *pAttr = rAttrs[i];
if( RES_PARATR_DROP==pAttr->GetItem().Which() )
{
// Fuer DropCaps noch die Anzahl der Zeichen anpassen. Wenn
// es am Ende 0 sind, wird das Attribut invalidiert und dann
// von _SetAttr gar nicht erst gesetzt.
xub_StrLen nChars = pPam->GetPoint()->nContent.GetIndex();
if( nChars < 1 )
pAttr->Invalidate();
else if( nChars > MAX_DROPCAP_CHARS )
nChars = MAX_DROPCAP_CHARS;
((SwFmtDrop&)pAttr->GetItem()).GetChars() = (sal_uInt8)nChars;
}
EndAttr( pAttr );
}
if( bRemove && rAttrs.Count() )
rAttrs.Remove( 0, rAttrs.Count() );
}
void SwHTMLParser::InsertParaAttrs( const SfxItemSet& rItemSet )
{
SfxItemIter aIter( rItemSet );
const SfxPoolItem *pItem = aIter.FirstItem();
while( pItem )
{
// den zu dem Item gehoehrenden Tabellen-Eintrag ermitteln ...
sal_uInt16 nWhich = pItem->Which();
_HTMLAttr **ppAttr = GetAttrTabEntry( nWhich );
if( ppAttr )
{
NewAttr( ppAttr, *pItem );
if( RES_PARATR_BEGIN > nWhich )
(*ppAttr)->SetLikePara();
aParaAttrs.Insert( *ppAttr, aParaAttrs.Count() );
EndAttr( *ppAttr, 0, sal_False );
}
pItem = aIter.NextItem();
}
}
void lcl_swcss1_setEncoding( SwFmt& rFmt, rtl_TextEncoding eEnc )
{
if( RTL_TEXTENCODING_DONTKNOW == eEnc )
return;
const SfxItemSet& rItemSet = rFmt.GetAttrSet();
static sal_uInt16 aWhichIds[3] = { RES_CHRATR_FONT, RES_CHRATR_CJK_FONT,
RES_CHRATR_CTL_FONT };
const SfxPoolItem *pItem;
for( sal_uInt16 i=0; i<3; i++ )
{
if( SFX_ITEM_SET == rItemSet.GetItemState( aWhichIds[i], sal_False,&pItem ) )
{
const SvxFontItem& rFont = *(const SvxFontItem *)pItem;
if( RTL_TEXTENCODING_SYMBOL != rFont.GetCharSet() )
{
SvxFontItem aFont( rFont.GetFamily(), rFont.GetFamilyName(),
rFont.GetStyleName(), rFont.GetPitch(),
eEnc, aWhichIds[i]);
rFmt.SetFmtAttr( aFont );
}
}
}
}
void SwCSS1Parser::SetDfltEncoding( rtl_TextEncoding eEnc )
{
if( eEnc != GetDfltEncoding() )
{
if( bIsNewDoc )
{
// Set new encoding as pool default
static sal_uInt16 aWhichIds[3] = { RES_CHRATR_FONT, RES_CHRATR_CJK_FONT,
RES_CHRATR_CTL_FONT };
sal_uInt16 i;
for( i=0; i<3; i++ )
{
const SvxFontItem& rDfltFont =
(const SvxFontItem&)pDoc->GetDefault( aWhichIds[i]);
SvxFontItem aFont( rDfltFont.GetFamily(),
rDfltFont.GetFamilyName(),
rDfltFont.GetStyleName(),
rDfltFont.GetPitch(),
eEnc, aWhichIds[i] );
pDoc->SetDefault( aFont );
}
// Change all paragraph styles that do specify a font.
sal_uInt16 nArrLen = pDoc->GetTxtFmtColls()->Count();
for( i=1; i<nArrLen; i++ )
lcl_swcss1_setEncoding( *(*pDoc->GetTxtFmtColls())[i], eEnc );
// Change all character styles that do specify a font.
nArrLen = pDoc->GetCharFmts()->Count();
for( i=1; i<nArrLen; i++ )
lcl_swcss1_setEncoding( *(*pDoc->GetCharFmts())[i], eEnc );
}
SvxCSS1Parser::SetDfltEncoding( eEnc );
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|