From d10a49d64469411a23b3660a82106405808da028 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Wed, 31 Mar 2021 20:38:30 +0300 Subject: Use o3tl::convert for conversion to/from EMUs Change-Id: Ifbf762194836a3d05157e98943e65ef8aa2149c3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113425 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- include/oox/export/utils.hxx | 7 +++++-- sw/source/filter/ww8/docxsdrexport.cxx | 2 +- sw/source/filter/ww8/rtfattributeoutput.cxx | 27 ++++++++++++++++++--------- sw/source/filter/ww8/wrtw8esh.cxx | 7 ++++--- sw/source/filter/ww8/ww8par.cxx | 18 ++++++++++-------- 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/include/oox/export/utils.hxx b/include/oox/export/utils.hxx index 510505aa3d84..1a9a790d2182 100644 --- a/include/oox/export/utils.hxx +++ b/include/oox/export/utils.hxx @@ -20,6 +20,9 @@ #ifndef INCLUDED_OOX_EXPORT_UTILS_HXX #define INCLUDED_OOX_EXPORT_UTILS_HXX +#include + +#include #include #include @@ -52,12 +55,12 @@ static constexpr const char* ToPsz10(bool b) static constexpr sal_Int64 PPTtoEMU( sal_Int32 nPPT ) { - return static_cast( static_cast(nPPT) * 1587.5 ); + return o3tl::convert(nPPT, o3tl::Length::master, o3tl::Length::emu); } static constexpr sal_Int64 TwipsToEMU( sal_Int32 nTwips ) { - return sal_Int64( nTwips ) * 635; + return o3tl::convert(nTwips, o3tl::Length::twip, o3tl::Length::emu); } template diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx index 9b461f4c3831..90a0183817e4 100644 --- a/sw/source/filter/ww8/docxsdrexport.cxx +++ b/sw/source/filter/ww8/docxsdrexport.cxx @@ -668,7 +668,7 @@ void DocxSdrExport::startDMLAnchorInline(const SwFrameFormat* pFrameFormat, cons && (!alignV || strcmp(alignV, "top") == 0)) { alignV = nullptr; - nPosYEMU = 635; + nPosYEMU = TwipsToEMU(1); } if (alignV != nullptr) diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index e96297635270..91a0362aa686 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -3195,9 +3196,11 @@ void RtfAttributeOutput::FormatLRSpace(const SvxLRSpaceItem& rLRSpace) { // Wrap: top and bottom spacing, convert from twips to EMUs. m_aFlyProperties.push_back(std::make_pair( - "dxWrapDistLeft", OString::number(rLRSpace.GetLeft() * 635))); + "dxWrapDistLeft", OString::number(o3tl::convert(rLRSpace.GetLeft(), o3tl::Length::twip, + o3tl::Length::emu)))); m_aFlyProperties.push_back(std::make_pair( - "dxWrapDistRight", OString::number(rLRSpace.GetRight() * 635))); + "dxWrapDistRight", OString::number(o3tl::convert( + rLRSpace.GetRight(), o3tl::Length::twip, o3tl::Length::emu)))); } } @@ -3287,9 +3290,11 @@ void RtfAttributeOutput::FormatULSpace(const SvxULSpaceItem& rULSpace) { // Wrap: top and bottom spacing, convert from twips to EMUs. m_aFlyProperties.push_back(std::make_pair( - "dyWrapDistTop", OString::number(rULSpace.GetUpper() * 635))); + "dyWrapDistTop", OString::number(o3tl::convert(rULSpace.GetUpper(), o3tl::Length::twip, + o3tl::Length::emu)))); m_aFlyProperties.push_back(std::make_pair( - "dyWrapDistBottom", OString::number(rULSpace.GetLower() * 635))); + "dyWrapDistBottom", OString::number(o3tl::convert( + rULSpace.GetLower(), o3tl::Length::twip, o3tl::Length::emu)))); } } @@ -3531,13 +3536,17 @@ void RtfAttributeOutput::FormatBox(const SvxBoxItem& rBox) { // Borders: spacing to contents, convert from twips to EMUs. m_aFlyProperties.push_back(std::make_pair( - "dxTextLeft", OString::number(rBox.GetDistance(SvxBoxItemLine::LEFT) * 635))); + "dxTextLeft", OString::number(o3tl::convert(rBox.GetDistance(SvxBoxItemLine::LEFT), + o3tl::Length::twip, o3tl::Length::emu)))); m_aFlyProperties.push_back(std::make_pair( - "dyTextTop", OString::number(rBox.GetDistance(SvxBoxItemLine::TOP) * 635))); + "dyTextTop", OString::number(o3tl::convert(rBox.GetDistance(SvxBoxItemLine::TOP), + o3tl::Length::twip, o3tl::Length::emu)))); m_aFlyProperties.push_back(std::make_pair( - "dxTextRight", OString::number(rBox.GetDistance(SvxBoxItemLine::RIGHT) * 635))); + "dxTextRight", OString::number(o3tl::convert(rBox.GetDistance(SvxBoxItemLine::RIGHT), + o3tl::Length::twip, o3tl::Length::emu)))); m_aFlyProperties.push_back(std::make_pair( - "dyTextBottom", OString::number(rBox.GetDistance(SvxBoxItemLine::BOTTOM) * 635))); + "dyTextBottom", OString::number(o3tl::convert(rBox.GetDistance(SvxBoxItemLine::BOTTOM), + o3tl::Length::twip, o3tl::Length::emu)))); const editeng::SvxBorderLine* pLeft = rBox.GetLine(SvxBoxItemLine::LEFT); const editeng::SvxBorderLine* pRight = rBox.GetLine(SvxBoxItemLine::RIGHT); @@ -3555,7 +3564,7 @@ void RtfAttributeOutput::FormatBox(const SvxBoxItem& rBox) { double const fConverted(editeng::ConvertBorderWidthToWord( pTop->GetBorderLineStyle(), pTop->GetWidth())); - sal_Int32 nWidth = fConverted * 635; // Twips -> EMUs + sal_Int32 nWidth = o3tl::convert(fConverted, o3tl::Length::twip, o3tl::Length::emu); m_aFlyProperties.push_back( std::make_pair("lineWidth", OString::number(nWidth))); } diff --git a/sw/source/filter/ww8/wrtw8esh.cxx b/sw/source/filter/ww8/wrtw8esh.cxx index a964516780db..e65161558edb 100644 --- a/sw/source/filter/ww8/wrtw8esh.cxx +++ b/sw/source/filter/ww8/wrtw8esh.cxx @@ -1986,12 +1986,13 @@ sal_Int32 SwBasicEscherEx::WriteFlyFrameAttr(const SwFrameFormat& rFormat, { const SvxShadowItem* pSI = static_cast(pShadItem); - constexpr sal_uInt16 nCstScale = 635; // unit scale between AOO and MS Word constexpr sal_uInt32 nShadowType = 131074; // shadow type of ms word. need to set the default value. Color nColor = pSI->GetColor(); - sal_Int32 nOffX = pSI->GetWidth() * nCstScale; - sal_Int32 nOffY = pSI->GetWidth() * nCstScale; + sal_Int32 nOffX + = o3tl::convert(pSI->GetWidth(), o3tl::Length::twip, o3tl::Length::emu); + sal_Int32 nOffY + = o3tl::convert(pSI->GetWidth(), o3tl::Length::twip, o3tl::Length::emu); SvxShadowLocation eLocation = pSI->GetLocation(); if( (eLocation!=SvxShadowLocation::NONE) && (pSI->GetWidth()!=0) ) diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index 66203d696493..9466e3adb452 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -127,6 +127,7 @@ #include #include "ww8toolbar.hxx" +#include #include #include @@ -1003,14 +1004,15 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt, pImpRec->aTextId.nSequence = static_cast(nTextId); } - pImpRec->nDxWrapDistLeft = GetPropertyValue( - DFF_Prop_dxWrapDistLeft, 114935 ) / 635; - pImpRec->nDyWrapDistTop = GetPropertyValue( - DFF_Prop_dyWrapDistTop, 0 ) / 635; - pImpRec->nDxWrapDistRight = GetPropertyValue( - DFF_Prop_dxWrapDistRight, 114935 ) / 635; - pImpRec->nDyWrapDistBottom = GetPropertyValue( - DFF_Prop_dyWrapDistBottom, 0 ) / 635; + pImpRec->nDxWrapDistLeft = o3tl::convert(GetPropertyValue(DFF_Prop_dxWrapDistLeft, 114935), + o3tl::Length::emu, o3tl::Length::twip); + pImpRec->nDyWrapDistTop = o3tl::convert(GetPropertyValue(DFF_Prop_dyWrapDistTop, 0), + o3tl::Length::emu, o3tl::Length::twip); + pImpRec->nDxWrapDistRight + = o3tl::convert(GetPropertyValue(DFF_Prop_dxWrapDistRight, 114935), o3tl::Length::emu, + o3tl::Length::twip); + pImpRec->nDyWrapDistBottom = o3tl::convert(GetPropertyValue(DFF_Prop_dyWrapDistBottom, 0), + o3tl::Length::emu, o3tl::Length::twip); // 16.16 fraction times total image width or height, as appropriate. if (SeekToContent(DFF_Prop_pWrapPolygonVertices, rSt)) -- cgit