sw/qa/extras/ooxmlexport/ooxmlexport22.cxx       |    4 
 sw/source/writerfilter/dmapper/GraphicImport.cxx |  137 ++++++++---------------
 sw/source/writerfilter/dmapper/GraphicImport.hxx |    1 
 3 files changed, 56 insertions(+), 86 deletions(-)

New commits:
commit 5e7895f759a25cf822596824cabcd9b113f8e38c
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Sat Aug 2 20:54:05 2025 -0400
Commit:     Justin Luth <justin.l...@collabora.com>
CommitDate: Mon Aug 4 21:05:06 2025 +0200

    NFC writerfilter: dedup with lcl_adjustMarginsAndOrientation
    
    No Functional Change intended.
    
    Change-Id: I9e4a7d131b95a8674447344c68efb4297ce20c75
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188866
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx
index ff62907e59e5..f4f1c89decc2 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport22.cxx
@@ -113,6 +113,10 @@ 
DECLARE_OOXMLEXPORT_TEST(testTdf167770_marginInsideOutside, "tdf167770_marginIns
     // When laying out that document:
     xmlDocUniquePtr pXmlDoc = parseLayoutDump();
 
+    // Note: emulation has decided to remove the mirrored gap completely.
+    // It works well for this document, but obviously wouldn't work for one 
that depends on margins.
+    // This part of the test is just documenting the historical decision
+    // (which is now expanded to more consistently cover shapes as well as the 
OUTSIDE case).
     const SwTwips nPageLeft = getXPath(pXmlDoc, "//page[1]/infos/bounds", 
"left").toInt32();
     const SwTwips nPicture1Left
         = getXPath(pXmlDoc, "//page[1]//fly/infos/bounds", "left").toInt32();
diff --git a/sw/source/writerfilter/dmapper/GraphicImport.cxx 
b/sw/source/writerfilter/dmapper/GraphicImport.cxx
index 14541cc61561..9efa5060217d 100644
--- a/sw/source/writerfilter/dmapper/GraphicImport.cxx
+++ b/sw/source/writerfilter/dmapper/GraphicImport.cxx
@@ -482,6 +482,54 @@ void GraphicImport::lcl_correctWord2007EffectExtent(const 
sal_Int32 nMSOAngle)
         *m_oEffectExtentBottom -= nDiff;
 }
 
+void GraphicImport::lcl_adjustMarginsAndOrientation()
+{
+    if (m_nHoriRelation != text::RelOrientation::CHAR)
+    {
+        const bool bRightSide = m_nHoriRelation == 
text::RelOrientation::PAGE_RIGHT;
+        const bool bLeftSide = m_nHoriRelation == 
text::RelOrientation::PAGE_LEFT;
+        const bool bPageOrMargin
+            = m_nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA // 
margin
+                || m_nHoriRelation == text::RelOrientation::PAGE_FRAME; // page
+
+        assert(bRightSide || bLeftSide || bPageOrMargin
+            || m_nHoriRelation == text::RelOrientation::PRINT_AREA // column
+            || m_nHoriRelation == text::RelOrientation::FRAME /*column*/ );
+
+        // emulation: when impossible to wrap text on a side, remove the 
margin gap
+        if (m_nHoriOrient == text::HoriOrientation::LEFT && !bRightSide)
+            m_nLeftMargin = 0;
+        else if (m_nHoriOrient == text::HoriOrientation::RIGHT && !bLeftSide)
+            m_nRightMargin = 0;
+        else if (m_nHoriOrient == text::HoriOrientation::INSIDE)
+        {
+            if (bPageOrMargin)
+            {
+                m_bPageToggle = true;
+                m_nHoriOrient = text::HoriOrientation::LEFT;
+                // LO currently has to emulate removing the gap on the 
non-text side,
+                // so for these mirrored situations where the shape could be 
on either side,
+                // either we have to keep the gap (wrong position, but proper 
text margin)
+                // or else remove the gap on both sides (losing potentially 
important text margin).
+                // Historically both gaps were removed, so I've kept that 
logic intact
+                // as I expanded the scope to include non-graphic shapes.
+                m_nLeftMargin = 0;
+                m_nRightMargin = 0;
+            }
+        }
+        else if (m_nHoriOrient == text::HoriOrientation::OUTSIDE)
+        {
+            if (bPageOrMargin)
+            {
+                m_bPageToggle = true;
+                m_nHoriOrient = text::HoriOrientation::RIGHT;
+                m_nLeftMargin = 0;
+                m_nRightMargin = 0;
+            }
+        }
+    }
+}
+
 static void lcl_doMSOWidthHeightSwap(awt::Point& rLeftTop, awt::Size& rSize,
                                        const sal_Int32 nMSOAngle)
 {
@@ -1218,49 +1266,7 @@ void GraphicImport::lcl_attribute(Id nName, const Value& 
rValue)
                                 m_nHoriRelation = 
text::RelOrientation::PRINT_AREA;
                         }
 
