[Libreoffice-commits] core.git: Branch 'libreoffice-7-1' - drawinglayer/source svx/qa svx/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Mon Aug 9 13:19:54 UTC 2021


 drawinglayer/source/tools/primitive2dxmldump.cxx   |   36 ++++++++++++++++++++-
 svx/qa/unit/data/slide-background.odp              |binary
 svx/qa/unit/data/slide-background.png              |binary
 svx/qa/unit/sdr.cxx                                |   24 ++++++++++++++
 svx/source/sdr/primitive2d/sdrattributecreator.cxx |    8 ++++
 5 files changed, 67 insertions(+), 1 deletion(-)

New commits:
commit 7a5f12ea03e72749b2d3ccc99ed72edc3ff22d4b
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Aug 3 13:39:20 2021 +0200
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Mon Aug 9 15:19:20 2021 +0200

    tdf#142436 svx: fix handling of linked background images
    
    Regression from commit 9fb7aaf570c03c8a26d763f1205fb8c890e8211a (Make
    linked graphic register into LinkedManager again, 2018-04-13), the
    problem was that now SvXMLImport::loadGraphicByURL() produces a Graphic
    that has its type set to GraphicType::Default, but when
    drawinglayer::primitive2d::createNewSdrFillGraphicAttribute() consumes
    this graphic, it expects that the type is either a bitmap or a metafile.
    
    Fix the problem by explicitly loading the image when the default-type,
    origin-url-set case happens: this is rendering, so no problem to load
    the URL and that will give us the expected graphic type.
    
    This is also meant to keep the original problem fixed, since the Graphic
    that is part of the doc model is unchanged.
    
    (cherry picked from commit c88ff9298b25132fc34102230cef0263f045a523)
    
    Conflicts:
            drawinglayer/source/tools/primitive2dxmldump.cxx
    
    Change-Id: If5bba09faa23ef35f99152d4b5d30cd9cf67ace8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120140
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/drawinglayer/source/tools/primitive2dxmldump.cxx b/drawinglayer/source/tools/primitive2dxmldump.cxx
index ade8cfaed89b..203f6d008d15 100644
--- a/drawinglayer/source/tools/primitive2dxmldump.cxx
+++ b/drawinglayer/source/tools/primitive2dxmldump.cxx
@@ -12,6 +12,8 @@
 #include <rtl/string.hxx>
 #include <tools/stream.hxx>
 #include <tools/XmlWriter.hxx>
+#include <vcl/bitmapex.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
 
 #include <memory>
 #include <sal/log.hxx>
@@ -30,6 +32,7 @@
 #include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
 #include <drawinglayer/primitive2d/svggradientprimitive2d.hxx>
 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
+#include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
 #include <drawinglayer/geometry/viewinformation2d.hxx>
 #include <drawinglayer/attribute/lineattribute.hxx>
 #include <drawinglayer/attribute/fontattribute.hxx>
