sw/qa/extras/ooxmlexport/ooxmlexport19.cxx   |   17 +++++++++++++++++
 sw/qa/extras/ooxmlimport/ooxmlimport2.cxx    |   20 --------------------
 sw/source/filter/ww8/docxattributeoutput.cxx |    9 +++++++++
 3 files changed, 26 insertions(+), 20 deletions(-)

New commits:
commit a4e7d0028efb8fa07d0877aff81fb406f9464fb4
Author:     Justin Luth <[email protected]>
AuthorDate: Wed Jun 18 16:16:35 2025 -0400
Commit:     Justin Luth <[email protected]>
CommitDate: Thu Jun 19 14:37:55 2025 +0200

    tdf#161521 tdf#166305 docx export: fix page margins when mirrorMargins
    
    This patch is basically Oliver's original work
    that he reverted in tdf#165083.
    
    His problem was that he trusted Sections().CurrentSectionInfo()
    to be accurate in this context.
    I substituted m_pCurrentPageDesc.
    
    make CppunitTest_sw_ooxmlexport19 CPPUNIT_TEST_NAME=testTdf153196
    
    Change-Id: Iedce7b6460664301f65f3ce2cf0a97c4e26194d2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186696
    Reviewed-by: Justin Luth <[email protected]>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/ooxmlimport/data/A019_min.docx 
b/sw/qa/extras/ooxmlexport/data/A019_min.docx
similarity index 100%
rename from sw/qa/extras/ooxmlimport/data/A019_min.docx
rename to sw/qa/extras/ooxmlexport/data/A019_min.docx
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
index ef8da13a9f15..1e5552b7a4b5 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
@@ -1280,6 +1280,23 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf148952_2010)
     CPPUNIT_ASSERT_EQUAL(u"Black"_ustr, title);
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf153196, "A019_min.docx")
+{
+    uno::Reference<beans::XPropertySet> xPageStyle;
+    getStyles("PageStyles")->getByName("Converted1") >>= xPageStyle;
+    sal_Int32 nLeftMargin{};
+    xPageStyle->getPropertyValue("LeftMargin") >>= nLeftMargin;
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 4265
+    // - Actual  : 0
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4265), nLeftMargin);
+    sal_Int32 nRightMargin{};
+    xPageStyle->getPropertyValue("RightMargin") >>= nRightMargin;
+    // - Expected: 0
+    // - Actual  : 4265
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nRightMargin);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx 
b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index 38ac0159960c..9e5daa6dab96 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -1333,26 +1333,6 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf154370)
         CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DIRECT_VALUE, 
ePropertyState);
     }
 }
-
-CPPUNIT_TEST_FIXTURE(Test, testTdf153196)
-{
-    createSwDoc("A019_min.docx");
-
-    uno::Reference<beans::XPropertySet> xPageStyle;
-    getStyles("PageStyles")->getByName("Converted1") >>= xPageStyle;
-    sal_Int32 nLeftMargin{};
-    xPageStyle->getPropertyValue("LeftMargin") >>= nLeftMargin;
-    // Without the accompanying fix in place, this test would have failed with:
-    // - Expected: 4265
-    // - Actual  : 0
-    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4265), nLeftMargin);
-    sal_Int32 nRightMargin{};
-    xPageStyle->getPropertyValue("RightMargin") >>= nRightMargin;
-    // - Expected: 0
-    // - Actual  : 4265
-    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nRightMargin);
-}
-
 // tests should only be added to ooxmlIMPORT *if* they fail round-tripping in 
ooxmlEXPORT
 
 } // end of anonymous namespace
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 5a5b01cdbfca..c1b36660d88d 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -9530,6 +9530,15 @@ void DocxAttributeOutput::FormatLRSpace( const 
SvxLRSpaceItem& rLRSpace )
 
         m_pageMargins.nLeft += 
sal::static_int_cast<sal_uInt16>(rLRSpace.ResolveLeft({}));
         m_pageMargins.nRight += 
sal::static_int_cast<sal_uInt16>(rLRSpace.ResolveRight({}));
+
+        // if page layout is 'left' then left/right margin may need to be 
exchanged
+        // as it is exported as mirrored layout starting with even page
+        if (m_rExport.isMirroredMargin()
+            && UseOnPage::Left == (m_rExport.m_pCurrentPageDesc->ReadUseOn() & 
UseOnPage::All))
+        {
+            std::swap(m_pageMargins.nLeft, m_pageMargins.nRight);
+        }
+
         sal_uInt16 nGutter = rLRSpace.GetGutterMargin();
 
         AddToAttrList( m_pSectionSpacingAttrList,

Reply via email to