summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-08-08 17:58:20 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-08-08 19:18:19 +0200
commit587803ba46055d43b5b108be744fdde17aeabc7c (patch)
treead9aadbd187184c155ae409a7e47850001c6f395 /sw
parent47db30bdb35a86bf34d2574c9af3f06b1d2a8bd7 (diff)
sw TextGraphicObject: handle XBitmap for GraphicURL
This restores compatibility for API users who called getByName() on the bitmap table and expected that the result can be set as a value for the GraphicURL property. Changing the property type to cppu::UnoType<css::uno::Any>::get() is necessary, otherwise scripting languages figure out (via reflection) that the type doesn't match, and SwXFrame::setPropertyValue() is not called. Change-Id: Idd62f109e91dbaebf1138b9038f66c6c648d780e Reviewed-on: https://gerrit.libreoffice.org/58745 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/unowriter/unowriter.cxx33
-rw-r--r--sw/source/core/unocore/unoframe.cxx7
-rw-r--r--sw/source/core/unocore/unomap1.cxx2
3 files changed, 41 insertions, 1 deletions
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
index cde8b9b9c47d..96945d25a40f 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -22,10 +22,12 @@ class SwUnoWriter : public SwModelTestBase
public:
void testDefaultCharStyle();
void testGraphicDesciptorURL();
+ void testGraphicDesciptorURLBitmap();
CPPUNIT_TEST_SUITE(SwUnoWriter);
CPPUNIT_TEST(testDefaultCharStyle);
CPPUNIT_TEST(testGraphicDesciptorURL);
+ CPPUNIT_TEST(testGraphicDesciptorURLBitmap);
CPPUNIT_TEST_SUITE_END();
};
@@ -82,6 +84,37 @@ void SwUnoWriter::testGraphicDesciptorURL()
CPPUNIT_ASSERT(xGraphic.is());
}
+void SwUnoWriter::testGraphicDesciptorURLBitmap()
+{
+ loadURL("private:factory/swriter", nullptr);
+
+ // Load a bitmap into the bitmap table.
+ uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XNameContainer> xBitmaps(
+ xFactory->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY);
+ OUString aGraphicURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "test.jpg";
+ xBitmaps->insertByName("test", uno::makeAny(aGraphicURL));
+
+ // Create a graphic.
+ uno::Reference<beans::XPropertySet> xTextGraphic(
+ xFactory->createInstance("com.sun.star.text.TextGraphicObject"), uno::UNO_QUERY);
+ xTextGraphic->setPropertyValue("GraphicURL", xBitmaps->getByName("test"));
+ 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: setting GraphicURL to the result of getByName() did not
+ // work anymore.
+ 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 c16f1b301b20..15f4b88b01f8 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -2754,8 +2754,15 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan
if (m_pProps->GetProperty(FN_UNO_GRAPHIC_URL, 0, pGraphicURL))
{
OUString sGraphicURL;
+ uno::Reference<awt::XBitmap> xBitmap;
if (((*pGraphicURL) >>= sGraphicURL) && !sGraphicURL.isEmpty())
aGraphic = vcl::graphic::loadFromURL(sGraphicURL);
+ else if ((*pGraphicURL) >>= xBitmap)
+ {
+ uno::Reference<graphic::XGraphic> xGraphic(xBitmap, uno::UNO_QUERY);
+ if (xGraphic.is())
+ aGraphic = xGraphic;
+ }
}
const ::uno::Any* pGraphicAny;
diff --git a/sw/source/core/unocore/unomap1.cxx b/sw/source/core/unocore/unomap1.cxx
index 6716483ea1a8..de331a18cbf8 100644
--- a/sw/source/core/unocore/unomap1.cxx
+++ b/sw/source/core/unocore/unomap1.cxx
@@ -850,7 +850,7 @@ const SfxItemPropertyMapEntry* SwUnoPropertyMapProvider::GetGraphicPropertyMap(
{ OUString(UNO_NAME_REPLACEMENT_GRAPHIC), FN_UNO_REPLACEMENT_GRAPHIC, cppu::UnoType<css::graphic::XGraphic>::get(), 0, 0 },
{ OUString(UNO_NAME_GRAPHIC_FILTER), FN_UNO_GRAPHIC_FILTER, cppu::UnoType<OUString>::get(), 0, 0 },
{ OUString(UNO_NAME_GRAPHIC), FN_UNO_GRAPHIC, cppu::UnoType<css::graphic::XGraphic>::get(), 0, 0 },
- { OUString(UNO_NAME_GRAPHIC_URL), FN_UNO_GRAPHIC_URL, cppu::UnoType<OUString>::get(), 0, 0 },
+ { OUString(UNO_NAME_GRAPHIC_URL), FN_UNO_GRAPHIC_URL, cppu::UnoType<css::uno::Any>::get(), 0, 0 },
{ OUString(UNO_NAME_ACTUAL_SIZE), FN_UNO_ACTUAL_SIZE, cppu::UnoType<css::awt::Size>::get(), PropertyAttribute::READONLY, CONVERT_TWIPS},
{ OUString(UNO_NAME_CONTOUR_POLY_POLYGON), FN_PARAM_CONTOUR_PP, cppu::UnoType<css::drawing::PointSequenceSequence>::get(), PropertyAttribute::MAYBEVOID, 0 },
{ OUString(UNO_NAME_IS_PIXEL_CONTOUR), FN_UNO_IS_PIXEL_CONTOUR, cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },