[Libreoffice-commits] core.git: emfio/inc emfio/qa emfio/source

Bartosz Kosiorek (via logerrit) logerrit at kemper.freedesktop.org
Fri May 7 19:03:04 UTC 2021


 emfio/inc/mtftools.hxx                                          |    6 -
 emfio/qa/cppunit/emf/EmfImportTest.cxx                          |   17 +++++
 emfio/qa/cppunit/emf/data/TestEllipseXformIntersectClipRect.emf |binary
 emfio/source/reader/mtftools.cxx                                |   34 +++++++---
 4 files changed, 45 insertions(+), 12 deletions(-)

New commits:
commit 1ef26ffe39618a745d3367310565e7eeb184a4c2
Author:     Bartosz Kosiorek <gang65 at poczta.onet.pl>
AuthorDate: Tue May 4 16:08:35 2021 +0200
Commit:     Bartosz Kosiorek <gang65 at poczta.onet.pl>
CommitDate: Fri May 7 21:02:22 2021 +0200

    tdf#55058 tdf#141982 EMF: Add rotation support for INTERSECTCLIPRECT record
    
    With this commit the rotation support was added
    for INTERSECTCLIPRECT.
    
    Before that change rotation was not applied to these CLIP rectangles.
    
    Change-Id: I3da66790e0aeeaaeeb28d2fc30780cba8dbda390
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115102
    Tested-by: Jenkins
    Reviewed-by: Bartosz Kosiorek <gang65 at poczta.onet.pl>

diff --git a/emfio/inc/mtftools.hxx b/emfio/inc/mtftools.hxx
index cd2484606f07..c79bdae4c4d7 100644
--- a/emfio/inc/mtftools.hxx
+++ b/emfio/inc/mtftools.hxx
@@ -273,9 +273,9 @@ namespace emfio
     public:
         WinMtfClipPath() : maClip() {};
 
-        void        setClipPath(const tools::PolyPolygon& rPolyPolygon, sal_Int32 nClippingMode);
-        void        intersectClipRect(const tools::Rectangle& rRect);
-        void        excludeClipRect(const tools::Rectangle& rRect);
+        void        setClipPath(const basegfx::B2DPolyPolygon&, sal_Int32 nClippingMode);
+        void        intersectClip(const basegfx::B2DPolyPolygon& rPolyPolygon);
+        void        excludeClip(const basegfx::B2DPolyPolygon& rPolyPolygon);
         void        moveClipRegion(const Size& rSize);
         void        setDefaultClipPath();
 
diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx b/emfio/qa/cppunit/emf/EmfImportTest.cxx
index 83b42a3020d0..e5b1f3f54114 100644
--- a/emfio/qa/cppunit/emf/EmfImportTest.cxx
+++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx
@@ -55,6 +55,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools, public unotest:
     void TestRectangleWithModifyWorldTransform();
     void TestChordWithModifyWorldTransform();
     void TestEllipseWithSelectClipPath();
+    void TestEllipseXformIntersectClipRect();
     void TestDrawPolyLine16WithClip();
     void TestFillRegion();
     void TestCreatePen();
@@ -78,6 +79,7 @@ public:
     CPPUNIT_TEST(TestRectangleWithModifyWorldTransform);
     CPPUNIT_TEST(TestChordWithModifyWorldTransform);
     CPPUNIT_TEST(TestEllipseWithSelectClipPath);
+    CPPUNIT_TEST(TestEllipseXformIntersectClipRect);
     CPPUNIT_TEST(TestDrawPolyLine16WithClip);
     CPPUNIT_TEST(TestFillRegion);
     CPPUNIT_TEST(TestCreatePen);
@@ -370,6 +372,21 @@ void Test::TestEllipseWithSelectClipPath()
     assertXPathContent(pDocument, "/primitive2D/metafile/transform/group/mask/polygonstroke[1]/polygon", "353,353 2825,353 2825,1410 353,1410");
 }
 
