From a4a301c67f4de992d2f4bc66721abd21ebd67494 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 11 Jan 2021 21:03:34 +0100 Subject: tdf#138995 DOCX import: fix handling of textbox zorders Regression from commit d379d18666aa42031359ca8eb34b0021960347ae (oox: import WPS shape with text as shape with textbox, 2014-06-18), the problem was that a textbox's shape + textframe are internally 2 sdr objects, so once GraphicZOrderHelper knows the current shape should be on top of a shape+frame pair, it should suggest a larger ZOrder. This is necessary till there is no setter version of SwTextBoxHelper::getOrdNum(), which would allow import filters to ignore this complexity, but that would be a larger change. (cherry picked from commit 200cd2b99bee18962a970edc5d059286f6c3ea0e) Change-Id: Ibbb1bcd9301eb369f25f211120f62be7c59b0fd2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109184 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sw/CppunitTest_sw_core_doc.mk | 1 + sw/qa/core/doc/data/textbox-zorder.docx | Bin 0 -> 5407 bytes sw/qa/core/doc/doc.cxx | 16 ++++++++++++++++ writerfilter/source/dmapper/GraphicHelpers.cxx | 14 ++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 sw/qa/core/doc/data/textbox-zorder.docx diff --git a/sw/CppunitTest_sw_core_doc.mk b/sw/CppunitTest_sw_core_doc.mk index ba2555099e3b..934ccf8eee6f 100644 --- a/sw/CppunitTest_sw_core_doc.mk +++ b/sw/CppunitTest_sw_core_doc.mk @@ -24,6 +24,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_core_doc, \ editeng \ sal \ sfx \ + svxcore \ sw \ swqahelper \ test \ diff --git a/sw/qa/core/doc/data/textbox-zorder.docx b/sw/qa/core/doc/data/textbox-zorder.docx new file mode 100644 index 000000000000..d5263f8bbd6b Binary files /dev/null and b/sw/qa/core/doc/data/textbox-zorder.docx differ diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx index f3bb4508189b..1bd9b4207444 100644 --- a/sw/qa/core/doc/doc.cxx +++ b/sw/qa/core/doc/doc.cxx @@ -113,6 +113,22 @@ CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testLocaleIndependentTemplate) ErrorRegistry::Reset(); } +CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testTextBoxZOrder) +{ + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "textbox-zorder.docx"); + SwFrameFormats& rFormats = *pDoc->GetSpzFrameFormats(); + CPPUNIT_ASSERT_EQUAL(static_cast(3), rFormats.size()); + const SwFrameFormat* pEllipse = rFormats[2]; + const SdrObject* pEllipseShape = pEllipse->FindRealSdrObject(); + // Make sure we test the right shape. + CPPUNIT_ASSERT_EQUAL(OUString("Shape3"), pEllipseShape->GetName()); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2 + // - Actual : 1 + // i.e. the ellipse was under the frame of the shape-frame pair, not on top of it. + CPPUNIT_ASSERT_EQUAL(static_cast(2), pEllipseShape->GetOrdNum()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/GraphicHelpers.cxx b/writerfilter/source/dmapper/GraphicHelpers.cxx index 0bd7354fd962..d4fc4b9a8c09 100644 --- a/writerfilter/source/dmapper/GraphicHelpers.cxx +++ b/writerfilter/source/dmapper/GraphicHelpers.cxx @@ -295,6 +295,20 @@ sal_Int32 GraphicZOrderHelper::findZOrder( sal_Int32 relativeHeight, bool bOldSt return 0; --it; itemZOrderOffset = 1; // after the topmost + + // Check if this shape has a textbox. If so, the textbox will have its own ZOrder, so + // suggest a larger offset. + bool bTextBox = false; + uno::Reference xShape = it->second; + uno::Reference xInfo = xShape->getPropertySetInfo(); + if (xInfo->hasPropertyByName("TextBox")) + { + xShape->getPropertyValue("TextBox") >>= bTextBox; + } + if (bTextBox) + { + ++itemZOrderOffset; + } } // SwXFrame::getPropertyValue throws uno::RuntimeException // when its GetFrameFormat() returns nullptr -- cgit