sw/qa/extras/ooxmlexport/data/A019_min.docx  |binary
 sw/qa/extras/ooxmlexport/ooxmlexport19.cxx   |   17 +++++++++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx |   11 +++++++++++
 sw/source/filter/ww8/docxexport.hxx          |    6 +++---
 writerfilter/source/dmapper/PropertyMap.cxx  |   11 ++++++++++-
 5 files changed, 41 insertions(+), 4 deletions(-)

New commits:
commit 2c1080565bb8f8dd3546384ca89fb7cfd3e9f9fd
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Tue Jun 11 08:51:09 2024 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Jan 20 10:49:50 2025 +0100

    tdf#161521 fix page margins on first page with mirrord layout
    
    Documents starting with an even page on a mirrored layout need
    to switch left/right margin on the first page.
    Applies also to docx export.
    JUnit test included
    
    Change-Id: Ia363941c6a7a25f9208acc7e40b77baa88080780
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168658
    Tested-by: Jenkins
    Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180427
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/qa/extras/ooxmlexport/data/A019_min.docx 
b/sw/qa/extras/ooxmlexport/data/A019_min.docx
new file mode 100755
index 000000000000..c7c0c890accf
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/A019_min.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
index d6193305e96c..793ee8171a1a 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
@@ -1220,6 +1220,23 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf148952_2010)
     CPPUNIT_ASSERT_EQUAL(OUString("Black"), 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/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 1116bbb4c7e0..f4ced57b4ad5 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -9302,6 +9302,17 @@ void DocxAttributeOutput::FormatLRSpace( const 
SvxLRSpaceItem& rLRSpace )
 
         m_pageMargins.nLeft += 
sal::static_int_cast<sal_uInt16>(rLRSpace.GetLeft());
         m_pageMargins.nRight += 
sal::static_int_cast<sal_uInt16>(rLRSpace.GetRight());
+        // if page layout is 'left' then left/right margin need to be exchanged
+        // as it is exported as mirrored layout starting with even page
+        const WW8_SepInfo *pSectionInfo = 
m_rExport.Sections().CurrentSectionInfo();
+        if (pSectionInfo->pPageDesc &&
+            m_rExport.isMirroredMargin() &&
+            ((pSectionInfo->pPageDesc->ReadUseOn() & UseOnPage::All) == 
UseOnPage::Left))
+        {
+            sal_uInt16 nLeft = m_pageMargins.nLeft;
+            m_pageMargins.nLeft = m_pageMargins.nRight;
+            m_pageMargins.nRight = nLeft;
+        }
         sal_uInt16 nGutter = rLRSpace.GetGutterMargin();
 
         AddToAttrList( m_pSectionSpacingAttrList,
diff --git a/sw/source/filter/ww8/docxexport.hxx 
b/sw/source/filter/ww8/docxexport.hxx
index 95da64d24408..7f4ab826c40d 100644
--- a/sw/source/filter/ww8/docxexport.hxx
+++ b/sw/source/filter/ww8/docxexport.hxx
@@ -282,9 +282,6 @@ private:
     /// Writes word/vbaProject.bin.
     void WriteVBA();
 
-    /// return true if Page Layout is set as Mirrored
-    bool isMirroredMargin();
-
 public:
     /// All xml namespaces to be used at the top of any text .xml file (main 
doc, headers, footers,...)
     rtl::Reference<sax_fastparser::FastAttributeList> MainXmlNamespaces();
@@ -322,6 +319,9 @@ public:
     // needed in docxsdrexport.cxx and docxattributeoutput.cxx
     sal_Int32 getWordCompatibilityModeFromGrabBag() const;
 
+    /// return true if Page Layout is set as Mirrored
+    bool isMirroredMargin();
+
 private:
     DocxExport( const DocxExport& ) = delete;
 
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx 
b/writerfilter/source/dmapper/PropertyMap.cxx
index eaadc04e6381..568560172156 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -1513,14 +1513,23 @@ void 
SectionPropertyMap::CreateEvenOddPageStyleCopy(DomainMapper_Impl& rDM_Impl,
         "HeaderText", "HeaderTextLeft", "HeaderTextFirst",
         "FooterText", "FooterTextLeft", "FooterTextFirst" };
 
+    bool isMirrorMargins = PageBreakType::Even == eBreakType && 
rDM_Impl.GetSettingsTable()->GetMirrorMarginSettings();
     for (const auto& rProperty : propertyList)
     {
         if ((rProperty.Attributes & beans::PropertyAttribute::READONLY) == 0)
         {
             if (staticDenylist.find(rProperty.Name) == staticDenylist.end())
             {
+                OUString sSetName = rProperty.Name;
+                if (isMirrorMargins)
+                {
+                    if (rProperty.Name == u"LeftMargin"_ustr)
+                        sSetName = u"RightMargin"_ustr;
+                    else if (rProperty.Name == u"RightMargin"_ustr)
+                        sSetName = u"LeftMargin"_ustr;
+                }
                 evenOddStyle->setPropertyValue(
-                    rProperty.Name,
+                    sSetName,
                     pageProperties->getPropertyValue(rProperty.Name));
             }
         }

Reply via email to