filter/qa/unit/data/text-in-image.odp |binary
 filter/qa/unit/svg.cxx                |   25 +++++++++++++
 svx/source/svdraw/svdxcgv.cxx         |   63 +++++++++++++++++-----------------
 3 files changed, 58 insertions(+), 30 deletions(-)

New commits:
commit d0241915eba35c9dc0cc42f322df798a270db00f
Author:     Jaume Pujantell <jaume.pujant...@collabora.com>
AuthorDate: Tue Feb 13 09:27:00 2024 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Feb 14 09:37:04 2024 +0100

    tdf#159704 svx: preserve text when getting grpahic from sdrobject
    
    When getting a Graphic object from an SdrGrafObj with text the text was 
lost.
    
    Change-Id: I3a8316511e502b832b65dc72faebaf8c00923c38
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163293
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/filter/qa/unit/data/text-in-image.odp 
b/filter/qa/unit/data/text-in-image.odp
new file mode 100644
index 000000000000..660e27062373
Binary files /dev/null and b/filter/qa/unit/data/text-in-image.odp differ
diff --git a/filter/qa/unit/svg.cxx b/filter/qa/unit/svg.cxx
index 4c1ddd10b58a..4900c742200e 100644
--- a/filter/qa/unit/svg.cxx
+++ b/filter/qa/unit/svg.cxx
@@ -346,6 +346,31 @@ CPPUNIT_TEST_FIXTURE(SvgFilterTest, testTab)
     assertXPath(pXmlDoc, 
"//svg:g[@class='TextShape']//svg:tspan[@class='TextPosition']", 2);
 }
 
+CPPUNIT_TEST_FIXTURE(SvgFilterTest, textInImage)
+{
+    // Load document containing empty paragraphs with ids.
+    loadFromURL(u"text-in-image.odp");
+
+    // Export to SVG.
+    uno::Reference<frame::XStorable> xStorable(mxComponent, 
uno::UNO_QUERY_THROW);
+    SvMemoryStream aStream;
+    uno::Reference<io::XOutputStream> xOut = new 
utl::OOutputStreamWrapper(aStream);
+    utl::MediaDescriptor aMediaDescriptor;
+    aMediaDescriptor["FilterName"] <<= OUString("impress_svg_Export");
+    aMediaDescriptor["OutputStream"] <<= xOut;
+    xStorable->storeToURL("private:stream", 
aMediaDescriptor.getAsConstPropertyValueList());
+    aStream.Seek(STREAM_SEEK_TO_BEGIN);
+
+    xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream);
+
+    // We expect the Graphic to have an image and a text
+    assertXPath(pXmlDoc, "//svg:g[@class='Graphic']//svg:image", 1);
+    assertXPath(pXmlDoc, "//svg:g[@class='Graphic']//svg:text", 1);
+    // Without the accomanying fix, this test would have failed with:
+    // - Expected: 1
+    // - Actual  : 0
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdxcgv.cxx b/svx/source/svdraw/svdxcgv.cxx
index f9365136afbd..01a43f86819c 100644
--- a/svx/source/svdraw/svdxcgv.cxx
+++ b/svx/source/svdraw/svdxcgv.cxx
@@ -604,42 +604,45 @@ Graphic SdrExchangeView::GetObjGraphic(const SdrObject& 
rSdrObject, bool bSVG)
 {
     Graphic aRet;
 
-    // try to get a graphic from the object first
-    const SdrGrafObj* pSdrGrafObj(dynamic_cast< const SdrGrafObj* 
>(&rSdrObject));
-    const SdrOle2Obj* pSdrOle2Obj(dynamic_cast< const SdrOle2Obj* 
>(&rSdrObject));
-
-    if(pSdrGrafObj)
+    if (!rSdrObject.HasText())
     {
-        if(pSdrGrafObj->isEmbeddedVectorGraphicData())
+        // try to get a graphic from the object first
+        const SdrGrafObj* pSdrGrafObj(dynamic_cast<const 
SdrGrafObj*>(&rSdrObject));
+        const SdrOle2Obj* pSdrOle2Obj(dynamic_cast<const 
SdrOle2Obj*>(&rSdrObject));
+
+        if (pSdrGrafObj)
         {
-            // get Metafile for Svg content
-            aRet = pSdrGrafObj->getMetafileFromEmbeddedVectorGraphicData();
+            if (pSdrGrafObj->isEmbeddedVectorGraphicData())
+            {
+                // get Metafile for Svg content
+                aRet = pSdrGrafObj->getMetafileFromEmbeddedVectorGraphicData();
+            }
+            else
+            {
+                // Make behaviour coherent with metafile
+                // recording below (which of course also takes
+                // view-transformed objects)
+                aRet = pSdrGrafObj->GetTransformedGraphic();
+            }
         }
-        else
+        else if (pSdrOle2Obj)
         {
-            // Make behaviour coherent with metafile
-            // recording below (which of course also takes
-            // view-transformed objects)
-            aRet = pSdrGrafObj->GetTransformedGraphic();
-        }
-    }
-    else if(pSdrOle2Obj)
-    {
-        if(pSdrOle2Obj->GetGraphic())
-        {
-            aRet = *pSdrOle2Obj->GetGraphic();
+            if (pSdrOle2Obj->GetGraphic())
+            {
+                aRet = *pSdrOle2Obj->GetGraphic();
+            }
         }
-    }
-    else
-    {
-        // Support extracting a snapshot from video media, if possible.
-        const SdrMediaObj* pSdrMediaObj = dynamic_cast<const 
SdrMediaObj*>(&rSdrObject);
-        if (pSdrMediaObj)
+        else
         {
-            const css::uno::Reference<css::graphic::XGraphic>& xGraphic
-                = pSdrMediaObj->getSnapshot();
-            if (xGraphic.is())
-                aRet = Graphic(xGraphic);
+            // Support extracting a snapshot from video media, if possible.
+            const SdrMediaObj* pSdrMediaObj = dynamic_cast<const 
SdrMediaObj*>(&rSdrObject);
+            if (pSdrMediaObj)
+            {
+                const css::uno::Reference<css::graphic::XGraphic>& xGraphic
+                    = pSdrMediaObj->getSnapshot();
+                if (xGraphic.is())
+                    aRet = Graphic(xGraphic);
+            }
         }
     }
 

Reply via email to