[Libreoffice-commits] core.git: include/editeng include/svx sd/qa svx/source sw/inc sw/source xmloff/source

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Thu Feb 22 08:28:41 UTC 2018


 include/editeng/unoprnms.hxx        |    2 +-
 include/svx/unoshprp.hxx            |    4 ++--
 sd/qa/unit/export-tests.cxx         |    6 +++---
 svx/source/unodraw/unoshap2.cxx     |    8 +++-----
 sw/inc/unoprnms.hxx                 |    1 +
 sw/source/core/unocore/unoframe.cxx |   21 +++++++++++++++++++++
 sw/source/core/unocore/unomap1.cxx  |    1 +
 xmloff/source/draw/shapeexport.cxx  |   27 +++++++++++++--------------
 xmloff/source/text/txtparae.cxx     |   23 +++++++++++------------
 9 files changed, 56 insertions(+), 37 deletions(-)

New commits:
commit 1cf55d6397418dd3cd86eae59c2f75085dbb0d51
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Mon Feb 19 21:52:33 2018 +0900

    Replace "ReplacementGraphicURL" with "ReplacementGraphic" property
    
    To transport the replacement graphic we use "ReplacementGraphicURL"
    property, but as it uses an GraphicObject URL it needs to be
    replaced. The new "ReplacementGraphic" does this with an XGraphic
    object as instead of the String URL.
    
    Change-Id: Iddf01c9aecb2a31a467e7b9d399495e0428d1859
    Reviewed-on: https://gerrit.libreoffice.org/49993
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/editeng/unoprnms.hxx b/include/editeng/unoprnms.hxx
index 44b4ce8843c9..6c98921dddaf 100644
--- a/include/editeng/unoprnms.hxx
+++ b/include/editeng/unoprnms.hxx
@@ -162,7 +162,7 @@
 
 #define UNO_NAME_GRAPHOBJ_FILLBITMAP            "GraphicObjectFillBitmap"
 #define UNO_NAME_GRAPHOBJ_GRAFURL               "GraphicURL"
-#define UNO_NAME_GRAPHOBJ_REPLACEMENTGRAFURL    "ReplacementGraphicURL"
+#define UNO_NAME_GRAPHOBJ_REPLACEMENT_GRAPHIC   "ReplacementGraphic"
 #define UNO_NAME_GRAPHOBJ_GRAFSTREAMURL         "GraphicStreamURL"
 #define UNO_NAME_GRAPHOBJ_URLPREFIX             "vnd.sun.star.GraphicObject:"
 #define UNO_NAME_GRAPHOBJ_URLPKGPREFIX          "vnd.sun.star.Package:"
diff --git a/include/svx/unoshprp.hxx b/include/svx/unoshprp.hxx
index b68e473e339e..9fea5f41ab73 100644
--- a/include/svx/unoshprp.hxx
+++ b/include/svx/unoshprp.hxx
@@ -115,7 +115,7 @@
 #define OWN_ATTR_BASE_GEOMETRY                  (OWN_ATTR_VALUE_START+47)
 
 /// reuse attr slots for GraphicObject which will never be used together with graphic object
-#define OWN_ATTR_REPLACEMENTGRAFURL             (OWN_ATTR_VALUE_START+14)
+#define OWN_ATTR_REPLACEMENT_GRAPHIC            (OWN_ATTR_VALUE_START+14)
 
 #define OWN_ATTR_APPLET_DOCBASE                 (OWN_ATTR_VALUE_START+48)
 #define OWN_ATTR_APPLET_CODEBASE                (OWN_ATTR_VALUE_START+49)
@@ -428,7 +428,7 @@
     SPECIAL_GRAPHOBJ_PROPERTIES_DEFAULTS \
     { OUString(UNO_NAME_GRAPHIC_GRAPHICCROP),           SDRATTR_GRAFCROP            , ::cppu::UnoType<css::text::GraphicCrop>::get(),        0,  0 }, \
     { OUString(UNO_NAME_GRAPHOBJ_GRAFURL),              OWN_ATTR_GRAFURL            , ::cppu::UnoType<OUString>::get(), 0, 0 }, \
