From c2726c29b233b8fa7fbd390aafe149bdf7e94b07 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 14 Dec 2021 13:51:14 +0100 Subject: [PATCH] sw ODF shape import: improve is-textbox check This builds on top of commit 28d67b792724a23015dec32fb0278b729f676736 (tdf#107776 sw ODF shape import: make is-textbox check more strict, 2019-08-26). Before that commit, any non-empty parent style name on a shape resulted in an sw textbox. After that commit, we filtered out Writer images by checking for the Frame parent style name. The problem with this approach is that in case two documents are to be merged together, then it's reasonable to rename the Frame style, but then the complex content inside the shape gets lost. Fix the problem by going with a middle ground: require Frame as a prefix, but allow other names as well. This gets e.g. FrameX to work without breaking the "reject Graphics" use-case. Change-Id: Id59ed28a64a9398f2f1620f69b5f148d65e6c95a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126828 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- xmloff/qa/unit/data/table-in-shape.fodt | 22 ++++++++++++++++++++++ xmloff/qa/unit/draw.cxx | 24 ++++++++++++++++++++++++ xmloff/source/draw/ximpshap.cxx | 4 +++- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 xmloff/qa/unit/data/table-in-shape.fodt diff --git a/xmloff/qa/unit/data/table-in-shape.fodt b/xmloff/qa/unit/data/table-in-shape.fodt new file mode 100644 index 000000000000..44c2bcb05db2 --- /dev/null +++ b/xmloff/qa/unit/data/table-in-shape.fodt @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + A1 + + + diff --git a/xmloff/qa/unit/draw.cxx b/xmloff/qa/unit/draw.cxx index f13a60082d7d..fc07053cbacf 100644 --- a/xmloff/qa/unit/draw.cxx +++ b/xmloff/qa/unit/draw.cxx @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include @@ -218,6 +220,28 @@ CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testReferToTheme) "color-lum-off"); } +CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testTableInShape) +{ + // Given a document with a shape with a "FrameX" parent style (starts with Frame, but is not + // Frame): + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "table-in-shape.fodt"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure the table inside the shape is not lost: + uno::Reference xDrawPageSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + uno::Reference xText(xShape->getText(), uno::UNO_QUERY); + uno::Reference xEnum = xText->createEnumeration(); + uno::Reference xTable(xEnum->nextElement(), uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have crashed, as xTable was an empty + // reference, i.e. the table inside the shape was lost. + uno::Reference xCell(xTable->getCellByName("A1"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("A1"), xCell->getString()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx index c1f93885c9c7..4d2dec38a3c8 100644 --- a/xmloff/source/draw/ximpshap.cxx +++ b/xmloff/source/draw/ximpshap.cxx @@ -3503,7 +3503,9 @@ SdXMLCustomShapeContext::SdXMLCustomShapeContext( rtl::Reference xTxtImport = GetImport().GetTextImport(); XMLPropStyleContext* pStyle = xTxtImport->FindAutoFrameStyle(aStyleName); // Note that this an API name, so intentionally not localized. - if (pStyle && pStyle->GetParentName() == "Frame") + // Also allow other Frame styles with the same prefix, we just want to reject + // Graphics after all. + if (pStyle && pStyle->GetParentName().startsWith("Frame")) { mbTextBox = true; break;