LCOV - code coverage report
Current view: top level - svx/source/table - tablertfexporter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 102 0.0 %
Date: 2012-08-25 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 234 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                 :            : 
      30                 :            : #include <vector>
      31                 :            : 
      32                 :            : #include <com/sun/star/table/XTable.hpp>
      33                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      34                 :            : 
      35                 :            : #include <tools/stream.hxx>
      36                 :            : #include <svtools/rtfkeywd.hxx>
      37                 :            : #include <svtools/rtfout.hxx>
      38                 :            : 
      39                 :            : #include <editeng/eeitem.hxx>
      40                 :            : #include <svx/sdtaitm.hxx>
      41                 :            : #include <editeng/wghtitem.hxx>
      42                 :            : #include <editeng/postitem.hxx>
      43                 :            : #include <editeng/udlnitem.hxx>
      44                 :            : 
      45                 :            : #include "cell.hxx"
      46                 :            : #include "celltypes.hxx"
      47                 :            : #include "svx/svdotable.hxx"
      48                 :            : #include "svx/svdoutl.hxx"
      49                 :            : #include "editeng/editeng.hxx"
      50                 :            : #include "editeng/outlobj.hxx"
      51                 :            : 
      52                 :            : 
      53                 :            : using ::rtl::OUString;
      54                 :            : using namespace ::com::sun::star::uno;
      55                 :            : using namespace ::com::sun::star::table;
      56                 :            : using namespace ::com::sun::star::container;
      57                 :            : using namespace ::com::sun::star::beans;
      58                 :            : 
      59                 :            : namespace sdr { namespace table {
      60                 :            : 
      61                 :          0 : class SdrTableRtfExporter
      62                 :            : {
      63                 :            : public:
      64                 :            :     SdrTableRtfExporter( SvStream& rStrmP, SdrTableObj& rObj );
      65                 :            :     sal_uLong Write();
      66                 :            :     void WriteRow( const Reference< XPropertySet >& xRowSet, sal_Int32 nRow, const std::vector< sal_Int32 >& aColumnStart );
      67                 :            :     void WriteCell( sal_Int32 nCol, sal_Int32 nRow );
      68                 :            : 
      69                 :            : private:
      70                 :            :     SvStream& mrStrm;
      71                 :            :     SdrTableObj& mrObj;
      72                 :            :     Reference< XTable > mxTable;
      73                 :            :     const OUString msSize;
      74                 :            : };
      75                 :            : 
      76                 :          0 : void SdrTableObj::ExportAsRTF( SvStream& rStrm, SdrTableObj& rObj )
      77                 :            : {
      78         [ #  # ]:          0 :     SdrTableRtfExporter aEx( rStrm, rObj );
      79 [ #  # ][ #  # ]:          0 :     aEx.Write();
      80                 :          0 : }
      81                 :            : 
      82                 :          0 : SdrTableRtfExporter::SdrTableRtfExporter( SvStream& rStrm, SdrTableObj& rObj )
      83                 :            : : mrStrm( rStrm )
      84                 :            : , mrObj( rObj )
      85                 :            : , mxTable( rObj.getTable() )
      86         [ #  # ]:          0 : , msSize( RTL_CONSTASCII_USTRINGPARAM("Size") )
      87                 :            : {
      88                 :          0 : }
      89                 :            : 
      90                 :          0 : long HundMMToTwips( long nIn )
      91                 :            : {
      92                 :          0 :     long nRet = OutputDevice::LogicToLogic( nIn, MAP_100TH_MM, MAP_TWIP );
      93                 :          0 :     return nRet;
      94                 :            : }
      95                 :            : 
      96                 :          0 : sal_uLong SdrTableRtfExporter::Write()
      97                 :            : {
      98 [ #  # ][ #  # ]:          0 :     mrStrm << '{' << OOO_STRING_SVTOOLS_RTF_RTF;
      99 [ #  # ][ #  # ]:          0 :     mrStrm << OOO_STRING_SVTOOLS_RTF_ANSI << RTFOutFuncs::sNewLine;
     100                 :            : 
     101 [ #  # ][ #  # ]:          0 :     Reference< XTableColumns > xColumns( mxTable->getColumns() );
     102 [ #  # ][ #  # ]:          0 :     const sal_Int32 nColCount = xColumns->getCount();
     103                 :            : 
     104         [ #  # ]:          0 :     std::vector< sal_Int32 > aColumnStart;
     105         [ #  # ]:          0 :     aColumnStart.reserve( nColCount );
     106                 :            : 
     107                 :            :     // determine right offset of cells
     108                 :          0 :     sal_Int32 nPos = 0;
     109         [ #  # ]:          0 :     for( sal_Int32 nCol = 0; nCol < nColCount; nCol++ ) try
     110                 :            :     {
     111 [ #  # ][ #  # ]:          0 :         Reference< XPropertySet > xSet( xColumns->getByIndex(nCol), UNO_QUERY_THROW );
                 [ #  # ]
     112                 :          0 :         sal_Int32 nWidth = 0;
     113 [ #  # ][ #  # ]:          0 :         xSet->getPropertyValue( msSize ) >>= nWidth;
     114         [ #  # ]:          0 :         nPos += HundMMToTwips( nWidth );
     115 [ #  # ][ #  # ]:          0 :         aColumnStart.push_back( nPos );
     116                 :            :     }
     117         [ #  # ]:          0 :     catch( Exception& e )
     118                 :            :     {
     119                 :            :         (void)e;
     120                 :            :         OSL_FAIL("SdrTableRtfExporter::Write(), exception caught!");
     121                 :            :     }
     122                 :            : 
     123                 :            :     // export rows
     124 [ #  # ][ #  # ]:          0 :     Reference< XTableRows > xRows( mxTable->getRows() );
     125 [ #  # ][ #  # ]:          0 :     const sal_Int32 nRowCount = xRows->getCount();
     126                 :            : 
     127         [ #  # ]:          0 :     for( sal_Int32 nRow = 0; nRow < nRowCount; nRow++ ) try
     128                 :            :     {
     129 [ #  # ][ #  # ]:          0 :         Reference< XPropertySet > xRowSet( xRows->getByIndex(nRow), UNO_QUERY_THROW );
                 [ #  # ]
     130 [ #  # ][ #  # ]:          0 :         WriteRow( xRowSet, nRow, aColumnStart );
     131                 :            :     }
     132         [ #  # ]:          0 :     catch( Exception& e )
     133                 :            :     {
     134                 :            :         (void)e;
     135                 :            :         OSL_FAIL("SdrTableRtfExporter::Write(), exception caught!");
     136                 :            :     }
     137                 :            : 
     138 [ #  # ][ #  # ]:          0 :     mrStrm << '}' << RTFOutFuncs::sNewLine;
     139                 :          0 :     return mrStrm.GetError();
     140                 :            : }
     141                 :            : 
     142                 :          0 : void SdrTableRtfExporter::WriteRow( const Reference< XPropertySet >& xRowSet, sal_Int32 nRow, const std::vector< sal_Int32 >& aColumnStart )
     143                 :            : {
     144                 :          0 :     sal_Int32 nRowHeight = 0;
     145 [ #  # ][ #  # ]:          0 :     xRowSet->getPropertyValue( msSize ) >>= nRowHeight;
     146                 :            : 
     147 [ #  # ][ #  # ]:          0 :     mrStrm << OOO_STRING_SVTOOLS_RTF_TROWD << OOO_STRING_SVTOOLS_RTF_TRGAPH << "30" << OOO_STRING_SVTOOLS_RTF_TRLEFT << "-30";
         [ #  # ][ #  # ]
                 [ #  # ]
     148 [ #  # ][ #  # ]:          0 :     mrStrm << OOO_STRING_SVTOOLS_RTF_TRRH << rtl::OString::valueOf(nRowHeight).getStr();
     149                 :            : 
     150 [ #  # ][ #  # ]:          0 :     const sal_Int32 nColCount = mxTable->getColumnCount();
     151         [ #  # ]:          0 :     for( sal_Int32 nCol = 0; nCol < nColCount; nCol++ )
     152                 :            :     {
     153 [ #  # ][ #  # ]:          0 :         CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
         [ #  # ][ #  # ]
     154                 :            : 
     155         [ #  # ]:          0 :         if( !xCell.is() )
     156                 :          0 :             continue;
     157                 :            : 
     158 [ #  # ][ #  # ]:          0 :         mrStrm << OOO_STRING_SVTOOLS_RTF_CELLX << rtl::OString::valueOf(aColumnStart[nCol]).getStr();
                 [ #  # ]
     159         [ #  # ]:          0 :         if ( (nCol & 0x0F) == 0x0F )
     160         [ #  # ]:          0 :             mrStrm << RTFOutFuncs::sNewLine;        // Zeilen nicht zu lang werden lassen
     161         [ #  # ]:          0 :     }
     162 [ #  # ][ #  # ]:          0 :     mrStrm << OOO_STRING_SVTOOLS_RTF_PARD << OOO_STRING_SVTOOLS_RTF_PLAIN << OOO_STRING_SVTOOLS_RTF_INTBL << RTFOutFuncs::sNewLine;
         [ #  # ][ #  # ]
     163                 :            : 
     164                 :          0 :     sal_uLong nStrmPos = mrStrm.Tell();
     165         [ #  # ]:          0 :     for( sal_Int32 nCol = 0; nCol < nColCount; nCol++ )
     166                 :            :     {
     167         [ #  # ]:          0 :         WriteCell( nCol, nRow );
     168         [ #  # ]:          0 :         if ( mrStrm.Tell() - nStrmPos > 255 )
     169                 :            :         {
     170         [ #  # ]:          0 :             mrStrm << RTFOutFuncs::sNewLine;
     171                 :          0 :             nStrmPos = mrStrm.Tell();
     172                 :            :         }
     173                 :            :     }
     174 [ #  # ][ #  # ]:          0 :     mrStrm << OOO_STRING_SVTOOLS_RTF_ROW << RTFOutFuncs::sNewLine;
     175                 :          0 : }
     176                 :            : 
     177                 :            : 
     178                 :          0 : void SdrTableRtfExporter::WriteCell( sal_Int32 nCol, sal_Int32 nRow )
     179                 :            : {
     180 [ #  # ][ #  # ]:          0 :     CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
         [ #  # ][ #  # ]
     181                 :            : 
     182 [ #  # ][ #  # ]:          0 :     if( !xCell.is() || xCell->isMerged() )
         [ #  # ][ #  # ]
     183                 :            :     {
     184         [ #  # ]:          0 :         mrStrm << OOO_STRING_SVTOOLS_RTF_CELL;
     185                 :          0 :         return ;
     186                 :            :     }
     187                 :            : 
     188         [ #  # ]:          0 :     String aContent;
     189                 :            : 
     190         [ #  # ]:          0 :     OutlinerParaObject* pParaObj = xCell->GetEditOutlinerParaObject();
     191                 :          0 :     bool bOwnParaObj = pParaObj != 0;
     192                 :            : 
     193         [ #  # ]:          0 :     if( pParaObj == 0 )
     194         [ #  # ]:          0 :         pParaObj = xCell->GetOutlinerParaObject();
     195                 :            : 
     196         [ #  # ]:          0 :     if(pParaObj)
     197                 :            :     {
     198                 :            :         // handle outliner attributes
     199         [ #  # ]:          0 :         SdrOutliner& rOutliner = mrObj.ImpGetDrawOutliner();
     200         [ #  # ]:          0 :         rOutliner.SetText(*pParaObj);
     201                 :            : 
     202 [ #  # ][ #  # ]:          0 :         aContent = rOutliner.GetEditEngine().GetText( LINEEND_LF );
                 [ #  # ]
     203                 :            : 
     204         [ #  # ]:          0 :         rOutliner.Clear();
     205                 :            : 
     206         [ #  # ]:          0 :         if( bOwnParaObj )
     207 [ #  # ][ #  # ]:          0 :             delete pParaObj;
     208                 :            :     }
     209                 :            : 
     210                 :            :     bool bResetPar, bResetAttr;
     211                 :          0 :     bResetPar = bResetAttr = sal_False;
     212                 :            : 
     213         [ #  # ]:          0 :     SdrTextHorzAdjust eHAdj = xCell->GetTextHorizontalAdjust();
     214                 :            : 
     215         [ #  # ]:          0 :     const SfxItemSet& rCellSet = xCell->GetItemSet();
     216                 :            : 
     217         [ #  # ]:          0 :     const SvxWeightItem&        rWeightItem     = (const SvxWeightItem&)    rCellSet.Get( EE_CHAR_WEIGHT );
     218         [ #  # ]:          0 :     const SvxPostureItem&       rPostureItem    = (const SvxPostureItem&)   rCellSet.Get( EE_CHAR_ITALIC );
     219         [ #  # ]:          0 :     const SvxUnderlineItem&     rUnderlineItem  = (const SvxUnderlineItem&) rCellSet.Get( EE_CHAR_UNDERLINE );
     220                 :            : 
     221                 :            :     const sal_Char* pChar;
     222                 :            : 
     223   [ #  #  #  # ]:          0 :     switch( eHAdj )
     224                 :            :     {
     225                 :          0 :         case SDRTEXTHORZADJUST_CENTER:  pChar = OOO_STRING_SVTOOLS_RTF_QC;  break;
     226                 :          0 :         case SDRTEXTHORZADJUST_BLOCK:   pChar = OOO_STRING_SVTOOLS_RTF_QJ;  break;
     227                 :          0 :         case SDRTEXTHORZADJUST_RIGHT:   pChar = OOO_STRING_SVTOOLS_RTF_QR;  break;
     228                 :            :         case SDRTEXTHORZADJUST_LEFT:
     229                 :          0 :         default:                        pChar = OOO_STRING_SVTOOLS_RTF_QL;  break;
     230                 :            :     }
     231         [ #  # ]:          0 :     mrStrm << pChar;
     232                 :            : 
     233         [ #  # ]:          0 :     if ( rWeightItem.GetWeight() >= WEIGHT_BOLD )
     234                 :            :     {   // bold
     235                 :          0 :         bResetAttr = true;
     236         [ #  # ]:          0 :         mrStrm << OOO_STRING_SVTOOLS_RTF_B;
     237                 :            :     }
     238         [ #  # ]:          0 :     if ( rPostureItem.GetPosture() != ITALIC_NONE )
     239                 :            :     {   // italic
     240                 :          0 :         bResetAttr = true;
     241         [ #  # ]:          0 :         mrStrm << OOO_STRING_SVTOOLS_RTF_I;
     242                 :            :     }
     243         [ #  # ]:          0 :     if ( rUnderlineItem.GetLineStyle() != UNDERLINE_NONE )
     244                 :            :     {   // underline
     245                 :          0 :         bResetAttr = true;
     246         [ #  # ]:          0 :         mrStrm << OOO_STRING_SVTOOLS_RTF_UL;
     247                 :            :     }
     248                 :            : 
     249         [ #  # ]:          0 :     mrStrm << ' ';
     250         [ #  # ]:          0 :     RTFOutFuncs::Out_String( mrStrm, aContent );
     251         [ #  # ]:          0 :     mrStrm << OOO_STRING_SVTOOLS_RTF_CELL;
     252                 :            : 
     253         [ #  # ]:          0 :     if ( bResetPar )
     254 [ #  # ][ #  # ]:          0 :         mrStrm << OOO_STRING_SVTOOLS_RTF_PARD << OOO_STRING_SVTOOLS_RTF_INTBL;
     255         [ #  # ]:          0 :     if ( bResetAttr )
     256 [ #  # ][ #  # ]:          0 :         mrStrm << OOO_STRING_SVTOOLS_RTF_PLAIN;
                 [ #  # ]
     257                 :            : }
     258                 :            : 
     259                 :            : } }
     260                 :            : 
     261                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10