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@poczta.onet.pl>
(cherry picked from commit 1ef26ffe39618a745d3367310565e7eeb184a4c2)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115207
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/emfio/inc/mtftools.hxx b/emfio/inc/mtftools.hxx
index 2864427..22c0cef 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 1f1976c..8dc864f 100644
--- a/emfio/qa/cppunit/emf/EmfImportTest.cxx
+++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx
@@ -53,6 +53,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools, public unotest:
void TestRectangleWithModifyWorldTransform();
void TestChordWithModifyWorldTransform();
void TestEllipseWithSelectClipPath();
void TestEllipseXformIntersectClipRect();
void TestDrawPolyLine16WithClip();
void TestFillRegion();
void TestCreatePen();
@@ -76,6 +77,7 @@ public:
CPPUNIT_TEST(TestRectangleWithModifyWorldTransform);
CPPUNIT_TEST(TestChordWithModifyWorldTransform);
CPPUNIT_TEST(TestEllipseWithSelectClipPath);
CPPUNIT_TEST(TestEllipseXformIntersectClipRect);
CPPUNIT_TEST(TestDrawPolyLine16WithClip);
CPPUNIT_TEST(TestFillRegion);
CPPUNIT_TEST(TestCreatePen);
@@ -368,6 +370,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 0000000..bda2ad2
--- /dev/null
+++ b/emfio/qa/cppunit/emf/data/TestEllipseXformIntersectClipRect.emf
Binary files differ
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index 092e26d..d54e0ff 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 :
@@ -1014,7 +1013,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 )
@@ -1022,7 +1029,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 )
@@ -1047,7 +1063,7 @@ namespace emfio
else
aPolyPolygon = ImplMap(aPolyPolygon);
}
maClipPath.setClipPath(aPolyPolygon, nClippingMode);
maClipPath.setClipPath(aPolyPolygon.getB2DPolyPolygon(), nClippingMode);
}
void MtfTools::SetDefaultClipPath()