LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/rtf - rtfexp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 115 0.0 %
Date: 2012-12-17 Functions: 0 8 0.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 "scitems.hxx"
      21             : #include <editeng/eeitem.hxx>
      22             : 
      23             : 
      24             : #include <svx/algitem.hxx>
      25             : #include <editeng/wghtitem.hxx>
      26             : #include <editeng/postitem.hxx>
      27             : #include <editeng/udlnitem.hxx>
      28             : #include <editeng/fontitem.hxx>
      29             : #include <editeng/fhgtitem.hxx>
      30             : #include <editeng/justifyitem.hxx>
      31             : #include <svl/style.hxx>
      32             : #include <svtools/rtfout.hxx>
      33             : #include <svtools/rtfkeywd.hxx>
      34             : 
      35             : #include "rtfexp.hxx"
      36             : #include "filter.hxx"
      37             : #include "document.hxx"
      38             : #include "patattr.hxx"
      39             : #include "attrib.hxx"
      40             : #include "cell.hxx"
      41             : #include "cellform.hxx"
      42             : #include "editutil.hxx"
      43             : #include "stlpool.hxx"
      44             : #include "ftools.hxx"
      45             : 
      46             : //------------------------------------------------------------------
      47             : 
      48           0 : FltError ScFormatFilterPluginImpl::ScExportRTF( SvStream& rStrm, ScDocument* pDoc,
      49             :         const ScRange& rRange, const CharSet /*eNach*/ )
      50             : {
      51           0 :     ScRTFExport aEx( rStrm, pDoc, rRange );
      52           0 :     return aEx.Write();
      53             : }
      54             : 
      55             : 
      56           0 : ScRTFExport::ScRTFExport( SvStream& rStrmP, ScDocument* pDocP, const ScRange& rRangeP )
      57             :             :
      58             :             ScExportBase( rStrmP, pDocP, rRangeP ),
      59           0 :             pCellX( new sal_uLong[ MAXCOL+2 ] )
      60             : {
      61           0 : }
      62             : 
      63             : 
      64           0 : ScRTFExport::~ScRTFExport()
      65             : {
      66           0 :     delete [] pCellX;
      67           0 : }
      68             : 
      69             : 
      70           0 : sal_uLong ScRTFExport::Write()
      71             : {
      72           0 :     rStrm << '{' << OOO_STRING_SVTOOLS_RTF_RTF;
      73           0 :     rStrm << OOO_STRING_SVTOOLS_RTF_ANSI << sNewLine;
      74             : 
      75             :     // Daten
      76           0 :     for ( SCTAB nTab = aRange.aStart.Tab(); nTab <= aRange.aEnd.Tab(); nTab++ )
      77             :     {
      78           0 :         if ( nTab > aRange.aStart.Tab() )
      79           0 :             rStrm << OOO_STRING_SVTOOLS_RTF_PAR;
      80           0 :         WriteTab( nTab );
      81             :     }
      82             : 
      83           0 :     rStrm << '}' << sNewLine;
      84           0 :     return rStrm.GetError();
      85             : }
      86             : 
      87             : 
      88           0 : void ScRTFExport::WriteTab( SCTAB nTab )
      89             : {
      90           0 :     rStrm << '{' << sNewLine;
      91           0 :     if ( pDoc->HasTable( nTab ) )
      92             :     {
      93           0 :         memset( &pCellX[0], 0, (MAXCOL+2) * sizeof(sal_uLong) );
      94             :         SCCOL nCol;
      95           0 :         SCCOL nEndCol = aRange.aEnd.Col();
      96           0 :         for ( nCol = aRange.aStart.Col(); nCol <= nEndCol; nCol++ )
      97             :         {
      98           0 :             pCellX[nCol+1] = pCellX[nCol] + pDoc->GetColWidth( nCol, nTab );
      99             :         }
     100             : 
     101           0 :         SCROW nEndRow = aRange.aEnd.Row();
     102           0 :         for ( SCROW nRow = aRange.aStart.Row(); nRow <= nEndRow; nRow++ )
     103             :         {
     104           0 :             WriteRow( nTab, nRow );
     105             :         }
     106             :     }
     107           0 :     rStrm << '}' << sNewLine;
     108           0 : }
     109             : 
     110             : 
     111           0 : void ScRTFExport::WriteRow( SCTAB nTab, SCROW nRow )
     112             : {
     113           0 :     rStrm << OOO_STRING_SVTOOLS_RTF_TROWD << OOO_STRING_SVTOOLS_RTF_TRGAPH << "30" << OOO_STRING_SVTOOLS_RTF_TRLEFT << "-30";
     114           0 :     rStrm << OOO_STRING_SVTOOLS_RTF_TRRH << rtl::OString::valueOf(static_cast<sal_Int32>(pDoc->GetRowHeight(nRow, nTab))).getStr();
     115             :     SCCOL nCol;
     116           0 :     SCCOL nEndCol = aRange.aEnd.Col();
     117           0 :     for ( nCol = aRange.aStart.Col(); nCol <= nEndCol; nCol++ )
     118             :     {
     119           0 :         const ScPatternAttr* pAttr = pDoc->GetPattern( nCol, nRow, nTab );
     120           0 :         const ScMergeAttr&      rMergeAttr      = (const ScMergeAttr&)      pAttr->GetItem( ATTR_MERGE );
     121           0 :         const SvxVerJustifyItem& rVerJustifyItem= (const SvxVerJustifyItem&)pAttr->GetItem( ATTR_VER_JUSTIFY );
     122             : 
     123             :         const sal_Char* pChar;
     124             : 
     125           0 :         if ( rMergeAttr.GetColMerge() != 0 )
     126           0 :             rStrm << OOO_STRING_SVTOOLS_RTF_CLMGF;
     127             :         else
     128             :         {
     129           0 :             const ScMergeFlagAttr& rMergeFlagAttr = (const ScMergeFlagAttr&) pAttr->GetItem( ATTR_MERGE_FLAG );
     130           0 :             if ( rMergeFlagAttr.IsHorOverlapped() )
     131           0 :                 rStrm << OOO_STRING_SVTOOLS_RTF_CLMRG;
     132             :         }
     133             : 
     134           0 :         switch( rVerJustifyItem.GetValue() )
     135             :         {
     136           0 :             case SVX_VER_JUSTIFY_TOP:       pChar = OOO_STRING_SVTOOLS_RTF_CLVERTALT;   break;
     137           0 :             case SVX_VER_JUSTIFY_CENTER:    pChar = OOO_STRING_SVTOOLS_RTF_CLVERTALC;   break;
     138           0 :             case SVX_VER_JUSTIFY_BOTTOM:    pChar = OOO_STRING_SVTOOLS_RTF_CLVERTALB;   break;
     139           0 :             case SVX_VER_JUSTIFY_STANDARD:  pChar = OOO_STRING_SVTOOLS_RTF_CLVERTALB;   break;  //! Bottom
     140           0 :             default:                        pChar = NULL;           break;
     141             :         }
     142           0 :         if ( pChar )
     143           0 :             rStrm << pChar;
     144             : 
     145           0 :         rStrm << OOO_STRING_SVTOOLS_RTF_CELLX << rtl::OString::valueOf(static_cast<sal_Int32>(pCellX[nCol+1])).getStr();
     146           0 :         if ( (nCol & 0x0F) == 0x0F )
     147           0 :             rStrm << sNewLine;      // Zeilen nicht zu lang werden lassen
     148             :     }
     149           0 :     rStrm << OOO_STRING_SVTOOLS_RTF_PARD << OOO_STRING_SVTOOLS_RTF_PLAIN << OOO_STRING_SVTOOLS_RTF_INTBL << sNewLine;
     150             : 
     151           0 :     sal_uLong nStrmPos = rStrm.Tell();
     152           0 :     for ( nCol = aRange.aStart.Col(); nCol <= nEndCol; nCol++ )
     153             :     {
     154           0 :         WriteCell( nTab, nRow, nCol );
     155           0 :         if ( rStrm.Tell() - nStrmPos > 255 )
     156             :         {   // Zeilen nicht zu lang werden lassen
     157           0 :             rStrm << sNewLine;
     158           0 :             nStrmPos = rStrm.Tell();
     159             :         }
     160             :     }
     161           0 :     rStrm << OOO_STRING_SVTOOLS_RTF_ROW << sNewLine;
     162           0 : }
     163             : 
     164             : 
     165           0 : void ScRTFExport::WriteCell( SCTAB nTab, SCROW nRow, SCCOL nCol )
     166             : {
     167           0 :     const ScPatternAttr* pAttr = pDoc->GetPattern( nCol, nRow, nTab );
     168             : 
     169           0 :     const ScMergeFlagAttr& rMergeFlagAttr = (const ScMergeFlagAttr&) pAttr->GetItem( ATTR_MERGE_FLAG );
     170           0 :     if ( rMergeFlagAttr.IsHorOverlapped() )
     171             :     {
     172           0 :         rStrm << OOO_STRING_SVTOOLS_RTF_CELL;
     173           0 :         return ;
     174             :     }
     175             : 
     176             :     ScBaseCell* pCell;
     177           0 :     pDoc->GetCell( nCol, nRow, nTab, pCell );
     178             :     sal_Bool bValueData;
     179           0 :     rtl::OUString aContent;
     180           0 :     if ( pCell )
     181             :     {
     182           0 :         switch ( pCell->GetCellType() )
     183             :         {
     184             :             case CELLTYPE_NOTE :
     185           0 :                 bValueData = false;
     186           0 :             break;      // nix
     187             :             case CELLTYPE_EDIT :
     188             :             {
     189           0 :                 bValueData = false;
     190           0 :                 EditEngine& rEngine = GetEditEngine();
     191             :                 const EditTextObject* pObj;
     192           0 :                 ((const ScEditCell*)pCell)->GetData( pObj );
     193           0 :                 if ( pObj )
     194             :                 {
     195           0 :                     rEngine.SetText( *pObj );
     196           0 :                     aContent = rEngine.GetText( LINEEND_LF );   // LineFeed zwischen Absaetzen!
     197             :                 }
     198             :             }
     199           0 :             break;
     200             :             default:
     201             :             {
     202           0 :                 bValueData = pCell->HasValueData();
     203           0 :                 sal_uLong nFormat = pAttr->GetNumberFormat( pFormatter );
     204             :                 Color* pColor;
     205           0 :                 ScCellFormat::GetString( pCell, nFormat, aContent, &pColor, *pFormatter );
     206             :             }
     207             :         }
     208             :     }
     209             :     else
     210           0 :         bValueData = false;
     211             : 
     212             :     sal_Bool bResetPar, bResetAttr;
     213           0 :     bResetPar = bResetAttr = false;
     214             : 
     215           0 :     const SvxHorJustifyItem&    rHorJustifyItem = (const SvxHorJustifyItem&)pAttr->GetItem( ATTR_HOR_JUSTIFY );
     216           0 :     const SvxWeightItem&        rWeightItem     = (const SvxWeightItem&)    pAttr->GetItem( ATTR_FONT_WEIGHT );
     217           0 :     const SvxPostureItem&       rPostureItem    = (const SvxPostureItem&)   pAttr->GetItem( ATTR_FONT_POSTURE );
     218           0 :     const SvxUnderlineItem&     rUnderlineItem  = (const SvxUnderlineItem&) pAttr->GetItem( ATTR_FONT_UNDERLINE );
     219             : 
     220             :     const sal_Char* pChar;
     221             : 
     222           0 :     switch( rHorJustifyItem.GetValue() )
     223             :     {
     224             :         case SVX_HOR_JUSTIFY_STANDARD:
     225           0 :             pChar = (bValueData ? OOO_STRING_SVTOOLS_RTF_QR : OOO_STRING_SVTOOLS_RTF_QL);
     226           0 :             break;
     227           0 :         case SVX_HOR_JUSTIFY_CENTER:    pChar = OOO_STRING_SVTOOLS_RTF_QC;  break;
     228           0 :         case SVX_HOR_JUSTIFY_BLOCK:     pChar = OOO_STRING_SVTOOLS_RTF_QJ;  break;
     229           0 :         case SVX_HOR_JUSTIFY_RIGHT:     pChar = OOO_STRING_SVTOOLS_RTF_QR;  break;
     230             :         case SVX_HOR_JUSTIFY_LEFT:
     231             :         case SVX_HOR_JUSTIFY_REPEAT:
     232           0 :         default:                        pChar = OOO_STRING_SVTOOLS_RTF_QL;  break;
     233             :     }
     234           0 :     rStrm << pChar;
     235             : 
     236           0 :     if ( rWeightItem.GetWeight() >= WEIGHT_BOLD )
     237             :     {   // bold
     238           0 :         bResetAttr = sal_True;
     239           0 :         rStrm << OOO_STRING_SVTOOLS_RTF_B;
     240             :     }
     241           0 :     if ( rPostureItem.GetPosture() != ITALIC_NONE )
     242             :     {   // italic
     243           0 :         bResetAttr = sal_True;
     244           0 :         rStrm << OOO_STRING_SVTOOLS_RTF_I;
     245             :     }
     246           0 :     if ( rUnderlineItem.GetLineStyle() != UNDERLINE_NONE )
     247             :     {   // underline
     248           0 :         bResetAttr = sal_True;
     249           0 :         rStrm << OOO_STRING_SVTOOLS_RTF_UL;
     250             :     }
     251             : 
     252           0 :     rStrm << ' ';
     253           0 :     RTFOutFuncs::Out_String( rStrm, aContent );
     254           0 :     rStrm << OOO_STRING_SVTOOLS_RTF_CELL;
     255             : 
     256           0 :     if ( bResetPar )
     257           0 :         rStrm << OOO_STRING_SVTOOLS_RTF_PARD << OOO_STRING_SVTOOLS_RTF_INTBL;
     258           0 :     if ( bResetAttr )
     259           0 :         rStrm << OOO_STRING_SVTOOLS_RTF_PLAIN;
     260             : }
     261             : 
     262             : 
     263             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10