Kaydet (Commit) 587803ba authored tarafından Miklos Vajna's avatar Miklos Vajna

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/58745Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins
üst 47db30bd
...@@ -22,10 +22,12 @@ class SwUnoWriter : public SwModelTestBase ...@@ -22,10 +22,12 @@ class SwUnoWriter : public SwModelTestBase
public: public:
void testDefaultCharStyle(); void testDefaultCharStyle();
void testGraphicDesciptorURL(); void testGraphicDesciptorURL();
void testGraphicDesciptorURLBitmap();
CPPUNIT_TEST_SUITE(SwUnoWriter); CPPUNIT_TEST_SUITE(SwUnoWriter);
CPPUNIT_TEST(testDefaultCharStyle); CPPUNIT_TEST(testDefaultCharStyle);
CPPUNIT_TEST(testGraphicDesciptorURL); CPPUNIT_TEST(testGraphicDesciptorURL);
CPPUNIT_TEST(testGraphicDesciptorURLBitmap);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; };
...@@ -82,6 +84,37 @@ void SwUnoWriter::testGraphicDesciptorURL() ...@@ -82,6 +84,37 @@ void SwUnoWriter::testGraphicDesciptorURL()
CPPUNIT_ASSERT(xGraphic.is()); 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_TEST_SUITE_REGISTRATION(SwUnoWriter);
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
...@@ -2754,8 +2754,15 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan ...@@ -2754,8 +2754,15 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan
if (m_pProps->GetProperty(FN_UNO_GRAPHIC_URL, 0, pGraphicURL)) if (m_pProps->GetProperty(FN_UNO_GRAPHIC_URL, 0, pGraphicURL))
{ {
OUString sGraphicURL; OUString sGraphicURL;
uno::Reference<awt::XBitmap> xBitmap;
if (((*pGraphicURL) >>= sGraphicURL) && !sGraphicURL.isEmpty()) if (((*pGraphicURL) >>= sGraphicURL) && !sGraphicURL.isEmpty())
aGraphic = vcl::graphic::loadFromURL(sGraphicURL); 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; const ::uno::Any* pGraphicAny;
......
...@@ -850,7 +850,7 @@ const SfxItemPropertyMapEntry* SwUnoPropertyMapProvider::GetGraphicPropertyMap( ...@@ -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_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_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), 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_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_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 }, { OUString(UNO_NAME_IS_PIXEL_CONTOUR), FN_UNO_IS_PIXEL_CONTOUR, cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment