diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-03-16 09:05:57 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-03-16 09:42:11 +0100 |
commit | d934cb370b1d660f996ec959fda4bcc6f29902a9 (patch) | |
tree | c1335fab930ded9d95d51b95cab7a1930b0f501c /sw | |
parent | 5ac7d9e0cb5172e3582b8fa4548913cdcdadc677 (diff) |
tdf#138895 DOCX filter: fix handling for effect extent vs line width
Regression from commit a5a836d8c43dc9cebbbf8af39bf0142de603a7c6 (DOCX
filter: effect extent should be part of the margin, 2014-12-04), the
problem was that effect extent is OK to be added as an extra margin, but
line width is part of that effect extent in Word, so Writer margin
should not be increased with the line width.
The Word behavior seems to be that half of the line width is part of
e.g. the top effect extent, then the other half is part of the bottom
one (and so on).
The bugdoc's case was that a too large margin shifted the last line
below the shape, and this tiny half-line-width extra margin handled
correctly puts the line back to its correct place.
Change-Id: Ic897926f3d79f979ea84aef3dbda49c46b18a3ac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112558
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/effect-extent-line-width.docx | bin | 0 -> 23257 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport16.cxx | 21 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxsdrexport.cxx | 11 |
3 files changed, 32 insertions, 0 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/effect-extent-line-width.docx b/sw/qa/extras/ooxmlexport/data/effect-extent-line-width.docx Binary files differnew file mode 100644 index 000000000000..5cc4d4e374ee --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/effect-extent-line-width.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx index 6338931f9ec3..0e0ad7cea8e1 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx @@ -149,6 +149,27 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testFooterMarginLost, "footer-margin-lost.do assertXPath(pXmlDoc, "/w:document/w:body/w:sectPr/w:pgMar", "footer", "709"); } +CPPUNIT_TEST_FIXTURE(Test, testEffectExtentLineWidth) +{ + auto verify = [this]() { + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(508), + getProperty<sal_Int32>(getShape(1), "TopMargin")); + }; + + // Given a document with a shape that has a non-zero line width and effect extent: + // When loading the document: + load(mpTestDocumentPath, "effect-extent-line-width.docx"); + // Then make sure that the line width is not taken twice (once as part of the margin, and then + // also as the line width): + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 508 + // - Actual : 561 + // i.e. the upper spacing was too large, the last line of the text moved below the shape. + verify(); + reload(mpFilter, "effect-extent-line-width.docx"); + verify(); +} + DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf140572_docDefault_superscript, "tdf140572_docDefault_superscript.docx") { // A round-trip was crashing. diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx index df4ce254908d..9b461f4c3831 100644 --- a/sw/source/filter/ww8/docxsdrexport.cxx +++ b/sw/source/filter/ww8/docxsdrexport.cxx @@ -37,6 +37,7 @@ #include <IDocumentDrawModelAccess.hxx> #include <tools/diagnose_ex.h> +#include <svx/xlnwtit.hxx> using namespace com::sun::star; using namespace oox; @@ -452,22 +453,32 @@ void DocxSdrExport::startDMLAnchorInline(const SwFrameFormat* pFrameFormat, cons } } attrList->add(XML_behindDoc, bOpaque ? "0" : "1"); + sal_Int32 nLineWidth = 0; + if (const SdrObject* pObject = pFrameFormat->FindRealSdrObject()) + { + nLineWidth = pObject->GetMergedItem(XATTR_LINEWIDTH).GetValue(); + } + // Extend distance with the effect extent if the shape is not rotated, which is the opposite // of the mapping done at import time. // The type of dist* attributes is unsigned, so make sure no negative value is written. sal_Int64 nTopExtDist = nRotation ? 0 : nTopExt; + nTopExtDist -= TwipsToEMU(nLineWidth / 2); sal_Int64 nDistT = std::max(static_cast<sal_Int64>(0), TwipsToEMU(aULSpaceItem.GetUpper()) - nTopExtDist); attrList->add(XML_distT, OString::number(nDistT).getStr()); sal_Int64 nBottomExtDist = nRotation ? 0 : nBottomExt; + nBottomExtDist -= TwipsToEMU(nLineWidth / 2); sal_Int64 nDistB = std::max(static_cast<sal_Int64>(0), TwipsToEMU(aULSpaceItem.GetLower()) - nBottomExtDist); attrList->add(XML_distB, OString::number(nDistB).getStr()); sal_Int64 nLeftExtDist = nRotation ? 0 : nLeftExt; + nLeftExtDist -= TwipsToEMU(nLineWidth / 2); sal_Int64 nDistL = std::max(static_cast<sal_Int64>(0), TwipsToEMU(aLRSpaceItem.GetLeft()) - nLeftExtDist); attrList->add(XML_distL, OString::number(nDistL).getStr()); sal_Int64 nRightExtDist = nRotation ? 0 : nRightExt; + nRightExtDist -= TwipsToEMU(nLineWidth / 2); sal_Int64 nDistR = std::max(static_cast<sal_Int64>(0), TwipsToEMU(aLRSpaceItem.GetRight()) - nRightExtDist); attrList->add(XML_distR, OString::number(nDistR).getStr()); |