LCOV - code coverage report
Current view: top level - sw/source/filter/html - htmlctxt.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 197 317 62.1 %
Date: 2014-04-11 Functions: 29 32 90.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "hintids.hxx"
      21             : #include <svl/itemiter.hxx>
      22             : #include <editeng/lrspitem.hxx>
      23             : #include <editeng/ulspitem.hxx>
      24             : #include <editeng/brushitem.hxx>
      25             : #include <editeng/fhgtitem.hxx>
      26             : #include <svtools/htmltokn.h>
      27             : #include <editeng/boxitem.hxx>
      28             : 
      29             : #include "doc.hxx"
      30             : #include "pam.hxx"
      31             : #include "ndtxt.hxx"
      32             : #include "shellio.hxx"
      33             : #include "paratr.hxx"
      34             : #include "htmlnum.hxx"
      35             : #include "css1kywd.hxx"
      36             : #include "swcss1.hxx"
      37             : #include "swhtml.hxx"
      38             : 
      39             : using namespace ::com::sun::star;
      40             : 
      41             : class _HTMLAttrContext_SaveDoc
      42             : {
      43             :     SwHTMLNumRuleInfo aNumRuleInfo; // In Umgebung gueltige Numerierung
      44             :     SwPosition  *pPos;              // hierhin beim verlassen den
      45             :                                     // Kontexts zurueckgesprungen
      46             :     _HTMLAttrTable *pAttrTab;       // In Umgebung gueltige Attribute,
      47             :                                     // wenn Attributierung nicht
      48             :                                     // beibehalten werden soll.
      49             : 
      50             :     sal_uInt16 nContextStMin;           // In Umgebung gueltige Stack-
      51             :                                     // Untergrenze, wenn der Stack
      52             :                                     // geschuetzt werden soll.
      53             :     sal_uInt16 nContextStAttrMin;       // In Umgebung gueltige Stack-
      54             :                                     // Untergrenze, wenn die Attribute
      55             :                                     // nicht beibehalten werden sollen.
      56             : 
      57             :     sal_Bool bStripTrailingPara : 1;    // letzen Absatz entfernen?
      58             :     sal_Bool bKeepNumRules : 1;         // Numerierung beibehalten?
      59             :     sal_Bool bFixHeaderDist : 1;
      60             :     sal_Bool bFixFooterDist : 1;
      61             : 
      62             : public:
      63             : 
      64           1 :     _HTMLAttrContext_SaveDoc() :
      65             :         pPos( 0 ), pAttrTab( 0 ),
      66             :         nContextStMin( USHRT_MAX ), nContextStAttrMin( USHRT_MAX ),
      67             :         bStripTrailingPara( sal_False ), bKeepNumRules( sal_False ),
      68           1 :         bFixHeaderDist( sal_False ), bFixFooterDist( sal_False )
      69           1 :     {}
      70             : 
      71           1 :     ~_HTMLAttrContext_SaveDoc() { delete pPos; delete pAttrTab; }
      72             : 
      73             :     // Die Position gehoert uns, muss also angelegt und zerstoert werden
      74           1 :     void SetPos( const SwPosition& rPos ) { pPos = new SwPosition(rPos); }
      75           2 :     const SwPosition *GetPos() const { return pPos; }
      76             : 
      77             :     // Der Index gehoert uns nicht. Kein Anlgen und Zerstoeren.
      78           1 :     void SetNumInfo( const SwHTMLNumRuleInfo& rInf ) { aNumRuleInfo.Set(rInf); }
      79           1 :     const SwHTMLNumRuleInfo& GetNumInfo() const { return aNumRuleInfo; }
      80             : 
      81             :     _HTMLAttrTable *GetAttrTab( sal_Bool bCreate= sal_False );
      82             : 
      83           1 :     void SetContextStMin( sal_uInt16 nMin ) { nContextStMin = nMin; }
      84           2 :     sal_uInt16 GetContextStMin() const { return nContextStMin; }
      85             : 
      86           1 :     void SetContextStAttrMin( sal_uInt16 nMin ) { nContextStAttrMin = nMin; }
      87           2 :     sal_uInt16 GetContextStAttrMin() const { return nContextStAttrMin; }
      88             : 
      89           1 :     void SetStripTrailingPara( sal_Bool bSet ) { bStripTrailingPara = bSet; }
      90           1 :     sal_Bool GetStripTrailingPara() const { return bStripTrailingPara; }
      91             : 
      92           1 :     void SetKeepNumRules( sal_Bool bSet ) { bKeepNumRules = bSet; }
      93           2 :     sal_Bool GetKeepNumRules() const { return bKeepNumRules; }
      94             : 
      95           1 :     void SetFixHeaderDist( sal_Bool bSet ) { bFixHeaderDist = bSet; }
      96           1 :     sal_Bool GetFixHeaderDist() const { return bFixHeaderDist; }
      97             : 
      98           1 :     void SetFixFooterDist( sal_Bool bSet ) { bFixFooterDist = bSet; }
      99           1 :     sal_Bool GetFixFooterDist() const { return bFixFooterDist; }
     100             : };
     101             : 
     102           2 : _HTMLAttrTable *_HTMLAttrContext_SaveDoc::GetAttrTab( sal_Bool bCreate )
     103             : {
     104           2 :     if( !pAttrTab && bCreate )
     105             :     {
     106           1 :         pAttrTab = new _HTMLAttrTable;
     107           1 :         memset( pAttrTab, 0, sizeof( _HTMLAttrTable ));
     108             :     }
     109           2 :     return pAttrTab;
     110             : }
     111             : 
     112           2 : _HTMLAttrContext_SaveDoc *_HTMLAttrContext::GetSaveDocContext( sal_Bool bCreate )
     113             : {
     114           2 :     if( !pSaveDocContext && bCreate )
     115           1 :         pSaveDocContext = new _HTMLAttrContext_SaveDoc;
     116             : 
     117           2 :     return pSaveDocContext;
     118             : }
     119             : 
     120         565 : void _HTMLAttrContext::ClearSaveDocContext()
     121             : {
     122         565 :     delete pSaveDocContext;
     123         565 :     pSaveDocContext = 0;
     124         565 : }
     125             : 
     126           0 : void SwHTMLParser::SplitAttrTab( const SwPosition& rNewPos )
     127             : {
     128             :     // preliminary paragraph attributes are not allowed here, they could
     129             :     // be set here and then the pointers become invalid!
     130             :     OSL_ENSURE(aParaAttrs.empty(),
     131             :         "Danger: there are non-final paragraph attributes");
     132           0 :     if( !aParaAttrs.empty() )
     133           0 :         aParaAttrs.clear();
     134             : 
     135           0 :     const SwNodeIndex* pOldEndPara = &pPam->GetPoint()->nNode;
     136           0 :     sal_Int32 nOldEndCnt = pPam->GetPoint()->nContent.GetIndex();
     137             : 
     138           0 :     const SwNodeIndex& rNewSttPara = rNewPos.nNode;
     139           0 :     sal_Int32 nNewSttCnt = rNewPos.nContent.GetIndex();
     140             : 
     141           0 :     sal_Bool bMoveBack = sal_False;
     142             : 
     143             :     // alle noch offenen Attribute beenden und hinter der Tabelle
     144             :     // neu aufspannen
     145           0 :     _HTMLAttr** pTbl = (_HTMLAttr**)&aAttrTab;
     146           0 :     for( sal_uInt16 nCnt = sizeof( _HTMLAttrTable ) / sizeof( _HTMLAttr* );
     147             :             nCnt--; ++pTbl )
     148             :     {
     149           0 :         _HTMLAttr *pAttr = *pTbl;
     150           0 :         while( pAttr )
     151             :         {
     152           0 :             _HTMLAttr *pNext = pAttr->GetNext();
     153           0 :             _HTMLAttr *pPrev = pAttr->GetPrev();
     154             : 
     155           0 :             sal_uInt16 nWhich = pAttr->pItem->Which();
     156           0 :             if( !nOldEndCnt && RES_PARATR_BEGIN <= nWhich &&
     157           0 :                 pAttr->GetSttParaIdx() < pOldEndPara->GetIndex() )
     158             :             {
     159             :                 // Das Attribut muss eine Content-Position weiter vorne
     160             :                 // beendet werden
     161           0 :                 if( !bMoveBack )
     162             :                 {
     163           0 :                     bMoveBack = pPam->Move( fnMoveBackward );
     164           0 :                     nOldEndCnt = pPam->GetPoint()->nContent.GetIndex();
     165             :                 }
     166             :             }
     167           0 :             else if( bMoveBack )
     168             :             {
     169           0 :                 pPam->Move( fnMoveForward );
     170           0 :                 nOldEndCnt = pPam->GetPoint()->nContent.GetIndex();
     171             :             }
     172             : 
     173           0 :             if( (RES_PARATR_BEGIN <= nWhich && bMoveBack) ||
     174           0 :                 pAttr->GetSttParaIdx() < pOldEndPara->GetIndex() ||
     175           0 :                 (pAttr->GetSttPara() == *pOldEndPara &&
     176           0 :                  pAttr->GetSttCnt() != nOldEndCnt) )
     177             :             {
     178             :                 // Das Attribut muss gesetzt werden. Da wir
     179             :                 // das Original noch brauchen, weil Zeiger auf das Attribut
     180             :                 // noch in den Kontexten existieren, muessen wir es clonen.
     181             :                 // Die Next-Liste geht dabei verloren, aber die
     182             :                 // Previous-Liste bleibt erhalten
     183           0 :                 _HTMLAttr *pSetAttr = pAttr->Clone( *pOldEndPara, nOldEndCnt );
     184             : 
     185           0 :                 if( pNext )
     186           0 :                     pNext->InsertPrev( pSetAttr );
     187             :                 else
     188             :                 {
     189           0 :                     if (pSetAttr->bInsAtStart)
     190           0 :                         aSetAttrTab.push_front( pSetAttr );
     191             :                     else
     192           0 :                         aSetAttrTab.push_back( pSetAttr );
     193             :                 }
     194             :             }
     195           0 :             else if( pPrev )
     196             :             {
     197             :                 // Wenn das Attribut nicht gesetzt vor der Tabelle
     198             :                 // gesetzt werden muss, muessen der Previous-Attribute
     199             :                 // trotzdem gesetzt werden.
     200           0 :                 if( pNext )
     201           0 :                     pNext->InsertPrev( pPrev );
     202             :                 else
     203             :                 {
     204           0 :                     if (pPrev->bInsAtStart)
     205           0 :                         aSetAttrTab.push_front( pPrev );
     206             :                     else
     207           0 :                         aSetAttrTab.push_back( pPrev );
     208             :                 }
     209             :             }
     210             : 
     211             :             // den Start des Attributs neu setzen
     212           0 :             pAttr->nSttPara = rNewSttPara;
     213           0 :             pAttr->nEndPara = rNewSttPara;
     214           0 :             pAttr->nSttCntnt = nNewSttCnt;
     215           0 :             pAttr->nEndCntnt = nNewSttCnt;
     216           0 :             pAttr->pPrev = 0;
     217             : 
     218           0 :             pAttr = pNext;
     219             :         }
     220             :     }
     221             : 
     222           0 :     if( bMoveBack )
     223           0 :         pPam->Move( fnMoveForward );
     224             : 
     225           0 : }
     226             : 
     227           1 : void SwHTMLParser::SaveDocContext( _HTMLAttrContext *pCntxt,
     228             :                                    sal_uInt16 nFlags,
     229             :                                    const SwPosition *pNewPos )
     230             : {
     231           1 :     _HTMLAttrContext_SaveDoc *pSave = pCntxt->GetSaveDocContext( sal_True );
     232           1 :     pSave->SetStripTrailingPara( (HTML_CNTXT_STRIP_PARA & nFlags) != 0 );
     233           1 :     pSave->SetKeepNumRules( (HTML_CNTXT_KEEP_NUMRULE & nFlags) != 0 );
     234           1 :     pSave->SetFixHeaderDist( (HTML_CNTXT_HEADER_DIST & nFlags) != 0 );
     235           1 :     pSave->SetFixFooterDist( (HTML_CNTXT_FOOTER_DIST & nFlags) != 0 );
     236             : 
     237           1 :     if( pNewPos )
     238             :     {
     239             :         // Wenn der PaM an eine andere Position gesetzt wird, muss
     240             :         // die Numerierung gerettet werden..
     241           1 :         if( !pSave->GetKeepNumRules() )
     242             :         {
     243             :             // Die Numerierung soll nicht beibehalten werden. Also muss
     244             :             // der aktuelle Zustand gerettet und die Numerierung
     245             :             // anschliessend ausgeschaltet werden.
     246           1 :             pSave->SetNumInfo( GetNumInfo() );
     247           1 :             GetNumInfo().Clear();
     248             :         }
     249             : 
     250           1 :         if( (HTML_CNTXT_KEEP_ATTRS & nFlags) != 0 )
     251             :         {
     252             :             // Attribute an aktueller Position beenden und an neuer neu anfangen
     253           0 :             SplitAttrTab( *pNewPos );
     254             :         }
     255             :         else
     256             :         {
     257           1 :             _HTMLAttrTable *pSaveAttrTab = pSave->GetAttrTab( sal_True );
     258           1 :             SaveAttrTab( *pSaveAttrTab );
     259             :         }
     260             : 
     261           1 :         pSave->SetPos( *pPam->GetPoint() );
     262           1 :         *pPam->GetPoint() = *pNewPos;
     263             :     }
     264             : 
     265             :     // Mit dem Setzen von nContextStMin koennen automatisch auch
     266             :     // keine gerade offenen Listen (DL/OL/UL) mehr beendet werden.
     267           1 :     if( (HTML_CNTXT_PROTECT_STACK & nFlags) != 0  )
     268             :     {
     269           1 :         pSave->SetContextStMin( nContextStMin );
     270           1 :         nContextStMin = aContexts.size();
     271             : 
     272           1 :         if( (HTML_CNTXT_KEEP_ATTRS & nFlags) == 0 )
     273             :         {
     274           1 :             pSave->SetContextStAttrMin( nContextStAttrMin );
     275           1 :             nContextStAttrMin = aContexts.size();
     276             :         }
     277             :     }
     278           1 : }
     279             : 
     280           1 : void SwHTMLParser::RestoreDocContext( _HTMLAttrContext *pCntxt )
     281             : {
     282           1 :     _HTMLAttrContext_SaveDoc *pSave = pCntxt->GetSaveDocContext();
     283           1 :     if( !pSave )
     284           1 :         return;
     285             : 
     286           1 :     if( pSave->GetStripTrailingPara() )
     287           1 :         StripTrailingPara();
     288             : 
     289           1 :     if( pSave->GetPos() )
     290             :     {
     291           1 :         if( pSave->GetFixHeaderDist() || pSave->GetFixFooterDist() )
     292           0 :             FixHeaderFooterDistance( pSave->GetFixHeaderDist(),
     293           0 :                                      pSave->GetPos() );
     294             : 
     295           1 :         _HTMLAttrTable *pSaveAttrTab = pSave->GetAttrTab();
     296           1 :         if( !pSaveAttrTab )
     297             :         {
     298             :             // Attribute an aktueller Position beenden und an alter neu
     299             :             // anfangen.
     300           0 :             SplitAttrTab( *pSave->GetPos() );
     301             :         }
     302             :         else
     303             :         {
     304           1 :             RestoreAttrTab( *pSaveAttrTab );
     305             :         }
     306             : 
     307           1 :         *pPam->GetPoint() = *pSave->GetPos();
     308             : 
     309             :         // Die bisherigen Attribute koennen wir schonmal setzen.
     310           1 :         SetAttr();
     311             :     }
     312             : 
     313           1 :     if( USHRT_MAX != pSave->GetContextStMin() )
     314             :     {
     315           1 :         nContextStMin = pSave->GetContextStMin();
     316           1 :         if( USHRT_MAX != pSave->GetContextStAttrMin() )
     317           1 :             nContextStAttrMin = pSave->GetContextStAttrMin();
     318             :     }
     319             : 
     320           1 :     if( !pSave->GetKeepNumRules() )
     321             :     {
     322             :         // Die bisherige gemerkte Numerierung wieder setzen
     323           1 :         GetNumInfo().Set( pSave->GetNumInfo() );
     324             :     }
     325             : 
     326           1 :     pCntxt->ClearSaveDocContext();
     327             : }
     328             : 
     329         564 : void SwHTMLParser::EndContext( _HTMLAttrContext *pContext )
     330             : {
     331         564 :     if( pContext->GetPopStack() )
     332             :     {
     333             :         // Alle noch offenen Kontexte beenden. Der eigene
     334             :         // Kontext muss bereits geloscht sein!
     335           2 :         while( aContexts.size() > nContextStMin )
     336             :         {
     337           0 :             _HTMLAttrContext *pCntxt = PopContext();
     338             :             OSL_ENSURE( pCntxt != pContext,
     339             :                     "Kontext noch im Stack" );
     340           0 :             if( pCntxt == pContext )
     341           0 :                 break;
     342             : 
     343           0 :             EndContext( pCntxt );
     344           0 :             delete pCntxt;
     345             :         }
     346             :     }
     347             : 
     348             :     // Alle noch offenen Attribute beenden
     349         564 :     if( pContext->HasAttrs() )
     350         287 :         EndContextAttrs( pContext );
     351             : 
     352             :     // Falls ein Bereich geoeffnet wurde, den verlassen. Da Bereiche
     353             :     // auch innerhalb von absolut positionierten Objekten angelegt werden,
     354             :     // muss das passieren, bever ein alter Dokument-Kontext restauriert wird.
     355         564 :     if( pContext->GetSpansSection() )
     356           9 :         EndSection();
     357             : 
     358             :     // Rahmen und sonstige Sonderbereiche verlassen.
     359         564 :     if( pContext->HasSaveDocContext() )
     360           1 :         RestoreDocContext( pContext );
     361             : 
     362             :     // Ggf. noch einen Ansatz-Umbruch einfuegen
     363         569 :     if( AM_NONE != pContext->GetAppendMode() &&
     364           5 :         pPam->GetPoint()->nContent.GetIndex() )
     365           2 :         AppendTxtNode( pContext->GetAppendMode() );
     366             : 
     367             :     // PRE-/LISTING- und XMP-Umgebungen wieder starten
     368         564 :     if( pContext->IsFinishPREListingXMP() )
     369         260 :         FinishPREListingXMP();
     370             : 
     371         564 :     if( pContext->IsRestartPRE() )
     372           0 :         StartPRE();
     373             : 
     374         564 :     if( pContext->IsRestartXMP() )
     375           0 :         StartXMP();
     376             : 
     377         564 :     if( pContext->IsRestartListing() )
     378           0 :         StartListing();
     379         564 : }
     380             : 
     381           0 : void SwHTMLParser::ClearContext( _HTMLAttrContext *pContext )
     382             : {
     383           0 :     _HTMLAttrs &rAttrs = pContext->GetAttrs();
     384           0 :     for( sal_uInt16 i=0; i<rAttrs.size(); i++ )
     385             :     {
     386             :         // einfaches Loeschen reicht hier nicht, weil das
     387             :         // Attribut auch aus seiner Liste ausgetragen werden
     388             :         // muss. Theoretisch koennt man natuerlich auch die Liste
     389             :         // und die Attribute getrennt loeschen, aber wenn man
     390             :         // dann was falsch gemacht hat, sieht es uebel aus.
     391           0 :         DeleteAttr( rAttrs[i] );
     392             :     }
     393             : 
     394             :     OSL_ENSURE( !pContext->GetSpansSection(),
     395             :             "Bereich kann nicht mehr verlassen werden" );
     396             : 
     397             :     OSL_ENSURE( !pContext->HasSaveDocContext(),
     398             :             "Rahmen kann nicht mehr verlassen werden" );
     399             : 
     400             :     // PRE-/LISTING- und XMP-Umgebungen wieder starten
     401           0 :     if( pContext->IsFinishPREListingXMP() )
     402           0 :         FinishPREListingXMP();
     403             : 
     404           0 :     if( pContext->IsRestartPRE() )
     405           0 :         StartPRE();
     406             : 
     407           0 :     if( pContext->IsRestartXMP() )
     408           0 :         StartXMP();
     409             : 
     410           0 :     if( pContext->IsRestartListing() )
     411           0 :         StartListing();
     412           0 : }
     413             : 
     414         286 : sal_Bool SwHTMLParser::DoPositioning( SfxItemSet &rItemSet,
     415             :                                   SvxCSS1PropertyInfo &rPropInfo,
     416             :                                   _HTMLAttrContext *pContext )
     417             : {
     418         286 :     sal_Bool bRet = sal_False;
     419             : 
     420             :     // Unter folgenden Umstaenden wird jetzt ein Rahmen aufgemacht:
     421             :     // - das Tag wird absolut positioniert und left/top sind beide
     422             :     //   gegeben und enthalten auch keine %-Angabe, oder
     423             :     // - das Tag soll fliessen, und
     424             :     // - es wurde eine Breite angegeben (in beiden Faellen noetig)
     425         286 :     if( SwCSS1Parser::MayBePositioned( rPropInfo ) )
     426             :     {
     427           1 :         SfxItemSet aFrmItemSet( pDoc->GetAttrPool(),
     428           1 :                                 RES_FRMATR_BEGIN, RES_FRMATR_END-1 );
     429           1 :         if( !IsNewDoc() )
     430           0 :             Reader::ResetFrmFmtAttrs(aFrmItemSet );
     431             : 
     432             :         // Ausrichtung setzen
     433             :         SetAnchorAndAdjustment( text::VertOrientation::NONE, text::HoriOrientation::NONE, rItemSet, rPropInfo,
     434           1 :                                 aFrmItemSet );
     435             : 
     436             :         // Groesse setzen
     437           1 :         SetVarSize( rItemSet, rPropInfo, aFrmItemSet );
     438             : 
     439             :         // Abstaende setzen
     440           1 :         SetSpace( Size(0,0), rItemSet, rPropInfo, aFrmItemSet );
     441             : 
     442             :         // Sonstige CSS1-Attribute Setzen
     443             :         SetFrmFmtAttrs( rItemSet, rPropInfo,
     444             :                         HTML_FF_BOX|HTML_FF_PADDING|HTML_FF_BACKGROUND|HTML_FF_DIRECTION,
     445           1 :                         aFrmItemSet );
     446             : 
     447             :         InsertFlyFrame( aFrmItemSet, pContext, rPropInfo.aId,
     448           1 :                         CONTEXT_FLAGS_ABSPOS );
     449           1 :         pContext->SetPopStack( sal_True );
     450           1 :         rPropInfo.aId = "";
     451           1 :         bRet = sal_True;
     452             :     }
     453             : 
     454         286 :     return bRet;
     455             : }
     456             : 
     457           2 : sal_Bool SwHTMLParser::CreateContainer( const OUString& rClass,
     458             :                                     SfxItemSet &rItemSet,
     459             :                                     SvxCSS1PropertyInfo &rPropInfo,
     460             :                                     _HTMLAttrContext *pContext )
     461             : {
     462           2 :     sal_Bool bRet = sal_False;
     463           2 :     if( rClass.equalsIgnoreAsciiCase( "sd-abs-pos" ) &&
     464           0 :         pCSS1Parser->MayBePositioned( rPropInfo ) )
     465             :     {
     466             :         // Container-Klasse
     467           0 :         SfxItemSet *pFrmItemSet = pContext->GetFrmItemSet( pDoc );
     468           0 :         if( !IsNewDoc() )
     469           0 :             Reader::ResetFrmFmtAttrs( *pFrmItemSet );
     470             : 
     471             :         SetAnchorAndAdjustment( text::VertOrientation::NONE, text::HoriOrientation::NONE,
     472           0 :                                 rItemSet, rPropInfo, *pFrmItemSet );
     473           0 :         Size aDummy(0,0);
     474             :         SetFixSize( aDummy, aDummy, sal_False, sal_False, rItemSet, rPropInfo,
     475           0 :                     *pFrmItemSet );
     476           0 :         SetSpace( aDummy, rItemSet, rPropInfo, *pFrmItemSet );
     477             :         SetFrmFmtAttrs( rItemSet, rPropInfo, HTML_FF_BOX|HTML_FF_BACKGROUND|HTML_FF_DIRECTION,
     478           0 :                         *pFrmItemSet );
     479             : 
     480           0 :         bRet = sal_True;
     481             :     }
     482             : 
     483           2 :     return bRet;
     484             : }
     485             : 
     486         546 : void SwHTMLParser::InsertAttrs( SfxItemSet &rItemSet,
     487             :                                 SvxCSS1PropertyInfo &rPropInfo,
     488             :                                 _HTMLAttrContext *pContext,
     489             :                                 sal_Bool bCharLvl )
     490             : {
     491             :     // Ein DropCap-Attribut basteln, wenn auf Zeichen-Ebene vor dem
     492             :     // ersten Zeichen ein float: left vorkommt
     493         569 :     if( bCharLvl && !pPam->GetPoint()->nContent.GetIndex() &&
     494          23 :         SVX_ADJUST_LEFT == rPropInfo.eFloat )
     495             :     {
     496           0 :         SwFmtDrop aDrop;
     497           0 :         aDrop.GetChars() = 1;
     498             : 
     499           0 :         pCSS1Parser->FillDropCap( aDrop, rItemSet );
     500             : 
     501             :         // Nur wenn das Initial auch ueber mehrere Zeilen geht, wird das
     502             :         // DropCap-Attribut gesetzt. Sonst setzten wir die Attribute hart.
     503           0 :         if( aDrop.GetLines() > 1 )
     504             :         {
     505           0 :             NewAttr( &aAttrTab.pDropCap, aDrop );
     506             : 
     507           0 :             _HTMLAttrs &rAttrs = pContext->GetAttrs();
     508           0 :             rAttrs.push_back( aAttrTab.pDropCap );
     509             : 
     510         546 :             return;
     511           0 :         }
     512             :     }
     513             : 
     514             : // Feature: PrintExt
     515         546 :     if( !bCharLvl )
     516         523 :         pCSS1Parser->SetFmtBreak( rItemSet, rPropInfo );
     517             : // /Feature: PrintExt
     518             : 
     519             :     OSL_ENSURE(aContexts.size() <= nContextStAttrMin ||
     520             :             aContexts.back() != pContext,
     521             :             "SwHTMLParser::InsertAttrs: Context already on the Stack");
     522             : 
     523         546 :     SfxItemIter aIter( rItemSet );
     524             : 
     525         546 :     const SfxPoolItem *pItem = aIter.FirstItem();
     526        2099 :     while( pItem )
     527             :     {
     528        1007 :         _HTMLAttr **ppAttr = 0;
     529             : 
     530        1007 :         switch( pItem->Which() )
     531             :         {
     532             :         case RES_LR_SPACE:
     533             :             {
     534             :                 // Absatz-Einzuege muessen addiert werden und werden immer
     535             :                 // nur absatzweise gesetzt (fuer den ersten Absatz hier,
     536             :                 // fuer alle folgenden in SetTxtCollAttrs)
     537             : 
     538             :                 const SvxLRSpaceItem *pLRItem =
     539           1 :                     (const SvxLRSpaceItem *)pItem;
     540             : 
     541             :                 // die bisherigen Absatz-Abstaende holen (ohne die vom
     542             :                 // obersten Kontext, denn den veraendern wir ja gerade) ...
     543           1 :                 sal_uInt16 nOldLeft = 0, nOldRight = 0;
     544           1 :                 short nOldIndent = 0;
     545           1 :                 sal_Bool bIgnoreTop = aContexts.size() > nContextStMin &&
     546           1 :                                   aContexts.back() == pContext;
     547             :                 GetMarginsFromContext( nOldLeft, nOldRight, nOldIndent,
     548           1 :                                        bIgnoreTop  );
     549             : 
     550             :                 // und noch die aktuell gueltigen
     551           1 :                 sal_uInt16 nLeft = nOldLeft, nRight = nOldRight;
     552           1 :                 short nIndent = nOldIndent;
     553           1 :                 pContext->GetMargins( nLeft, nRight, nIndent );
     554             : 
     555             :                 // ... und die neuen Abstaende zu den alten addieren
     556             :                 // Hier werden nicht die aus dem Item genommen, sondern die
     557             :                 // extra gemerkten, weil die auch negativ sein koennen. Die
     558             :                 // Abfrage ueber das Item funktioniert aber trotzdem, denn
     559             :                 // fuer negative Werte wird das Item (mit Wert 0) auch
     560             :                 // eingefuegt.
     561           1 :                 if( rPropInfo.bLeftMargin )
     562             :                 {
     563             :                     OSL_ENSURE( rPropInfo.nLeftMargin < 0 ||
     564             :                             rPropInfo.nLeftMargin == pLRItem->GetTxtLeft(),
     565             :                             "linker Abstand stimmt nicht mit Item ueberein" );
     566           1 :                     if( rPropInfo.nLeftMargin < 0 &&
     567           0 :                         -rPropInfo.nLeftMargin > nOldLeft )
     568           0 :                         nLeft = 0;
     569             :                     else
     570           1 :                         nLeft = nOldLeft + static_cast< sal_uInt16 >(rPropInfo.nLeftMargin);
     571             :                 }
     572           1 :                 if( rPropInfo.bRightMargin )
     573             :                 {
     574             :                     OSL_ENSURE( rPropInfo.nRightMargin < 0 ||
     575             :                             rPropInfo.nRightMargin == pLRItem->GetRight(),
     576             :                             "rechter Abstand stimmt nicht mit Item ueberein" );
     577           0 :                     if( rPropInfo.nRightMargin < 0 &&
     578           0 :                         -rPropInfo.nRightMargin > nOldRight )
     579           0 :                         nRight = 0;
     580             :                     else
     581           0 :                         nRight = nOldRight + static_cast< sal_uInt16 >(rPropInfo.nRightMargin);
     582             :                 }
     583           1 :                 if( rPropInfo.bTextIndent )
     584           0 :                     nIndent = pLRItem->GetTxtFirstLineOfst();
     585             : 
     586             :                 // und die Werte fuer nachfolgende Absaetze merken
     587           1 :                 pContext->SetMargins( nLeft, nRight, nIndent );
     588             : 
     589             :                 // das Attribut noch am aktuellen Absatz setzen
     590           1 :                 SvxLRSpaceItem aLRItem( *pLRItem );
     591           1 :                 aLRItem.SetTxtFirstLineOfst( nIndent );
     592           1 :                 aLRItem.SetTxtLeft( nLeft );
     593           1 :                 aLRItem.SetRight( nRight );
     594           1 :                 NewAttr( &aAttrTab.pLRSpace, aLRItem );
     595           1 :                 EndAttr( aAttrTab.pLRSpace, 0, sal_False );
     596             :             }
     597           1 :             break;
     598             : 
     599             :         case RES_UL_SPACE:
     600         212 :             if( !rPropInfo.bTopMargin || !rPropInfo.bBottomMargin )
     601             :             {
     602         211 :                 sal_uInt16 nUpper = 0, nLower = 0;
     603         211 :                 GetULSpaceFromContext( nUpper, nLower );
     604         211 :                 SvxULSpaceItem aULSpace( *((const SvxULSpaceItem *)pItem) );
     605         211 :                 if( !rPropInfo.bTopMargin )
     606           2 :                     aULSpace.SetUpper( nUpper );
     607         211 :                 if( !rPropInfo.bBottomMargin )
     608         209 :                     aULSpace.SetLower( nLower );
     609             : 
     610         211 :                 NewAttr( &aAttrTab.pULSpace, aULSpace );
     611             : 
     612             :                 // ... und noch die Kontext-Information speichern
     613         211 :                 _HTMLAttrs &rAttrs = pContext->GetAttrs();
     614         211 :                 rAttrs.push_back( aAttrTab.pULSpace );
     615             : 
     616         211 :                 pContext->SetULSpace( aULSpace.GetUpper(), aULSpace.GetLower() );
     617             :             }
     618             :             else
     619             :             {
     620           1 :                 ppAttr = &aAttrTab.pULSpace;
     621             :             }
     622         212 :             break;
     623             :         case RES_CHRATR_FONTSIZE:
     624             :             // es werden keine Attribute mit %-Angaben gesetzt
     625           5 :             if( ((const SvxFontHeightItem *)pItem)->GetProp() == 100 )
     626           5 :                 ppAttr = &aAttrTab.pFontHeight;
     627           5 :             break;
     628             :         case RES_CHRATR_CJK_FONTSIZE:
     629             :             // es werden keine Attribute mit %-Angaben gesetzt
     630           5 :             if( ((const SvxFontHeightItem *)pItem)->GetProp() == 100 )
     631           5 :                 ppAttr = &aAttrTab.pFontHeightCJK;
     632           5 :             break;
     633             :         case RES_CHRATR_CTL_FONTSIZE:
     634             :             // es werden keine Attribute mit %-Angaben gesetzt
     635           5 :             if( ((const SvxFontHeightItem *)pItem)->GetProp() == 100 )
     636           5 :                 ppAttr = &aAttrTab.pFontHeightCTL;
     637           5 :             break;
     638             : 
     639             :         case RES_BACKGROUND:
     640           0 :             if( bCharLvl )
     641             :             {
     642             :                 // das Frame-Attr ggf. in ein Char-Attr umwandeln
     643           0 :                 SvxBrushItem aBrushItem( *(const SvxBrushItem *)pItem );
     644           0 :                 aBrushItem.SetWhich( RES_CHRATR_BACKGROUND );
     645             : 
     646             :                 // Das Attribut setzen ...
     647           0 :                 NewAttr( &aAttrTab.pCharBrush, aBrushItem );
     648             : 
     649             :                 // ... und noch die Kontext-Information speichern
     650           0 :                 _HTMLAttrs &rAttrs = pContext->GetAttrs();
     651           0 :                 rAttrs.push_back( aAttrTab.pCharBrush );
     652             :             }
     653           0 :             else if( pContext->GetToken() != HTML_TABLEHEADER_ON &&
     654           0 :                      pContext->GetToken() != HTML_TABLEDATA_ON )
     655             :             {
     656           0 :                 ppAttr = &aAttrTab.pBrush;
     657             :             }
     658           0 :             break;
     659             : 
     660             :         case RES_BOX:
     661           1 :             if( bCharLvl )
     662             :             {
     663           1 :                 SvxBoxItem aBoxItem( *(const SvxBoxItem *)pItem );
     664           1 :                 aBoxItem.SetWhich( RES_CHRATR_BOX );
     665             : 
     666           1 :                 NewAttr( &aAttrTab.pCharBox, aBoxItem );
     667             : 
     668           1 :                 _HTMLAttrs &rAttrs = pContext->GetAttrs();
     669           1 :                 rAttrs.push_back( aAttrTab.pCharBox );
     670             :             }
     671             :             else
     672             :             {
     673           0 :                 ppAttr = &aAttrTab.pBox;
     674             :             }
     675           1 :             break;
     676             : 
     677             :         default:
     678             :             // den zu dem Item gehoehrenden Tabellen-Eintrag ermitteln ...
     679         778 :             ppAttr = GetAttrTabEntry( pItem->Which() );
     680         778 :             break;
     681             :         }
     682             : 
     683        1007 :         if( ppAttr )
     684             :         {
     685             :             // Das Attribut setzen ...
     686         794 :             NewAttr( ppAttr, *pItem );
     687             : 
     688             :             // ... und noch die Kontext-Information speichern
     689         794 :             _HTMLAttrs &rAttrs = pContext->GetAttrs();
     690         794 :             rAttrs.push_back( *ppAttr );
     691             :         }
     692             : 
     693             :         // auf zum naechsten Item
     694        1007 :         pItem = aIter.NextItem();
     695             :     }
     696             : 
     697         546 :     if( !rPropInfo.aId.isEmpty() )
     698           2 :         InsertBookmark( rPropInfo.aId );
     699             : }
     700             : 
     701          24 : void SwHTMLParser::InsertAttr( _HTMLAttr **ppAttr, const SfxPoolItem & rItem,
     702             :                                _HTMLAttrContext *pCntxt )
     703             : {
     704          24 :     if( !ppAttr )
     705             :     {
     706           0 :         ppAttr = GetAttrTabEntry( rItem.Which() );
     707           0 :         if( !ppAttr )
     708          24 :             return;
     709             :     }
     710             : 
     711             :     // das Attribut setzen
     712          24 :     NewAttr( ppAttr, rItem );
     713             : 
     714             :     // und im Kontext merken
     715          24 :     _HTMLAttrs &rAttrs = pCntxt->GetAttrs();
     716          24 :     rAttrs.push_back( *ppAttr );
     717             : }
     718             : 
     719         260 : void SwHTMLParser::SplitPREListingXMP( _HTMLAttrContext *pCntxt )
     720             : {
     721             :     // PRE/Listing/XMP soll beim beenden des Kontexts beendet werden.
     722         260 :     pCntxt->SetFinishPREListingXMP( sal_True );
     723             : 
     724             :     // Und die jetzt gueltigen Flags sollen wieder gesetzt werden.
     725         260 :     if( IsReadPRE() )
     726           0 :         pCntxt->SetRestartPRE( sal_True );
     727         260 :     if( IsReadXMP() )
     728           0 :         pCntxt->SetRestartXMP( sal_True );
     729         260 :     if( IsReadListing() )
     730           0 :         pCntxt->SetRestartListing( sal_True );
     731             : 
     732             :     // PRE/Listing/XMP wird auuserdem sofort beendet
     733         260 :     FinishPREListingXMP();
     734         260 : }
     735             : 
     736           0 : SfxItemSet *_HTMLAttrContext::GetFrmItemSet( SwDoc *pCreateDoc )
     737             : {
     738           0 :     if( !pFrmItemSet && pCreateDoc )
     739           0 :         pFrmItemSet = new SfxItemSet( pCreateDoc->GetAttrPool(),
     740           0 :                         RES_FRMATR_BEGIN, RES_FRMATR_END-1 );
     741           0 :     return pFrmItemSet;
     742             : }
     743             : 
     744             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10