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

Generated by: LCOV version 1.11