summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-08-12 09:06:14 +0200
committerGülşah Köse <gulsah.kose@collabora.com>2021-04-09 11:36:35 +0200
commit35c51033317e7a7df73b72fa95aab9c765e7f542 (patch)
tree7d02d0bf25ea843a59eed941ecaacf4a1aad4dc7
parentfa38daf5036fbcf32d3c561840b8e249faba02f2 (diff)
tdf#135144 xmloff textbox: fix export style name to be consitent with import
Regression from commit 28d67b792724a23015dec32fb0278b729f676736 (tdf#107776 sw ODF shape import: make is-textbox check more strict, 2019-08-26), the problem was that in case the import side in SdXMLCustomShapeContext expects a fixed "Frame" parent style name, then the export side should go with that name as well. Fix the problem by simplifying XMLShapeExport::collectShapeAutoStyles(), which initially assumed that the string may be localized, so try to look it up: instead just use the fixed string that the import side will look for. This solves all problem which may stem from a parent style name which is non-empty, but other than Frame. (cherry picked from commit 347d05edd8910907ae185c61c1e56eee139b3c09) Change-Id: I8146440c591d3dd5a904d243d85741d704711e9c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100595 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113787 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Gülşah Köse <gulsah.kose@collabora.com>
-rw-r--r--xmloff/CppunitTest_xmloff_draw.mk45
-rw-r--r--xmloff/Module_xmloff.mk1
-rw-r--r--xmloff/qa/unit/data/textbox-loss.docxbin0 -> 42192 bytes
-rw-r--r--xmloff/qa/unit/draw.cxx79
-rw-r--r--xmloff/source/draw/shapeexport.cxx14
5 files changed, 127 insertions, 12 deletions
diff --git a/xmloff/CppunitTest_xmloff_draw.mk b/xmloff/CppunitTest_xmloff_draw.mk
new file mode 100644
index 000000000000..4ebac5c27a3b
--- /dev/null
+++ b/xmloff/CppunitTest_xmloff_draw.mk
@@ -0,0 +1,45 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,xmloff_draw))
+
+$(eval $(call gb_CppunitTest_use_externals,xmloff_draw,\
+ boost_headers \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,xmloff_draw, \
+ xmloff/qa/unit/draw \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,xmloff_draw, \
+ comphelper \
+ cppu \
+ embobj \
+ sal \
+ test \
+ unotest \
+ utl \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,xmloff_draw))
+
+$(eval $(call gb_CppunitTest_use_ure,xmloff_draw))
+$(eval $(call gb_CppunitTest_use_vcl,xmloff_draw))
+
+$(eval $(call gb_CppunitTest_use_rdb,xmloff_draw,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,xmloff_draw,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,xmloff_draw))
+
+# vim: set noet sw=4 ts=4:
diff --git a/xmloff/Module_xmloff.mk b/xmloff/Module_xmloff.mk
index fe69b86b09f6..8f5853c9da41 100644
--- a/xmloff/Module_xmloff.mk
+++ b/xmloff/Module_xmloff.mk
@@ -31,6 +31,7 @@ $(eval $(call gb_Module_add_check_targets,xmloff,\
CppunitTest_xmloff_uxmloff) \
CppunitTest_xmloff_style \
CppunitTest_xmloff_text \
+ CppunitTest_xmloff_draw \
))
$(eval $(call gb_Module_add_subsequentcheck_targets,xmloff,\
diff --git a/xmloff/qa/unit/data/textbox-loss.docx b/xmloff/qa/unit/data/textbox-loss.docx
new file mode 100644
index 000000000000..9190e662f851
--- /dev/null
+++ b/xmloff/qa/unit/data/textbox-loss.docx
Binary files differ
diff --git a/xmloff/qa/unit/draw.cxx b/xmloff/qa/unit/draw.cxx
new file mode 100644
index 000000000000..cd19c878550e
--- /dev/null
+++ b/xmloff/qa/unit/draw.cxx
@@ -0,0 +1,79 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/bootstrapfixture.hxx>
+#include <unotest/macros_test.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+
+#include <unotools/mediadescriptor.hxx>
+#include <unotools/tempfile.hxx>
+
+using namespace ::com::sun::star;
+
+char const DATA_DIRECTORY[] = "/xmloff/qa/unit/data/";
+
+/// Covers xmloff/source/draw/ fixes.
+class XmloffDrawTest : public test::BootstrapFixture, public unotest::MacrosTest
+{
+private:
+ uno::Reference<lang::XComponent> mxComponent;
+
+public:
+ void setUp() override;
+ void tearDown() override;
+ uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
+};
+
+void XmloffDrawTest::setUp()
+{
+ test::BootstrapFixture::setUp();
+
+ mxDesktop.set(frame::Desktop::create(getComponentContext()));
+}
+
+void XmloffDrawTest::tearDown()
+{
+ if (mxComponent.is())
+ mxComponent->dispose();
+
+ test::BootstrapFixture::tearDown();
+}
+
+CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testTextBoxLoss)
+{
+ // Load a document that has a shape with a textbox in it. Save it to ODF and reload.
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "textbox-loss.docx";
+ getComponent() = loadFromDesktop(aURL);
+ uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY);
+ utl::TempFile aTempFile;
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= OUString("writer8");
+ xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+ getComponent()->dispose();
+ getComponent() = loadFromDesktop(aTempFile.GetURL());
+
+ // Make sure that the shape is still a textbox.
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(getComponent(), uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
+ uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+ bool bTextBox = false;
+ xShape->getPropertyValue("TextBox") >>= bTextBox;
+
+ // Without the accompanying fix in place, this test would have failed, as the shape only had
+ // editeng text, loosing the image part of the shape text.
+ CPPUNIT_ASSERT(bTextBox);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/draw/shapeexport.cxx b/xmloff/source/draw/shapeexport.cxx
index 9d8a04c55b1f..6f33aee76805 100644
--- a/xmloff/source/draw/shapeexport.cxx
+++ b/xmloff/source/draw/shapeexport.cxx
@@ -382,18 +382,8 @@ void XMLShapeExport::collectShapeAutoStyles(const uno::Reference< drawing::XShap
if (aParentName.isEmpty() && xPropertySetInfo->hasPropertyByName("TextBox") && xPropSet->getPropertyValue("TextBox").hasValue() && xPropSet->getPropertyValue("TextBox").get<bool>())
{
// Shapes with a Writer TextBox always have a parent style.
- // If there would be none, then just assign the first available.
- uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(GetExport().GetModel(), uno::UNO_QUERY);
- if (xStyleFamiliesSupplier.is()) // tdf#108231
- {
- uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
- uno::Reference<container::XNameAccess> xFrameStyles = xStyleFamilies->getByName("FrameStyles").get< uno::Reference<container::XNameAccess> >();
- uno::Sequence<OUString> aFrameStyles = xFrameStyles->getElementNames();
- if (aFrameStyles.hasElements())
- {
- aParentName = aFrameStyles[0];
- }
- }
+ // If there would be none, then assign the default one.
+ aParentName = "Frame";
}
// filter propset