diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-08-07 11:06:30 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-08-07 12:45:46 +0200 |
commit | bba0ccd743a3d023e4829155571cdf0318fcb81c (patch) | |
tree | a6c286027b54e5abdcfee29556af49376280b0fa /sw | |
parent | c57191e0c45f9735a33953d6b95d54b0e10c876f (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.
Change-Id: I52a7f96e820f614d9d031df3ba03c794984ad68b
Reviewed-on: https://gerrit.libreoffice.org/58669
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/unowriter/data/test.jpg | bin | 0 -> 1136 bytes | |||
-rw-r--r-- | sw/qa/extras/unowriter/unowriter.cxx | 35 | ||||
-rw-r--r-- | sw/source/core/unocore/unoframe.cxx | 10 |
3 files changed, 45 insertions, 0 deletions
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 index 59a045586423..cde8b9b9c47d 100644 --- a/sw/qa/extras/unowriter/unowriter.cxx +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -9,15 +9,23 @@ #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 testDefaultCharStyle(); + void testGraphicDesciptorURL(); CPPUNIT_TEST_SUITE(SwUnoWriter); CPPUNIT_TEST(testDefaultCharStyle); + CPPUNIT_TEST(testGraphicDesciptorURL); CPPUNIT_TEST_SUITE_END(); }; @@ -47,6 +55,33 @@ void SwUnoWriter::testDefaultCharStyle() getProperty<awt::FontSlant>(xCursorProps, "CharPosture")); } +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(); diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index bf25aeb4d4f7..c16f1b301b20 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -2748,6 +2748,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) |