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

Bartosz Kosiorek (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 7 20:00:58 UTC 2021


 drawinglayer/source/tools/emfphelperdata.cxx                |   44 ++++++++++--
 emfio/qa/cppunit/emf/EmfImportTest.cxx                      |   34 +++++++++
 emfio/qa/cppunit/emf/data/TestDrawImagePointsTypeBitmap.emf |binary
 3 files changed, 73 insertions(+), 5 deletions(-)

New commits:
commit 032b00382f654962ec787029b3a887f9efbd2a3d
Author:     Bartosz Kosiorek <gang65 at poczta.onet.pl>
AuthorDate: Tue Jun 22 14:36:15 2021 +0200
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Wed Jul 7 22:00:24 2021 +0200

    EMF+ tdf#142941 Fixes for SrcRect in DrawImagePoints
    
    The SrcRect could be specified outside of source bitmap.
    In such cases the Destination bitmap should be displayed as shifted
    (eg. if position is negative), and scaled properly.
    Change-Id: Ied6d339703999faaae061802ef6a28e190d5a176
    
    Change-Id: Ia9772ced282684c2c94a261d97d30b53921d6171
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118345
    Tested-by: Jenkins
    Reviewed-by: Bartosz Kosiorek <gang65 at poczta.onet.pl>
    (cherry picked from commit 4992780d2bc996c111b333549314d72f6891308d)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118304
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/drawinglayer/source/tools/emfphelperdata.cxx b/drawinglayer/source/tools/emfphelperdata.cxx
index 23ceb6487d66..7a2007da07ba 100644
--- a/drawinglayer/source/tools/emfphelperdata.cxx
+++ b/drawinglayer/source/tools/emfphelperdata.cxx
@@ -1443,7 +1443,8 @@ namespace emfplushelper
                             EMFPImage& image = *static_cast<EMFPImage *>(maEMFPObjects[flags & 0xff].get());
                             float sx, sy, sw, sh;
                             ReadRectangle(rMS, sx, sy, sw, sh);
-                            ::tools::Rectangle aSource(Point(sx, sy), Size(sw, sh));
+
+                            ::tools::Rectangle aSource(Point(sx, sy), Size(sw + 1, sh + 1));
                             SAL_INFO("drawinglayer.emf", "EMF+\t " << (type == EmfPlusRecordTypeDrawImagePoints ? "DrawImagePoints" : "DrawImage") << " source rectangle: " << sx << "," << sy << " " << sw << "x" << sh);
                             ::basegfx::B2DPoint aDstPoint;
                             ::basegfx::B2DSize aDstSize;
@@ -1464,10 +1465,43 @@ namespace emfplushelper
                                     ReadPoint(rMS, x2, y2, flags); // upper-right
                                     ReadPoint(rMS, x3, y3, flags); // lower-left
 
-                                    SAL_INFO("drawinglayer.emf", "EMF+\t destination points: P1:" << x1 << "," << y1 << " P2:" << x2 << "," << y2 << " P3:" << x3 << "," << y3);
-
-                                    aDstPoint = ::basegfx::B2DPoint(x1, y1);
-                                    aDstSize = ::basegfx::B2DSize(x2 - x1, y3 - y1);
+                                    SAL_INFO("drawinglayer.emf",
+                                             "EMF+\t destination points: " << x1 << "," << y1 << " "
+                                                                           << x2 << "," << y2 << " "
+                                                                           << x3 << "," << y3);
+                                    float xDstShift = x1;
+                                    float yDstShift = y2;
+                                    float xDstSize = x2 - x1;
+                                    float yDstSize = y3 - y1;
+                                    if (image.type == ImageDataTypeBitmap)
+                                    {
+                                        const Size aSize(image.graphic.GetBitmapEx().GetSizePixel());
+                                        if (sx < 0)
+                                        {
+                                            // If src position is negative then we need shift image to right
+                                            xDstShift = xDstShift + ((-sx) / sw) * (x2 - x1);
+                                            if (sx + sw <= aSize.Width())
+                                                xDstSize = ((sw + sx) / sw) * xDstSize;
+                                            else
+                                                xDstSize = (aSize.Width() / sw) * xDstSize;
+                                        }
+                                        else if (sx + sw > aSize.Width())
+                                            // If the src image is smaller that what we want to cut, then we need to scale down
+                                            xDstSize = ((aSize.Width() - sx) / sw) * xDstSize;
+
+                                        if (sy < 0)
+                                        {
+                                            yDstShift = yDstShift + ((-sy) / sh) * (y3 - y1);
+                                            if (sy + sh <= aSize.Height())
+                                                yDstSize = ((sh + sy) / sh) * yDstSize;
+                                            else
+                                                yDstSize = (aSize.Height() / sh) * yDstSize;
+                                        }
+                                        else if (sy + sh > aSize.Height())
+                                            yDstSize = ((aSize.Height() - sy) / sh) * yDstSize;
+                                    }
+                                    aDstPoint = ::basegfx::B2DPoint(xDstShift, yDstShift);
+                                    aDstSize = ::basegfx::B2DSize(xDstSize, yDstSize);
                                     fShearX = x3 - x1;
                                     fShearY = y2 - y1;
                                 }
diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx b/emfio/qa/cppunit/emf/EmfImportTest.cxx
index 7e28b2a326d0..f894c2d9a666 100644
--- a/emfio/qa/cppunit/emf/EmfImportTest.cxx
+++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx
@@ -46,6 +46,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools, public unotest:
     uno::Reference<lang::XComponent> mxComponent;
 
     void testPolyPolygon();
+    void TestDrawImagePointsTypeBitmap();
     void TestDrawString();
     void TestDrawStringAlign();
     void TestDrawStringTransparent();
@@ -87,6 +88,7 @@ public:
 
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(testPolyPolygon);
+    CPPUNIT_TEST(TestDrawImagePointsTypeBitmap);
     CPPUNIT_TEST(TestDrawString);
     CPPUNIT_TEST(TestDrawStringAlign);
     CPPUNIT_TEST(TestDrawStringTransparent);
@@ -190,6 +192,38 @@ void Test::testPolyPolygon()
 
 }
 
+void Test::TestDrawImagePointsTypeBitmap()
+{
+    // tdf#142941 EMF+ file with ObjectTypeImage, FillRects, DrawImagePoints ,records
+    // The test is checking the position of displaying bitmap with too large SrcRect
+
+    Primitive2DSequence aSequence
+        = parseEmf(u"/emfio/qa/cppunit/emf/data/TestDrawImagePointsTypeBitmap.emf");
+    CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength()));
+    drawinglayer::Primitive2dXmlDump dumper;
+    xmlDocUniquePtr pDocument
+        = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequence));
+    CPPUNIT_ASSERT(pDocument);
+
+    assertXPath(pDocument, "/primitive2D/metafile/transform/polypolygoncolor", "color", "#0080ff");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/bitmap", "xy11", "5346");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/bitmap", "xy12", "0");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/bitmap", "xy13", "5558");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/bitmap", "xy21", "0");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/bitmap", "xy22", "4716");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/bitmap", "xy23", "5564");
+    assertXPath(
+        pDocument, "/primitive2D/metafile/transform/bitmap/data[2]", "row",
+        "020202,ffffff,ffffff,ffffff,fefefe,ffffff,ffffff,fefefe,ffffff,ffffff,f8f8f8,ffffff,"
+        "fdfdfd,ffffff,ffffff,fdfdfd,ffffff,ffffff,ffffff,fbfbfb,010101,ffffff,fefefe,ffffff,"
+        "ffffff,fbfbfb,ffffff,fdfdfd,fcfcfc,fdfdfd,ffffff,ffffff,ffffff,ffffff,ffffff,ffffff,"
+        "ffffff,ffffff,ffffff,ffffff,020202,fdfdfd,ffffff,ffffff,fefefe,ffffff,ffffff,ffffff,"
+        "ffffff,fbfbfb,fefefe,ffffff,fcfcfc,ffffff,fdfdfd,ffffff,ffffff,ffffff,ffffff,fbfbfb,"
+        "010101,ffffff,fefefe,ffffff,ffffff,ffffff,fcfcfc,ffffff,fafafa,ffffff,ffffff,fefefe,"
+        "ffffff,fdfdfd,fefefe,fefefe,ffffff,ffffff,fdfdfd,fffbfb,1e0000,8f4347,b13a3e,b82d32,"
+        "bb3438,b73237,b63338,b33035,b63338");
+}
+
 void Test::TestDrawString()
 {
 #if HAVE_MORE_FONTS
diff --git a/emfio/qa/cppunit/emf/data/TestDrawImagePointsTypeBitmap.emf b/emfio/qa/cppunit/emf/data/TestDrawImagePointsTypeBitmap.emf
new file mode 100644
index 000000000000..291052a165a8
Binary files /dev/null and b/emfio/qa/cppunit/emf/data/TestDrawImagePointsTypeBitmap.emf differ


More information about the Libreoffice-commits mailing list