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

Generated by: LCOV version 1.10