LCOV - code coverage report
Current view: top level - sc/source/filter/rtf - rtfexp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 115 0.0 %
Date: 2012-08-25 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 133 0.0 %

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

Generated by: LCOV version 1.10