diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-08-12 09:06:14 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-08-22 15:36:12 +0200 |
commit | 25c20d74c3f3cf99648debb2bc7d752e33917cae (patch) | |
tree | 465b6521c7590cb4ac0f0b23700e891c277561b7 | |
parent | 3ff1220c4a6a0b2e978ba722c9d65485ed2cd8e7 (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>
(cherry picked from commit 9902f6f7e567e6a1585833c751f5c19bf559705c)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100701
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | xmloff/CppunitTest_xmloff_draw.mk | 45 | ||||
-rw-r--r-- | xmloff/Module_xmloff.mk | 1 | ||||
-rw-r--r-- | xmloff/qa/unit/data/textbox-loss.docx | bin | 0 -> 42192 bytes | |||
-rw-r--r-- | xmloff/qa/unit/draw.cxx | 79 | ||||
-rw-r--r-- | xmloff/source/draw/shapeexport.cxx | 14 |
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 Binary files differnew file mode 100644 index 000000000000..9190e662f851 --- /dev/null +++ b/xmloff/qa/unit/data/textbox-loss.docx diff --git a/xmloff/qa/unit/draw.cxx b/xmloff/qa/unit/draw.cxx new file mode 100644 index 000000000000..afffa65354e0 --- /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(mxComponentContext)); +} + +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 aeb12d61c1c8..90daa243c741 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 |