-                        // adjust margins
-                        // when impossible to wrap text on a side, remove the 
margin gap
-                        if (m_nHoriRelation != text::RelOrientation::CHAR)
-                        {
-                            const bool bRightSide
-                                = m_nHoriRelation == 
text::RelOrientation::PAGE_RIGHT
-                                    || m_nHoriRelation == 
text::RelOrientation::FRAME_RIGHT;
-                            const bool bLeftSide
-                                = m_nHoriRelation == 
text::RelOrientation::PAGE_LEFT
-                                    || m_nHoriRelation == 
text::RelOrientation::FRAME_LEFT;
-                            const bool bPageOrMargin
-                                = m_nHoriRelation == 
text::RelOrientation::PAGE_PRINT_AREA // margin
-                                    || m_nHoriRelation == 
text::RelOrientation::PAGE_FRAME; // page
-
-                            assert(bRightSide || bLeftSide || bPageOrMargin
-                                || m_nHoriRelation == 
text::RelOrientation::PRINT_AREA // column
-                                || m_nHoriRelation == 
text::RelOrientation::FRAME /*column*/ );
-
-                            if (m_nHoriOrient == text::HoriOrientation::LEFT 
&& !bRightSide)
-                                m_nLeftMargin = 0;
-                            else if (m_nHoriOrient == 
text::HoriOrientation::RIGHT && !bLeftSide)
-                                m_nRightMargin = 0;
-                            else if (m_nHoriOrient == 
text::HoriOrientation::INSIDE)
-                            {
-                                if (bPageOrMargin)
-                                {
-                                    m_bPageToggle = true;
-                                    m_nHoriOrient = 
text::HoriOrientation::LEFT;
-                                    m_nLeftMargin = 0;
-                                    m_nRightMargin = 0;
-                                }
-                            }
-                            else if (m_nHoriOrient == 
text::HoriOrientation::OUTSIDE)
-                            {
-                                if (bPageOrMargin)
-                                {
-                                    m_bPageToggle = true;
-                                    m_nHoriOrient = 
text::HoriOrientation::RIGHT;
-                                    m_nLeftMargin = 0;
-                                    m_nRightMargin = 0;
-                                }
-                            }
-                        }
+                        lcl_adjustMarginsAndOrientation();
 
                         // Anchored: Word only supports at-char in that case.
                         text::TextContentAnchorType eAnchorType = 
text::TextContentAnchorType_AT_CHARACTER;
@@ -1815,49 +1821,8 @@ rtl::Reference<SwXTextGraphicObject> 
GraphicImport::createGraphicObject(uno::Ref
                         m_nHoriRelation = text::RelOrientation::PRINT_AREA;
                 }
 
-                //adjust margins
-                // when impossible to wrap text on a side, remove the margin 
gap
-                if (m_nHoriRelation != text::RelOrientation::CHAR)
-                {
-                    const bool bRightSide
-                        = m_nHoriRelation == text::RelOrientation::PAGE_RIGHT
-                            || m_nHoriRelation == 
text::RelOrientation::FRAME_RIGHT;
-                    const bool bLeftSide
-                        = m_nHoriRelation == text::RelOrientation::PAGE_LEFT
-                            || m_nHoriRelation == 
text::RelOrientation::FRAME_LEFT;
-                    const bool bPageOrMargin
-                        = m_nHoriRelation == 
text::RelOrientation::PAGE_PRINT_AREA // margin
-                            || m_nHoriRelation == 
text::RelOrientation::PAGE_FRAME; // page
-
-                    assert(bRightSide || bLeftSide || bPageOrMargin
-                           || m_nHoriRelation == 
text::RelOrientation::PRINT_AREA // column
-                           || m_nHoriRelation == text::RelOrientation::FRAME 
/*column*/ );
-
-                    if (m_nHoriOrient == text::HoriOrientation::LEFT && 
!bRightSide)
-                        m_nLeftMargin = 0;
-                    else if (m_nHoriOrient == text::HoriOrientation::RIGHT && 
!bLeftSide)
-                        m_nRightMargin = 0;
-                    else if (m_nHoriOrient == text::HoriOrientation::INSIDE)
-                    {
-                        if (bPageOrMargin)
-                        {
-                            m_bPageToggle = true;
-                            m_nHoriOrient = text::HoriOrientation::LEFT;
-                            m_nLeftMargin = 0;
-                            m_nRightMargin = 0;
-                        }
-                    }
-                    else if (m_nHoriOrient == text::HoriOrientation::OUTSIDE)
-                    {
-                        if (bPageOrMargin)
-                        {
-                            m_bPageToggle = true;
-                            m_nHoriOrient = text::HoriOrientation::RIGHT;
-                            m_nLeftMargin = 0;
-                            m_nRightMargin = 0;
-                        }
-                    }
-                }
+                lcl_adjustMarginsAndOrientation();
+
                 // adjust top/bottom margins
                 if( m_nVertOrient == text::VertOrientation::TOP &&
                     ( m_nVertRelation == text::RelOrientation::PAGE_PRINT_AREA 
||
diff --git a/sw/source/writerfilter/dmapper/GraphicImport.hxx 
b/sw/source/writerfilter/dmapper/GraphicImport.hxx
index 97eae285fac0..6db245f1cbbf 100644
--- a/sw/source/writerfilter/dmapper/GraphicImport.hxx
+++ b/sw/source/writerfilter/dmapper/GraphicImport.hxx
@@ -226,6 +226,7 @@ public:
     void handleWrapTextValue(sal_uInt32 nVal);
     void lcl_expandRectangleByEffectExtent(css::awt::Point& rLeftTop, 
css::awt::Size& rSize);
     void lcl_correctWord2007EffectExtent(const sal_Int32 nMSOAngle);
+    void lcl_adjustMarginsAndOrientation();
 
     void setXSize(sal_Int32 _nXSize);
     sal_uInt32 getXSize() const;

Reply via email to