tdf#138995 DOCX import: fix handling of textbox zorders

Regression from commit d379d18666 (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.

Change-Id: Ibbb1bcd9301eb369f25f211120f62be7c59b0fd2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109111
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
This commit is contained in:
Miklos Vajna
2021-01-12 16:07:41 +01:00
parent f2e04fe98e
commit 200cd2b99b
4 changed files with 31 additions and 0 deletions
+1
View File
@@ -24,6 +24,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_core_doc, \
editeng \
sal \
sfx \
svxcore \
sw \
swqahelper \
test \
Binary file not shown.
+16
View File
@@ -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: */
@@ -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