-    { OUString(UNO_NAME_GRAPHOBJ_REPLACEMENTGRAFURL),   OWN_ATTR_REPLACEMENTGRAFURL , ::cppu::UnoType<OUString>::get(), 0, 0 }, \
+    { OUString(UNO_NAME_GRAPHOBJ_REPLACEMENT_GRAPHIC),  OWN_ATTR_REPLACEMENT_GRAPHIC, cppu::UnoType<css::graphic::XGraphic>::get()  ,   0,     0}, \
     { OUString(UNO_NAME_GRAPHOBJ_GRAFSTREAMURL),        OWN_ATTR_GRAFSTREAMURL      , ::cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 }, \
     { OUString(UNO_NAME_GRAPHOBJ_FILLBITMAP),           OWN_ATTR_VALUE_FILLBITMAP   , cppu::UnoType<css::awt::XBitmap>::get()  ,    0,     0},    \
     { OUString(UNO_NAME_GRAPHOBJ_GRAPHIC),              OWN_ATTR_VALUE_GRAPHIC      , cppu::UnoType<css::graphic::XGraphic>::get()  ,   0,     0}, \
diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx
index 8994f0d8883c..e0c31b2b0da3 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -736,9 +736,9 @@ void SdExportTest::testEmbeddedPdf()
     xShell = saveAndReload( xShell.get(), ODP );
     uno::Reference<drawing::XDrawPage> xPage = getPage(0, xShell);
     uno::Reference<beans::XPropertySet> xShape(xPage->getByIndex(0), uno::UNO_QUERY);
-    OUString aReplacementGraphicURL;
-    xShape->getPropertyValue("ReplacementGraphicURL") >>= aReplacementGraphicURL;
-    CPPUNIT_ASSERT(!aReplacementGraphicURL.isEmpty());
+    uno::Reference<graphic::XGraphic> xGraphic;
+    xShape->getPropertyValue("ReplacementGraphic") >>= xGraphic;
+    CPPUNIT_ASSERT(xGraphic.is());
     xShell->DoClose();
 #endif
 }
diff --git a/svx/source/unodraw/unoshap2.cxx b/svx/source/unodraw/unoshap2.cxx
index b8500ac7643b..79e7c24296b6 100644
--- a/svx/source/unodraw/unoshap2.cxx
+++ b/svx/source/unodraw/unoshap2.cxx
@@ -1579,15 +1579,13 @@ bool SvxGraphicObject::getPropertyValueImpl( const OUString& rName, const SfxIte
         break;
     }
 
-    case OWN_ATTR_REPLACEMENTGRAFURL:
+    case OWN_ATTR_REPLACEMENT_GRAPHIC:
     {
         const GraphicObject* pGrafObj = static_cast< SdrGrafObj* >(mpObj.get())->GetReplacementGraphicObject();
 
-        if(pGrafObj)
+        if (pGrafObj)
         {
-            OUString aURL(UNO_NAME_GRAPHOBJ_URLPREFIX);
-            aURL += OStringToOUString(pGrafObj->GetUniqueID(), RTL_TEXTENCODING_ASCII_US);
-            rValue <<= aURL;
+            rValue <<= pGrafObj->GetGraphic().GetXGraphic();
         }
 
         break;
diff --git a/sw/inc/unoprnms.hxx b/sw/inc/unoprnms.hxx
index 21e68ea83296..e5e1f31d2464 100644
--- a/sw/inc/unoprnms.hxx
+++ b/sw/inc/unoprnms.hxx
@@ -829,6 +829,7 @@
 #define UNO_NAME_INITIALS "Initials"
 #define UNO_NAME_TABLE_BORDER2 "TableBorder2"
 #define UNO_NAME_REPLACEMENT_GRAPHIC_URL "ReplacementGraphicURL"
+#define UNO_NAME_REPLACEMENT_GRAPHIC "ReplacementGraphic"
 #define UNO_NAME_HIDDEN "Hidden"
 #define UNO_NAME_DEFAULT_PAGE_MODE "DefaultPageMode"
 #define UNO_NAME_CHAR_SHADING_VALUE "CharShadingValue"
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index c576e2ffc459..8b3595b40af0 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -2107,6 +2107,27 @@ uno::Any SwXFrame::getPropertyValue(const OUString& rPropertyName)
 
             aAny <<= sGrfName;
         }
