Files
libreoffice/svx/source/table/tablertfexporter.cxx
Release Engineers 262b6f4b50 CWS-TOOLING: integrate CWS impress168
2009-04-24 11:26:33 +0200 wg  r271204 : i101157
2009-04-24 10:17:59 +0200 wg  r271200 : i101157
2009-04-23 15:50:12 +0200 wg  r271178 : i101157
2009-04-23 15:16:58 +0200 wg  r271176 : i101157
2009-04-23 13:04:41 +0200 wg  r271158 : i101157
2009-04-22 15:39:32 +0200 wg  r271123 : i101157
2009-04-22 14:27:24 +0200 wg  r271111 : i101157
2009-04-22 14:14:02 +0200 wg  r271109 : i101157
2009-04-17 14:34:19 +0200 wg  r270946 : i101157
2009-04-17 13:49:15 +0200 wg  r270939 : i101157
2009-03-31 14:54:52 +0200 sj  r270281 : CWS-TOOLING: rebase CWS impress168 to trunk@270033 (milestone: DEV300:m45)
2009-03-26 16:56:44 +0100 sj  r270089 : removed invalid file names
2009-03-24 14:02:54 +0100 sj  r269944 : CWS-TOOLING: rebase CWS impress168 to trunk@269781 (milestone: DEV300:m44)
2009-03-06 16:32:14 +0100 sj  r269020 : #i99970# importing customshapes without group object, taking care of the correct text alignment
2009-02-27 13:53:24 +0100 sj  r268591 : #158501,158483# fixed positioning problem of 3d customshapes
2009-02-19 16:02:00 +0100 sj  r268292 : #76543# fixed interactive hyperlink program action with relativ url
2009-02-18 15:36:52 +0100 sj  r268233 : #158503# added import of circular gradients for ellipse shapes
2009-02-16 19:51:54 +0100 sj  r267836 : #i99146# calculating correct text bounds
2009-02-12 13:59:46 +0100 sj  r267654 : #i96179# fixed bullet problem
2009-02-10 17:26:41 +0100 sj  r267566 : #158476# fixed import of the ribbon shape
2009-02-10 17:10:27 +0100 cl  r267561 : #i95364# fixed type detection of linked images
2009-02-09 18:31:59 +0100 cl  r267531 : #i98352# removed assertion
2009-02-09 18:31:17 +0100 cl  r267530 : #i98355# fixed alien attribute import for sd in binfilter
2009-02-09 18:30:53 +0100 cl  r267529 : #i98355# fixed alien attribute import for sd in binfilter
2009-02-09 09:52:15 +0100 cl  r267501 : #i98573# fixed build error
2009-02-06 17:02:21 +0100 sj  r267476 : #i96179# fixed bullet problem
2009-02-06 14:58:39 +0100 cl  r267466 : #i14832# fixed page count field for handout printing
2009-02-06 10:23:01 +0100 cl  r267447 : #i98573# fixed GetEditOutlinerParaObject() memory leak
2009-02-05 18:03:34 +0100 cl  r267435 : #i98573# fixed GetEditOutlinerParaObject() memory leak
2009-02-05 18:03:08 +0100 cl  r267434 : #i85481# added XMultiPropertyStates to text implementations
2009-02-05 18:02:54 +0100 cl  r267433 : #i85481# added XMultiPropertyStates to text implementations
2009-02-05 18:02:42 +0100 cl  r267432 : #i85481# added XMultiPropertyStates to text implementations
2009-02-04 18:54:46 +0100 sj  r267400 : #i33630# fixed arrow size of word import
2009-02-04 15:40:16 +0100 cl  r267389 : #i58702# fixed tiled bitmap fill for vcl canvas
2009-02-04 15:39:07 +0100 cl  r267388 : #i58702# fixed tiled bitmap fill for vcl canvas
2009-02-04 14:23:27 +0100 cl  r267382 : #i98573# fixed memory leaks caused by wron usage of GetEditOutlinerParaObject()
2009-02-04 14:22:34 +0100 cl  r267381 : #i98573# fixed memory leaks caused by wron usage of GetEditOutlinerParaObject()
2009-02-04 12:51:50 +0100 cl  r267371 : #i14832# added Page Count field to impress
2009-02-04 12:41:31 +0100 cl  r267368 : #i14832# added Page Count field to impress
2009-05-06 21:51:02 +00:00

288 lines
9.1 KiB
C++

