[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - oox/source sd/qa

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 15 09:04:24 UTC 2020


 oox/source/export/drawingml.cxx                          |   13 +++++++
 sd/qa/unit/data/pptx/customshape-bitmapfill-srcrect.pptx |binary
 sd/qa/unit/export-tests-ooxml1.cxx                       |   25 +++++++++++++++
 3 files changed, 38 insertions(+)

New commits:
commit 34dbd676ffb38fdd2f3a49dcff54925b98486eb2
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Jun 10 14:51:04 2020 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Jun 15 10:24:01 2020 +0200

    PPTX export, custom shape, bitmap fill: fix source vs fill rect confusion
    
    Commit 682ab832522b1349f1714bcb16f6e83468ea2920 (drawingML
    export\import: cropping of shape's fill texture, 2014-02-12) improved
    the DOCX filter, so the fill rectangle of a custom shape with bitmap
    fill is handled.
    
    The problem is drawingML has a source rectangle (similar to our crop
    rect) to limit the usage of the bitmap, and also it has a fill rectangle
    in case some margin is wanted around a stretched bitmap. We don't have a
    mapping for the later.
    
    Fix the problem by limiting the above work for DOCX, this way PPTX's
    source rectangle won't be turned into a stretch's fill rectangle.
    
    This way no unwanted margins will appear around the image -- those
    margins can be large enough that the image effectively disappears on
    export.
    
    (cherry picked from commit b00e43fa5848be0cc7ba81b185021511d94cdc00)
    
    Change-Id: Ic35063545a56eec9eaf885bbd397a854705d134f

diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 8ca75aaa9522..327d5a27931a 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -1455,6 +1455,12 @@ void DrawingML::WriteXGraphicBlipFill(uno::Reference<beans::XPropertySet> const
 
     WriteXGraphicBlip(rXPropSet, rxGraphic, bRelPathToMedia);
 
+    if (GetDocumentType() != DOCUMENT_DOCX)
+    {
+        // Write the crop rectangle of Impress as a source rectangle.
+        WriteSrcRectXGraphic(rXPropSet, rxGraphic);
+    }
+
     if (bWriteMode)
     {
         WriteXGraphicBlipMode(rXPropSet, rxGraphic);
@@ -1550,6 +1556,13 @@ void DrawingML::WriteSrcRectXGraphic(uno::Reference<beans::XPropertySet> const &
 void DrawingML::WriteXGraphicStretch(uno::Reference<beans::XPropertySet> const & rXPropSet,
                                      uno::Reference<graphic::XGraphic> const & rxGraphic)
 {
+    if (GetDocumentType() != DOCUMENT_DOCX)
+    {
+        // Limiting the area used for stretching is not supported in Impress.
+        mpFS->singleElementNS(XML_a, XML_stretch);
+        return;
+    }
+
     mpFS->startElementNS(XML_a, XML_stretch);
 
     bool bCrop = false;
diff --git a/sd/qa/unit/data/pptx/customshape-bitmapfill-srcrect.pptx b/sd/qa/unit/data/pptx/customshape-bitmapfill-srcrect.pptx
new file mode 100644
index 000000000000..e162f7e9923f
Binary files /dev/null and b/sd/qa/unit/data/pptx/customshape-bitmapfill-srcrect.pptx differ
diff --git a/sd/qa/unit/export-tests-ooxml1.cxx b/sd/qa/unit/export-tests-ooxml1.cxx
index 769bf6e52456..0da3de5332b6 100644
--- a/sd/qa/unit/export-tests-ooxml1.cxx
+++ b/sd/qa/unit/export-tests-ooxml1.cxx
@@ -90,6 +90,7 @@ public:
     void testRoundtripOwnLineStyles();
     void testRoundtripPrstDash();
     void testDashOnHairline();
+    void testCustomshapeBitmapfillSrcrect();
 
     CPPUNIT_TEST_SUITE(SdOOXMLExportTest1);
 
@@ -129,6 +130,7 @@ public:
     CPPUNIT_TEST(testRoundtripOwnLineStyles);
     CPPUNIT_TEST(testRoundtripPrstDash);
     CPPUNIT_TEST(testDashOnHairline);
+    CPPUNIT_TEST(testCustomshapeBitmapfillSrcrect);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -1071,6 +1073,29 @@ void SdOOXMLExportTest1::testDashOnHairline()
     assertXPath(pXmlDoc, sXmlPath, 11);
 }
 
+void SdOOXMLExportTest1::testCustomshapeBitmapfillSrcrect()
+{
+    ::sd::DrawDocShellRef xDocShRef = loadURL(
+        m_directories.getURLFromSrc("sd/qa/unit/data/pptx/customshape-bitmapfill-srcrect.pptx"),
+        PPTX);
+    utl::TempFile tempFile;
+    xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile);
+    xDocShRef->DoClose();
+
+    xmlDocPtr pXmlDoc = parseExport(tempFile, "ppt/slides/slide1.xml");
+    const OString sXmlPath = "//a:blipFill/a:srcRect";
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 1
+    // - Actual  : 0
+    // - XPath '//a:blipFill/a:srcRect' number of nodes is incorrect
+    // i.e. <a:srcRect> was exported as <a:fillRect> in <a:stretch>, which made part of the image
+    // invisible.
+    double fLeftPercent = std::round(getXPath(pXmlDoc, sXmlPath, "l").toDouble() / 1000);
+    CPPUNIT_ASSERT_EQUAL(4.0, fLeftPercent);
+    double fRightPercent = std::round(getXPath(pXmlDoc, sXmlPath, "r").toDouble() / 1000);
+    CPPUNIT_ASSERT_EQUAL(4.0, fRightPercent);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest1);
 
 CPPUNIT_PLUGIN_IMPLEMENT();


More information about the Libreoffice-commits mailing list