[Libreoffice-commits] core.git: Branch 'libreoffice-7-1' - sw/qa sw/source writerfilter/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Thu Mar 18 13:11:03 UTC 2021
sw/qa/extras/ooxmlexport/data/effect-extent-line-width.docx |binary
sw/qa/extras/ooxmlexport/ooxmlexport16.cxx | 21 +++++++
sw/source/filter/ww8/docxsdrexport.cxx | 11 +++
writerfilter/source/dmapper/GraphicImport.cxx | 36 ++++++++++--
4 files changed, 63 insertions(+), 5 deletions(-)
New commits:
commit ea6193d64c5bed72bfb919b782434a0b3674c525
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Mar 16 09:05:57 2021 +0100
Commit: Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Thu Mar 18 14:10:26 2021 +0100
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 at collabora.com>
Tested-by: Jenkins
Signed-off-by: Xisco Fauli <xiscofauli at libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112582
diff --git a/sw/qa/extras/ooxmlexport/data/effect-extent-line-width.docx b/sw/qa/extras/ooxmlexport/data/effect-extent-line-width.docx
new file mode 100644
index 000000000000..5cc4d4e374ee
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/effect-extent-line-width.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
index f532794e3874..a397bb073ecf 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
@@ -74,6 +74,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 8d68eb5da6f7..bcf2959dd149 100644
--- a/sw/source/filter/ww8/docxsdrexport.cxx
+++ b/sw/source/filter/ww8/docxsdrexport.cxx
@@ -35,6 +35,7 @@
#include <fmtpdsc.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <comphelper/propertysequence.hxx>
+#include <svx/xlnwtit.hxx>
using namespace com::sun::star;
using namespace oox;
@@ -447,22 +448,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());
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index c4f724d22653..5fb9a3499de3 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -810,25 +810,51 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
// Include effect extent in the margin to bring Writer layout closer
// to Word. But do this for non-rotated shapes only, where effect
// extents map to increased margins as-is.
+
+ sal_Int32 nLineWidth{};
+ if (xShapeProps->getPropertySetInfo()->hasPropertyByName("LineWidth"))
+ {
+ xShapeProps->getPropertyValue("LineWidth") >>= nLineWidth;
+ }
+
if (m_pImpl->m_oEffectExtentLeft)
{
- m_pImpl->nLeftMargin += oox::drawingml::convertEmuToHmm(
+ sal_Int32 nLeft = oox::drawingml::convertEmuToHmm(
*m_pImpl->m_oEffectExtentLeft);
+ if (nLeft >= nLineWidth / 2)
+ {
+ nLeft -= nLineWidth / 2;
+ }
+ m_pImpl->nLeftMargin += nLeft;
}
if (m_pImpl->m_oEffectExtentTop)
{
- m_pImpl->nTopMargin += oox::drawingml::convertEmuToHmm(
- *m_pImpl->m_oEffectExtentTop);
+ sal_Int32 nTop = oox::drawingml::convertEmuToHmm(*m_pImpl->m_oEffectExtentTop);
+ if (nTop >= nLineWidth / 2)
+ {
+ nTop -= nLineWidth / 2;
+ }
+ m_pImpl->nTopMargin += nTop;
}
if (m_pImpl->m_oEffectExtentRight)
{
- m_pImpl->nRightMargin += oox::drawingml::convertEmuToHmm(
+ sal_Int32 nRight = oox::drawingml::convertEmuToHmm(
*m_pImpl->m_oEffectExtentRight);
+ if (nRight >= nLineWidth / 2)
+ {
+ nRight -= nLineWidth / 2;
+ }
+ m_pImpl->nRightMargin += nRight;
}
if (m_pImpl->m_oEffectExtentBottom)
{
- m_pImpl->nBottomMargin += oox::drawingml::convertEmuToHmm(
+ sal_Int32 nBottom = oox::drawingml::convertEmuToHmm(
*m_pImpl->m_oEffectExtentBottom);
+ if (nBottom >= nLineWidth / 2)
+ {
+ nBottom -= nLineWidth / 2;
+ }
+ m_pImpl->nBottomMargin += nBottom;
}
}
}
More information about the Libreoffice-commits
mailing list