[Libreoffice-commits] core.git: Branch 'libreoffice-6-1' - sw/qa sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Sep 3 14:32:14 UTC 2018


 sw/qa/extras/unowriter/unowriter.cxx |   33 +++++++++++++++++++++++++++++++++
 sw/source/core/unocore/unoframe.cxx  |    7 +++++++
 sw/source/core/unocore/unomap1.cxx   |    2 +-
 3 files changed, 41 insertions(+), 1 deletion(-)

New commits:
commit 2fb37f232849db1f0ae852203fef4d4a40145755
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Wed Aug 8 17:58:20 2018 +0200
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Mon Sep 3 16:31:52 2018 +0200

    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 at collabora.co.uk>
    Tested-by: Jenkins
    (cherry picked from commit 587803ba46055d43b5b108be744fdde17aeabc7c)
    Reviewed-on: https://gerrit.libreoffice.org/59850
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
index 9b993618769f..ca1e8cab28fd 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -21,9 +21,11 @@ class SwUnoWriter : public SwModelTestBase
 {
 public:
     void testGraphicDesciptorURL();
+    void testGraphicDesciptorURLBitmap();
 
     CPPUNIT_TEST_SUITE(SwUnoWriter);
     CPPUNIT_TEST(testGraphicDesciptorURL);
+    CPPUNIT_TEST(testGraphicDesciptorURLBitmap);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -54,6 +56,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 c4a1b7dfbf6e..b0de9f773463 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -2753,8 +2753,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 10365bd83082..273edc7c4dab 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 },


More information about the Libreoffice-commits mailing list