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 +++--- sw/source/writerfilter/dmapper/PropertyMap.cxx | 11 ++++++++++- 5 files changed, 41 insertions(+), 4 deletions(-)
New commits: commit 8ef9573f087b86f93860c8d07d04b60a40512836 Author: Oliver Specht <oliver.spe...@cib.de> AuthorDate: Tue Jun 11 08:51:09 2024 +0200 Commit: Thorsten Behrens <thorsten.behr...@allotropia.de> CommitDate: Tue Jun 18 00:59:10 2024 +0200 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 Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de> Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de> 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 d74b4883a7d0..8080bd448a55 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx @@ -1234,6 +1234,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/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index fb11a5247f5f..15928d5d414f 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -9272,6 +9272,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 722e3b571291..a29ad9aaf3e9 100644 --- a/sw/source/filter/ww8/docxexport.hxx +++ b/sw/source/filter/ww8/docxexport.hxx @@ -285,9 +285,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(); @@ -325,6 +322,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/sw/source/writerfilter/dmapper/PropertyMap.cxx b/sw/source/writerfilter/dmapper/PropertyMap.cxx index b5c70b6309f8..6c169b610d4b 100644 --- a/sw/source/writerfilter/dmapper/PropertyMap.cxx +++ b/sw/source/writerfilter/dmapper/PropertyMap.cxx @@ -1472,14 +1472,23 @@ void SectionPropertyMap::CreateEvenOddPageStyleCopy(DomainMapper_Impl& rDM_Impl, u"HeaderText", u"HeaderTextLeft", u"HeaderTextFirst", u"FooterText", u"FooterTextLeft", u"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)); } }