LCOV - code coverage report
Current view: top level - sw/source/filter/ascii - ascatr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 67 80 83.8 %
Date: 2012-08-25 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 76 139 54.7 %

           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                 :            : #include <tools/stream.hxx>
      31                 :            : #include <comphelper/string.hxx>
      32                 :            : #include <editeng/fontitem.hxx>
      33                 :            : #include <pam.hxx>
      34                 :            : #include <doc.hxx>
      35                 :            : #include <ndtxt.hxx>
      36                 :            : #include <wrtasc.hxx>
      37                 :            : #include <txatbase.hxx>
      38                 :            : #include <fchrfmt.hxx>
      39                 :            : #include <txtfld.hxx>
      40                 :            : #include <txtatr.hxx>
      41                 :            : #include <fmtftn.hxx>
      42                 :            : #include <charfmt.hxx>
      43                 :            : #include <fmtfld.hxx>
      44                 :            : #include <fldbas.hxx>
      45                 :            : #include <ftninfo.hxx>
      46                 :            : 
      47                 :            : /*
      48                 :            :  * This file contains all output functions of the ASCII-Writer;
      49                 :            :  * For all nodes, attributes, formats and chars.
      50                 :            :  */
      51                 :            : 
      52                 :            : class SwASC_AttrIter
      53                 :            : {
      54                 :            :     SwASCWriter& rWrt;
      55                 :            :     const SwTxtNode& rNd;
      56                 :            :     xub_StrLen nAktSwPos;
      57                 :            : 
      58                 :            :     xub_StrLen SearchNext( xub_StrLen nStartPos );
      59                 :            : 
      60                 :            : public:
      61                 :            :     SwASC_AttrIter( SwASCWriter& rWrt, const SwTxtNode& rNd, xub_StrLen nStt );
      62                 :            : 
      63                 :      10692 :     void NextPos()      { nAktSwPos = SearchNext( nAktSwPos + 1 ); }
      64                 :            : 
      65                 :      10692 :     xub_StrLen WhereNext() const        { return nAktSwPos; }
      66                 :            :     sal_Bool OutAttr( xub_StrLen nSwPos );
      67                 :            : };
      68                 :            : 
      69                 :            : 
      70                 :      10676 : SwASC_AttrIter::SwASC_AttrIter( SwASCWriter& rWr, const SwTxtNode& rTxtNd,
      71                 :            :                                 xub_StrLen nStt )
      72                 :      10676 :     : rWrt( rWr ), rNd( rTxtNd ), nAktSwPos( 0 )
      73                 :            : {
      74                 :      10676 :     nAktSwPos = SearchNext( nStt + 1 );
      75                 :      10676 : }
      76                 :            : 
      77                 :            : 
      78                 :      21368 : xub_StrLen SwASC_AttrIter::SearchNext( xub_StrLen nStartPos )
      79                 :            : {
      80                 :      21368 :     xub_StrLen nMinPos = STRING_MAXLEN;
      81                 :      21368 :     const SwpHints* pTxtAttrs = rNd.GetpSwpHints();
      82         [ +  + ]:      21368 :     if( pTxtAttrs )
      83                 :            :     {
      84                 :            : // TODO: This can be optimized, if we make use of the fact that the TxtAttrs
      85                 :            : // are sorted by starting position. We would need to remember two indices, however.
      86         [ +  + ]:       3310 :         for ( sal_uInt16 i = 0; i < pTxtAttrs->Count(); i++ )
      87                 :            :         {
      88                 :       2932 :             const SwTxtAttr* pHt = (*pTxtAttrs)[i];
      89         [ +  + ]:       2932 :             if (pHt->HasDummyChar())
      90                 :            :             {
      91                 :       2036 :                 xub_StrLen nPos = *pHt->GetStart();
      92                 :            : 
      93 [ +  + ][ +  + ]:       2036 :                 if( nPos >= nStartPos && nPos <= nMinPos )
      94                 :        136 :                     nMinPos = nPos;
      95                 :            : 
      96 [ +  + ][ +  + ]:       2036 :                 if( ( ++nPos ) >= nStartPos && nPos < nMinPos )
                 [ +  + ]
      97                 :         90 :                     nMinPos = nPos;
      98                 :            :             }
      99                 :            :         }
     100                 :            :     }
     101                 :      21368 :     return nMinPos;
     102                 :            : }
     103                 :            : 
     104                 :            : 
     105                 :      10692 : sal_Bool SwASC_AttrIter::OutAttr( xub_StrLen nSwPos )
     106                 :            : {
     107                 :      10692 :     sal_Bool bRet = sal_False;
     108                 :      10692 :     const SwpHints* pTxtAttrs = rNd.GetpSwpHints();
     109         [ +  + ]:      10692 :     if( pTxtAttrs )
     110                 :            :     {
     111                 :            :         sal_uInt16 i;
     112         [ +  + ]:       1369 :         for( i = 0; i < pTxtAttrs->Count(); i++ )
     113                 :            :         {
     114                 :       1172 :             const SwTxtAttr* pHt = (*pTxtAttrs)[i];
     115 [ +  + ][ +  + ]:       1172 :             if ( pHt->HasDummyChar() && nSwPos == *pHt->GetStart() )
                 [ +  + ]
     116                 :            :             {
     117                 :         32 :                 bRet = sal_True;
     118         [ +  - ]:         32 :                 String sOut;
     119         [ +  - ]:         32 :                 switch( pHt->Which() )
              [ +  -  + ]
     120                 :            :                 {
     121                 :            :                 case RES_TXTATR_FIELD:
     122                 :         20 :                     sOut = static_cast<SwTxtFld const*>(pHt)->GetFld().GetFld()
     123 [ +  - ][ +  - ]:         20 :                             ->ExpandField(true);
                 [ +  - ]
     124                 :         20 :                     break;
     125                 :            : 
     126                 :            :                 case RES_TXTATR_FTN:
     127                 :            :                     {
     128                 :          0 :                         const SwFmtFtn& rFtn = pHt->GetFtn();
     129         [ #  # ]:          0 :                         if( rFtn.GetNumStr().Len() )
     130         [ #  # ]:          0 :                             sOut = rFtn.GetNumStr();
     131         [ #  # ]:          0 :                         else if( rFtn.IsEndNote() )
     132                 :          0 :                             sOut = rWrt.pDoc->GetEndNoteInfo().aFmt.
     133 [ #  # ][ #  # ]:          0 :                                             GetNumStr( rFtn.GetNumber() );
                 [ #  # ]
     134                 :            :                         else
     135                 :          0 :                             sOut = rWrt.pDoc->GetFtnInfo().aFmt.
     136 [ #  # ][ #  # ]:          0 :                                             GetNumStr( rFtn.GetNumber() );
                 [ #  # ]
     137                 :            :                     }
     138                 :          0 :                     break;
     139                 :            :                 }
     140         [ +  + ]:         32 :                 if( sOut.Len() )
     141 [ +  - ][ +  - ]:         32 :                     rWrt.Strm().WriteUnicodeOrByteText( sOut );
                 [ +  - ]
     142                 :            :             }
     143         [ +  + ]:       1140 :             else if( nSwPos < *pHt->GetStart() )
     144                 :         83 :                 break;
     145                 :            :         }
     146                 :            :     }
     147                 :      10692 :     return bRet;
     148                 :            : }
     149                 :            : 
     150                 :            : 
     151                 :            : //------------------------
     152                 :            : // Output of the node
     153                 :            : //------------------------
     154                 :            : 
     155                 :      10676 : static Writer& OutASC_SwTxtNode( Writer& rWrt, SwCntntNode& rNode )
     156                 :            : {
     157                 :      10676 :     const SwTxtNode& rNd = (SwTxtNode&)rNode;
     158                 :            : 
     159                 :      10676 :     xub_StrLen nStrPos = rWrt.pCurPam->GetPoint()->nContent.GetIndex();
     160         [ +  - ]:      10676 :     xub_StrLen nNodeEnde = rNd.Len(), nEnde = nNodeEnde;
     161                 :      10676 :     sal_Bool bLastNd =  rWrt.pCurPam->GetPoint()->nNode == rWrt.pCurPam->GetMark()->nNode;
     162         [ +  + ]:      10676 :     if( bLastNd )
     163                 :      10465 :         nEnde = rWrt.pCurPam->GetMark()->nContent.GetIndex();
     164                 :            : 
     165         [ +  - ]:      10676 :     SwASC_AttrIter aAttrIter( (SwASCWriter&)rWrt, rNd, nStrPos );
     166                 :            : 
     167 [ +  + ][ +  + ]:      10676 :     if( !nStrPos && rWrt.bExportPargraphNumbering )
     168                 :            :     {
     169         [ +  - ]:          9 :         String numString( rNd.GetNumString() );
     170         [ -  + ]:          9 :         if (numString.Len())
     171                 :            :         {
     172         [ #  # ]:          0 :             numString.Append(' ');
     173 [ #  # ][ #  # ]:          0 :             rWrt.Strm().WriteUnicodeOrByteText(numString);
     174         [ +  - ]:          9 :         }
     175                 :            :     }
     176                 :            : 
     177         [ +  - ]:      10676 :     String aStr( rNd.GetTxt() );
     178         [ -  + ]:      10676 :     if( rWrt.bASCII_ParaAsBlanc )
     179         [ #  # ]:          0 :         aStr.SearchAndReplaceAll( 0x0A, ' ' );
     180                 :            : 
     181                 :      10676 :     const bool bExportSoftHyphens = RTL_TEXTENCODING_UCS2 == rWrt.GetAsciiOptions().GetCharSet() ||
     182 [ +  - ][ +  + ]:      10676 :                                     RTL_TEXTENCODING_UTF8 == rWrt.GetAsciiOptions().GetCharSet();
     183                 :            : 
     184         [ +  + ]:      10692 :     do {
     185                 :      10692 :         xub_StrLen nNextAttr = aAttrIter.WhereNext();
     186                 :            : 
     187         [ +  + ]:      10692 :         if( nNextAttr > nEnde )
     188                 :      10606 :             nNextAttr = nEnde;
     189                 :            : 
     190 [ +  - ][ +  + ]:      10692 :         if( !aAttrIter.OutAttr( nStrPos ))
     191                 :            :         {
     192         [ +  - ]:      10660 :             String aOutStr( aStr.Copy( nStrPos, nNextAttr - nStrPos ) );
     193         [ -  + ]:      10660 :             if ( !bExportSoftHyphens )
     194 [ #  # ][ #  # ]:          0 :                 aOutStr = comphelper::string::remove(aOutStr, CHAR_SOFTHYPHEN);
     195                 :            : 
     196 [ +  - ][ +  - ]:      10660 :             rWrt.Strm().WriteUnicodeOrByteText( aOutStr );
                 [ +  - ]
     197                 :            :         }
     198                 :      10692 :         nStrPos = nNextAttr;
     199         [ +  - ]:      10692 :         aAttrIter.NextPos();
     200                 :            :     } while( nStrPos < nEnde );
     201                 :            : 
     202 [ +  + ][ +  - ]:      10676 :     if( !bLastNd ||
         [ -  + ][ #  # ]
                 [ #  # ]
     203                 :      20930 :         ( ( !rWrt.bWriteClipboardDoc && !rWrt.bASCII_NoLastLineEnd )
     204                 :            :             && !nStrPos && nEnde == nNodeEnde ) )
     205 [ +  - ][ +  - ]:        211 :         rWrt.Strm().WriteUnicodeOrByteText( ((SwASCWriter&)rWrt).GetLineEnd());
     206                 :            : 
     207         [ +  - ]:      10676 :     return rWrt;
     208                 :            : }
     209                 :            : 
     210                 :            : /*
     211                 :            :  * Create the table for the ASCII function pointers to the output
     212                 :            :  * functon.
     213                 :            :  * There are local structures that only need to be known to the ASCII DLL.
     214                 :            :  */
     215                 :            : 
     216                 :            : SwNodeFnTab aASCNodeFnTab = {
     217                 :            : /* RES_TXTNODE  */                   OutASC_SwTxtNode,
     218                 :            : /* RES_GRFNODE  */                   0,
     219                 :            : /* RES_OLENODE  */                   0
     220                 :            : };
     221                 :            : 
     222                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10