sc/source/filter/excel/xestyle.cxx | 78 +++++++++++++++++++++++-------------- sc/source/filter/inc/xestyle.hxx | 25 ++++++----- 2 files changed, 64 insertions(+), 39 deletions(-)
New commits: commit 9894f158a287bdfe9933df96ab117a9527e9195b Author: Markus Mohrhard <markus.mohrh...@googlemail.com> Date: Sat Apr 21 03:12:11 2012 +0200 simplify lifetime management of some variables diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx index ce902cd..7d98fcf 100644 --- a/sc/source/filter/excel/xestyle.cxx +++ b/sc/source/filter/excel/xestyle.cxx @@ -1234,7 +1234,7 @@ XclExpNumFmtBuffer::XclExpNumFmtBuffer( const XclExpRoot& rRoot ) : cannot convert from 'class String *' to 'class String (*)[54]' The effective result here is class String (*)[54*1] */ mxFormatter( new SvNumberFormatter( rRoot.GetDoc().GetServiceManager(), LANGUAGE_ENGLISH_US ) ), - mpKeywordTable( new NfKeywordTable[ 1 ] ), + mpKeywordTable( new NfKeywordTable ), mnStdFmt( GetFormatter().GetStandardFormat( ScGlobal::eLnge ) ) { switch( GetBiff() ) @@ -1256,7 +1256,6 @@ XclExpNumFmtBuffer::XclExpNumFmtBuffer( const XclExpRoot& rRoot ) : XclExpNumFmtBuffer::~XclExpNumFmtBuffer() { - delete[] mpKeywordTable; } sal_uInt16 XclExpNumFmtBuffer::Insert( sal_uLong nScNumFmt ) @@ -1367,7 +1366,7 @@ String GetNumberFormatCode(XclRoot& rRoot, const sal_uInt16 nScNumFmt, SvNumberF String XclExpNumFmtBuffer::GetFormatCode( sal_uInt16 nScNumFmt ) { - return GetNumberFormatCode( *this, nScNumFmt, mxFormatter.get(), mpKeywordTable ); + return GetNumberFormatCode( *this, nScNumFmt, mxFormatter.get(), mpKeywordTable.get() ); } // XF, STYLE record - Cell formatting ========================================= @@ -2840,7 +2839,7 @@ void XclExpXFBuffer::AddBorderAndFill( const XclExpXF& rXF ) XclExpDxfs::XclExpDxfs( const XclExpRoot& rRoot ) : XclExpRoot( rRoot ), mxFormatter( new SvNumberFormatter( rRoot.GetDoc().GetServiceManager(), LANGUAGE_ENGLISH_US ) ), - mpKeywordTable( new NfKeywordTable[ 1 ] ) + mpKeywordTable( new NfKeywordTable ) { mxFormatter->FillKeywordTable( *mpKeywordTable, LANGUAGE_ENGLISH_US ); // remap codes unknown to Excel diff --git a/sc/source/filter/inc/xestyle.hxx b/sc/source/filter/inc/xestyle.hxx index 42a7c1b..ba7dc67 100644 --- a/sc/source/filter/inc/xestyle.hxx +++ b/sc/source/filter/inc/xestyle.hxx @@ -322,7 +322,7 @@ private: SvNumberFormatterPtr mxFormatter; /// Special number formatter for conversion. XclExpNumFmtVec maFormatMap; /// Maps core formats to Excel indexes. - NfKeywordTable* mpKeywordTable; /// Replacement table. + boost::scoped_ptr<NfKeywordTable> mpKeywordTable; /// Replacement table. sal_uLong mnStdFmt; /// Key for standard number format. sal_uInt16 mnXclOffset; /// Offset to first user defined format. }; @@ -751,6 +751,7 @@ class XclExpDxfs : public XclExpRecordBase, protected XclExpRoot { public: XclExpDxfs( const XclExpRoot& rRoot ); + virtual ~XclExpDxfs() {} sal_Int32 GetDxfId(const rtl::OUString& rName); commit 0019c67a587a6c780fe5ae10cedf51cd1914f811 Author: Markus Mohrhard <markus.mohrh...@googlemail.com> Date: Sat Apr 21 02:53:55 2012 +0200 simplify dxfs/dxf export diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx index 0e7c1cf..ce902cd 100644 --- a/sc/source/filter/excel/xestyle.cxx +++ b/sc/source/filter/excel/xestyle.cxx @@ -2916,7 +2916,7 @@ XclExpDxfs::XclExpDxfs( const XclExpRoot& rRoot ) { sal_uLong nScNumFmt = static_cast< sal_uInt32 >( static_cast< const SfxInt32Item* >(pPoolItem)->GetValue()); sal_uInt16 nXclNumFmt = static_cast< sal_uInt16 >( EXC_FORMAT_OFFSET8 + nIndex ); - pNumFormat = new XclExpNumFmt( nScNumFmt, nXclNumFmt, GetNumberFormatCode( *this, nScNumFmt, mxFormatter.get(), mpKeywordTable )); + pNumFormat = new XclExpNumFmt( nScNumFmt, nXclNumFmt, GetNumberFormatCode( *this, nScNumFmt, mxFormatter.get(), mpKeywordTable.get() )); ++nNumFmtIndex; } @@ -2939,6 +2939,9 @@ sal_Int32 XclExpDxfs::GetDxfId( const rtl::OUString& rStyleName ) void XclExpDxfs::SaveXml( XclExpXmlStream& rStrm ) { + if(maDxf.empty()) + return; + sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream(); rStyleSheet->startElement( XML_dxfs, XML_count, rtl::OString::valueOf( static_cast<sal_Int32>(maDxf.size())).getStr(), @@ -3000,16 +3003,8 @@ void XclExpDxf::SaveXml( XclExpXmlStream& rStrm ) // ============================================================================ XclExpXmlStyleSheet::XclExpXmlStyleSheet( const XclExpRoot& rRoot ) - : XclExpRoot( rRoot ), - mbDxfs(false) + : XclExpRoot( rRoot ) { - if ( ScConditionalFormatList* pList = rRoot.GetDoc().GetCondFormList() ) - { - if ( pList->Count() ) - { - mbDxfs = true; - } - } } void XclExpXmlStyleSheet::SaveXml( XclExpXmlStream& rStrm ) @@ -3030,10 +3025,7 @@ void XclExpXmlStyleSheet::SaveXml( XclExpXmlStream& rStrm ) CreateRecord( EXC_ID_FONTLIST )->SaveXml( rStrm ); CreateRecord( EXC_ID_XFLIST )->SaveXml( rStrm ); CreateRecord( EXC_ID_PALETTE )->SaveXml( rStrm ); - if(mbDxfs) - { - CreateRecord( EXC_ID_DXFS )->SaveXml( rStrm ); - } + CreateRecord( EXC_ID_DXFS )->SaveXml( rStrm ); aStyleSheet->endElement( XML_styleSheet ); diff --git a/sc/source/filter/inc/xestyle.hxx b/sc/source/filter/inc/xestyle.hxx index 345d31c..42a7c1b 100644 --- a/sc/source/filter/inc/xestyle.hxx +++ b/sc/source/filter/inc/xestyle.hxx @@ -40,6 +40,7 @@ #include "xeroot.hxx" #include "conditio.hxx" #include <boost/shared_ptr.hpp> +#include <boost/scoped_ptr.hpp> #include <boost/ptr_container/ptr_vector.hpp> /* ============================================================================ @@ -759,7 +760,7 @@ private: std::map<rtl::OUString, sal_Int32> maStyleNameToDxfId; DxfContainer maDxf; SvNumberFormatterPtr mxFormatter; /// Special number formatter for conversion. - NfKeywordTable* mpKeywordTable; /// Replacement table. + boost::scoped_ptr<NfKeywordTable> mpKeywordTable; /// Replacement table. }; // ============================================================================ @@ -770,8 +771,6 @@ public: explicit XclExpXmlStyleSheet( const XclExpRoot& rRoot ); virtual void SaveXml( XclExpXmlStream& rStrm ); -private: - bool mbDxfs; }; // ============================================================================ commit 6df9865612873b8c01bf789d6c0ac884a17f38ee Author: Markus Mohrhard <markus.mohrh...@googlemail.com> Date: Sat Apr 21 02:44:14 2012 +0200 first version of number format export into dxf diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx index c73a08b..0e7c1cf 100644 --- a/sc/source/filter/excel/xestyle.cxx +++ b/sc/source/filter/excel/xestyle.cxx @@ -1217,12 +1217,12 @@ struct XclExpNumFmtPred // ---------------------------------------------------------------------------- -void XclExpNumFmt::SaveXml( XclExpXmlStream& rStrm, const String& rFormatCode ) +void XclExpNumFmt::SaveXml( XclExpXmlStream& rStrm ) { sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream(); rStyleSheet->singleElement( XML_numFmt, XML_numFmtId, OString::valueOf( static_cast<sal_Int32>(mnXclNumFmt) ).getStr(), - XML_formatCode, XclXmlUtils::ToOString( rFormatCode ).getStr(), + XML_formatCode, rtl::OUStringToOString(maNumFmtString, RTL_TEXTENCODING_UTF8).getStr(), FSEND ); } @@ -1270,7 +1270,7 @@ sal_uInt16 XclExpNumFmtBuffer::Insert( sal_uLong nScNumFmt ) if( nSize < static_cast< size_t >( 0xFFFF - mnXclOffset ) ) { sal_uInt16 nXclNumFmt = static_cast< sal_uInt16 >( nSize + mnXclOffset ); - maFormatMap.push_back( XclExpNumFmt( nScNumFmt, nXclNumFmt ) ); + maFormatMap.push_back( XclExpNumFmt( nScNumFmt, nXclNumFmt, GetFormatCode( nScNumFmt ) ) ); return nXclNumFmt; } @@ -1294,7 +1294,7 @@ void XclExpNumFmtBuffer::SaveXml( XclExpXmlStream& rStrm ) FSEND ); for( XclExpNumFmtVec::iterator aIt = maFormatMap.begin(), aEnd = maFormatMap.end(); aIt != aEnd; ++aIt ) { - aIt->SaveXml( rStrm, GetFormatCode( *aIt ) ); + aIt->SaveXml( rStrm ); } rStyleSheet->endElement( XML_numFmts ); } @@ -1314,14 +1314,16 @@ void XclExpNumFmtBuffer::WriteFormatRecord( XclExpStream& rStrm, sal_uInt16 nXcl void XclExpNumFmtBuffer::WriteFormatRecord( XclExpStream& rStrm, const XclExpNumFmt& rFormat ) { - WriteFormatRecord( rStrm, rFormat.mnXclNumFmt, GetFormatCode( rFormat ) ); + WriteFormatRecord( rStrm, rFormat.mnXclNumFmt, GetFormatCode( rFormat.mnScNumFmt ) ); } -String XclExpNumFmtBuffer::GetFormatCode( const XclExpNumFmt& rFormat ) +namespace { + +String GetNumberFormatCode(XclRoot& rRoot, const sal_uInt16 nScNumFmt, SvNumberFormatter* xFormatter, NfKeywordTable* pKeywordTable) { String aFormatStr; - if( const SvNumberformat* pEntry = GetFormatter().GetEntry( rFormat.mnScNumFmt ) ) + if( const SvNumberformat* pEntry = rRoot.GetFormatter().GetEntry( nScNumFmt ) ) { if( pEntry->GetType() == NUMBERFORMAT_LOGICAL ) { @@ -1342,12 +1344,12 @@ String XclExpNumFmtBuffer::GetFormatCode( const XclExpNumFmt& rFormat ) short nType = NUMBERFORMAT_DEFINED; sal_uInt32 nKey; String aTemp( pEntry->GetFormatstring() ); - mxFormatter->PutandConvertEntry( aTemp, nCheckPos, nType, nKey, eLang, LANGUAGE_ENGLISH_US ); + xFormatter->PutandConvertEntry( aTemp, nCheckPos, nType, nKey, eLang, LANGUAGE_ENGLISH_US ); OSL_ENSURE( nCheckPos == 0, "XclExpNumFmtBuffer::WriteFormatRecord - format code not convertible" ); - pEntry = mxFormatter->GetEntry( nKey ); + pEntry = xFormatter->GetEntry( nKey ); } - aFormatStr = pEntry->GetMappedFormatstring( *mpKeywordTable, *mxFormatter->GetLocaleData() ); + aFormatStr = pEntry->GetMappedFormatstring( *pKeywordTable, *xFormatter->GetLocaleData() ); if( aFormatStr.EqualsAscii( "Standard" ) ) aFormatStr.AssignAscii( "General" ); } @@ -1361,6 +1363,13 @@ String XclExpNumFmtBuffer::GetFormatCode( const XclExpNumFmt& rFormat ) return aFormatStr; } +} + +String XclExpNumFmtBuffer::GetFormatCode( sal_uInt16 nScNumFmt ) +{ + return GetNumberFormatCode( *this, nScNumFmt, mxFormatter.get(), mpKeywordTable ); +} + // XF, STYLE record - Cell formatting ========================================= bool XclExpCellProt::FillFromItemSet( const SfxItemSet& rItemSet, bool bStyle ) @@ -2829,8 +2838,20 @@ void XclExpXFBuffer::AddBorderAndFill( const XclExpXF& rXF ) XclExpDxfs::XclExpDxfs( const XclExpRoot& rRoot ) - : XclExpRoot( rRoot ) + : XclExpRoot( rRoot ), + mxFormatter( new SvNumberFormatter( rRoot.GetDoc().GetServiceManager(), LANGUAGE_ENGLISH_US ) ), + mpKeywordTable( new NfKeywordTable[ 1 ] ) { + mxFormatter->FillKeywordTable( *mpKeywordTable, LANGUAGE_ENGLISH_US ); + // remap codes unknown to Excel + (*mpKeywordTable)[ NF_KEY_NN ] = String( RTL_CONSTASCII_USTRINGPARAM( "DDD" ) ); + (*mpKeywordTable)[ NF_KEY_NNN ] = String( RTL_CONSTASCII_USTRINGPARAM( "DDDD" ) ); + // NNNN gets a separator appended in SvNumberformat::GetMappedFormatString() + (*mpKeywordTable)[ NF_KEY_NNNN ] = String( RTL_CONSTASCII_USTRINGPARAM( "DDDD" ) ); + // Export the Thai T NatNum modifier. + (*mpKeywordTable)[ NF_KEY_THAI_T ] = String( RTL_CONSTASCII_USTRINGPARAM( "T" ) ); + sal_Int32 nNumFmtIndex = 0; + ScConditionalFormatList* pList = rRoot.GetDoc().GetCondFormList(); if (pList) { @@ -2889,7 +2910,17 @@ XclExpDxfs::XclExpDxfs( const XclExpRoot& rRoot ) pFont = new XclExpFont( GetRoot(), XclFontData( aFont ), EXC_COLOR_CELLTEXT ); } - maDxf.push_back(new XclExpDxf( rRoot, pAlign, pBorder, pFont, NULL, pCellProt, pCellArea )); + XclExpNumFmt* pNumFormat = NULL; + const SfxPoolItem *pPoolItem = NULL; + if( rSet.GetItemState( SID_ATTR_NUMBERFORMAT_VALUE, sal_True, &pPoolItem ) == SFX_ITEM_SET ) + { + sal_uLong nScNumFmt = static_cast< sal_uInt32 >( static_cast< const SfxInt32Item* >(pPoolItem)->GetValue()); + sal_uInt16 nXclNumFmt = static_cast< sal_uInt16 >( EXC_FORMAT_OFFSET8 + nIndex ); + pNumFormat = new XclExpNumFmt( nScNumFmt, nXclNumFmt, GetNumberFormatCode( *this, nScNumFmt, mxFormatter.get(), mpKeywordTable )); + ++nNumFmtIndex; + } + + maDxf.push_back(new XclExpDxf( rRoot, pAlign, pBorder, pFont, pNumFormat, pCellProt, pCellArea )); ++nIndex; } @@ -2958,7 +2989,7 @@ void XclExpDxf::SaveXml( XclExpXmlStream& rStrm ) if (mpFont) mpFont->SaveXml(rStrm); if (mpNumberFmt) - mpNumberFmt->SaveXml(rStrm, String()); + mpNumberFmt->SaveXml(rStrm); if (mpProt) mpProt->SaveXml(rStrm); if (mpCellArea) diff --git a/sc/source/filter/inc/xestyle.hxx b/sc/source/filter/inc/xestyle.hxx index 18975c4..345d31c 100644 --- a/sc/source/filter/inc/xestyle.hxx +++ b/sc/source/filter/inc/xestyle.hxx @@ -274,18 +274,20 @@ private: /** Stores a core number format index with corresponding Excel format index. */ struct XclExpNumFmt { - sal_uLong mnScNumFmt; /// Core index of the number format. + sal_uLong mnScNumFmt; /// Core index of the number format. sal_uInt16 mnXclNumFmt; /// Resulting Excel format index. + rtl::OUString maNumFmtString; /// format string - inline explicit XclExpNumFmt( sal_uLong nScNumFmt, sal_uInt16 nXclNumFmt ) : - mnScNumFmt( nScNumFmt ), mnXclNumFmt( nXclNumFmt ) {} + inline explicit XclExpNumFmt( sal_uLong nScNumFmt, sal_uInt16 nXclNumFmt, const rtl::OUString& rFrmt ) : + mnScNumFmt( nScNumFmt ), mnXclNumFmt( nXclNumFmt ), maNumFmtString( rFrmt ) {} - void SaveXml( XclExpXmlStream& rStrm, const String& rFormatCode ); + void SaveXml( XclExpXmlStream& rStrm ); }; // ---------------------------------------------------------------------------- class SvNumberFormatter; +typedef ::std::auto_ptr< SvNumberFormatter > SvNumberFormatterPtr; /** Stores all number formats used in the document. */ class XclExpNumFmtBuffer : public XclExpRecordBase, protected XclExpRoot @@ -295,7 +297,7 @@ public: virtual ~XclExpNumFmtBuffer(); /** Returns the core index of the current standard number format. */ - inline sal_uLong GetStandardFormat() const { return mnStdFmt; } + inline sal_uLong GetStandardFormat() const { return mnStdFmt; } /** Inserts a number format into the format buffer. @param nScNumFmt The core index of the number format. @@ -312,16 +314,15 @@ private: /** Writes the FORMAT record represented by rFormat. */ void WriteFormatRecord( XclExpStream& rStrm, const XclExpNumFmt& rFormat ); - String GetFormatCode ( const XclExpNumFmt& rFormat ); + String GetFormatCode ( sal_uInt16 nScNumFmt ); private: - typedef ::std::auto_ptr< SvNumberFormatter > SvNumberFormatterPtr; typedef ::std::vector< XclExpNumFmt > XclExpNumFmtVec; SvNumberFormatterPtr mxFormatter; /// Special number formatter for conversion. XclExpNumFmtVec maFormatMap; /// Maps core formats to Excel indexes. NfKeywordTable* mpKeywordTable; /// Replacement table. - sal_uLong mnStdFmt; /// Key for standard number format. + sal_uLong mnStdFmt; /// Key for standard number format. sal_uInt16 mnXclOffset; /// Offset to first user defined format. }; @@ -757,6 +758,8 @@ private: typedef boost::ptr_vector<XclExpDxf> DxfContainer; std::map<rtl::OUString, sal_Int32> maStyleNameToDxfId; DxfContainer maDxf; + SvNumberFormatterPtr mxFormatter; /// Special number formatter for conversion. + NfKeywordTable* mpKeywordTable; /// Replacement table. }; // ============================================================================ _______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits