diff options
author | Regényi Balázs <regenyi.balazs+gerrit@gmail.com> | 2020-07-15 16:02:16 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-07-17 17:05:31 +0200 |
commit | fa84e889b8cabdd7c174b640883c692b8d514ae7 (patch) | |
tree | b964505e8bf4ca84da4e4d4764691bff48a8e8a4 | |
parent | 713c6b1880ee06f8ff0aa869906058f247db6e3a (diff) |
tdf#134299 DOCX shape export: fix relative size of shapes
relative to left/right/inside/outside/top/bottom page margins.
This fixes bugs: tdf#134300, tdf#134828, tdf#134830, tdf#134834
and tdf#134835.
Follow-up of commits:
d9bee5677edc857d7d119197a85c22b9410ed876
(tdf#133670 DOCX import: fix shape width relative to right margin)
abc818e5f2fb2884f1041e9626115e69cde766d5
(tdf#132976 DOCX import: fix shape width relative to left margin)
1a391f6ed056c95b9d7b5f18988ab8650723ffc5
(tdf#123324 DOCX import: fix shape height relative to top page margin)
d94ebb64e18839b430760dba525a885b10ae8093
(tdf#133863 tdf#133864 DOCX shape import: width relative to inside)
9693e9aac005b1406e0cdb1655efe45554a90f86
(tdf#133070 DOCX import: fix shape height relative to bottom page margin)
Co-authored-by: Szabolcs Tóth
Change-Id: I42cd7693c80cc62f71560e9ab0f226b51aff6bb7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98850
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf133861_RelativeAnchorWidthFromInsideOutsideMargin.docx | bin | 18324 -> 10536 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport14.cxx | 18 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport15.cxx | 18 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport3.cxx | 32 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport4.cxx | 11 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxsdrexport.cxx | 51 |
6 files changed, 70 insertions, 60 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf133861_RelativeAnchorWidthFromInsideOutsideMargin.docx b/sw/qa/extras/ooxmlexport/data/tdf133861_RelativeAnchorWidthFromInsideOutsideMargin.docx Binary files differindex 453320f388f1..216434db3c06 100644 --- a/sw/qa/extras/ooxmlexport/data/tdf133861_RelativeAnchorWidthFromInsideOutsideMargin.docx +++ b/sw/qa/extras/ooxmlexport/data/tdf133861_RelativeAnchorWidthFromInsideOutsideMargin.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index becf005b10e6..3e919588d498 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -1195,25 +1195,19 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf108505, "tdf108505.docx") DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorHeightFromTopMarginHasHeader, "tdf123324_testRelativeAnchorHeightFromTopMarginHasHeader.docx") { - // TODO: fix export too - if (mbExported) - return; // tdf#123324 The height was set relative to page print area top, // but this was handled relative to page height. // Note: page print area top = margin + header height. // In this case the header exists. xmlDocUniquePtr pXmlDoc = parseLayoutDump(); - const sal_Int32 nAnchoredHeight - = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "height").toInt32(); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2551), nAnchoredHeight); + if (!pXmlDoc) + return; + assertXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "height", "2551"); } DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorHeightFromTopMarginNoHeader, "tdf123324_testRelativeAnchorHeightFromTopMarginNoHeader.docx") { - // TODO: fix export too - if (mbExported) - return; // tdf#123324 The height was set relative from top margin, but this was handled relative from page height. // Note: the MSO Word margin = LO margin + LO header height. // In this case the header does not exist, so MSO Word margin and LO Writer margin are the same. @@ -1223,9 +1217,9 @@ DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorHeightFromTopMarginNoHeader, // Note: page print area top = margin + header height. // In this case the header does not exist, so OpenDocument and OOXML margins are the same. xmlDocUniquePtr pXmlDoc = parseLayoutDump(); - const sal_Int32 nAnchoredHeight - = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "height").toInt32(); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2551), nAnchoredHeight); + if (!pXmlDoc) + return; + assertXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "height", "2551"); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx index c987501901f5..f5f4b1657007 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx @@ -161,17 +161,14 @@ DECLARE_OOXMLEXPORT_TEST(testTdf134063, "tdf134063.docx") DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorHeightFromBottomMarginHasFooter, "tdf133070_testRelativeAnchorHeightFromBottomMarginHasFooter.docx") { - // TODO: fix export too - if (mbExported) - return; // tdf#133070 The height was set relative to page print area bottom, // but this was handled relative to page height. // Note: page print area bottom = margin + footer height. // In this case the footer exists. xmlDocUniquePtr pXmlDoc = parseLayoutDump(); - const sal_Int32 nAnchoredHeight - = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "height").toInt32(); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1147), nAnchoredHeight); + if (!pXmlDoc) + return; + assertXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "height", "1147"); } DECLARE_OOXMLIMPORT_TEST(TestTdf132483, "tdf132483.docx") @@ -190,17 +187,14 @@ DECLARE_OOXMLIMPORT_TEST(TestTdf132483, "tdf132483.docx") DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorHeightFromBottomMarginNoFooter, "tdf133070_testRelativeAnchorHeightFromBottomMarginNoFooter.docx") { - // TODO: fix export too - if (mbExported) - return; // tdf#133070 The height was set relative to page print area bottom, // but this was handled relative to page height. // Note: page print area bottom = margin + footer height. // In this case the footer does not exist, so OpenDocument and OOXML margins are the same. xmlDocUniquePtr pXmlDoc = parseLayoutDump(); - const sal_Int32 nAnchoredHeight - = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "height").toInt32(); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1147), nAnchoredHeight); + if (!pXmlDoc) + return; + assertXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "height", "1147"); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx index 99c908351898..cedff600d3e4 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx @@ -1160,39 +1160,29 @@ DECLARE_OOXMLEXPORT_TEST(testShapeLineWidth, "tdf92526_ShapeLineWidth.odt") DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorWidthFromLeftMargin, "tdf132976_testRelativeAnchorWidthFromLeftMargin.docx") { - // TODO: Fix export. - if (mbExported) - return; - // tdf#132976 The size of the width of this shape should come from the size of the left margin. // It was set to the size of the width of the entire page before. xmlDocUniquePtr pXmlDoc = parseLayoutDump(); - const sal_Int32 nAnchoredWidth - = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "width").toInt32(); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1133), nAnchoredWidth); + if (!pXmlDoc) + return; + assertXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "width", "1133"); } DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorWidthFromInsideOutsideMargin, "tdf133861_RelativeAnchorWidthFromInsideOutsideMargin.docx") { - // TODO: Fix export. - if (mbExported) - return; - // tdf#133863 tdf#133864 The sizes of the width of these shapes depend on the sizes of the inside and outside margins. // The open book: outside --text-- inside | inside --text-- outside xmlDocUniquePtr pXmlDoc = parseLayoutDump(); - // Outside - sal_Int32 nAnchoredWidth = getXPath(pXmlDoc, "(//SwAnchoredDrawObject)[1]/bounds", "width").toInt32(); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2552), nAnchoredWidth); - // Inside - nAnchoredWidth = getXPath(pXmlDoc, "(//SwAnchoredDrawObject)[2]/bounds", "width").toInt32(); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1440), nAnchoredWidth); + if (!pXmlDoc) + return; // Inside - nAnchoredWidth = getXPath(pXmlDoc, "(//SwAnchoredDrawObject)[3]/bounds", "width").toInt32(); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1440), nAnchoredWidth); + assertXPath(pXmlDoc, "(//SwAnchoredDrawObject)[1]/bounds", "width", "1440"); + // Outside + assertXPath(pXmlDoc, "(//SwAnchoredDrawObject)[2]/bounds", "width", "2552"); // Outside - nAnchoredWidth = getXPath(pXmlDoc, "(//SwAnchoredDrawObject)[4]/bounds", "width").toInt32(); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2552), nAnchoredWidth); + assertXPath(pXmlDoc, "(//SwAnchoredDrawObject)[3]/bounds", "width", "2552"); + // Inside + assertXPath(pXmlDoc, "(//SwAnchoredDrawObject)[4]/bounds", "width", "1440"); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx index 2687707bb5e8..7fe92c72eede 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx @@ -1258,15 +1258,12 @@ DECLARE_OOXMLEXPORT_TEST(testUnderlineColorGroupedShapes, "tdf132491_UnderlineCo DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorWidthFromRightMargin, "tdf133670_testRelativeAnchorWidthFromRightMargin.docx") { - // TODO: Fix export. - if (mbExported) - return; - // tdf#133670 The width was set relative from right margin, but this was handled relative from page width. xmlDocUniquePtr pXmlDoc = parseLayoutDump(); - const sal_Int32 nAnchoredWidth - = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "width").toInt32(); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2408), nAnchoredWidth); + if (!pXmlDoc) + return; + auto nWidth = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "width").toInt32(); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2408, nWidth, 1); } DECLARE_OOXMLEXPORT_TEST(testAutoFitForLegacyShapes, "tdf112312_AutoFitForLegacyShapes.odt") diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx index 458493391b27..bc540c232337 100644 --- a/sw/source/filter/ww8/docxsdrexport.cxx +++ b/sw/source/filter/ww8/docxsdrexport.cxx @@ -32,6 +32,7 @@ #include <comphelper/sequenceashashmap.hxx> #include <sal/log.hxx> #include <frmfmt.hxx> +#include <fmtpdsc.hxx> #include <IDocumentDrawModelAccess.hxx> #include <comphelper/propertysequence.hxx> @@ -920,10 +921,30 @@ void DocxSdrExport::writeDMLDrawing(const SdrObject* pSdrObject, const SwFrameFo if (pSdrObject->GetRelativeWidth()) { // At the moment drawinglayer objects are always relative from page. - pFS->startElementNS(XML_wp14, XML_sizeRelH, XML_relativeFrom, - (pSdrObject->GetRelativeWidthRelation() == text::RelOrientation::FRAME - ? "margin" - : "page")); + OUString sValue; + switch (pSdrObject->GetRelativeWidthRelation()) + { + case text::RelOrientation::FRAME: + sValue = "margin"; + break; + case text::RelOrientation::PAGE_LEFT: + if (pFrameFormat->GetDoc()->GetPageDesc(0).GetUseOn() == UseOnPage::Mirror) + sValue = "outsideMargin"; + else + sValue = "leftMargin"; + break; + case text::RelOrientation::PAGE_RIGHT: + if (pFrameFormat->GetDoc()->GetPageDesc(0).GetUseOn() == UseOnPage::Mirror) + sValue = "insideMargin"; + else + sValue = "rightMargin"; + break; + case text::RelOrientation::PAGE_FRAME: + default: + sValue = "page"; + break; + } + pFS->startElementNS(XML_wp14, XML_sizeRelH, XML_relativeFrom, sValue); pFS->startElementNS(XML_wp14, XML_pctWidth); pFS->writeEscaped( OUString::number(*pSdrObject->GetRelativeWidth() * 100 * oox::drawingml::PER_PERCENT)); @@ -932,10 +953,24 @@ void DocxSdrExport::writeDMLDrawing(const SdrObject* pSdrObject, const SwFrameFo } if (pSdrObject->GetRelativeHeight()) { - pFS->startElementNS(XML_wp14, XML_sizeRelV, XML_relativeFrom, - (pSdrObject->GetRelativeHeightRelation() == text::RelOrientation::FRAME - ? "margin" - : "page")); + OUString sValue; + switch (pSdrObject->GetRelativeHeightRelation()) + { + case text::RelOrientation::FRAME: + sValue = "margin"; + break; + case text::RelOrientation::PAGE_PRINT_AREA: + sValue = "topMargin"; + break; + case text::RelOrientation::PAGE_PRINT_AREA_BOTTOM: + sValue = "bottomMargin"; + break; + case text::RelOrientation::PAGE_FRAME: + default: + sValue = "page"; + break; + } + pFS->startElementNS(XML_wp14, XML_sizeRelV, XML_relativeFrom, sValue); pFS->startElementNS(XML_wp14, XML_pctHeight); pFS->writeEscaped( OUString::number(*pSdrObject->GetRelativeHeight() * 100 * oox::drawingml::PER_PERCENT)); |