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
|
/* -*- 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 <com/sun/star/style/NumberingType.hpp>
#include <hintids.hxx>
#include <svtools/htmltokn.h>
#include <svtools/htmlkywd.hxx>
#include <svtools/htmlout.hxx>
#include <svl/urihelper.hxx>
#include <editeng/brshitem.hxx>
#include <editeng/lrspitem.hxx>
#include <vcl/svapp.hxx>
#include <vcl/wrkwin.hxx>
#include <numrule.hxx>
#include <doc.hxx>
#include <docary.hxx>
#include <poolfmt.hxx>
#include <ndtxt.hxx>
#include <paratr.hxx>
#include "htmlnum.hxx"
#include "swcss1.hxx"
#include "swhtml.hxx"
#include "wrthtml.hxx"
#include <SwNodeNum.hxx>
#include <rtl/strbuf.hxx>
using namespace ::com::sun::star;
// TODO: Unicode: Are these characters the correct ones?
#define HTML_BULLETCHAR_DISC (0xe008)
#define HTML_BULLETCHAR_CIRCLE (0xe009)
#define HTML_BULLETCHAR_SQUARE (0xe00b)
// <UL TYPE=...>
static HTMLOptionEnum aHTMLULTypeTable[] =
{
{ OOO_STRING_SVTOOLS_HTML_ULTYPE_disc, HTML_BULLETCHAR_DISC },
{ OOO_STRING_SVTOOLS_HTML_ULTYPE_circle, HTML_BULLETCHAR_CIRCLE },
{ OOO_STRING_SVTOOLS_HTML_ULTYPE_square, HTML_BULLETCHAR_SQUARE },
{ 0, 0 }
};
void SwHTMLNumRuleInfo::Set( const SwTxtNode& rTxtNd )
{
const SwNumRule* pTxtNdNumRule( rTxtNd.GetNumRule() );
if ( pTxtNdNumRule &&
pTxtNdNumRule != rTxtNd.GetDoc()->GetOutlineNumRule() )
{
pNumRule = const_cast<SwNumRule*>(pTxtNdNumRule);
nDeep = static_cast< sal_uInt16 >(pNumRule ? rTxtNd.GetActualListLevel() + 1 : 0);
bNumbered = rTxtNd.IsCountedInList();
// #i57919# - correction of refactoring done by cws swnumtree:
// <bRestart> has to be set to <true>, if numbering is restarted at this
// text node and the start value equals <USHRT_MAX>.
// Start value <USHRT_MAX> indicates, that at this text node the numbering
// is restarted with the value given at the corresponding level.
bRestart = rTxtNd.IsListRestart() && !rTxtNd.HasAttrListRestartValue();
}
else
{
pNumRule = 0;
nDeep = 0;
bNumbered = bRestart = sal_False;
}
}
void SwHTMLParser::NewNumBulList( int nToken )
{
SwHTMLNumRuleInfo& rInfo = GetNumInfo();
// Erstmal einen neuen Absatz aufmachen
sal_Bool bSpace = (rInfo.GetDepth() + nDefListDeep) == 0;
if( pPam->GetPoint()->nContent.GetIndex() )
AppendTxtNode( bSpace ? AM_SPACE : AM_NOSPACE, sal_False );
else if( bSpace )
AddParSpace();
// Die Numerierung-Ebene erhoehen
rInfo.IncDepth();
sal_uInt8 nLevel = (sal_uInt8)( (rInfo.GetDepth() <= MAXLEVEL ? rInfo.GetDepth()
: MAXLEVEL) - 1 );
// ggf. ein Regelwerk anlegen
if( !rInfo.GetNumRule() )
{
sal_uInt16 nPos = pDoc->MakeNumRule( pDoc->GetUniqueNumRuleName() );
rInfo.SetNumRule( pDoc->GetNumRuleTbl()[nPos] );
}
// das Format anpassen, falls es fuer den Level noch nicht
// geschehen ist!
sal_Bool bNewNumFmt = rInfo.GetNumRule()->GetNumFmt( nLevel ) == 0;
sal_Bool bChangeNumFmt = sal_False;
// das default Numerierungsformat erstellen
SwNumFmt aNumFmt( rInfo.GetNumRule()->Get(nLevel) );
rInfo.SetNodeStartValue( nLevel );
if( bNewNumFmt )
{
sal_uInt16 nChrFmtPoolId = 0;
if( HTML_ORDERLIST_ON == nToken )
{
aNumFmt.SetNumberingType(SVX_NUM_ARABIC);
nChrFmtPoolId = RES_POOLCHR_NUM_LEVEL;
}
else
{
// Wir setzen hier eine Zeichenvorlage, weil die UI das auch
// so macht. Dadurch wurd immer auch eine 9pt-Schrift
// eingestellt, was in Netscape nicht der Fall ist. Bisher hat
// das noch niemanden gestoert.
// #i63395# - Only apply user defined default bullet font
if ( numfunc::IsDefBulletFontUserDefined() )
{
aNumFmt.SetBulletFont( &numfunc::GetDefBulletFont() );
}
aNumFmt.SetNumberingType(SVX_NUM_CHAR_SPECIAL);
aNumFmt.SetBulletChar( cBulletChar ); // das Bulletzeichen !!
nChrFmtPoolId = RES_POOLCHR_BUL_LEVEL;
}
sal_uInt16 nAbsLSpace = HTML_NUMBUL_MARGINLEFT;
short nFirstLineIndent = HTML_NUMBUL_INDENT;
if( nLevel > 0 )
{
const SwNumFmt& rPrevNumFmt = rInfo.GetNumRule()->Get( nLevel-1 );
nAbsLSpace = nAbsLSpace + rPrevNumFmt.GetAbsLSpace();
nFirstLineIndent = rPrevNumFmt.GetFirstLineOffset();
}
aNumFmt.SetAbsLSpace( nAbsLSpace );
aNumFmt.SetFirstLineOffset( nFirstLineIndent );
aNumFmt.SetCharFmt( pCSS1Parser->GetCharFmtFromPool(nChrFmtPoolId) );
bChangeNumFmt = sal_True;
}
else if( 1 != aNumFmt.GetStart() )
{
// Wenn die Ebene schon mal benutzt wurde, muss der Start-Wert
// ggf. hart am Absatz gesetzt werden.
rInfo.SetNodeStartValue( nLevel, 1 );
}
// und es ggf. durch die Optionen veraendern
String aId, aStyle, aClass, aBulletSrc, aLang, aDir;
sal_Int16 eVertOri = text::VertOrientation::NONE;
sal_uInt16 nWidth=USHRT_MAX, nHeight=USHRT_MAX;
const HTMLOptions& rHTMLOptions = GetOptions();
for (size_t i = rHTMLOptions.size(); i; )
{
const HTMLOption& rOption = rHTMLOptions[--i];
switch( rOption.GetToken() )
{
case HTML_O_ID:
aId = rOption.GetString();
break;
case HTML_O_TYPE:
if( bNewNumFmt && rOption.GetString().Len() )
{
switch( nToken )
{
case HTML_ORDERLIST_ON:
bChangeNumFmt = sal_True;
switch( rOption.GetString().GetChar(0) )
{
case 'A': aNumFmt.SetNumberingType(SVX_NUM_CHARS_UPPER_LETTER); break;
case 'a': aNumFmt.SetNumberingType(SVX_NUM_CHARS_LOWER_LETTER); break;
case 'I': aNumFmt.SetNumberingType(SVX_NUM_ROMAN_UPPER); break;
case 'i': aNumFmt.SetNumberingType(SVX_NUM_ROMAN_LOWER); break;
default: bChangeNumFmt = sal_False;
}
break;
case HTML_UNORDERLIST_ON:
aNumFmt.SetBulletChar( (sal_Unicode)rOption.GetEnum(
aHTMLULTypeTable,aNumFmt.GetBulletChar() ) );
bChangeNumFmt = sal_True;
break;
}
}
break;
case HTML_O_START:
{
sal_uInt16 nStart = (sal_uInt16)rOption.GetNumber();
if( bNewNumFmt )
{
aNumFmt.SetStart( nStart );
bChangeNumFmt = sal_True;
}
else
{
rInfo.SetNodeStartValue( nLevel, nStart );
}
}
break;
case HTML_O_STYLE:
aStyle = rOption.GetString();
break;
case HTML_O_CLASS:
aClass = rOption.GetString();
break;
case HTML_O_LANG:
aLang = rOption.GetString();
break;
case HTML_O_DIR:
aDir = rOption.GetString();
break;
case HTML_O_SRC:
if( bNewNumFmt )
{
aBulletSrc = rOption.GetString();
if( !InternalImgToPrivateURL(aBulletSrc) )
aBulletSrc = URIHelper::SmartRel2Abs( INetURLObject( sBaseURL ), aBulletSrc, Link(), false );
}
break;
case HTML_O_WIDTH:
nWidth = (sal_uInt16)rOption.GetNumber();
break;
case HTML_O_HEIGHT:
nHeight = (sal_uInt16)rOption.GetNumber();
break;
case HTML_O_ALIGN:
eVertOri =
(sal_Int16)rOption.GetEnum( aHTMLImgVAlignTable,
static_cast< sal_uInt16 >(eVertOri) );
break;
}
}
if( aBulletSrc.Len() )
{
// Eine Bullet-Liste mit Grafiken
aNumFmt.SetNumberingType(SVX_NUM_BITMAP);
// Die Grafik als Brush anlegen
SvxBrushItem aBrushItem( RES_BACKGROUND );
aBrushItem.SetGraphicLink( aBulletSrc );
aBrushItem.SetGraphicPos( GPOS_AREA );
// Die Groesse nur beachten, wenn Breite und Hoehe vorhanden sind
Size aTwipSz( nWidth, nHeight), *pTwipSz=0;
if( nWidth!=USHRT_MAX && nHeight!=USHRT_MAX )
{
aTwipSz =
Application::GetDefaultDevice()->PixelToLogic( aTwipSz,
MapMode(MAP_TWIP) );
pTwipSz = &aTwipSz;
}
// Die Ausrichtung auch nur beachten, wenn eine Ausrichtung
// angegeben wurde
aNumFmt.SetGraphicBrush( &aBrushItem, pTwipSz,
text::VertOrientation::NONE!=eVertOri ? &eVertOri : 0);
// Und noch die Grafik merken, um sie in den Absaetzen nicht
// einzufuegen
aBulletGrfs[nLevel] = aBulletSrc;
bChangeNumFmt = sal_True;
}
else
aBulletGrfs[nLevel].Erase();
// den aktuellen Absatz erst einmal nicht numerieren
{
sal_uInt8 nLvl = nLevel;
SetNodeNum( nLvl, false );
}
// einen neuen Kontext anlegen
_HTMLAttrContext *pCntxt = new _HTMLAttrContext( static_cast< sal_uInt16 >(nToken) );
// Styles parsen
if( HasStyleOptions( aStyle, aId, aClass, &aLang, &aDir ) )
{
SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
SvxCSS1PropertyInfo aPropInfo;
if( ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo, &aLang, &aDir ) )
{
if( bNewNumFmt )
{
if( aPropInfo.bLeftMargin )
{
// Der Der Default-Einzug wurde schon eingefuegt.
sal_uInt16 nAbsLSpace =
aNumFmt.GetAbsLSpace() - HTML_NUMBUL_MARGINLEFT;
if( aPropInfo.nLeftMargin < 0 &&
nAbsLSpace < -aPropInfo.nLeftMargin )
nAbsLSpace = 0U;
else if( aPropInfo.nLeftMargin > USHRT_MAX ||
(long)nAbsLSpace +
aPropInfo.nLeftMargin > USHRT_MAX )
nAbsLSpace = USHRT_MAX;
else
nAbsLSpace = nAbsLSpace + (sal_uInt16)aPropInfo.nLeftMargin;
aNumFmt.SetAbsLSpace( nAbsLSpace );
bChangeNumFmt = sal_True;
}
if( aPropInfo.bTextIndent )
{
short nTextIndent =
((const SvxLRSpaceItem &)aItemSet.Get( RES_LR_SPACE ))
.GetTxtFirstLineOfst();
aNumFmt.SetFirstLineOffset( nTextIndent );
bChangeNumFmt = sal_True;
}
}
aPropInfo.bLeftMargin = aPropInfo.bTextIndent = sal_False;
if( !aPropInfo.bRightMargin )
aItemSet.ClearItem( RES_LR_SPACE );
// #i89812# - Perform change to list style before calling <DoPositioning(..)>,
// because <DoPositioning(..)> may open a new context and thus may
// clear the <SwHTMLNumRuleInfo> instance hold by local variable <rInfo>.
if( bChangeNumFmt )
{
rInfo.GetNumRule()->Set( nLevel, aNumFmt );
pDoc->ChgNumRuleFmts( *rInfo.GetNumRule() );
bChangeNumFmt = sal_False;
}
DoPositioning( aItemSet, aPropInfo, pCntxt );
InsertAttrs( aItemSet, aPropInfo, pCntxt );
}
}
if( bChangeNumFmt )
{
rInfo.GetNumRule()->Set( nLevel, aNumFmt );
pDoc->ChgNumRuleFmts( *rInfo.GetNumRule() );
}
PushContext( pCntxt );
// die Attribute der neuen Vorlage setzen
SetTxtCollAttrs( pCntxt );
}
void SwHTMLParser::EndNumBulList( int nToken )
{
SwHTMLNumRuleInfo& rInfo = GetNumInfo();
// Ein neuer Absatz muss aufgemacht werden, wenn
// - der aktuelle nicht leer ist, also Text oder absatzgebundene Objekte
// enthaelt.
// - der aktuelle Absatz numeriert ist.
sal_Bool bAppend = pPam->GetPoint()->nContent.GetIndex() > 0;
if( !bAppend )
{
SwTxtNode* pTxtNode = pPam->GetNode()->GetTxtNode();
bAppend = (pTxtNode && ! pTxtNode->IsOutline() && pTxtNode->IsCountedInList()) ||
HasCurrentParaFlys();
}
sal_Bool bSpace = (rInfo.GetDepth() + nDefListDeep) == 1;
if( bAppend )
AppendTxtNode( bSpace ? AM_SPACE : AM_NOSPACE, sal_False );
else if( bSpace )
AddParSpace();
// den aktuellen Kontext vom Stack holen
_HTMLAttrContext *pCntxt = nToken!=0 ? PopContext( static_cast< sal_uInt16 >(nToken & ~1) ) : 0;
// Keine Liste aufgrund eines Tokens beenden, wenn der Kontext
// nie angelgt wurde oder nicht beendet werden darf.
if( rInfo.GetDepth()>0 && (!nToken || pCntxt) )
{
rInfo.DecDepth();
if( !rInfo.GetDepth() ) // wars der letze Level ?
{
// Die noch nicht angepassten Formate werden jetzt noch
// angepasst, damit es sich besser Editieren laesst.
const SwNumFmt *pRefNumFmt = 0;
sal_Bool bChanged = sal_False;
for( sal_uInt16 i=0; i<MAXLEVEL; i++ )
{
const SwNumFmt *pNumFmt = rInfo.GetNumRule()->GetNumFmt(i);
if( pNumFmt )
{
pRefNumFmt = pNumFmt;
}
else if( pRefNumFmt )
{
SwNumFmt aNumFmt( rInfo.GetNumRule()->Get(i) );
aNumFmt.SetNumberingType(pRefNumFmt->GetNumberingType() != SVX_NUM_BITMAP
? pRefNumFmt->GetNumberingType() : style::NumberingType::CHAR_SPECIAL);
if( SVX_NUM_CHAR_SPECIAL == aNumFmt.GetNumberingType() )
{
// #i63395# - Only apply user defined default bullet font
if ( numfunc::IsDefBulletFontUserDefined() )
{
aNumFmt.SetBulletFont( &numfunc::GetDefBulletFont() );
}
aNumFmt.SetBulletChar( cBulletChar );
}
aNumFmt.SetAbsLSpace( (i+1) * HTML_NUMBUL_MARGINLEFT );
aNumFmt.SetFirstLineOffset( HTML_NUMBUL_INDENT );
aNumFmt.SetCharFmt( pRefNumFmt->GetCharFmt() );
rInfo.GetNumRule()->Set( i, aNumFmt );
bChanged = sal_True;
}
}
if( bChanged )
pDoc->ChgNumRuleFmts( *rInfo.GetNumRule() );
// Beim letzen Append wurde das NumRule-Item und das
// NodeNum-Objekt mit kopiert. Beides muessen wir noch
// loeschen. Das ResetAttr loescht das NodeNum-Objekt mit!
pPam->GetNode()->GetTxtNode()->ResetAttr( RES_PARATR_NUMRULE );
rInfo.Clear();
}
else
{
// the next paragraph not numbered first
SetNodeNum( rInfo.GetLevel(), false );
}
}
// und noch Attribute beenden
sal_Bool bSetAttrs = sal_False;
if( pCntxt )
{
EndContext( pCntxt );
delete pCntxt;
bSetAttrs = sal_True;
}
if( nToken )
SetTxtCollAttrs();
if( bSetAttrs )
SetAttr(); // Absatz-Atts wegen JavaScript moeglichst schnell setzen
}
void SwHTMLParser::NewNumBulListItem( int nToken )
{
sal_uInt8 nLevel = GetNumInfo().GetLevel();
String aId, aStyle, aClass, aLang, aDir;
sal_uInt16 nStart = HTML_LISTHEADER_ON != nToken
? GetNumInfo().GetNodeStartValue( nLevel )
: USHRT_MAX;
if( USHRT_MAX != nStart )
GetNumInfo().SetNodeStartValue( nLevel );
const HTMLOptions& rHTMLOptions = GetOptions();
for (size_t i = rHTMLOptions.size(); i; )
{
const HTMLOption& rOption = rHTMLOptions[--i];
switch( rOption.GetToken() )
{
case HTML_O_VALUE:
nStart = (sal_uInt16)rOption.GetNumber();
break;
case HTML_O_ID:
aId = rOption.GetString();
break;
case HTML_O_STYLE:
aStyle = rOption.GetString();
break;
case HTML_O_CLASS:
aClass = rOption.GetString();
break;
case HTML_O_LANG:
aLang = rOption.GetString();
break;
case HTML_O_DIR:
aDir = rOption.GetString();
break;
}
}
// einen neuen Absatz aufmachen
if( pPam->GetPoint()->nContent.GetIndex() )
AppendTxtNode( AM_NOSPACE, sal_False );
bNoParSpace = sal_False; // In <LI> wird kein Abstand eingefuegt!
const bool bCountedInList( HTML_LISTHEADER_ON==nToken ? false : true );
_HTMLAttrContext *pCntxt = new _HTMLAttrContext( static_cast< sal_uInt16 >(nToken) );
String aNumRuleName;
if( GetNumInfo().GetNumRule() )
{
aNumRuleName = GetNumInfo().GetNumRule()->GetName();
}
else
{
aNumRuleName = pDoc->GetUniqueNumRuleName();
SwNumRule aNumRule( aNumRuleName,
SvxNumberFormat::LABEL_WIDTH_AND_POSITION );
SwNumFmt aNumFmt( aNumRule.Get( 0 ) );
// #i63395# - Only apply user defined default bullet font
if ( numfunc::IsDefBulletFontUserDefined() )
{
aNumFmt.SetBulletFont( &numfunc::GetDefBulletFont() );
}
aNumFmt.SetNumberingType(SVX_NUM_CHAR_SPECIAL);
aNumFmt.SetBulletChar( cBulletChar ); // das Bulletzeichen !!
aNumFmt.SetCharFmt( pCSS1Parser->GetCharFmtFromPool(RES_POOLCHR_BUL_LEVEL) );
aNumFmt.SetLSpace( (sal_uInt16)(-HTML_NUMBUL_INDENT) );
aNumFmt.SetFirstLineOffset( HTML_NUMBUL_INDENT );
aNumRule.Set( 0, aNumFmt );
pDoc->MakeNumRule( aNumRuleName, &aNumRule );
OSL_ENSURE( !nOpenParaToken,
"Jetzt geht ein offenes Absatz-Element verloren" );
// Wir tun so, als ob wir in einem Absatz sind. Dann wird
// beim naechsten Absatz wenigstens die Numerierung
// weggeschmissen, die nach dem naechsten AppendTxtNode uebernommen
// wird.
nOpenParaToken = static_cast< sal_uInt16 >(nToken);
}
SwTxtNode* pTxtNode = pPam->GetNode()->GetTxtNode();
((SwCntntNode *)pTxtNode)->SetAttr( SwNumRuleItem(aNumRuleName) );
pTxtNode->SetAttrListLevel(nLevel);
// #i57656# - <IsCounted()> state of text node has to be adjusted accordingly.
if ( nLevel < MAXLEVEL )
{
pTxtNode->SetCountedInList( bCountedInList );
}
// #i57919#
// correction of refactoring done by cws swnumtree
// - <nStart> contains the start value, if the numbering has to be restarted
// at this text node. Value <USHRT_MAX> indicates, that numbering isn't
// restarted at this text node
if ( nStart != USHRT_MAX )
{
pTxtNode->SetListRestart( true );
pTxtNode->SetAttrListRestartValue( nStart );
}
if( GetNumInfo().GetNumRule() )
GetNumInfo().GetNumRule()->SetInvalidRule( sal_True );
// Styles parsen
if( HasStyleOptions( aStyle, aId, aClass, &aLang, &aDir ) )
{
SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
SvxCSS1PropertyInfo aPropInfo;
if( ParseStyleOptions( aStyle, aId, aClass, aItemSet, aPropInfo, &aLang, &aDir ) )
{
DoPositioning( aItemSet, aPropInfo, pCntxt );
InsertAttrs( aItemSet, aPropInfo, pCntxt );
}
}
PushContext( pCntxt );
// die neue Vorlage setzen
SetTxtCollAttrs( pCntxt );
// Laufbalkenanzeige aktualisieren
ShowStatline();
}
void SwHTMLParser::EndNumBulListItem( int nToken, sal_Bool bSetColl,
sal_Bool /*bLastPara*/ )
{
// einen neuen Absatz aufmachen
if( !nToken && pPam->GetPoint()->nContent.GetIndex() )
AppendTxtNode( AM_NOSPACE );
// Kontext zu dem Token suchen und vom Stack holen
_HTMLAttrContext *pCntxt = 0;
sal_uInt16 nPos = aContexts.Count();
nToken &= ~1;
while( !pCntxt && nPos>nContextStMin )
{
sal_uInt16 nCntxtToken = aContexts[--nPos]->GetToken();
switch( nCntxtToken )
{
case HTML_LI_ON:
case HTML_LISTHEADER_ON:
if( !nToken || nToken == nCntxtToken )
{
pCntxt = aContexts[nPos];
aContexts.Remove( nPos, 1 );
}
break;
case HTML_ORDERLIST_ON:
case HTML_UNORDERLIST_ON:
case HTML_MENULIST_ON:
case HTML_DIRLIST_ON:
// keine LI/LH ausserhalb der aktuellen Liste betrachten
nPos = nContextStMin;
break;
}
}
// und noch Attribute beenden
if( pCntxt )
{
EndContext( pCntxt );
SetAttr(); // Absatz-Atts wegen JavaScript moeglichst schnell setzen
delete pCntxt;
}
// und die bisherige Vorlage setzen
if( bSetColl )
SetTxtCollAttrs();
}
void SwHTMLParser::SetNodeNum( sal_uInt8 nLevel, bool bCountedInList )
{
SwTxtNode* pTxtNode = pPam->GetNode()->GetTxtNode();
OSL_ENSURE( pTxtNode, "Kein Text-Node an PaM-Position" );
OSL_ENSURE( GetNumInfo().GetNumRule(), "Kein Numerierungs-Regel" );
const String& rName = GetNumInfo().GetNumRule()->GetName();
((SwCntntNode *)pTxtNode)->SetAttr( SwNumRuleItem(rName) );
pTxtNode->SetAttrListLevel( nLevel );
pTxtNode->SetCountedInList( bCountedInList );
// NumRule invalidieren, weil sie durch ein EndAction bereits
// auf valid geschaltet worden sein kann.
GetNumInfo().GetNumRule()->SetInvalidRule( sal_False );
}
void SwHTMLWriter::FillNextNumInfo()
{
pNextNumRuleInfo = 0;
sal_uLong nPos = pCurPam->GetPoint()->nNode.GetIndex() + 1;
sal_Bool bTable = sal_False;
do
{
const SwNode* pNd = pDoc->GetNodes()[nPos];
if( pNd->IsTxtNode() )
{
// Der naechste wird als naechstes ausgegeben.
pNextNumRuleInfo = new SwHTMLNumRuleInfo( *pNd->GetTxtNode() );
// Vor einer Tabelle behalten wir erst einmal die alte Ebene bei,
// wenn die gleiche Numerierung hinter der Tabelle
// fortgesetzt wird und dort nicht von vorne numeriert
// wird. Die Tabelle wird ann beim Import so weit eingeruckt,
// wie es der Num-Ebene entspricht.
if( bTable &&
pNextNumRuleInfo->GetNumRule()==GetNumInfo().GetNumRule() &&
!pNextNumRuleInfo->IsRestart() )
{
pNextNumRuleInfo->SetDepth( GetNumInfo().GetDepth() );
}
}
else if( pNd->IsTableNode() )
{
// Eine Tabelle wird uebersprungen, also den Node
// hinter der Tabelle betrachten.
nPos = pNd->EndOfSectionIndex() + 1;
bTable = sal_True;
}
else
{
// In allen anderen Faellen ist die Numerierung erstmal
// zu Ende.
pNextNumRuleInfo = new SwHTMLNumRuleInfo;
}
}
while( !pNextNumRuleInfo );
}
void SwHTMLWriter::ClearNextNumInfo()
{
delete pNextNumRuleInfo;
pNextNumRuleInfo = 0;
}
Writer& OutHTML_NumBulListStart( SwHTMLWriter& rWrt,
const SwHTMLNumRuleInfo& rInfo )
{
SwHTMLNumRuleInfo& rPrevInfo = rWrt.GetNumInfo();
sal_Bool bSameRule = rPrevInfo.GetNumRule() == rInfo.GetNumRule();
if( bSameRule && rPrevInfo.GetDepth() >= rInfo.GetDepth() &&
!rInfo.IsRestart() )
{
return rWrt;
}
sal_Bool bStartValue = sal_False;
if( !bSameRule && rInfo.GetDepth() )
{
String aName( rInfo.GetNumRule()->GetName() );
if( 0 != rWrt.aNumRuleNames.count( aName ) )
{
// The rule has been applied before
sal_Int16 eType = rInfo.GetNumRule()
->Get( rInfo.GetDepth()-1 ).GetNumberingType();
if( SVX_NUM_CHAR_SPECIAL != eType && SVX_NUM_BITMAP != eType )
{
// If its a numbering rule, the current number should be
// exported as start value, but only if there are no nodes
// within the numbering that have a lower level
bStartValue = sal_True;
if( rInfo.GetDepth() > 1 )
{
sal_uLong nPos =
rWrt.pCurPam->GetPoint()->nNode.GetIndex() + 1;
do
{
const SwNode* pNd = rWrt.pDoc->GetNodes()[nPos];
if( pNd->IsTxtNode() )
{
const SwTxtNode *pTxtNd = pNd->GetTxtNode();
if( !pTxtNd->GetNumRule() )
{
// node isn't numbered => check completed
break;
}
OSL_ENSURE(! pTxtNd->IsOutline(),
"outline not expected");
if( pTxtNd->GetActualListLevel() + 1 <
rInfo.GetDepth() )
{
// node is numbered, but level is lower
// => check completed
bStartValue = sal_False;
break;
}
nPos++;
}
else if( pNd->IsTableNode() )
{
// skip table
nPos = pNd->EndOfSectionIndex() + 1;
}
else
{
// end node or sections start node -> check
// completed
break;
}
}
while( sal_True );
}
}
}
else
{
rWrt.aNumRuleNames.insert( aName );
}
}
OSL_ENSURE( rWrt.nLastParaToken == 0,
"<PRE> wurde nicht vor <OL> beendet." );
sal_uInt16 nPrevDepth =
(bSameRule && !rInfo.IsRestart()) ? rPrevInfo.GetDepth() : 0;
for( sal_uInt16 i=nPrevDepth; i<rInfo.GetDepth(); i++ )
{
rWrt.OutNewLine(); // <OL>/<UL> in eine neue Zeile
rWrt.aBulletGrfs[i].Erase();
rtl::OStringBuffer sOut;
sOut.append('<');
const SwNumFmt& rNumFmt = rInfo.GetNumRule()->Get( i );
sal_Int16 eType = rNumFmt.GetNumberingType();
if( SVX_NUM_CHAR_SPECIAL == eType )
{
// Aufzaehlungs-Liste: <OL>
sOut.append(OOO_STRING_SVTOOLS_HTML_unorderlist);
// den Typ ueber das Bullet-Zeichen bestimmen
const sal_Char *pStr = 0;
switch( rNumFmt.GetBulletChar() )
{
case HTML_BULLETCHAR_DISC:
pStr = OOO_STRING_SVTOOLS_HTML_ULTYPE_disc;
break;
case HTML_BULLETCHAR_CIRCLE:
pStr = OOO_STRING_SVTOOLS_HTML_ULTYPE_circle;
break;
case HTML_BULLETCHAR_SQUARE:
pStr = OOO_STRING_SVTOOLS_HTML_ULTYPE_square;
break;
}
if( pStr )
{
sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_type).
append('=').append(pStr);
}
}
else if( SVX_NUM_BITMAP == eType )
{
// Aufzaehlungs-Liste: <OL>
sOut.append(OOO_STRING_SVTOOLS_HTML_unorderlist);
rWrt.Strm() << sOut.makeStringAndClear().getStr();
OutHTML_BulletImage( rWrt,
0,
rNumFmt.GetBrush(),
rWrt.aBulletGrfs[i],
rNumFmt.GetGraphicSize(),
rNumFmt.GetGraphicOrientation() );
}
else
{
// Numerierungs-Liste: <UL>
sOut.append(OOO_STRING_SVTOOLS_HTML_orderlist);
// den Typ ueber das Format bestimmen
sal_Char cType = 0;
switch( eType )
{
case SVX_NUM_CHARS_UPPER_LETTER: cType = 'A'; break;
case SVX_NUM_CHARS_LOWER_LETTER: cType = 'a'; break;
case SVX_NUM_ROMAN_UPPER: cType = 'I'; break;
case SVX_NUM_ROMAN_LOWER: cType = 'i'; break;
}
if( cType )
{
sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_type).
append('=').append(cType);
}
sal_uInt16 nStartVal = rNumFmt.GetStart();
if( bStartValue && 1 == nStartVal && i == rInfo.GetDepth()-1 )
{
// #i51089 - TUNING#
if ( rWrt.pCurPam->GetNode()->GetTxtNode()->GetNum() )
{
nStartVal = static_cast< sal_uInt16 >( rWrt.pCurPam->GetNode()
->GetTxtNode()->GetNumberVector()[i] );
}
else
{
OSL_FAIL( "<OutHTML_NumBulListStart(..) - text node has no number." );
}
}
if( nStartVal != 1 )
{
sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_start).
append('=').append(static_cast<sal_Int32>(nStartVal));
}
}
if (sOut.getLength())
rWrt.Strm() << sOut.makeStringAndClear().getStr();
if( rWrt.bCfgOutStyles )
OutCSS1_NumBulListStyleOpt( rWrt, *rInfo.GetNumRule(), (sal_uInt8)i );
rWrt.Strm() << '>';
rWrt.IncIndentLevel(); // Inhalt von <OL> einruecken
}
return rWrt;
}
Writer& OutHTML_NumBulListEnd( SwHTMLWriter& rWrt,
const SwHTMLNumRuleInfo& rNextInfo )
{
SwHTMLNumRuleInfo& rInfo = rWrt.GetNumInfo();
sal_Bool bSameRule = rNextInfo.GetNumRule() == rInfo.GetNumRule();
if( bSameRule && rNextInfo.GetDepth() >= rInfo.GetDepth() &&
!rNextInfo.IsRestart() )
{
return rWrt;
}
OSL_ENSURE( rWrt.nLastParaToken == 0,
"<PRE> wurde nicht vor </OL> beendet." );
sal_uInt16 nNextDepth =
(bSameRule && !rNextInfo.IsRestart()) ? rNextInfo.GetDepth() : 0;
// MIB 23.7.97: Die Schleife muss doch rueckwaerts durchlaufen
// werden, weil die Reihenfolge von </OL>/</UL> stimmen muss
for( sal_uInt16 i=rInfo.GetDepth(); i>nNextDepth; i-- )
{
rWrt.DecIndentLevel(); // Inhalt von <OL> einruecken
if( rWrt.bLFPossible )
rWrt.OutNewLine(); // </OL>/</UL> in eine neue Zeile
// es wird also eine Liste angefangen oder beendet:
sal_Int16 eType = rInfo.GetNumRule()->Get( i-1 ).GetNumberingType();
const sal_Char *pStr;
if( SVX_NUM_CHAR_SPECIAL == eType || SVX_NUM_BITMAP == eType)
pStr = OOO_STRING_SVTOOLS_HTML_unorderlist;
else
pStr = OOO_STRING_SVTOOLS_HTML_orderlist;
HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), pStr, sal_False );
rWrt.bLFPossible = sal_True;
}
return rWrt;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|