summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-01-11 21:03:34 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2021-01-14 08:34:42 +0100
commita4a301c67f4de992d2f4bc66721abd21ebd67494 (patch)
tree1384c9398e82c768c86e8582e9c3f0f10a7a4b98
parentf9c3a734221228cdf5a52ed6ebf9c0a3c1d44607 (diff)
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 <xiscofauli@libreoffice.org>
-rw-r--r--sw/CppunitTest_sw_core_doc.mk1
-rw-r--r--sw/qa/core/doc/data/textbox-zorder.docxbin0 -> 5407 bytes
-rw-r--r--sw/qa/core/doc/doc.cxx16
-rw-r--r--writerfilter/source/dmapper/GraphicHelpers.cxx14
4 files changed, 31 insertions, 0 deletions
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
--- /dev/null
+++ b/sw/qa/core/doc/data/textbox-zorder.docx
Binary files 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<size_t>(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<sal_uInt32>(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<beans::XPropertySet> xShape = it->second;
+ uno::Reference<beans::XPropertySetInfo> xInfo = xShape->getPropertySetInfo();
+ if (xInfo->hasPropertyByName("TextBox"))
+ {
+ xShape->getPropertyValue("TextBox") >>= bTextBox;
+ }
+ if (bTextBox)
+ {
+ ++itemZOrderOffset;
+ }
}
// SwXFrame::getPropertyValue throws uno::RuntimeException
// when its GetFrameFormat() returns nullptr