2010-10-12 08:53:47 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2008-03-12 04:06:33 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 21:33:49 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2008-03-12 04:06:33 -05:00
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2008-03-12 04:06:33 -05:00
|
|
|
*
|
2008-04-10 21:33:49 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2008-03-12 04:06:33 -05:00
|
|
|
*
|
2008-04-10 21:33:49 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2008-03-12 04:06:33 -05:00
|
|
|
*
|
2008-04-10 21:33:49 -05:00
|
|
|
* 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.
|
2008-03-12 04:06:33 -05:00
|
|
|
*
|
2008-04-10 21:33:49 -05:00
|
|
|
* 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).
|
2008-03-12 04:06:33 -05:00
|
|
|
*
|
2008-04-10 21:33:49 -05:00
|
|
|
* 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.
|
2008-03-12 04:06:33 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
2010-01-07 11:52:36 -06:00
|
|
|
#include <editeng/eeitem.hxx>
|
2008-03-12 04:06:33 -05:00
|
|
|
#include <svx/sdtaitm.hxx>
|
2010-01-07 11:52:36 -06:00
|
|
|
#include <editeng/wghtitem.hxx>
|
|
|
|
#include <editeng/postitem.hxx>
|
|
|
|
#include <editeng/udlnitem.hxx>
|
2008-03-12 04:06:33 -05:00
|
|
|
|
|
|
|
#include "cell.hxx"
|
|
|
|
#include "celltypes.hxx"
|
|
|
|
#include "svx/svdotable.hxx"
|
|
|
|
#include "svx/svdoutl.hxx"
|
2010-01-07 11:52:36 -06:00
|
|
|
#include "editeng/editeng.hxx"
|
|
|
|
#include "editeng/outlobj.hxx"
|
2008-03-12 04:06:33 -05:00
|
|
|
|
|
|
|
|
|
|
|
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 );
|
2011-01-13 09:27:50 -06:00
|
|
|
sal_uLong Write();
|
2008-03-12 04:06:33 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:27:50 -06:00
|
|
|
sal_uLong SdrTableRtfExporter::Write()
|
2008-03-12 04:06:33 -05:00
|
|
|
{
|
2009-04-27 06:24:10 -05:00
|
|
|
mrStrm << '{' << OOO_STRING_SVTOOLS_RTF_RTF;
|
|
|
|
mrStrm << OOO_STRING_SVTOOLS_RTF_ANSI << RTFOutFuncs::sNewLine;
|
2008-03-12 04:06:33 -05:00
|
|
|
|
|
|
|
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;
|
2011-03-01 12:07:44 -06:00
|
|
|
OSL_FAIL("SdrTableRtfExporter::Write(), exception caught!");
|
2008-03-12 04:06:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2011-03-01 12:07:44 -06:00
|
|
|
OSL_FAIL("SdrTableRtfExporter::Write(), exception caught!");
|
2008-03-12 04:06:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-04-27 06:24:10 -05:00
|
|
|
mrStrm << OOO_STRING_SVTOOLS_RTF_TROWD << OOO_STRING_SVTOOLS_RTF_TRGAPH << "30" << OOO_STRING_SVTOOLS_RTF_TRLEFT << "-30";
|
2011-07-28 15:30:34 -05:00
|
|
|
mrStrm << OOO_STRING_SVTOOLS_RTF_TRRH << rtl::OString::valueOf(nRowHeight).getStr();
|
2008-03-12 04:06:33 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2011-07-28 15:30:34 -05:00
|
|
|
mrStrm << OOO_STRING_SVTOOLS_RTF_CELLX << rtl::OString::valueOf(aColumnStart[nCol]).getStr();
|
2008-03-12 04:06:33 -05:00
|
|
|
if ( (nCol & 0x0F) == 0x0F )
|
|
|
|
mrStrm << RTFOutFuncs::sNewLine; // Zeilen nicht zu lang werden lassen
|
|
|
|
}
|
2009-04-27 06:24:10 -05:00
|
|
|
mrStrm << OOO_STRING_SVTOOLS_RTF_PARD << OOO_STRING_SVTOOLS_RTF_PLAIN << OOO_STRING_SVTOOLS_RTF_INTBL << RTFOutFuncs::sNewLine;
|
2008-03-12 04:06:33 -05:00
|
|
|
|
2011-01-13 09:27:50 -06:00
|
|
|
sal_uLong nStrmPos = mrStrm.Tell();
|
2008-03-12 04:06:33 -05:00
|
|
|
for( sal_Int32 nCol = 0; nCol < nColCount; nCol++ )
|
|
|
|
{
|
|
|
|
WriteCell( nCol, nRow );
|
|
|
|
if ( mrStrm.Tell() - nStrmPos > 255 )
|
|
|
|
{
|
|
|
|
mrStrm << RTFOutFuncs::sNewLine;
|
|
|
|
nStrmPos = mrStrm.Tell();
|
|
|
|
}
|
|
|
|
}
|
2009-04-27 06:24:10 -05:00
|
|
|
mrStrm << OOO_STRING_SVTOOLS_RTF_ROW << RTFOutFuncs::sNewLine;
|
2008-03-12 04:06:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SdrTableRtfExporter::WriteCell( sal_Int32 nCol, sal_Int32 nRow )
|
|
|
|
{
|
|
|
|
CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
|
|
|
|
|
|
|
|
if( !xCell.is() || xCell->isMerged() )
|
|
|
|
{
|
2009-04-27 06:24:10 -05:00
|
|
|
mrStrm << OOO_STRING_SVTOOLS_RTF_CELL;
|
2008-03-12 04:06:33 -05:00
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
String aContent;
|
|
|
|
|
|
|
|
OutlinerParaObject* pParaObj = xCell->GetEditOutlinerParaObject();
|
2009-05-06 16:51:02 -05:00
|
|
|
bool bOwnParaObj = pParaObj != 0;
|
2008-03-12 04:06:33 -05:00
|
|
|
|
|
|
|
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();
|
2009-05-06 16:51:02 -05:00
|
|
|
|
|
|
|
if( bOwnParaObj )
|
|
|
|
delete pParaObj;
|
2008-03-12 04:06:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool bResetPar, bResetAttr;
|
2011-01-13 09:27:50 -06:00
|
|
|
bResetPar = bResetAttr = sal_False;
|
2008-03-12 04:06:33 -05:00
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2009-04-27 06:24:10 -05:00
|
|
|
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;
|
2008-03-12 04:06:33 -05:00
|
|
|
case SDRTEXTHORZADJUST_LEFT:
|
2009-04-27 06:24:10 -05:00
|
|
|
default: pChar = OOO_STRING_SVTOOLS_RTF_QL; break;
|
2008-03-12 04:06:33 -05:00
|
|
|
}
|
|
|
|
mrStrm << pChar;
|
|
|
|
|
|
|
|
if ( rWeightItem.GetWeight() >= WEIGHT_BOLD )
|
|
|
|
{ // bold
|
|
|
|
bResetAttr = true;
|
2009-04-27 06:24:10 -05:00
|
|
|
mrStrm << OOO_STRING_SVTOOLS_RTF_B;
|
2008-03-12 04:06:33 -05:00
|
|
|
}
|
|
|
|
if ( rPostureItem.GetPosture() != ITALIC_NONE )
|
|
|
|
{ // italic
|
|
|
|
bResetAttr = true;
|
2009-04-27 06:24:10 -05:00
|
|
|
mrStrm << OOO_STRING_SVTOOLS_RTF_I;
|
2008-03-12 04:06:33 -05:00
|
|
|
}
|
2009-01-05 11:49:45 -06:00
|
|
|
if ( rUnderlineItem.GetLineStyle() != UNDERLINE_NONE )
|
2008-03-12 04:06:33 -05:00
|
|
|
{ // underline
|
|
|
|
bResetAttr = true;
|
2009-04-27 06:24:10 -05:00
|
|
|
mrStrm << OOO_STRING_SVTOOLS_RTF_UL;
|
2008-03-12 04:06:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
mrStrm << ' ';
|
|
|
|
RTFOutFuncs::Out_String( mrStrm, aContent );
|
2009-04-27 06:24:10 -05:00
|
|
|
mrStrm << OOO_STRING_SVTOOLS_RTF_CELL;
|
2008-03-12 04:06:33 -05:00
|
|
|
|
|
|
|
if ( bResetPar )
|
2009-04-27 06:24:10 -05:00
|
|
|
mrStrm << OOO_STRING_SVTOOLS_RTF_PARD << OOO_STRING_SVTOOLS_RTF_INTBL;
|
2008-03-12 04:06:33 -05:00
|
|
|
if ( bResetAttr )
|
2009-04-27 06:24:10 -05:00
|
|
|
mrStrm << OOO_STRING_SVTOOLS_RTF_PLAIN;
|
2008-03-12 04:06:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
} }
|
|
|
|
|
2010-10-12 08:53:47 -05:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|