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

Generated by: LCOV version 1.10