/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: tablertfexporter.cxx,v $
* $Revision: 1.3.212.1 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"
#include <vector>
#include <com/sun/star/table/XTable.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <tools/stream.hxx>
#include <svtools/rtfkeywd.hxx>
#include <svtools/rtfout.hxx>
#include <svx/eeitem.hxx>
#include <svx/sdtaitm.hxx>
#include <svx/wghtitem.hxx>
#include <svx/postitem.hxx>
#include <svx/udlnitem.hxx>
#include "cell.hxx"
#include "celltypes.hxx"
#include "svx/svdotable.hxx"
#include "svx/svdoutl.hxx"
#include "svx/editeng.hxx"
#include "svx/outlobj.hxx"
//#include <tablertfexporter.hxx>
using ::rtl::OUString;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::table;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::beans;
namespace sdr { namespace table {
class SdrTableRtfExporter
{
public:
SdrTableRtfExporter( SvStream& rStrmP, SdrTableObj& rObj );
ULONG Write();
void WriteRow( const Reference< XPropertySet >& xRowSet, sal_Int32 nRow, const std::vector< sal_Int32 >& aColumnStart );
void WriteCell( sal_Int32 nCol, sal_Int32 nRow );
private:
SvStream& mrStrm;
SdrTableObj& mrObj;
Reference< XTable > mxTable;
const OUString msSize;
};
void SdrTableObj::ExportAsRTF( SvStream& rStrm, SdrTableObj& rObj )
{
SdrTableRtfExporter aEx( rStrm, rObj );
aEx.Write();
}
SdrTableRtfExporter::SdrTableRtfExporter( SvStream& rStrm, SdrTableObj& rObj )
: mrStrm( rStrm )
, mrObj( rObj )
, mxTable( rObj.getTable() )
, msSize( RTL_CONSTASCII_USTRINGPARAM("Size") )
{
}
long HundMMToTwips( long nIn )
{
long nRet = OutputDevice::LogicToLogic( nIn, MAP_100TH_MM, MAP_TWIP );
return nRet;
}
ULONG SdrTableRtfExporter::Write()
{
mrStrm << '{' << OOO_STRING_SVTOOLS_RTF_RTF;
mrStrm << OOO_STRING_SVTOOLS_RTF_ANSI << RTFOutFuncs::sNewLine;
Reference< XTableColumns > xColumns( mxTable->getColumns() );
const sal_Int32 nColCount = xColumns->getCount();
std::vector< sal_Int32 > aColumnStart;
aColumnStart.reserve( nColCount );
// determine right offset of cells
sal_Int32 nPos = 0;
for( sal_Int32 nCol = 0; nCol < nColCount; nCol++ ) try
{
Reference< XPropertySet > xSet( xColumns->getByIndex(nCol), UNO_QUERY_THROW );
sal_Int32 nWidth = 0;
xSet->getPropertyValue( msSize ) >>= nWidth;
nPos += HundMMToTwips( nWidth );
aColumnStart.push_back( nPos );
}
catch( Exception& e )
{
(void)e;
DBG_ERROR("SdrTableRtfExporter::Write(), exception caught!");
}
// export rows
Reference< XTableRows > xRows( mxTable->getRows() );
const sal_Int32 nRowCount = xRows->getCount();
for( sal_Int32 nRow = 0; nRow < nRowCount; nRow++ ) try
{
Reference< XPropertySet > xRowSet( xRows->getByIndex(nRow), UNO_QUERY_THROW );
WriteRow( xRowSet, nRow, aColumnStart );
}
catch( Exception& e )
{
(void)e;
DBG_ERROR("SdrTableRtfExporter::Write(), exception caught!");
}
mrStrm << '}' << RTFOutFuncs::sNewLine;
return mrStrm.GetError();
}
void SdrTableRtfExporter::WriteRow( const Reference< XPropertySet >& xRowSet, sal_Int32 nRow, const std::vector< sal_Int32 >& aColumnStart )
{
sal_Int32 nRowHeight = 0;
xRowSet->getPropertyValue( msSize ) >>= nRowHeight;
mrStrm << OOO_STRING_SVTOOLS_RTF_TROWD << OOO_STRING_SVTOOLS_RTF_TRGAPH << "30" << OOO_STRING_SVTOOLS_RTF_TRLEFT << "-30";
mrStrm << OOO_STRING_SVTOOLS_RTF_TRRH << ByteString::CreateFromInt32( nRowHeight ).GetBuffer();
const sal_Int32 nColCount = mxTable->getColumnCount();
for( sal_Int32 nCol = 0; nCol < nColCount; nCol++ )
{
CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
if( !xCell.is() )
continue;
/*
const sal_Bool bIsMerged = xCell->isMerged();
const sal_Int32 nRowSpan = xCell->getRowSpan();
const sal_Int32 nColSpan = xCell->getColumnSpan();
const sal_Char* pChar;
if( !bIsMerged && ((nRowSpan > 1) || (nColSpan > 1)) )
mrStrm << OOO_STRING_SVTOOLS_RTF_CLMGF; // The first cell in a range of table cells to be merged.
SdrTextVertAdjust eVAdj = xCell->GetTextVerticalAdjust();
switch( eVAdj )
{
case SVX_VER_JUSTIFY_TOP: pChar = OOO_STRING_SVTOOLS_RTF_CLVERTALT; break;
case SVX_VER_JUSTIFY_CENTER: pChar = OOO_STRING_SVTOOLS_RTF_CLVERTALC; break;
case SVX_VER_JUSTIFY_BOTTOM: pChar = OOO_STRING_SVTOOLS_RTF_CLVERTALB; break;
case SVX_VER_JUSTIFY_STANDARD: pChar = OOO_STRING_SVTOOLS_RTF_CLVERTALB; break; //! Bottom
default: pChar = NULL; break;
}
if ( pChar )
mrStrm << pChar;
*/
mrStrm << OOO_STRING_SVTOOLS_RTF_CELLX << ByteString::CreateFromInt32( aColumnStart[nCol] ).GetBuffer();
if ( (nCol & 0x0F) == 0x0F )
mrStrm << RTFOutFuncs::sNewLine; // Zeilen nicht zu lang werden lassen
}
mrStrm << OOO_STRING_SVTOOLS_RTF_PARD << OOO_STRING_SVTOOLS_RTF_PLAIN << OOO_STRING_SVTOOLS_RTF_INTBL << RTFOutFuncs::sNewLine;
ULONG nStrmPos = mrStrm.Tell();
for( sal_Int32 nCol = 0; nCol < nColCount; nCol++ )
{
WriteCell( nCol, nRow );
if ( mrStrm.Tell() - nStrmPos > 255 )
{
mrStrm << RTFOutFuncs::sNewLine;
nStrmPos = mrStrm.Tell();
}
}
mrStrm << OOO_STRING_SVTOOLS_RTF_ROW << RTFOutFuncs::sNewLine;
}
void SdrTableRtfExporter::WriteCell( sal_Int32 nCol, sal_Int32 nRow )
{
CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
if( !xCell.is() || xCell->isMerged() )
{
mrStrm << OOO_STRING_SVTOOLS_RTF_CELL;
return ;
}
String aContent;
OutlinerParaObject* pParaObj = xCell->GetEditOutlinerParaObject();
bool bOwnParaObj = pParaObj != 0;
if( pParaObj == 0 )
pParaObj = xCell->GetOutlinerParaObject();
if(pParaObj)
{
// handle outliner attributes
SdrOutliner& rOutliner = mrObj.ImpGetDrawOutliner();
rOutliner.SetText(*pParaObj);
aContent = rOutliner.GetEditEngine().GetText( LINEEND_LF );
rOutliner.Clear();
if( bOwnParaObj )
delete pParaObj;
}
bool bResetPar, bResetAttr;
bResetPar = bResetAttr = FALSE;
SdrTextHorzAdjust eHAdj = xCell->GetTextHorizontalAdjust();
const SfxItemSet& rCellSet = xCell->GetItemSet();
const SvxWeightItem& rWeightItem = (const SvxWeightItem&) rCellSet.Get( EE_CHAR_WEIGHT );
const SvxPostureItem& rPostureItem = (const SvxPostureItem&) rCellSet.Get( EE_CHAR_ITALIC );
const SvxUnderlineItem& rUnderlineItem = (const SvxUnderlineItem&) rCellSet.Get( EE_CHAR_UNDERLINE );
const sal_Char* pChar;
switch( eHAdj )
{
case SDRTEXTHORZADJUST_CENTER: pChar = OOO_STRING_SVTOOLS_RTF_QC; break;
case SDRTEXTHORZADJUST_BLOCK: pChar = OOO_STRING_SVTOOLS_RTF_QJ; break;
case SDRTEXTHORZADJUST_RIGHT: pChar = OOO_STRING_SVTOOLS_RTF_QR; break;
case SDRTEXTHORZADJUST_LEFT:
default: pChar = OOO_STRING_SVTOOLS_RTF_QL; break;
}
mrStrm << pChar;
if ( rWeightItem.GetWeight() >= WEIGHT_BOLD )
{ // bold
bResetAttr = true;
mrStrm << OOO_STRING_SVTOOLS_RTF_B;
}
if ( rPostureItem.GetPosture() != ITALIC_NONE )
{ // italic
bResetAttr = true;
mrStrm << OOO_STRING_SVTOOLS_RTF_I;
}
if ( rUnderlineItem.GetLineStyle() != UNDERLINE_NONE )
{ // underline
bResetAttr = true;
mrStrm << OOO_STRING_SVTOOLS_RTF_UL;
}
mrStrm << ' ';
RTFOutFuncs::Out_String( mrStrm, aContent );
mrStrm << OOO_STRING_SVTOOLS_RTF_CELL;
if ( bResetPar )
mrStrm << OOO_STRING_SVTOOLS_RTF_PARD << OOO_STRING_SVTOOLS_RTF_INTBL;
if ( bResetAttr )
mrStrm << OOO_STRING_SVTOOLS_RTF_PLAIN;
}
} }