diff options
author | Michael Stahl <mst@openoffice.org> | 2011-10-11 14:19:09 +0200 |
---|---|---|
committer | Michael Stahl <mst@openoffice.org> | 2011-10-11 17:57:01 +0200 |
commit | 8666469d7b0f450ec1448f80eda3c591f8d8d318 (patch) | |
tree | ae63c5f07df7d3c2d45ea03e47f147661f280923 /sw | |
parent | ae3e2f170045a1525f67e9f3e9b7e03d94f2b56b (diff) |
#i108468#: clean up xmluconv code duplication, measured approach:
modify sax::Converter::convertMeasure to use sal_Int64 instead of BigInt:
should be sufficient, since the largest number is SAL_INT32_MAX * 10^7.
remove duplicate methods from SvXMLUnitConverter:
convertMeasurePx, convertMeasure (static variants)
remove entirely duplicative class SvXMLExportHelper:
GetConversionFactor, GetUnitFromString, AddLength
change SvXMLUnitConverter interface from MapUnit to css::util::MeasureUnit.
change SvXMLExport constructor params from MapUnit to css::util::MeasureUnit.
rename some methods to turn compiler into merge conflict detector :)
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/swg/SwXMLBlockExport.cxx | 5 | ||||
-rw-r--r-- | sw/source/filter/xml/xmlexp.cxx | 13 | ||||
-rw-r--r-- | sw/source/filter/xml/xmlexpit.cxx | 50 | ||||
-rw-r--r-- | sw/source/filter/xml/xmlimpit.cxx | 23 | ||||
-rw-r--r-- | sw/source/filter/xml/xmliteme.cxx | 7 | ||||
-rw-r--r-- | sw/source/filter/xml/xmlitemi.cxx | 5 | ||||
-rw-r--r-- | sw/source/filter/xml/xmlithlp.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/xml/xmltble.cxx | 3 |
8 files changed, 67 insertions, 41 deletions
diff --git a/sw/source/core/swg/SwXMLBlockExport.cxx b/sw/source/core/swg/SwXMLBlockExport.cxx index 848bd6c542df..61644079c548 100644 --- a/sw/source/core/swg/SwXMLBlockExport.cxx +++ b/sw/source/core/swg/SwXMLBlockExport.cxx @@ -30,6 +30,7 @@ #include "precompiled_sw.hxx" #include <SwXMLBlockExport.hxx> #include <SwXMLTextBlocks.hxx> +#include <com/sun/star/util/MeasureUnit.hpp> #include <xmloff/nmspmap.hxx> #include <xmloff/xmlnmspe.hxx> using namespace ::com::sun::star::uno; @@ -43,7 +44,7 @@ SwXMLBlockListExport::SwXMLBlockListExport( SwXMLTextBlocks & rBlocks, const rtl::OUString &rFileName, uno::Reference< xml::sax::XDocumentHandler> &rHandler) -: SvXMLExport( xServiceFactory, rFileName, rHandler ), +: SvXMLExport( xServiceFactory, rFileName, util::MeasureUnit::CM, rHandler ), rBlockList(rBlocks) { _GetNamespaceMap().Add( GetXMLToken ( XML_NP_BLOCK_LIST ), @@ -94,7 +95,7 @@ SwXMLTextBlockExport::SwXMLTextBlockExport( SwXMLTextBlocks & rBlocks, const rtl::OUString &rFileName, uno::Reference< xml::sax::XDocumentHandler> &rHandler) -: SvXMLExport( xServiceFactory, rFileName, rHandler ), +: SvXMLExport( xServiceFactory, rFileName, util::MeasureUnit::CM, rHandler ), rBlockList(rBlocks) { _GetNamespaceMap().Add( GetXMLToken ( XML_NP_BLOCK_LIST ), diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx index 520aa17025f2..f03a7b339495 100644 --- a/sw/source/filter/xml/xmlexp.cxx +++ b/sw/source/filter/xml/xmlexp.cxx @@ -130,7 +130,8 @@ void SwXMLExport::SetCurPaM( SwPaM& rPaM, sal_Bool bWhole, sal_Bool bTabOnly ) SwXMLExport::SwXMLExport( const uno::Reference< lang::XMultiServiceFactory > xServiceFactory, sal_uInt16 nExportFlags) -: SvXMLExport( xServiceFactory, MAP_INCH, XML_TEXT, nExportFlags ), +: SvXMLExport( util::MeasureUnit::INCH, xServiceFactory, XML_TEXT, + nExportFlags ), #ifdef XML_CORE_API pCurPaM( 0 ), pOrigPaM( &rPaM ), @@ -271,12 +272,12 @@ sal_uInt32 SwXMLExport::exportDoc( enum XMLTokenEnum eClass ) } } - MapUnit eUnit = - SvXMLUnitConverter::GetMapUnit( SW_MOD()->GetMetric(pDoc->get(IDocumentSettingAccess::HTML_MODE)) ); - if( GetMM100UnitConverter().getXMLMeasureUnit() != eUnit ) + sal_uInt16 const eUnit = SvXMLUnitConverter::GetMeasureUnit( + SW_MOD()->GetMetric(pDoc->get(IDocumentSettingAccess::HTML_MODE))); + if (GetMM100UnitConverter().GetXMLMeasureUnit() != eUnit ) { - GetMM100UnitConverter().setXMLMeasureUnit( eUnit ); - pTwipUnitConv->setXMLMeasureUnit( eUnit ); + GetMM100UnitConverter().SetXMLMeasureUnit( eUnit ); + pTwipUnitConv->SetXMLMeasureUnit( eUnit ); } SetExtended( bExtended ); diff --git a/sw/source/filter/xml/xmlexpit.cxx b/sw/source/filter/xml/xmlexpit.cxx index 065571abf15d..74043062da48 100644 --- a/sw/source/filter/xml/xmlexpit.cxx +++ b/sw/source/filter/xml/xmlexpit.cxx @@ -419,7 +419,10 @@ sal_Bool SvXMLExportItemMapper::QueryXMLValue( aOut, pLRSpace->GetPropLeft() ); } else - rUnitConverter.convertMeasure( aOut, pLRSpace->GetLeft() ); + { + rUnitConverter.convertMeasureToXML( + aOut, pLRSpace->GetLeft() ); + } break; case MID_R_MARGIN: @@ -429,7 +432,10 @@ sal_Bool SvXMLExportItemMapper::QueryXMLValue( aOut, pLRSpace->GetPropRight() ); } else - rUnitConverter.convertMeasure( aOut, pLRSpace->GetRight() ); + { + rUnitConverter.convertMeasureToXML( + aOut, pLRSpace->GetRight() ); + } break; case MID_FIRST_AUTO: @@ -451,7 +457,10 @@ sal_Bool SvXMLExportItemMapper::QueryXMLValue( aOut, pLRSpace->GetPropTxtFirstLineOfst() ); } else - rUnitConverter.convertMeasure( aOut, pLRSpace->GetTxtFirstLineOfst() ); + { + rUnitConverter.convertMeasureToXML( + aOut, pLRSpace->GetTxtFirstLineOfst() ); + } } else bOk = sal_False; @@ -479,7 +488,10 @@ sal_Bool SvXMLExportItemMapper::QueryXMLValue( aOut, pULSpace->GetPropUpper() ); } else - rUnitConverter.convertMeasure( aOut, pULSpace->GetUpper() ); + { + rUnitConverter.convertMeasureToXML( + aOut, pULSpace->GetUpper() ); + } break; case MID_LO_MARGIN: @@ -489,7 +501,10 @@ sal_Bool SvXMLExportItemMapper::QueryXMLValue( aOut, pULSpace->GetPropLower() ); } else - rUnitConverter.convertMeasure( aOut, pULSpace->GetLower() ); + { + rUnitConverter.convertMeasureToXML( + aOut, pULSpace->GetLower() ); + } break; default: @@ -531,9 +546,9 @@ sal_Bool SvXMLExportItemMapper::QueryXMLValue( ::sax::Converter::convertColor(aOut, pShadow->GetColor().GetColor()); aOut.append( sal_Unicode(' ') ); - rUnitConverter.convertMeasure( aOut, nX ); + rUnitConverter.convertMeasureToXML( aOut, nX ); aOut.append( sal_Unicode(' ') ); - rUnitConverter.convertMeasure( aOut, nY ); + rUnitConverter.convertMeasureToXML( aOut, nY ); bOk = sal_True; } @@ -692,16 +707,16 @@ sal_Bool SvXMLExportItemMapper::QueryXMLValue( // padding case ALL_BORDER_PADDING: case LEFT_BORDER_PADDING: - rUnitConverter.convertMeasure( aOut, nLeftDist ); + rUnitConverter.convertMeasureToXML( aOut, nLeftDist ); break; case RIGHT_BORDER_PADDING: - rUnitConverter.convertMeasure( aOut, nRightDist ); + rUnitConverter.convertMeasureToXML( aOut, nRightDist ); break; case TOP_BORDER_PADDING: - rUnitConverter.convertMeasure( aOut, nTopDist ); + rUnitConverter.convertMeasureToXML( aOut, nTopDist ); break; case BOTTOM_BORDER_PADDING: - rUnitConverter.convertMeasure( aOut, nBottomDist ); + rUnitConverter.convertMeasureToXML( aOut, nBottomDist ); break; // border @@ -776,8 +791,9 @@ sal_Bool SvXMLExportItemMapper::QueryXMLValue( if ( !bNoBorder ) { - rUnitConverter.convertMeasure( aOut, nWidth, - MAP_TWIP, MAP_POINT ); + ::sax::Converter::convertMeasure(aOut, nWidth, + util::MeasureUnit::TWIP, + util::MeasureUnit::POINT); aOut.append( sal_Unicode( ' ' ) ); aOut.append( GetXMLToken( eStyle ) ); aOut.append( sal_Unicode( ' ' ) ); @@ -817,11 +833,11 @@ sal_Bool SvXMLExportItemMapper::QueryXMLValue( default: return sal_False; } - rUnitConverter.convertMeasure( aOut, pLine->GetInWidth() ); + rUnitConverter.convertMeasureToXML( aOut, pLine->GetInWidth() ); aOut.append( sal_Unicode( ' ' ) ); - rUnitConverter.convertMeasure( aOut, pLine->GetDistance() ); + rUnitConverter.convertMeasureToXML( aOut, pLine->GetDistance() ); aOut.append( sal_Unicode( ' ' ) ); - rUnitConverter.convertMeasure( aOut, pLine->GetOutWidth() ); + rUnitConverter.convertMeasureToXML( aOut, pLine->GetOutWidth() ); break; } @@ -1084,7 +1100,7 @@ sal_Bool SvXMLExportItemMapper::QueryXMLValue( if( bOutHeight ) { - rUnitConverter.convertMeasure( aOut, pFrmSize->GetHeight() ); + rUnitConverter.convertMeasureToXML(aOut, pFrmSize->GetHeight()); bOk = sal_True; } } diff --git a/sw/source/filter/xml/xmlimpit.cxx b/sw/source/filter/xml/xmlimpit.cxx index 21f9ea7c3364..dec39650f61d 100644 --- a/sw/source/filter/xml/xmlimpit.cxx +++ b/sw/source/filter/xml/xmlimpit.cxx @@ -263,7 +263,7 @@ sal_Bool SvXMLImportItemMapper::PutXMLValue( if( rValue.indexOf( sal_Unicode('%') ) != -1 ) bOk = ::sax::Converter::convertPercent(nProp, rValue); else - bOk = rUnitConverter.convertMeasure( nAbs, rValue ); + bOk = rUnitConverter.convertMeasureToCore(nAbs, rValue); if( bOk ) { @@ -287,7 +287,7 @@ sal_Bool SvXMLImportItemMapper::PutXMLValue( if( rValue.indexOf( sal_Unicode('%') ) != -1 ) bOk = ::sax::Converter::convertPercent(nProp, rValue); else - bOk = rUnitConverter.convertMeasure( nAbs, rValue, + bOk = rUnitConverter.convertMeasureToCore(nAbs, rValue, -0x7fff, 0x7fff ); pLRSpace->SetTxtFirstLineOfst( (short)nAbs, (sal_uInt16)nProp ); @@ -319,7 +319,7 @@ sal_Bool SvXMLImportItemMapper::PutXMLValue( if( rValue.indexOf( sal_Unicode('%') ) != -1 ) bOk = ::sax::Converter::convertPercent( nProp, rValue ); else - bOk = rUnitConverter.convertMeasure( nAbs, rValue ); + bOk = rUnitConverter.convertMeasureToCore( nAbs, rValue ); switch( nMemberId ) { @@ -370,9 +370,9 @@ sal_Bool SvXMLImportItemMapper::PutXMLValue( { sal_Int32 nX = 0, nY = 0; - bOk = rUnitConverter.convertMeasure( nX, aToken ); + bOk = rUnitConverter.convertMeasureToCore( nX, aToken ); if( bOk && aTokenEnum.getNextToken( aToken ) ) - bOk = rUnitConverter.convertMeasure( nY, aToken ); + bOk = rUnitConverter.convertMeasureToCore( nY, aToken ); if( bOk ) { @@ -440,8 +440,11 @@ sal_Bool SvXMLImportItemMapper::PutXMLValue( case RIGHT_BORDER_PADDING: case TOP_BORDER_PADDING: case BOTTOM_BORDER_PADDING: - if(!rUnitConverter.convertMeasure( nTemp, rValue, 0, 0xffff )) + if (!rUnitConverter.convertMeasureToCore( nTemp, rValue, + 0, 0xffff )) + { return sal_False; + } if( nMemberId == LEFT_BORDER_PADDING || nMemberId == ALL_BORDER_PADDING ) @@ -518,19 +521,19 @@ sal_Bool SvXMLImportItemMapper::PutXMLValue( if( !aTokenEnum.getNextToken( aToken ) ) return sal_False; - if( !rUnitConverter.convertMeasure( nInWidth, aToken ) ) + if (!rUnitConverter.convertMeasureToCore(nInWidth, aToken)) return sal_False; if( !aTokenEnum.getNextToken( aToken ) ) return sal_False; - if( !rUnitConverter.convertMeasure( nDistance, aToken ) ) + if (!rUnitConverter.convertMeasureToCore(nDistance, aToken)) return sal_False; if( !aTokenEnum.getNextToken( aToken ) ) return sal_False; - if( !rUnitConverter.convertMeasure( nOutWidth, aToken ) ) + if (!rUnitConverter.convertMeasureToCore(nOutWidth, aToken)) return sal_False; // #i61946: accept line style even it's not part of our "normal" set of line styles @@ -919,7 +922,7 @@ sal_Bool SvXMLImportItemMapper::PutXMLValue( sal_Int32 nValue; if( bSetHeight || bSetWidth ) { - bOk = rUnitConverter.convertMeasure( nValue, rValue, nMin, + bOk = rUnitConverter.convertMeasureToCore(nValue, rValue, nMin, USHRT_MAX ); if( bOk ) { diff --git a/sw/source/filter/xml/xmliteme.cxx b/sw/source/filter/xml/xmliteme.cxx index 1f38c952459e..f76faf6511bf 100644 --- a/sw/source/filter/xml/xmliteme.cxx +++ b/sw/source/filter/xml/xmliteme.cxx @@ -29,6 +29,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sw.hxx" +#include <com/sun/star/util/MeasureUnit.hpp> #include <hintids.hxx> #include <rtl/ustring.hxx> @@ -179,7 +180,7 @@ void SwXMLTableItemMapper_Impl::handleSpecialItem( if( nAbsWidth ) { OUStringBuffer sBuffer; - rUnitConverter.convertMeasure( sBuffer, nAbsWidth ); + rUnitConverter.convertMeasureToXML( sBuffer, nAbsWidth ); AddAttribute( rEntry.nNameSpace, rEntry.eLocalName, sBuffer.makeStringAndClear(), rNamespaceMap, rAttrList ); @@ -232,8 +233,8 @@ inline void SwXMLTableItemMapper_Impl::SetAbsWidth( sal_uInt32 nAbs ) void SwXMLExport::_InitItemExport() { - pTwipUnitConv = new SvXMLUnitConverter( MAP_TWIP, - GetMM100UnitConverter().getXMLMeasureUnit(), getServiceFactory() ); + pTwipUnitConv = new SvXMLUnitConverter(getServiceFactory(), + util::MeasureUnit::TWIP, GetMM100UnitConverter().GetXMLMeasureUnit()); xTableItemMap = new SvXMLItemMapEntries( aXMLTableItemMap ); xTableRowItemMap = new SvXMLItemMapEntries( aXMLTableRowItemMap ); diff --git a/sw/source/filter/xml/xmlitemi.cxx b/sw/source/filter/xml/xmlitemi.cxx index d9a98955c1f1..977349eb9182 100644 --- a/sw/source/filter/xml/xmlitemi.cxx +++ b/sw/source/filter/xml/xmlitemi.cxx @@ -31,6 +31,8 @@ #include <rtl/ustring.hxx> +#include <com/sun/star/util/MeasureUnit.hpp> + #include <rsc/rscsfx.hxx> #include <xmloff/i18nmap.hxx> @@ -344,7 +346,8 @@ SvXMLImportContext *SwXMLItemSetContext_Impl::CreateChildContext( void SwXMLImport::_InitItemImport() { - pTwipUnitConv = new SvXMLUnitConverter( MAP_TWIP, MAP_TWIP, getServiceFactory() ); + pTwipUnitConv = new SvXMLUnitConverter( getServiceFactory(), + util::MeasureUnit::TWIP, util::MeasureUnit::TWIP ); xTableItemMap = new SvXMLItemMapEntries( aXMLTableItemMap ); xTableColItemMap = new SvXMLItemMapEntries( aXMLTableColItemMap ); diff --git a/sw/source/filter/xml/xmlithlp.cxx b/sw/source/filter/xml/xmlithlp.cxx index d972c73e63e3..992c00d758d1 100644 --- a/sw/source/filter/xml/xmlithlp.cxx +++ b/sw/source/filter/xml/xmlithlp.cxx @@ -139,7 +139,7 @@ sal_Bool lcl_frmitems_parseXMLBorder( const OUString& rValue, rHasColor = sal_True; } else if( !rHasWidth && - rUnitConverter.convertMeasure( nTemp, aToken, 0, USHRT_MAX ) ) + rUnitConverter.convertMeasureToCore(nTemp, aToken, 0, USHRT_MAX)) { rWidth = (sal_uInt16)nTemp; rHasWidth = sal_True; diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx index 222d6a1b3822..e3c0ea3dc2e5 100644 --- a/sw/source/filter/xml/xmltble.cxx +++ b/sw/source/filter/xml/xmltble.cxx @@ -552,7 +552,8 @@ void SwXMLExport::ExportTableColumnStyle( const SwXMLTableColumn_Impl& rCol ) OUStringBuffer sValue; if( rCol.GetWidthOpt() ) { - GetTwipUnitConverter().convertMeasure( sValue, rCol.GetWidthOpt() ); + GetTwipUnitConverter().convertMeasureToXML( sValue, + rCol.GetWidthOpt() ); AddAttribute( XML_NAMESPACE_STYLE, XML_COLUMN_WIDTH, sValue.makeStringAndClear() ); } |