LCOV - code coverage report
Current view: top level - sw/source/filter/ascii - wrtasc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 54 91 59.3 %
Date: 2012-08-25 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 64 155 41.3 %

           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 <osl/endian.h>
      31                 :            : #include <tools/stream.hxx>
      32                 :            : #include <pam.hxx>
      33                 :            : #include <doc.hxx>
      34                 :            : #include <ndtxt.hxx>
      35                 :            : #include <mdiexp.hxx>           // ...Percent()
      36                 :            : #include <docary.hxx>
      37                 :            : #include <fmtcntnt.hxx>
      38                 :            : #include <frmfmt.hxx>
      39                 :            : #include <wrtasc.hxx>
      40                 :            : 
      41                 :            : #include <statstr.hrc>          // ResId for status bar
      42                 :            : 
      43                 :            : //-----------------------------------------------------------------
      44                 :            : 
      45         [ +  - ]:      10468 : SwASCWriter::SwASCWriter( const String& rFltNm )
      46                 :            : {
      47         [ +  - ]:      10468 :     SwAsciiOptions aNewOpts;
      48                 :            : 
      49 [ +  + ][ -  -  :      10468 :     switch( 5 <= rFltNm.Len() ? rFltNm.GetChar( 4 ) : 0 )
                -  -  + ]
      50                 :            :     {
      51                 :            :     case 'D':
      52                 :          0 :                 aNewOpts.SetCharSet( RTL_TEXTENCODING_IBM_850 );
      53                 :          0 :                 aNewOpts.SetParaFlags( LINEEND_CRLF );
      54         [ #  # ]:          0 :                 if( 5 < rFltNm.Len() )
      55 [ #  # ][ #  # ]:          0 :                     switch( rFltNm.Copy( 5 ).ToInt32() )
         [ #  # ][ #  #  
             #  #  #  #  
                      # ]
      56                 :            :                     {
      57                 :          0 :                     case 437: aNewOpts.SetCharSet( RTL_TEXTENCODING_IBM_437 );  break;
      58                 :          0 :                     case 850: aNewOpts.SetCharSet( RTL_TEXTENCODING_IBM_850 );  break;
      59                 :          0 :                     case 860: aNewOpts.SetCharSet( RTL_TEXTENCODING_IBM_860 );  break;
      60                 :          0 :                     case 861: aNewOpts.SetCharSet( RTL_TEXTENCODING_IBM_861 );  break;
      61                 :          0 :                     case 863: aNewOpts.SetCharSet( RTL_TEXTENCODING_IBM_863 );  break;
      62                 :          0 :                     case 865: aNewOpts.SetCharSet( RTL_TEXTENCODING_IBM_865 );  break;
      63                 :            :                     }
      64                 :          0 :                 break;
      65                 :            : 
      66                 :            :     case 'A':
      67                 :            : #if !defined(WNT)
      68                 :          0 :                 aNewOpts.SetCharSet( RTL_TEXTENCODING_MS_1252 );
      69                 :          0 :                 aNewOpts.SetParaFlags( LINEEND_CRLF );
      70                 :            : #endif
      71                 :          0 :                 break;
      72                 :            : 
      73                 :            :     case 'M':
      74                 :          0 :                 aNewOpts.SetCharSet( RTL_TEXTENCODING_APPLE_ROMAN );
      75                 :          0 :                 aNewOpts.SetParaFlags( LINEEND_CR );
      76                 :          0 :                 break;
      77                 :            : 
      78                 :            :     case 'X':
      79                 :            : #if !defined(UNX)
      80                 :            :                 aNewOpts.SetCharSet( RTL_TEXTENCODING_MS_1252 );
      81                 :            :                 aNewOpts.SetParaFlags( LINEEND_LF );
      82                 :            : #endif
      83                 :          0 :                 break;
      84                 :            : 
      85                 :            :     default:
      86 [ +  - ][ +  - ]:      10468 :         if( rFltNm.Copy( 4 ).EqualsAscii( "_DLG" ))
         [ +  - ][ +  + ]
      87                 :            :         {
      88                 :            :             // use the options
      89         [ +  - ]:      10463 :             aNewOpts = GetAsciiOptions();
      90                 :            :         }
      91                 :            :     }
      92 [ +  - ][ +  - ]:      10468 :     SetAsciiOptions( aNewOpts );
      93                 :      10468 : }
      94                 :            : 
      95 [ +  - ][ -  + ]:      20936 : SwASCWriter::~SwASCWriter() {}
      96                 :            : 
      97                 :      10468 : sal_uLong SwASCWriter::WriteStream()
      98                 :            : {
      99                 :            :     sal_Char cLineEnd[ 3 ];
     100                 :      10468 :     sal_Char* pCEnd = cLineEnd;
     101         [ +  + ]:      10468 :     if( bASCII_ParaAsCR )           // If predefined
     102                 :          2 :         *pCEnd++ = '\015';
     103         [ -  + ]:      10466 :     else if( bASCII_ParaAsBlanc )
     104                 :          0 :         *pCEnd++ = ' ';
     105                 :            :     else
     106   [ -  +  -  - ]:      10466 :         switch( GetAsciiOptions().GetParaFlags() )
     107                 :            :         {
     108                 :          0 :         case LINEEND_CR:    *pCEnd++ = '\015'; break;
     109                 :      10466 :         case LINEEND_LF:    *pCEnd++ = '\012'; break;
     110                 :          0 :         case LINEEND_CRLF:  *pCEnd++ = '\015', *pCEnd++ = '\012'; break;
     111                 :            :         }
     112                 :      10468 :     *pCEnd = 0;
     113                 :            : 
     114         [ +  - ]:      10468 :     sLineEnd.AssignAscii( cLineEnd );
     115                 :            : 
     116         [ +  - ]:      10468 :     long nMaxNode = pDoc->GetNodes().Count();
     117                 :            : 
     118         [ +  + ]:      10468 :     if( bShowProgress )
     119         [ +  - ]:          3 :         ::StartProgress( STR_STATSTR_W4WWRITE, 0, nMaxNode, pDoc->GetDocShell() );
     120                 :            : 
     121                 :      10468 :     SwPaM* pPam = pOrigPam;
     122                 :            : 
     123                 :            :     sal_Bool bWriteSttTag = bUCS2_WithStartChar &&
     124                 :          3 :         (RTL_TEXTENCODING_UCS2 == GetAsciiOptions().GetCharSet() ||
     125   [ +  +  +  - ]:      10471 :         RTL_TEXTENCODING_UTF8 == GetAsciiOptions().GetCharSet());
                 [ +  - ]
     126                 :            : 
     127         [ +  - ]:      10468 :     rtl_TextEncoding eOld = Strm().GetStreamCharSet();
     128         [ +  - ]:      10468 :     Strm().SetStreamCharSet( GetAsciiOptions().GetCharSet() );
     129                 :            : 
     130                 :            :     // Output all areas of the pam into the ASC file
     131         [ -  + ]:      10468 :     do {
     132                 :      10468 :         sal_Bool bTstFly = sal_True;
     133   [ +  +  +  +  :      50074 :         while( pCurPam->GetPoint()->nNode.GetIndex() < pCurPam->GetMark()->nNode.GetIndex() ||
           +  - ][ +  + ]
     134                 :      19699 :               (pCurPam->GetPoint()->nNode.GetIndex() == pCurPam->GetMark()->nNode.GetIndex() &&
     135                 :      10465 :                pCurPam->GetPoint()->nContent.GetIndex() <= pCurPam->GetMark()->nContent.GetIndex()) )
     136                 :            :         {
     137                 :      10676 :             SwTxtNode* pNd = pCurPam->GetPoint()->nNode.GetNode().GetTxtNode();
     138         [ +  - ]:      10676 :             if( pNd )
     139                 :            :             {
     140                 :            :                 // Should we have frames only?
     141                 :            :                 // That's possible, if we put a frame selection into the clipboard
     142 [ +  + ][ +  +  :      10682 :                 if( bTstFly && bWriteAll &&
          +  -  -  +  #  
                #  #  # ]
                 [ -  + ]
     143                 :            :                     // No length
     144                 :          3 :                     !pNd->GetTxt().Len() &&
     145                 :            :                     // Frame exists
     146                 :          3 :                     pDoc->GetSpzFrmFmts()->size() &&
     147                 :            :                     // Only one node in the array
     148         [ #  # ]:          0 :                     pDoc->GetNodes().GetEndOfExtras().GetIndex() + 3 ==
     149         [ #  # ]:          0 :                     pDoc->GetNodes().GetEndOfContent().GetIndex() &&
     150                 :            :                     // And exactly this one is selected
     151         [ #  # ]:          0 :                     pDoc->GetNodes().GetEndOfContent().GetIndex() - 1 ==
     152                 :          0 :                     pCurPam->GetPoint()->nNode.GetIndex() )
     153                 :            :                 {
     154                 :            :                     // Print the frame's content.
     155                 :            :                     // It is always at position 0!
     156                 :          0 :                     SwFrmFmt* pFmt = (*pDoc->GetSpzFrmFmts())[ 0 ];
     157         [ #  # ]:          0 :                     const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
     158         [ #  # ]:          0 :                     if( pIdx )
     159                 :            :                     {
     160 [ #  # ][ #  # ]:          0 :                         delete pCurPam;
     161                 :            :                         pCurPam = NewSwPaM( *pDoc, pIdx->GetIndex(),
     162         [ #  # ]:          0 :                                     pIdx->GetNode().EndOfSectionIndex() );
     163                 :          0 :                         pCurPam->Exchange();
     164                 :          0 :                         continue;       // reset while loop!
     165                 :            :                     }
     166                 :            :                 }
     167                 :            :                 else
     168                 :            :                 {
     169         [ +  + ]:      10676 :                     if (bWriteSttTag)
     170                 :            :                     {
     171      [ +  -  - ]:          3 :                         switch(GetAsciiOptions().GetCharSet())
     172                 :            :                         {
     173                 :            :                             case RTL_TEXTENCODING_UTF8:
     174 [ +  - ][ +  - ]:          3 :                                 Strm() << sal_uInt8(0xEF) << sal_uInt8(0xBB) <<
                 [ +  - ]
     175         [ +  - ]:          3 :                                     sal_uInt8(0xBF);
     176                 :          3 :                                 break;
     177                 :            :                             case RTL_TEXTENCODING_UCS2:
     178 [ #  # ][ #  # ]:          0 :                                 Strm().SetEndianSwap(sal_False);
     179                 :            : #ifdef OSL_LITENDIAN
     180 [ #  # ][ #  # ]:          0 :                                 Strm() << sal_uInt8(0xFF) << sal_uInt8(0xFE);
                 [ #  # ]
     181                 :            : #else
     182                 :            :                                 Strm() << sal_uInt8(0xFE) << sal_uInt8(0xFF);
     183                 :            : #endif
     184                 :          0 :                                 break;
     185                 :            : 
     186                 :            :                         }
     187                 :          3 :                         bWriteSttTag = sal_False;
     188                 :            :                     }
     189         [ +  - ]:      10676 :                     Out( aASCNodeFnTab, *pNd, *this );
     190                 :            :                 }
     191                 :      10676 :                 bTstFly = sal_False;        // Testing once is enough
     192                 :            :             }
     193                 :            : 
     194 [ +  - ][ +  + ]:      10676 :             if( !pCurPam->Move( fnMoveForward, fnGoNode ) )
     195                 :       1234 :                 break;
     196                 :            : 
     197         [ -  + ]:       9442 :             if( bShowProgress )
     198                 :          0 :                 ::SetProgressState( pCurPam->GetPoint()->nNode.GetIndex(),
     199         [ #  # ]:          0 :                                     pDoc->GetDocShell() );   // How far?
     200                 :            : 
     201                 :            :         }
     202         [ +  - ]:      10468 :     } while( CopyNextPam( &pPam ) ); // Until all pams are processed
     203                 :            : 
     204         [ +  - ]:      10468 :     Strm().SetStreamCharSet( eOld );
     205                 :            : 
     206         [ +  + ]:      10468 :     if( bShowProgress )
     207         [ +  - ]:          3 :         ::EndProgress( pDoc->GetDocShell() );
     208                 :            : 
     209                 :      10468 :     return 0;
     210                 :            : }
     211                 :            : 
     212                 :            : 
     213                 :      10468 : void GetASCWriter( const String& rFltNm, const String& /*rBaseURL*/, WriterRef& xRet )
     214                 :            : {
     215         [ +  - ]:      10468 :   xRet = new SwASCWriter( rFltNm );
     216                 :      10468 : }
     217                 :            : 
     218                 :            : 
     219                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10