diff options
author | Regényi Balázs <regenyi.balazs+gerrit@gmail.com> | 2020-06-22 10:28:15 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-07-02 12:32:33 +0200 |
commit | a85c2504c002dff069c129ab244cb2ba5820943d (patch) | |
tree | 1a391f6ed056c95b9d7b5f18988ab8650723ffc5 /sw | |
parent | bedc5bf125bdc0377b7dc845192b274e90945e13 (diff) |
tdf#123324 DOCX import: fix shape height relative to top page margin
using UNO API RelativeHeightRelation and the associated
lo-ext attribute for OpenDocument export.
See commit 43d7f4e3640c5e370fd1204739c2b0c7eb5f40e4
(offapi: document the 4 new properties which are no longer read-only).
Co-authored-by: Szabolcs Tóth
Change-Id: Ibaba4b3762de5a70506dacd85a818b8972b18144
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96869
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginHasHeader.docx | bin | 0 -> 20882 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginNoHeader.docx | bin | 0 -> 14683 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport14.cxx | 36 | ||||
-rw-r--r-- | sw/source/core/inc/pagefrm.hxx | 1 | ||||
-rw-r--r-- | sw/source/core/layout/anchoreddrawobject.cxx | 9 | ||||
-rw-r--r-- | sw/source/core/layout/pagechg.cxx | 12 |
6 files changed, 58 insertions, 0 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginHasHeader.docx b/sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginHasHeader.docx Binary files differnew file mode 100644 index 000000000000..b978eec993c7 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginHasHeader.docx diff --git a/sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginNoHeader.docx b/sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginNoHeader.docx Binary files differnew file mode 100644 index 000000000000..70c2793cbf96 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginNoHeader.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index 167c05111a51..3ca1a456182f 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -1163,6 +1163,42 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf108505, "tdf108505.docx") getProperty<OUString>(xText, "CharFontName")); } +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); +} + +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. + + // 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 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); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx index 3c7f29f52ad0..a9f642c1f03e 100644 --- a/sw/source/core/inc/pagefrm.hxx +++ b/sw/source/core/inc/pagefrm.hxx @@ -330,6 +330,7 @@ public: /// If false is returned, then the caller should handle negative difference as (at least) zero difference instead. bool CheckPageHeightValidForHideWhitespace(SwTwips nDiff); + const SwHeaderFrame* GetHeaderFrame() const; const SwFooterFrame* GetFooterFrame() const; }; diff --git a/sw/source/core/layout/anchoreddrawobject.cxx b/sw/source/core/layout/anchoreddrawobject.cxx index 1af32ed2fa80..1ea69271f202 100644 --- a/sw/source/core/layout/anchoreddrawobject.cxx +++ b/sw/source/core/layout/anchoreddrawobject.cxx @@ -688,6 +688,15 @@ SwRect SwAnchoredDrawObject::GetObjBoundRect() const if (GetDrawObj()->GetRelativeHeightRelation() == text::RelOrientation::FRAME) // Exclude margins. nHeight = GetPageFrame()->getFramePrintArea().SVRect().GetHeight(); + else if (GetDrawObj()->GetRelativeHeightRelation() == text::RelOrientation::PAGE_PRINT_AREA) + { + // count required height: print area top = top margin + header + SwRect aHeaderRect; + const SwHeaderFrame* pHeaderFrame = GetPageFrame()->GetHeaderFrame(); + if (pHeaderFrame) + aHeaderRect = pHeaderFrame->GetPaintArea(); + nHeight = GetPageFrame()->GetTopMargin() + aHeaderRect.Height(); + } else if (GetDrawObj()->GetRelativeHeightRelation() == text::RelOrientation::PAGE_PRINT_AREA_BOTTOM) { // count required height: print area bottom = bottom margin + footer diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx index a3188eb2a5ca..ebcf239ef580 100644 --- a/sw/source/core/layout/pagechg.cxx +++ b/sw/source/core/layout/pagechg.cxx @@ -2512,6 +2512,18 @@ bool SwPageFrame::CheckPageHeightValidForHideWhitespace(SwTwips nDiff) return true; } +const SwHeaderFrame* SwPageFrame::GetHeaderFrame() const +{ + const SwFrame* pLowerFrame = Lower(); + while (pLowerFrame) + { + if (pLowerFrame->IsHeaderFrame()) + return dynamic_cast<const SwHeaderFrame*>(pLowerFrame); + pLowerFrame = pLowerFrame->GetNext(); + } + return nullptr; +} + const SwFooterFrame* SwPageFrame::GetFooterFrame() const { const SwFrame* pLowerFrame = Lower(); |