+void Test::TestEllipseXformIntersectClipRect()
+{
+    // EMF import test with records: EXTCREATEPEN, CREATEBRUSHINDIRECT, MODIFYWORLDTRANSFORM, INTERSECTCLIPRECT, ELLIPSE
+    Primitive2DSequence aSequence = parseEmf(u"/emfio/qa/cppunit/emf/data/TestEllipseXformIntersectClipRect.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/mask/polypolygon", "path", "m0 0h3000v2000h-3000z");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/mask/group/mask/polypolygon", "path", "m370 152 1128-409 592 1623-1128 410z");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/mask/group/mask/polypolygoncolor/polypolygon", "path", "m3565 155-58-55-205-150-90-42-124-30-392-45-368 21-211 39-598 217-187 105-21 46-121 81-66 24-87 69-272 287-75 102-42 90-61 247-9 79 97 265 57 54 205 150 91 42 124 31 392 45 112-3 467-58 597-217 187-105 296-220 271-286 76-103 42-90 60-247 9-78z");
+    assertXPathContent(pDocument, "/primitive2D/metafile/transform/mask/group/mask/polygonstroke/polygon", "3565,155 3507,100 3302,-50 3212,-92 3088,-122 2696,-167 2328,-146 2117,-107 1519,110 1332,215 1311,261 1190,342 1124,366 1037,435 765,722 690,824 648,914 587,1161 578,1240 675,1505 732,1559 937,1709 1028,1751 1152,1782 1544,1827 1656,1824 2123,1766 2720,1549 2907,1444 3203,1224 3474,938 3550,835 3592,745 3652,498 3661,420");
+}
+
 void Test::TestDrawPolyLine16WithClip()
 {
     // Check import of EMF image with records:
diff --git a/emfio/qa/cppunit/emf/data/TestEllipseXformIntersectClipRect.emf b/emfio/qa/cppunit/emf/data/TestEllipseXformIntersectClipRect.emf
new file mode 100644
index 000000000000..bda2ad233f4a
Binary files /dev/null and b/emfio/qa/cppunit/emf/data/TestEllipseXformIntersectClipRect.emf differ
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index 4e325c10622e..2b1c1d406d1b 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -66,19 +66,18 @@ namespace emfio
         return rInStream;
     }
 
-    void WinMtfClipPath::intersectClipRect( const tools::Rectangle& rRect )
+    void WinMtfClipPath::intersectClip( const basegfx::B2DPolyPolygon& rPolyPolygon )
     {
-        maClip.intersectRange(vcl::unotools::b2DRectangleFromRectangle(rRect));
+        maClip.intersectPolyPolygon(rPolyPolygon);
     }
 
-    void WinMtfClipPath::excludeClipRect( const tools::Rectangle& rRect )
+    void WinMtfClipPath::excludeClip( const basegfx::B2DPolyPolygon& rPolyPolygon )
     {
-        maClip.subtractRange(vcl::unotools::b2DRectangleFromRectangle(rRect));
+        maClip.subtractPolyPolygon(rPolyPolygon);
     }
 
-    void WinMtfClipPath::setClipPath( const tools::PolyPolygon& rPolyPolygon, sal_Int32 nClippingMode )
+    void WinMtfClipPath::setClipPath( const basegfx::B2DPolyPolygon& rB2DPoly, sal_Int32 nClippingMode )
     {
-        const basegfx::B2DPolyPolygon& rB2DPoly=rPolyPolygon.getB2DPolyPolygon();
         switch ( nClippingMode )
         {
             case RGN_OR :
@@ -1032,7 +1031,15 @@ namespace emfio
         {
             return; // empty rectangles cause trouble
         }
-        maClipPath.intersectClipRect( ImplMap( rRect ) );
+        Point aPoints[] { Point(rRect.Left(), rRect.Top()),
+                          Point(rRect.Right(), rRect.Top()),
+                          Point(rRect.Right(), rRect.Bottom()),
+                          Point(rRect.Left(), rRect.Bottom()) };
+        tools::Polygon aPoly(4, aPoints);
+        aPoly = ImplMap( aPoly );
+        aPoly.Optimize( PolyOptimizeFlags::CLOSE );
+        tools::PolyPolygon aPolyPolyRect( aPoly );
+        maClipPath.intersectClip( aPolyPolyRect.getB2DPolyPolygon() );
     }
 
     void MtfTools::ExcludeClipRect( const tools::Rectangle& rRect )
@@ -1040,7 +1047,16 @@ namespace emfio
         if (utl::ConfigManager::IsFuzzing())
             return;
         mbClipNeedsUpdate=true;
-        maClipPath.excludeClipRect( ImplMap( rRect ) );
+
+        Point aPoints[] { Point(rRect.Left(), rRect.Top()),
+                          Point(rRect.Right(), rRect.Top()),
+                          Point(rRect.Right(), rRect.Bottom()),
+                          Point(rRect.Left(), rRect.Bottom()) };
+        tools::Polygon aPoly(4, aPoints);
+        aPoly = ImplMap( aPoly );
+        aPoly.Optimize( PolyOptimizeFlags::CLOSE );
+        tools::PolyPolygon aPolyPolyRect( aPoly );
+        maClipPath.excludeClip( aPolyPolyRect.getB2DPolyPolygon() );
     }
 
     void MtfTools::MoveClipRegion( const Size& rSize )
@@ -1065,7 +1081,7 @@ namespace emfio
             else
                 aPolyPolygon = ImplMap(aPolyPolygon);
         }
-        maClipPath.setClipPath(aPolyPolygon, nClippingMode);
+        maClipPath.setClipPath(aPolyPolygon.getB2DPolyPolygon(), nClippingMode);
     }
 
     void MtfTools::SetDefaultClipPath()


More information about the Libreoffice-commits mailing list