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 <jluth@mail.com>
This commit is contained in:
Justin Luth
2023-04-22 02:56:45 +02:00
committed by Justin Luth
parent 006b35d500
commit d3a121cecf
3 changed files with 29 additions and 11 deletions
@@ -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();
+18 -11
View File
@@ -933,17 +933,6 @@ 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));
sal_Int16 nLeft = pFrameFormat->GetLRSpace().GetLeft();
sal_Int16 nRight = pFrameFormat->GetLRSpace().GetRight();
sal_Int16 nUpper = pFrameFormat->GetULSpace().GetUpper();
sal_Int16 nLower = pFrameFormat->GetULSpace().GetLower();
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())
@@ -951,6 +940,24 @@ void DocxAttributeOutput::PopulateFrameProperties(const SwFrameFormat* pFrameFor
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());
switch (pFrameFormat->GetSurround().GetValue())
{
case css::text::WrapTextMode_NONE: