sw/qa/extras/ooxmlexport/data/tdf154703_framePrWrapSpacing.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport18.cxx                      |   11 +++++
 sw/source/filter/ww8/docxattributeoutput.cxx                    |   21 
++++++----
 3 files changed, 25 insertions(+), 7 deletions(-)

New commits:
commit d3a121cecfa8fb3c6f81b05822ba3309d77ab85d
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Fri Apr 21 19:42:55 2023 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Sat Apr 22 02:56:45 2023 +0200

    tdf#154703 sw framePr: export knowing import wrap spacing limitations
    
    I noticed that the wrap margin spacing was being cut in half each 
round-trip.
    That is because MS Word ignores the spacing on LEFT or RIGHT alignment,
    while LO doesn't. Rather than monkey with layout, import just ignored
    the spacing. Sounds like a good idea - but needed to do the same on export.
    
    make CppunitTest_sw_ooxmlexport18 \
        CPPUNIT_TEST_NAME=testTdf154703_framePrWrapSpacing
    
    Change-Id: I3878d1bdb98cf027fe95137939caf6901c7188a6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150796
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf154703_framePrWrapSpacing.docx 
b/sw/qa/extras/ooxmlexport/data/tdf154703_framePrWrapSpacing.docx
new file mode 100644
index 000000000000..57a9bea5a174
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf154703_framePrWrapSpacing.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index 171826175e0b..72cfe1723870 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -233,6 +233,17 @@ DECLARE_OOXMLEXPORT_TEST(testTdf154703_framePr2, 
"tdf154703_framePr2.rtf")
     assertXPath(pXmlDoc, "//w:body/w:p[3]/w:pPr/w:shd", "fill", "800000");
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf154703_framePrWrapSpacing, 
"tdf154703_framePrWrapSpacing.docx")
+{
+    CPPUNIT_ASSERT_EQUAL(2, getPages());
+    if (!isExported())
+        return;
+
+    xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+    // before the fix, this was half of the correct value.
+    assertXPath(pXmlDoc, "//w:body/w:p/w:pPr/w:framePr", "hSpace", "2552");
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf153613_anchoredAfterPgBreak, 
"tdf153613_anchoredAfterPgBreak.docx")
 {
     const auto& pLayout = parseLayoutDump();
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 43cfa953a041..94ed8bac2ba9 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -933,24 +933,31 @@ void DocxAttributeOutput::PopulateFrameProperties(const 
SwFrameFormat* pFrameFor
     attrList->add( FSNS( XML_w, XML_x), OString::number(aPos.X));
     attrList->add( FSNS( XML_w, XML_y), OString::number(aPos.Y));
 
+    OString aXAlign = convertToOOXMLHoriOrient(rHoriOrient.GetHoriOrient(), 
/*bIsPosToggle=*/false);
+    OString aYAlign = convertToOOXMLVertOrient(rVertOrient.GetVertOrient());
+    if (!aXAlign.isEmpty())
+        attrList->add(FSNS(XML_w, XML_xAlign), aXAlign);
+    if (!aYAlign.isEmpty())
+        attrList->add(FSNS(XML_w, XML_yAlign), aYAlign);
+
     sal_Int16 nLeft = pFrameFormat->GetLRSpace().GetLeft();
     sal_Int16 nRight = pFrameFormat->GetLRSpace().GetRight();
     sal_Int16 nUpper = pFrameFormat->GetULSpace().GetUpper();
     sal_Int16 nLower = pFrameFormat->GetULSpace().GetLower();
 
+    // To emulate, on import left was ignored (set to zero) if aligned to left,
+    // so just double up the right spacing in order to prevent cutting in half 
each round-trip.
+    if (rHoriOrient.GetHoriOrient() == text::HoriOrientation::LEFT)
+        nLeft = nRight;
+    else if (rHoriOrient.GetHoriOrient() == text::HoriOrientation::RIGHT)
+        nRight = nLeft;
+
     attrList->add(FSNS(XML_w, XML_hSpace), OString::number((nLeft + nRight) / 
2));
     attrList->add(FSNS(XML_w, XML_vSpace), OString::number((nUpper + nLower) / 
2));
 
     OString relativeFromH = 
convertToOOXMLHoriOrientRel(rHoriOrient.GetRelationOrient());
     OString relativeFromV = 
convertToOOXMLVertOrientRel(rVertOrient.GetRelationOrient());
 
-    OString aXAlign = convertToOOXMLHoriOrient(rHoriOrient.GetHoriOrient(), 
/*bIsPosToggle=*/false);
-    OString aYAlign = convertToOOXMLVertOrient(rVertOrient.GetVertOrient());
-    if (!aXAlign.isEmpty())
-        attrList->add(FSNS(XML_w, XML_xAlign), aXAlign);
-    if (!aYAlign.isEmpty())
-        attrList->add(FSNS(XML_w, XML_yAlign), aYAlign);
-
     switch (pFrameFormat->GetSurround().GetValue())
     {
     case css::text::WrapTextMode_NONE:

Reply via email to