@@ -164,6 +167,35 @@ void Primitive2dXmlDump::decomposeAndWrite(
 
         switch (nId)
         {
+            case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D:
+            {
+                const BitmapPrimitive2D& rBitmapPrimitive2D
+                    = dynamic_cast<const BitmapPrimitive2D&>(*pBasePrimitive);
+                rWriter.startElement("bitmap");
+
+                const BitmapEx aBitmapEx(VCLUnoHelper::GetBitmap(rBitmapPrimitive2D.getXBitmap()));
+                const Size& rSizePixel(aBitmapEx.GetSizePixel());
+
+                rWriter.attribute("height", rSizePixel.getHeight());
+                rWriter.attribute("width", rSizePixel.getWidth());
+                rWriter.attribute("checksum", OString(std::to_string(aBitmapEx.GetChecksum())));
+
+                for (tools::Long y = 0; y < rSizePixel.getHeight(); y++)
+                {
+                    rWriter.startElement("data");
+                    OUString aBitmapData = "";
+                    for (tools::Long x = 0; x < rSizePixel.getHeight(); x++)
+                    {
+                        if (x != 0)
+                            aBitmapData = aBitmapData + ",";
+                        aBitmapData = aBitmapData + aBitmapEx.GetPixelColor(x, y).AsRGBHexString();
+                    }
+                    rWriter.attribute("row", aBitmapData);
+                    rWriter.endElement();
+                }
+                rWriter.endElement();
+            }
+            break;
             case PRIMITIVE2D_ID_HIDDENGEOMETRYPRIMITIVE2D:
             {
                 const HiddenGeometryPrimitive2D& rHiddenGeometryPrimitive2D = dynamic_cast<const HiddenGeometryPrimitive2D&>(*pBasePrimitive);
@@ -302,7 +334,9 @@ void Primitive2dXmlDump::decomposeAndWrite(
                 }
                 rWriter.attribute("x", aTranslate.getX());
                 rWriter.attribute("y", aTranslate.getY());
-                rWriter.attribute("text", rTextSimplePortionPrimitive2D.getText());
+                OUString aText = rTextSimplePortionPrimitive2D.getText();
+                // TODO share code with sax_fastparser::FastSaxSerializer::write().
+                rWriter.attribute("text", aText.replaceAll("", "	"));
                 rWriter.attribute("fontcolor", convertColorToString(rTextSimplePortionPrimitive2D.getFontColor()));
 
                 const drawinglayer::attribute::FontAttribute& aFontAttribute = rTextSimplePortionPrimitive2D.getFontAttribute();
diff --git a/svx/qa/unit/data/slide-background.odp b/svx/qa/unit/data/slide-background.odp
new file mode 100644
index 000000000000..ea62bd63903b
Binary files /dev/null and b/svx/qa/unit/data/slide-background.odp differ
diff --git a/svx/qa/unit/data/slide-background.png b/svx/qa/unit/data/slide-background.png
new file mode 100644
index 000000000000..3a8c5ceb4262
Binary files /dev/null and b/svx/qa/unit/data/slide-background.png differ
diff --git a/svx/qa/unit/sdr.cxx b/svx/qa/unit/sdr.cxx
index cde622cffe6f..fd951da96100 100644
--- a/svx/qa/unit/sdr.cxx
+++ b/svx/qa/unit/sdr.cxx
@@ -118,6 +118,30 @@ CPPUNIT_TEST_FIXTURE(SdrTest, testZeroWidthTextWrap)
     // i.e. the text on the only shape on the slide had 12 lines, not a single one.
     assertXPath(pDocument, "//textsimpleportion", 1);
 }
+
+CPPUNIT_TEST_FIXTURE(SdrTest, testSlideBackground)
+{
+    // Given a document with a slide what has a linked background image:
+    test::Directories aDirectories;
+    OUString aURL = aDirectories.getURLFromSrc(u"svx/qa/unit/data/slide-background.odp");
+    getComponent() = loadFromDesktop(aURL);
+    uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+                                                 uno::UNO_QUERY);
+
+    // When rendering that document:
+    drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
+        = renderPageToPrimitives(xDrawPage);
+
+    // Then make sure that the background has a bitmap:
+    drawinglayer::Primitive2dXmlDump aDumper;
+    xmlDocUniquePtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence);
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 1
+    // - Actual  : 0
+    // i.e. the rendering did not find the bitmap.
+    assertXPath(pDocument, "//bitmap", 1);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/sdr/primitive2d/sdrattributecreator.cxx b/svx/source/sdr/primitive2d/sdrattributecreator.cxx
index c3cad4f96209..90ebe3dc634f 100644
--- a/svx/source/sdr/primitive2d/sdrattributecreator.cxx
+++ b/svx/source/sdr/primitive2d/sdrattributecreator.cxx
@@ -58,6 +58,7 @@
 #include <svx/xbtmpit.hxx>
 #include <svl/itempool.hxx>
 #include <vcl/svapp.hxx>
+#include <vcl/GraphicLoader.hxx>
 #include <basegfx/range/b2drange.hxx>
 #include <svx/svx3ditems.hxx>
 #include <com/sun/star/drawing/ProjectionMode.hpp>
@@ -658,6 +659,13 @@ namespace drawinglayer::primitive2d
         {
             Graphic aGraphic(rSet.Get(XATTR_FILLBITMAP).GetGraphicObject().GetGraphic());
 
+            OUString aOriginURL = aGraphic.getOriginURL();
+            if (aGraphic.GetType() == GraphicType::Default && !aOriginURL.isEmpty())
+            {
+                aGraphic = vcl::graphic::loadFromURL(aGraphic.getOriginURL());
+                aGraphic.setOriginURL(aOriginURL);
+            }
+
             if(GraphicType::Bitmap != aGraphic.GetType() && GraphicType::GdiMetafile != aGraphic.GetType())
             {
                 // no content if not bitmap or metafile


More information about the Libreoffice-commits mailing list