LCOV - code coverage report
Current view: top level - sw/source/filter/writer - writer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 178 239 74.5 %
Date: 2012-08-25 Functions: 28 35 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 133 372 35.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <hintids.hxx>
      30                 :            : 
      31                 :            : #include <sot/storage.hxx>
      32                 :            : #include <sfx2/docfile.hxx>
      33                 :            : #include <svl/urihelper.hxx>
      34                 :            : #include <svtools/filter.hxx>
      35                 :            : #include <editeng/fontitem.hxx>
      36                 :            : #include <editeng/eeitem.hxx>
      37                 :            : #include <shellio.hxx>
      38                 :            : #include <doc.hxx>
      39                 :            : #include <docary.hxx>
      40                 :            : #include <IMark.hxx>
      41                 :            : #include <numrule.hxx>
      42                 :            : #include <swerror.h>
      43                 :            : #include <boost/bind.hpp>
      44                 :            : #include <boost/scoped_ptr.hpp>
      45                 :            : 
      46                 :            : using namespace ::com::sun::star;
      47                 :            : 
      48                 :            : 
      49                 :            : // Stringbuffer fuer die umgewandelten Zahlen
      50                 :            : static sal_Char aNToABuf[] = "0000000000000000000000000";
      51                 :            : #define NTOABUFLEN (sizeof(aNToABuf))
      52                 :            : 
      53                 :            : typedef std::multimap<sal_uLong, const ::sw::mark::IMark*> SwBookmarkNodeTable;
      54                 :            : 
      55                 :            : struct Writer_Impl
      56                 :            : {
      57                 :            :     SvStream * m_pStream;
      58                 :            : 
      59                 :            :     boost::scoped_ptr< std::map<String, String> > pFileNameMap;
      60                 :            :     std::vector<const SvxFontItem*> aFontRemoveLst;
      61                 :            :     SwBookmarkNodeTable aBkmkNodePos;
      62                 :            : 
      63                 :            :     Writer_Impl();
      64                 :            :     ~Writer_Impl();
      65                 :            : 
      66                 :            :     void RemoveFontList( SwDoc& rDoc );
      67                 :            :     void InsertBkmk( const ::sw::mark::IMark& rBkmk );
      68                 :            : };
      69                 :            : 
      70                 :      21078 : Writer_Impl::Writer_Impl()
      71 [ +  - ][ +  - ]:      21078 :     : m_pStream(0)
      72                 :            : {
      73                 :      21078 : }
      74                 :            : 
      75                 :      21078 : Writer_Impl::~Writer_Impl()
      76                 :            : {
      77                 :      21078 : }
      78                 :            : 
      79                 :      10500 : void Writer_Impl::RemoveFontList( SwDoc& rDoc )
      80                 :            : {
      81         [ +  - ]:      21120 :     for( std::vector<const SvxFontItem*>::const_iterator it = aFontRemoveLst.begin();
           [ +  -  +  - ]
                 [ +  + ]
      82                 :      10560 :         it != aFontRemoveLst.end(); ++it )
      83                 :            :     {
      84 [ +  - ][ +  - ]:         60 :         rDoc.GetAttrPool().Remove( **it );
      85                 :            :     }
      86                 :      10500 : }
      87                 :            : 
      88                 :          6 : void Writer_Impl::InsertBkmk(const ::sw::mark::IMark& rBkmk)
      89                 :            : {
      90                 :            : 
      91         [ +  - ]:          6 :     sal_uLong nNd = rBkmk.GetMarkPos().nNode.GetIndex();
      92                 :            : 
      93 [ +  - ][ +  - ]:          6 :     aBkmkNodePos.insert( SwBookmarkNodeTable::value_type( nNd, &rBkmk ) );
      94                 :            : 
      95 [ +  - ][ +  - ]:          6 :     if(rBkmk.IsExpanded() && rBkmk.GetOtherMarkPos().nNode != nNd)
         [ +  - ][ -  + ]
                 [ -  + ]
      96                 :            :     {
      97         [ #  # ]:          0 :         nNd = rBkmk.GetOtherMarkPos().nNode.GetIndex();
      98 [ #  # ][ #  # ]:          0 :         aBkmkNodePos.insert( SwBookmarkNodeTable::value_type( nNd, &rBkmk ));
      99                 :            :     }
     100                 :          6 : }
     101                 :            : 
     102                 :            : /*
     103                 :            :  * Dieses Modul ist die Zentrale-Sammelstelle fuer alle Write-Filter
     104                 :            :  * und ist eine DLL !
     105                 :            :  *
     106                 :            :  * Damit der Writer mit den unterschiedlichen Writern arbeiten kann,
     107                 :            :  * muessen fuer diese die Ausgabe-Funktionen der Inhalts tragenden
     108                 :            :  * Objecte auf die verschiedenen Ausgabe-Funktionen gemappt werden.
     109                 :            :  *
     110                 :            :  * Dazu kann fuer jedes Object ueber den Which-Wert in einen Tabelle ge-
     111                 :            :  * griffen werden, um seine Ausgabe-Funktion zu erfragen.
     112                 :            :  * Diese Funktionen stehen in den entsprechenden Writer-DLL's.
     113                 :            :  */
     114                 :            : 
     115                 :      10578 : Writer::Writer()
     116         [ +  - ]:      10578 :     : m_pImpl(new Writer_Impl)
     117 [ +  - ][ +  - ]:      21156 :     , pOrigPam(0), pOrigFileName(0), pDoc(0), pCurPam(0)
                 [ +  - ]
     118                 :            : {
     119                 :      10578 :     bWriteAll = bShowProgress = bUCS2_WithStartChar = true;
     120                 :            :     bASCII_NoLastLineEnd = bASCII_ParaAsBlanc = bASCII_ParaAsCR =
     121                 :            :         bWriteClipboardDoc = bWriteOnlyFirstTable = bBlock =
     122                 :      10578 :         bOrganizerMode = false;
     123                 :      10578 :     bExportPargraphNumbering = sal_True;
     124                 :      10578 : }
     125                 :            : 
     126 [ +  - ][ +  - ]:      10578 : Writer::~Writer()
                 [ +  - ]
     127                 :            : {
     128         [ -  + ]:      10578 : }
     129                 :            : 
     130                 :            : /*
     131                 :            :  * Document Interface Access
     132                 :            :  */
     133         [ +  - ]:          9 : IDocumentSettingAccess* Writer::getIDocumentSettingAccess() { return pDoc; }
     134         [ #  # ]:          0 : const IDocumentSettingAccess* Writer::getIDocumentSettingAccess() const { return pDoc; }
     135         [ +  - ]:          4 : IDocumentStylePoolAccess* Writer::getIDocumentStylePoolAccess() { return pDoc; }
     136         [ #  # ]:          0 : const IDocumentStylePoolAccess* Writer::getIDocumentStylePoolAccess() const { return pDoc; }
     137                 :            : 
     138                 :      10500 : void Writer::ResetWriter()
     139                 :            : {
     140                 :      10500 :     m_pImpl->RemoveFontList( *pDoc );
     141         [ +  - ]:      10500 :     m_pImpl.reset(new Writer_Impl);
     142                 :            : 
     143         [ +  - ]:      10500 :     if( pCurPam )
     144                 :            :     {
     145         [ -  + ]:      10500 :         while( pCurPam->GetNext() != pCurPam )
     146         [ #  # ]:          0 :             delete pCurPam->GetNext();
     147         [ +  - ]:      10500 :         delete pCurPam;
     148                 :            :     }
     149                 :      10500 :     pCurPam = 0;
     150                 :      10500 :     pOrigFileName = 0;
     151                 :      10500 :     pDoc = 0;
     152                 :            : 
     153                 :      10500 :     bShowProgress = bUCS2_WithStartChar = sal_True;
     154                 :            :     bASCII_NoLastLineEnd = bASCII_ParaAsBlanc = bASCII_ParaAsCR =
     155                 :            :         bWriteClipboardDoc = bWriteOnlyFirstTable = bBlock =
     156                 :      10500 :         bOrganizerMode = sal_False;
     157                 :      10500 : }
     158                 :            : 
     159                 :      10470 : sal_Bool Writer::CopyNextPam( SwPaM ** ppPam )
     160                 :            : {
     161         [ +  - ]:      10470 :     if( (*ppPam)->GetNext() == pOrigPam )
     162                 :            :     {
     163                 :      10470 :         *ppPam = pOrigPam;          // wieder auf den Anfangs-Pam setzen
     164                 :      10470 :         return sal_False;               // Ende vom Ring
     165                 :            :     }
     166                 :            : 
     167                 :            :     // ansonsten kopiere den die Werte aus dem naechsten Pam
     168                 :          0 :     *ppPam = ((SwPaM*)(*ppPam)->GetNext() );
     169                 :            : 
     170                 :          0 :     *pCurPam->GetPoint() = *(*ppPam)->Start();
     171                 :          0 :     *pCurPam->GetMark() = *(*ppPam)->End();
     172                 :            : 
     173                 :      10470 :     return sal_True;
     174                 :            : }
     175                 :            : 
     176                 :            : // suche die naechste Bookmark-Position aus der Bookmark-Tabelle
     177                 :            : 
     178                 :          2 : sal_Int32 Writer::FindPos_Bkmk(const SwPosition& rPos) const
     179                 :            : {
     180         [ +  - ]:          2 :     const IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
     181                 :            :     const IDocumentMarkAccess::const_iterator_t ppBkmk = ::std::lower_bound(
     182                 :          2 :         pMarkAccess->getMarksBegin(),
     183                 :          2 :         pMarkAccess->getMarksEnd(),
     184                 :            :         rPos,
     185 [ +  - ][ +  - ]:          2 :         ::boost::bind(&::sw::mark::IMark::StartsBefore, _1, _2)); // find the first Mark that does not start before
         [ +  - ][ +  - ]
     186 [ +  - ][ +  - ]:          2 :     if(ppBkmk != pMarkAccess->getMarksEnd())
                 [ -  + ]
     187 [ #  # ][ #  # ]:          0 :         return ppBkmk - pMarkAccess->getMarksBegin();
     188                 :          2 :     return -1;
     189                 :            : }
     190                 :            : 
     191                 :            : 
     192                 :            : SwPaM *
     193                 :          9 : Writer::NewSwPaM(SwDoc & rDoc, sal_uLong const nStartIdx, sal_uLong const nEndIdx)
     194                 :            : {
     195         [ +  - ]:          9 :     SwNodes *const pNds = &rDoc.GetNodes();
     196                 :            : 
     197         [ +  - ]:          9 :     SwNodeIndex aStt( *pNds, nStartIdx );
     198                 :          9 :     SwCntntNode* pCNode = aStt.GetNode().GetCntntNode();
     199 [ #  # ][ #  # ]:          9 :     if( !pCNode && 0 == ( pCNode = pNds->GoNext( &aStt )) )
                 [ -  + ]
     200                 :            :     {
     201                 :            :         OSL_FAIL( "An StartPos kein ContentNode mehr" );
     202                 :            :     }
     203                 :            : 
     204 [ +  - ][ +  - ]:          9 :     SwPaM* pNew = new SwPaM( aStt );
     205         [ +  - ]:          9 :     pNew->SetMark();
     206         [ +  - ]:          9 :     aStt = nEndIdx;
     207 [ +  - ][ +  - ]:          9 :     if( 0 == (pCNode = aStt.GetNode().GetCntntNode()) &&
                 [ -  + ]
     208                 :            :         0 == (pCNode = pNds->GoPrevious( &aStt )) )
     209                 :            :     {
     210                 :            :         OSL_FAIL( "An StartPos kein ContentNode mehr" );
     211                 :            :     }
     212         [ +  - ]:          9 :     pCNode->MakeEndIndex( &pNew->GetPoint()->nContent );
     213         [ +  - ]:          9 :     pNew->GetPoint()->nNode = aStt;
     214         [ +  - ]:          9 :     return pNew;
     215                 :            : }
     216                 :            : 
     217                 :            : /////////////////////////////////////////////////////////////////////////////
     218                 :            : 
     219                 :            : // Stream-spezifisches
     220                 :      57679 : SvStream& Writer::Strm()
     221                 :            : {
     222                 :            :     OSL_ENSURE( m_pImpl->m_pStream, "Oh-oh. Writer with no Stream!" );
     223                 :      57679 :     return *m_pImpl->m_pStream;
     224                 :            : }
     225                 :            : 
     226                 :        126 : void Writer::SetStream(SvStream *const pStream)
     227                 :        126 : { m_pImpl->m_pStream = pStream; }
     228                 :            : 
     229                 :        546 : SvStream& Writer::OutLong( SvStream& rStrm, long nVal )
     230                 :            : {
     231                 :            :     // Pointer an das Bufferende setzen
     232                 :        546 :     sal_Char* pStr = aNToABuf + (NTOABUFLEN-1);
     233                 :            : 
     234                 :        546 :     int bNeg = nVal < 0;
     235         [ -  + ]:        546 :     if( bNeg )
     236                 :          0 :         nVal = -nVal;
     237                 :            : 
     238         [ +  + ]:       1482 :     do {
     239                 :       1482 :         *(--pStr) = (sal_Char)(nVal % 10 ) + 48;
     240                 :       1482 :         nVal /= 10;
     241                 :            :     } while( nVal );
     242                 :            : 
     243                 :            :     // Ist Zahl negativ, dann noch -
     244         [ -  + ]:        546 :     if( bNeg )
     245                 :          0 :         *(--pStr) = '-';
     246                 :            : 
     247                 :        546 :     return rStrm << pStr;
     248                 :            : }
     249                 :            : 
     250                 :       4497 : SvStream& Writer::OutULong( SvStream& rStrm, sal_uLong nVal )
     251                 :            : {
     252                 :            :     // Pointer an das Bufferende setzen
     253                 :       4497 :     sal_Char* pStr = aNToABuf + (NTOABUFLEN-1);
     254                 :            : 
     255         [ +  + ]:       6234 :     do {
     256                 :       6234 :         *(--pStr) = (sal_Char)(nVal % 10 ) + 48;
     257                 :       6234 :         nVal /= 10;
     258                 :            :     } while ( nVal );
     259                 :       4497 :     return rStrm << pStr;
     260                 :            : }
     261                 :            : 
     262                 :            : 
     263                 :      10479 : sal_uLong Writer::Write( SwPaM& rPaM, SvStream& rStrm, const String* pFName )
     264                 :            : {
     265         [ +  + ]:      10479 :     if ( IsStgWriter() )
     266                 :            :     {
     267 [ +  - ][ +  - ]:          9 :         SotStorageRef aRef = new SotStorage( rStrm );
     268         [ +  - ]:          9 :         sal_uLong nResult = Write( rPaM, *aRef, pFName );
     269         [ +  - ]:          9 :         if ( nResult == ERRCODE_NONE )
     270         [ +  - ]:          9 :             aRef->Commit();
     271         [ +  - ]:          9 :         return nResult;
     272                 :            :     }
     273                 :            : 
     274                 :      10470 :     pDoc = rPaM.GetDoc();
     275                 :      10470 :     pOrigFileName = pFName;
     276                 :      10470 :     m_pImpl->m_pStream = &rStrm;
     277                 :            : 
     278                 :            :     // PaM kopieren, damit er veraendert werden kann
     279         [ +  - ]:      10470 :     pCurPam = new SwPaM( *rPaM.End(), *rPaM.Start() );
     280                 :            :     // zum Vergleich auf den akt. Pam sichern
     281                 :      10470 :     pOrigPam = &rPaM;
     282                 :            : 
     283                 :      10470 :     sal_uLong nRet = WriteStream();
     284                 :            : 
     285                 :      10470 :     ResetWriter();
     286                 :            : 
     287                 :      10479 :     return nRet;
     288                 :            : }
     289                 :            : 
     290                 :         14 : sal_uLong Writer::Write( SwPaM& rPam, SfxMedium& rMed, const String* pFileName )
     291                 :            : {
     292                 :            :     // This method must be overloaded in SwXMLWriter a storage from medium will be used there.
     293                 :            :     // The microsoft format can write to storage but the storage will be based on the stream.
     294                 :         14 :     return Write( rPam, *rMed.GetOutStream(), pFileName );
     295                 :            : }
     296                 :            : 
     297                 :          0 : sal_uLong Writer::Write( SwPaM& /*rPam*/, SvStorage&, const String* )
     298                 :            : {
     299                 :            :     OSL_ENSURE( !this, "Schreiben in Storages auf einem Stream?" );
     300                 :          0 :     return ERR_SWG_WRITE_ERROR;
     301                 :            : }
     302                 :            : 
     303                 :          0 : sal_uLong Writer::Write( SwPaM&, const uno::Reference < embed::XStorage >&, const String*, SfxMedium* )
     304                 :            : {
     305                 :            :     OSL_ENSURE( !this, "Schreiben in Storages auf einem Stream?" );
     306                 :          0 :     return ERR_SWG_WRITE_ERROR;
     307                 :            : }
     308                 :            : 
     309                 :          0 : sal_Bool Writer::CopyLocalFileToINet( String& rFileNm )
     310                 :            : {
     311         [ #  # ]:          0 :     if( !pOrigFileName )                // can be happen, by example if we
     312                 :          0 :         return sal_False;                   // write into the clipboard
     313                 :            : 
     314                 :          0 :     sal_Bool bRet = sal_False;
     315 [ #  # ][ #  # ]:          0 :     INetURLObject aFileUrl( rFileNm ), aTargetUrl( *pOrigFileName );
         [ #  # ][ #  # ]
     316                 :            : 
     317                 :            : // this is our old without the Mail-Export
     318         [ #  # ]:          0 :     if( ! ( INET_PROT_FILE == aFileUrl.GetProtocol() &&
     319                 :          0 :             INET_PROT_FILE != aTargetUrl.GetProtocol() &&
     320                 :          0 :             INET_PROT_FTP <= aTargetUrl.GetProtocol() &&
     321 [ #  # ][ #  #  :          0 :             INET_PROT_NEWS >= aTargetUrl.GetProtocol() ) )
             #  #  #  # ]
     322                 :          0 :         return bRet;
     323                 :            : 
     324         [ #  # ]:          0 :     if (m_pImpl->pFileNameMap)
     325                 :            :     {
     326                 :            :         // wurde die Datei schon verschoben
     327         [ #  # ]:          0 :         std::map<String, String>::iterator it = m_pImpl->pFileNameMap->find( rFileNm );
     328 [ #  # ][ #  # ]:          0 :         if ( it != m_pImpl->pFileNameMap->end() )
     329                 :            :         {
     330 [ #  # ][ #  # ]:          0 :             rFileNm = it->second;
     331                 :          0 :             return sal_True;
     332                 :            :         }
     333                 :            :     }
     334                 :            :     else
     335                 :            :     {
     336 [ #  # ][ #  # ]:          0 :         m_pImpl->pFileNameMap.reset( new std::map<String, String>() );
                 [ #  # ]
     337                 :            :     }
     338                 :            : 
     339         [ #  # ]:          0 :     String aSrc  = rFileNm;
     340 [ #  # ][ #  # ]:          0 :     String aDest = aTargetUrl.GetPartBeforeLastName();
     341 [ #  # ][ #  # ]:          0 :     aDest += String(aFileUrl.GetName());
         [ #  # ][ #  # ]
     342                 :            : 
     343         [ #  # ]:          0 :     SfxMedium aSrcFile( aSrc, STREAM_READ );
     344         [ #  # ]:          0 :     SfxMedium aDstFile( aDest, STREAM_WRITE | STREAM_SHARE_DENYNONE );
     345                 :            : 
     346 [ #  # ][ #  # ]:          0 :     *aDstFile.GetOutStream() << *aSrcFile.GetInStream();
                 [ #  # ]
     347                 :            : 
     348         [ #  # ]:          0 :     aSrcFile.Close();
     349         [ #  # ]:          0 :     aDstFile.Commit();
     350                 :            : 
     351         [ #  # ]:          0 :     bRet = 0 == aDstFile.GetError();
     352                 :            : 
     353         [ #  # ]:          0 :     if( bRet )
     354                 :            :     {
     355 [ #  # ][ #  # ]:          0 :         m_pImpl->pFileNameMap->insert( std::make_pair( aSrc, aDest ) );
                 [ #  # ]
     356         [ #  # ]:          0 :         rFileNm = aDest;
     357                 :            :     }
     358                 :            : 
     359 [ #  # ][ #  # ]:          0 :     return bRet;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     360                 :            : }
     361                 :            : 
     362                 :         21 : void Writer::PutNumFmtFontsInAttrPool()
     363                 :            : {
     364                 :            :     // dann gibt es noch in den NumRules ein paar Fonts
     365                 :            :     // Diese in den Pool putten. Haben sie danach einen RefCount > 1
     366                 :            :     // kann es wieder entfernt werden - ist schon im Pool
     367                 :         21 :     SfxItemPool& rPool = pDoc->GetAttrPool();
     368                 :         21 :     const SwNumRuleTbl& rListTbl = pDoc->GetNumRuleTbl();
     369                 :            :     const SwNumRule* pRule;
     370                 :            :     const SwNumFmt* pFmt;
     371                 :            :     const Font* pFont;
     372                 :         21 :     const Font* pDefFont = &numfunc::GetDefBulletFont();
     373                 :         21 :     sal_Bool bCheck = sal_False;
     374                 :            : 
     375         [ +  + ]:         42 :     for( sal_uInt16 nGet = rListTbl.size(); nGet; )
     376         [ -  + ]:         21 :         if( pDoc->IsUsed( *(pRule = rListTbl[ --nGet ] )))
     377         [ #  # ]:          0 :             for( sal_uInt8 nLvl = 0; nLvl < MAXLEVEL; ++nLvl )
     378   [ #  #  #  # ]:          0 :                 if( SVX_NUM_CHAR_SPECIAL == (pFmt = &pRule->Get( nLvl ))->GetNumberingType() ||
                 [ #  # ]
     379                 :          0 :                     SVX_NUM_BITMAP == pFmt->GetNumberingType() )
     380                 :            :                 {
     381         [ #  # ]:          0 :                     if( 0 == ( pFont = pFmt->GetBulletFont() ) )
     382                 :          0 :                         pFont = pDefFont;
     383                 :            : 
     384         [ #  # ]:          0 :                     if( bCheck )
     385                 :            :                     {
     386         [ #  # ]:          0 :                         if( *pFont == *pDefFont )
     387                 :          0 :                             continue;
     388                 :            :                     }
     389         [ #  # ]:          0 :                     else if( *pFont == *pDefFont )
     390                 :          0 :                         bCheck = sal_True;
     391                 :            : 
     392                 :            :                     _AddFontItem( rPool, SvxFontItem( pFont->GetFamily(),
     393                 :          0 :                                 pFont->GetName(), pFont->GetStyleName(),
     394         [ #  # ]:          0 :                                 pFont->GetPitch(), pFont->GetCharSet(), RES_CHRATR_FONT ));
     395                 :            :                 }
     396                 :         21 : }
     397                 :            : 
     398                 :         21 : void Writer::PutEditEngFontsInAttrPool( sal_Bool bIncl_CJK_CTL )
     399                 :            : {
     400                 :         21 :     SfxItemPool& rPool = pDoc->GetAttrPool();
     401         [ +  + ]:         21 :     if( rPool.GetSecondaryPool() )
     402                 :            :     {
     403                 :         19 :         _AddFontItems( rPool, EE_CHAR_FONTINFO );
     404         [ +  - ]:         19 :         if( bIncl_CJK_CTL )
     405                 :            :         {
     406                 :         19 :             _AddFontItems( rPool, EE_CHAR_FONTINFO_CJK );
     407                 :         19 :             _AddFontItems( rPool, EE_CHAR_FONTINFO_CTL );
     408                 :            :         }
     409                 :            :     }
     410                 :         21 : }
     411                 :            : 
     412                 :         57 : void Writer::_AddFontItems( SfxItemPool& rPool, sal_uInt16 nW )
     413                 :            : {
     414                 :         57 :     const SvxFontItem* pFont = (const SvxFontItem*)&rPool.GetDefaultItem( nW );
     415                 :         57 :     _AddFontItem( rPool, *pFont );
     416                 :            : 
     417         [ +  - ]:         57 :     if( 0 != ( pFont = (const SvxFontItem*)rPool.GetPoolDefaultItem( nW )) )
     418                 :         57 :         _AddFontItem( rPool, *pFont );
     419                 :            : 
     420                 :         57 :     sal_uInt32 nMaxItem = rPool.GetItemCount2( nW );
     421         [ +  + ]:         66 :     for( sal_uInt32 nGet = 0; nGet < nMaxItem; ++nGet )
     422         [ +  - ]:          9 :         if( 0 != (pFont = (const SvxFontItem*)rPool.GetItem2( nW, nGet )) )
     423                 :          9 :             _AddFontItem( rPool, *pFont );
     424                 :         57 : }
     425                 :            : 
     426                 :        123 : void Writer::_AddFontItem( SfxItemPool& rPool, const SvxFontItem& rFont )
     427                 :            : {
     428                 :            :     const SvxFontItem* pItem;
     429         [ +  - ]:        123 :     if( RES_CHRATR_FONT != rFont.Which() )
     430                 :            :     {
     431         [ +  - ]:        123 :         SvxFontItem aFont( rFont );
     432                 :        123 :         aFont.SetWhich( RES_CHRATR_FONT );
     433 [ +  - ][ +  - ]:        123 :         pItem = (SvxFontItem*)&rPool.Put( aFont );
     434                 :            :     }
     435                 :            :     else
     436         [ #  # ]:          0 :         pItem = (SvxFontItem*)&rPool.Put( rFont );
     437                 :            : 
     438         [ +  + ]:        123 :     if( 1 < pItem->GetRefCount() )
     439         [ +  - ]:         63 :         rPool.Remove( *pItem );
     440                 :            :     else
     441                 :            :     {
     442         [ +  - ]:         60 :         m_pImpl->aFontRemoveLst.push_back( pItem );
     443                 :            :     }
     444                 :        123 : }
     445                 :            : 
     446                 :            : // build a bookmark table, which is sort by the node position. The
     447                 :            : // OtherPos of the bookmarks also inserted.
     448                 :          9 : void Writer::CreateBookmarkTbl()
     449                 :            : {
     450                 :          9 :     const IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
     451 [ +  - ][ +  + ]:         30 :     for(IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->getBookmarksBegin();
                 [ +  - ]
     452         [ +  - ]:         15 :         ppBkmk != pMarkAccess->getBookmarksEnd();
     453                 :            :         ++ppBkmk)
     454                 :            :     {
     455         [ +  - ]:          6 :         m_pImpl->InsertBkmk(**ppBkmk);
     456                 :            :     }
     457                 :          9 : }
     458                 :            : 
     459                 :            : 
     460                 :            : // search alle Bookmarks in the range and return it in the Array
     461                 :        153 : sal_uInt16 Writer::GetBookmarks(const SwCntntNode& rNd, xub_StrLen nStt,
     462                 :            :     xub_StrLen nEnd, std::vector< const ::sw::mark::IMark* >& rArr)
     463                 :            : {
     464                 :            :     OSL_ENSURE( rArr.empty(), "es sind noch Eintraege vorhanden" );
     465                 :            : 
     466                 :        153 :     sal_uLong nNd = rNd.GetIndex();
     467                 :            :     std::pair<SwBookmarkNodeTable::const_iterator, SwBookmarkNodeTable::const_iterator> aIterPair 
     468 [ +  - ][ +  - ]:        153 :         = m_pImpl->aBkmkNodePos.equal_range( nNd );
     469 [ +  - ][ +  + ]:        153 :     if( aIterPair.first != aIterPair.second )
     470                 :            :     {
     471                 :            :         // there exist some bookmarks, search now all which is in the range
     472 [ +  + ][ +  - ]:         12 :         if( !nStt && nEnd == rNd.Len() )
         [ -  + ][ -  + ]
     473                 :            :             // all
     474 [ #  # ][ #  # ]:          0 :             for( SwBookmarkNodeTable::const_iterator it = aIterPair.first; it != aIterPair.second; ++it )
                 [ #  # ]
     475 [ #  # ][ #  # ]:          0 :                 rArr.push_back( it->second );
     476                 :            :         else
     477                 :            :         {
     478 [ +  - ][ +  - ]:         36 :             for( SwBookmarkNodeTable::const_iterator it = aIterPair.first; it != aIterPair.second; ++it )
                 [ +  + ]
     479                 :            :             {
     480         [ +  - ]:         24 :                 const ::sw::mark::IMark& rBkmk = *(it->second);
     481                 :            :                 xub_StrLen nCntnt;
     482 [ +  - ][ +  - ]:         48 :                 if( rBkmk.GetMarkPos().nNode == nNd &&
         [ +  + ][ +  - ]
                 [ +  + ]
     483         [ +  - ]:         24 :                     (nCntnt = rBkmk.GetMarkPos().nContent.GetIndex() ) >= nStt &&
     484                 :            :                     nCntnt < nEnd )
     485                 :            :                 {
     486         [ +  - ]:          6 :                     rArr.push_back( &rBkmk );
     487                 :            :                 }
     488         [ +  - ]:         54 :                 else if( rBkmk.IsExpanded() && nNd ==
           [ +  -  +  - ]
         [ +  + ][ +  - ]
                 [ +  + ]
     489         [ +  - ]:         18 :                         rBkmk.GetOtherMarkPos().nNode.GetIndex() && (nCntnt =
     490         [ +  - ]:         18 :                         rBkmk.GetOtherMarkPos().nContent.GetIndex() ) >= nStt &&
     491                 :            :                         nCntnt < nEnd )
     492                 :            :                 {
     493         [ +  - ]:          6 :                     rArr.push_back( &rBkmk );
     494                 :            :                 }
     495                 :            :             }
     496                 :            :         }
     497                 :            :     }
     498                 :        153 :     return rArr.size();
     499                 :            : }
     500                 :            : 
     501                 :            : ////////////////////////////////////////////////////////////////////////////
     502                 :            : 
     503                 :            : // Storage-spezifisches
     504                 :            : 
     505                 :          0 : sal_uLong StgWriter::WriteStream()
     506                 :            : {
     507                 :            :     OSL_ENSURE( !this, "Schreiben in Streams auf einem Storage?" );
     508                 :          0 :     return ERR_SWG_WRITE_ERROR;
     509                 :            : }
     510                 :            : 
     511                 :          9 : sal_uLong StgWriter::Write( SwPaM& rPaM, SvStorage& rStg, const String* pFName )
     512                 :            : {
     513                 :          9 :     SetStream(0);
     514                 :          9 :     pStg = &rStg;
     515                 :          9 :     pDoc = rPaM.GetDoc();
     516                 :          9 :     pOrigFileName = pFName;
     517                 :            : 
     518                 :            :     // PaM kopieren, damit er veraendert werden kann
     519         [ +  - ]:          9 :     pCurPam = new SwPaM( *rPaM.End(), *rPaM.Start() );
     520                 :            :     // zum Vergleich auf den akt. Pam sichern
     521                 :          9 :     pOrigPam = &rPaM;
     522                 :            : 
     523                 :          9 :     sal_uLong nRet = WriteStorage();
     524                 :            : 
     525                 :          9 :     pStg = NULL;
     526                 :          9 :     ResetWriter();
     527                 :            : 
     528                 :          9 :     return nRet;
     529                 :            : }
     530                 :            : 
     531                 :         21 : sal_uLong StgWriter::Write( SwPaM& rPaM, const uno::Reference < embed::XStorage >& rStg, const String* pFName, SfxMedium* pMedium )
     532                 :            : {
     533                 :         21 :     SetStream(0);
     534                 :         21 :     pStg = 0;
     535                 :         21 :     xStg = rStg;
     536                 :         21 :     pDoc = rPaM.GetDoc();
     537                 :         21 :     pOrigFileName = pFName;
     538                 :            : 
     539                 :            :     // PaM kopieren, damit er veraendert werden kann
     540         [ +  - ]:         21 :     pCurPam = new SwPaM( *rPaM.End(), *rPaM.Start() );
     541                 :            :     // zum Vergleich auf den akt. Pam sichern
     542                 :         21 :     pOrigPam = &rPaM;
     543                 :            : 
     544         [ +  + ]:         21 :     sal_uLong nRet = pMedium ? WriteMedium( *pMedium ) : WriteStorage();
     545                 :            : 
     546                 :         21 :     pStg = NULL;
     547                 :         21 :     ResetWriter();
     548                 :            : 
     549                 :         21 :     return nRet;
     550 [ +  - ][ +  - ]:        219 : }
     551                 :            : 
     552                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10