[Libreoffice-commits] core.git: include/oox sw/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Thu Apr 1 04:16:42 UTC 2021


 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(-)

New commits:
commit d10a49d64469411a23b3660a82106405808da028
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Wed Mar 31 20:38:30 2021 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Thu Apr 1 06:16:04 2021 +0200

    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 <mike.kaganski at collabora.com>

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 <sal/config.h>
+
+#include <o3tl/unit_conversion.hxx>
 #include <rtl/string.hxx>
 #include <sal/types.h>
 
@@ -52,12 +55,12 @@ static constexpr const char* ToPsz10(bool b)
 
 static constexpr sal_Int64 PPTtoEMU( sal_Int32 nPPT )
 {
-    return static_cast<sal_Int64>( static_cast<double>(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 <typename T>
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 <editeng/keepitem.hxx>
 #include <editeng/frmdiritem.hxx>
 #include <editeng/opaqitem.hxx>
+#include <o3tl/unit_conversion.hxx>
 #include <svx/svdouno.hxx>
 #include <filter/msfilter/rtfutil.hxx>
 #include <sfx2/sfxbasemodel.hxx>
@@ -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<OString, OString>(
-            "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<OString, OString>(
-            "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<OString, OString>(
-            "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<OString, OString>(
-            "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<OString, OString>(
-            "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<OString, OString>(
-            "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<OString, OString>(
-            "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<OString, OString>(
-            "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<OString, OString>("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<const SvxShadowItem*>(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 <basic/basmgr.hxx>
 
 #include "ww8toolbar.hxx"
+#include <o3tl/unit_conversion.hxx>
 #include <o3tl/safeint.hxx>
 #include <osl/file.hxx>
 
@@ -1003,14 +1004,15 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt,
             pImpRec->aTextId.nSequence = static_cast<sal_uInt16>(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))


More information about the Libreoffice-commits mailing list