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

Generated by: LCOV version 1.10