+        else if (FN_UNO_REPLACEMENT_GRAPHIC == pEntry->nWID)
+        {
+            const SwNodeIndex* pIdx = pFormat->GetContent().GetContentIdx();
+            uno::Reference<graphic::XGraphic> xGraphic;
+
+            if (pIdx)
+            {
+                SwNodeIndex aIdx(*pIdx, 1);
+                SwGrfNode* pGrfNode = aIdx.GetNode().GetGrfNode();
+                if (!pGrfNode)
+                    throw uno::RuntimeException();
+
+                const GraphicObject* pGraphicObject = pGrfNode->GetReplacementGrfObj();
+
+                if (pGraphicObject)
+                {
+                    xGraphic = pGraphicObject->GetGraphic().GetXGraphic();
+                }
+            }
+            aAny <<= xGraphic;
+        }
         else if( FN_UNO_GRAPHIC_FILTER == pEntry->nWID )
         {
             OUString sFltName;
diff --git a/sw/source/core/unocore/unomap1.cxx b/sw/source/core/unocore/unomap1.cxx
index 8f0352f09394..7074c5b2b0f6 100644
--- a/sw/source/core/unocore/unomap1.cxx
+++ b/sw/source/core/unocore/unomap1.cxx
@@ -848,6 +848,7 @@ const SfxItemPropertyMapEntry*  SwUnoPropertyMapProvider::GetGraphicPropertyMap(
         { OUString(UNO_NAME_VERT_MIRRORED), RES_GRFATR_MIRRORGRF,   cppu::UnoType<bool>::get(),             PROPERTY_NONE,     MID_MIRROR_VERT            },
         { OUString(UNO_NAME_GRAPHIC_URL), FN_UNO_GRAPHIC_U_R_L, cppu::UnoType<OUString>::get(), 0, 0 },
         { OUString(UNO_NAME_REPLACEMENT_GRAPHIC_URL), FN_UNO_REPLACEMENT_GRAPHIC_U_R_L, cppu::UnoType<OUString>::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), FN_UNO_GRAPHIC, cppu::UnoType<css::graphic::XGraphic>::get(), 0, 0 },
         { OUString(UNO_NAME_ACTUAL_SIZE), FN_UNO_ACTUAL_SIZE,    cppu::UnoType<css::awt::Size>::get(),  PropertyAttribute::READONLY, CONVERT_TWIPS},
diff --git a/xmloff/source/draw/shapeexport.cxx b/xmloff/source/draw/shapeexport.cxx
index b1b5ea0e1537..89a92f14229c 100644
--- a/xmloff/source/draw/shapeexport.cxx
+++ b/xmloff/source/draw/shapeexport.cxx
@@ -2454,34 +2454,33 @@ void XMLShapeExport::ImpExportGraphicObjectShape(
         //fallback here
         if( !bIsEmptyPresObj )
         {
-            OUString aReplacementUrl;
-            xPropSet->getPropertyValue("ReplacementGraphicURL") >>= aReplacementUrl;
+            uno::Reference<graphic::XGraphic> xReplacementGraphic;
+            xPropSet->getPropertyValue("ReplacementGraphic") >>= xReplacementGraphic;
 
             // If there is no url, then the graphic is empty
-            if(!aReplacementUrl.isEmpty())
+            if (xReplacementGraphic.is())
             {
-                const OUString aStr = mrExport.AddEmbeddedGraphicObject(aReplacementUrl);
+                OUString aMimeType;
+                const OUString aHref = mrExport.AddEmbeddedXGraphic(xReplacementGraphic, aMimeType);
 
-                if(!aStr.isEmpty())
+                if (aMimeType.isEmpty())
+                    mrExport.GetGraphicMimeTypeFromStream(xReplacementGraphic, aMimeType);
+
+                if (!aHref.isEmpty())
                 {
-                    mrExport.AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, aStr);
+                    mrExport.AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, aHref);
                     mrExport.AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
                     mrExport.AddAttribute(XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
                     mrExport.AddAttribute(XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
                 }
 
-                uno::Reference<io::XInputStream> xInputStream(
-                    mrExport.GetEmbeddedGraphicObjectStream(aReplacementUrl));
-                OUString aMimeType(
-                    comphelper::GraphicMimeTypeHelper::GetMimeTypeForImageStream(xInputStream));
                 if (!aMimeType.isEmpty())
-                    GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, "mime-type", aMimeType);
+                    mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, "mime-type", aMimeType);
 
-                SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DRAW, XML_IMAGE, true, true);
+                SvXMLElementExport aElement(mrExport, XML_NAMESPACE_DRAW, XML_IMAGE, true, true);
 
                 // optional office:binary-data
-                mrExport.AddEmbeddedGraphicObjectAsBase64(aReplacementUrl);
-
+                mrExport.AddEmbeddedXGraphicAsBase64(xReplacementGraphic);
             }
         }
     }
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 2cc83399191a..75a192125d16 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -1194,7 +1194,6 @@ XMLTextParagraphExport::XMLTextParagraphExport(
     sGraphicFilter("GraphicFilter"),
     sGraphicRotation("GraphicRotation"),
     sGraphicURL("GraphicURL"),
-    sReplacementGraphicURL("ReplacementGraphicURL"),
     sHeight("Height"),
     sHoriOrient("HoriOrient"),
     sHoriOrientPosition("HoriOrientPosition"),
@@ -3107,8 +3106,8 @@ void XMLTextParagraphExport::_exportTextGraphic(
 
     // replacement graphic for backwards compatibility, but
     // only for SVG and metafiles currently
-    OUString sReplacementOrigURL;
-    rPropSet->getPropertyValue( sReplacementGraphicURL ) >>= sReplacementOrigURL;
+    uno::Reference<graphic::XGraphic> xReplacementGraphic;
+    rPropSet->getPropertyValue("ReplacementGraphic") >>= xReplacementGraphic;
 
     // xlink:href
     OUString sOrigURL;
@@ -3159,30 +3158,30 @@ void XMLTextParagraphExport::_exportTextGraphic(
 
     //Resolves: fdo#62461 put preferred image first above, followed by
     //fallback here
-    if (!sReplacementOrigURL.isEmpty())
+    if (xReplacementGraphic.is())
     {
-        const OUString sReplacementURL(GetExport().AddEmbeddedGraphicObject( sReplacementOrigURL ));
+        OUString aMimeType;
+        const OUString sHref = GetExport().AddEmbeddedXGraphic(xReplacementGraphic, aMimeType);
+
+        if (aMimeType.isEmpty())
+            GetExport().GetGraphicMimeTypeFromStream(xReplacementGraphic, aMimeType);
 
         // If there is no url, then graphic is empty
-        if(!sReplacementURL.isEmpty())
+        if (!sHref.isEmpty())
         {
-            GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sReplacementURL);
+            GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sHref);
             GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE);
             GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED);
             GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD);
         }
 
-        uno::Reference<io::XInputStream> xInputStream(
-            GetExport().GetEmbeddedGraphicObjectStream(sReplacementOrigURL));
-        OUString aMimeType(
-            comphelper::GraphicMimeTypeHelper::GetMimeTypeForImageStream(xInputStream));
         if (!aMimeType.isEmpty())
             GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, "mime-type", aMimeType);
 
         SvXMLElementExport aElement(GetExport(), XML_NAMESPACE_DRAW, XML_IMAGE, true, true);
 
         // optional office:binary-data
-        GetExport().AddEmbeddedGraphicObjectAsBase64(sReplacementOrigURL);
+        GetExport().AddEmbeddedXGraphicAsBase64(xReplacementGraphic);
     }
 
     // script:events


More information about the Libreoffice-commits mailing list