diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-08-07 11:06:30 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-09-03 16:30:52 +0200 |
commit | d687d1bbba3f7226f3a533c31b2c84d833331755 (patch) | |
tree | af573d02e05f2309a6cec4d9727b7198cd4b3310 /sw | |
parent | 481730bc4c9d63e831c088d9862b0f50f2da209f (diff) |
sw TextGraphicObject: fix GraphicURL handling in the descriptor
Commit dfee7d93b4e863d673c45921f79bb876b5738ea6 (sw: get rid of
FN_UNO_GRAPHIC_U_R_L and "GraphicURL" property, 2018-03-08) removed
support for string-based graphic references, then a later commit
restored the setter. But one scenario (when setting the graphic URL
before inserting the text graphic object) was still unsupported for real
URL setter; restore that as well.
(cherry picked from commit bba0ccd743a3d023e4829155571cdf0318fcb81c)
Conflicts:
sw/qa/extras/unowriter/unowriter.cxx
Change-Id: I52a7f96e820f614d9d031df3ba03c794984ad68b
Reviewed-on: https://gerrit.libreoffice.org/59849
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/CppunitTest_sw_unowriter.mk | 76 | ||||
-rw-r--r-- | sw/Module_sw.mk | 1 | ||||
-rw-r--r-- | sw/qa/extras/unowriter/data/test.jpg | bin | 0 -> 1136 bytes | |||
-rw-r--r-- | sw/qa/extras/unowriter/unowriter.cxx | 60 | ||||
-rw-r--r-- | sw/source/core/unocore/unoframe.cxx | 10 |
5 files changed, 147 insertions, 0 deletions
diff --git a/sw/CppunitTest_sw_unowriter.mk b/sw/CppunitTest_sw_unowriter.mk new file mode 100644 index 000000000000..a51f4ac38000 --- /dev/null +++ b/sw/CppunitTest_sw_unowriter.mk @@ -0,0 +1,76 @@ +# -*- 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,sw_unowriter)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sw_unowriter, \ + sw/qa/extras/unowriter/unowriter \ +)) + +# note: this links msword only for the reason to have a order dependency, +# because "make sw.check" will not see the dependency through services.rdb +$(eval $(call gb_CppunitTest_use_libraries,sw_unowriter, \ + comphelper \ + cppu \ + cppuhelper \ + editeng \ + msword \ + sal \ + sfx \ + svl \ + svt \ + svxcore \ + sw \ + test \ + unotest \ + vcl \ + tl \ + utl \ +)) + +$(eval $(call gb_CppunitTest_use_externals,sw_unowriter,\ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_set_include,sw_unowriter,\ + -I$(SRCDIR)/sw/inc \ + -I$(SRCDIR)/sw/source/core/inc \ + -I$(SRCDIR)/sw/qa/extras/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_api,sw_unowriter,\ + udkapi \ + offapi \ + oovbaapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,sw_unowriter)) +$(eval $(call gb_CppunitTest_use_vcl,sw_unowriter)) + +$(eval $(call gb_CppunitTest_use_rdb,sw_unowriter,services)) + +$(eval $(call gb_CppunitTest_use_configuration,sw_unowriter)) + +$(eval $(call gb_CppunitTest_use_uiconfigs,sw_unowriter, \ + modules/swriter \ +)) + +$(call gb_CppunitTest_get_target,sw_unowriter): \ + $(call gb_Library_get_target,textconv_dict) + +ifneq ($(filter MORE_FONTS,$(BUILD_TYPE)),) +$(call gb_CppunitTest_get_target,sw_unowriter): \ + $(call gb_ExternalPackage_get_target,fonts_liberation) +endif + +# vim: set noet sw=4 ts=4: diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk index 1e56264ac8de..d36b96a94cfe 100644 --- a/sw/Module_sw.mk +++ b/sw/Module_sw.mk @@ -94,6 +94,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\ CppunitTest_sw_globalfilter \ CppunitTest_sw_accessible_relation_set \ CppunitTest_sw_apitests \ + CppunitTest_sw_unowriter \ )) ifneq ($(ENABLE_HEADLESS),TRUE) diff --git a/sw/qa/extras/unowriter/data/test.jpg b/sw/qa/extras/unowriter/data/test.jpg Binary files differnew file mode 100644 index 000000000000..12b393569efb --- /dev/null +++ b/sw/qa/extras/unowriter/data/test.jpg diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx new file mode 100644 index 000000000000..9b993618769f --- /dev/null +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -0,0 +1,60 @@ +/* -*- 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 <swmodeltestbase.hxx> +#include <com/sun/star/awt/FontSlant.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> + +namespace +{ +char const DATA_DIRECTORY[] = "/sw/qa/extras/unowriter/data/"; +} + +/// Test to assert UNO API call results of Writer. +class SwUnoWriter : public SwModelTestBase +{ +public: + void testGraphicDesciptorURL(); + + CPPUNIT_TEST_SUITE(SwUnoWriter); + CPPUNIT_TEST(testGraphicDesciptorURL); + CPPUNIT_TEST_SUITE_END(); +}; + +void SwUnoWriter::testGraphicDesciptorURL() +{ + loadURL("private:factory/swriter", nullptr); + + // Create a graphic object, but don't insert it yet. + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xTextGraphic( + xFactory->createInstance("com.sun.star.text.TextGraphicObject"), uno::UNO_QUERY); + + // Set an URL on it. + OUString aGraphicURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "test.jpg"; + xTextGraphic->setPropertyValue("GraphicURL", uno::makeAny(aGraphicURL)); + xTextGraphic->setPropertyValue("AnchorType", + uno::makeAny(text::TextContentAnchorType_AT_CHARACTER)); + + // Insert it. + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xBodyText(xTextDocument->getText(), uno::UNO_QUERY); + uno::Reference<text::XTextCursor> xCursor(xBodyText->createTextCursor()); + uno::Reference<text::XTextContent> xTextContent(xTextGraphic, uno::UNO_QUERY); + xBodyText->insertTextContent(xCursor, xTextContent, false); + + // This failed, the graphic object had no graphic. + auto xGraphic = getProperty<uno::Reference<graphic::XGraphic>>(getShape(1), "Graphic"); + CPPUNIT_ASSERT(xGraphic.is()); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(SwUnoWriter); +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index 663b13162498..c4a1b7dfbf6e 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -2747,6 +2747,16 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan { UnoActionContext aActionContext(pDoc); Graphic aGraphic; + + // Read graphic URL from the descriptor, if it has any. + const ::uno::Any* pGraphicURL; + if (m_pProps->GetProperty(FN_UNO_GRAPHIC_URL, 0, pGraphicURL)) + { + OUString sGraphicURL; + if (((*pGraphicURL) >>= sGraphicURL) && !sGraphicURL.isEmpty()) + aGraphic = vcl::graphic::loadFromURL(sGraphicURL); + } + const ::uno::Any* pGraphicAny; const bool bHasGraphic = m_pProps->GetProperty(FN_UNO_GRAPHIC, 0, pGraphicAny); if (bHasGraphic) |