From f26ba7f7c951164cc8677e55fa73081e16659147 Mon Sep 17 00:00:00 2001 From: Bartosz Kosiorek Date: Fri, 1 Apr 2022 11:43:30 +0200 Subject: tdf#147818 EMF+ Fix restoring clipping states With previous implementation the clipping restoring with EmfPlusRecordTypeRestore was implemented wrongly as it is only taken to account the shape of clipping (state.getClipPolyPolygon) and doesn't take if clipping was even enabled (state.getClipPolyPolygonActive). Additionally the changing states should be made by using method: wmfemfhelper::HandleNewClipRegion() and not directly. The similar implementation was applied also to EmfPlusRecordTypeGetDC. Additionally the clipping for EmfPlusRecordTypeSetClipRect EmfPlusRecordTypeSetClipPath EmfPlusRecordTypeSetClipRegion was fixed, as initially the clipping is disabled (state.getClipPolyPolygonActive) and the clipping shape is empty (state.getClipPolyPolygon). It means that combination other than EmfPlusCombineModeReplace, was not working correctly. With this implementation, if Clipping is disabled, then treat clip combining in special way. Change-Id: I258bda64e8bfdade7f47ffc7518bf04b7340344f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132415 Tested-by: Jenkins Reviewed-by: Bartosz Kosiorek --- emfio/qa/cppunit/emf/EmfImportTest.cxx | 66 +++++++++++++++++++++++++ emfio/qa/cppunit/emf/data/TestEmfPlusGetDC.emf | Bin 0 -> 23856 bytes emfio/qa/cppunit/emf/data/TestEmfPlusSave.emf | Bin 0 -> 1140 bytes 3 files changed, 66 insertions(+) create mode 100644 emfio/qa/cppunit/emf/data/TestEmfPlusGetDC.emf create mode 100644 emfio/qa/cppunit/emf/data/TestEmfPlusSave.emf (limited to 'emfio') diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx b/emfio/qa/cppunit/emf/EmfImportTest.cxx index fce8961a849a..0f2816962a91 100644 --- a/emfio/qa/cppunit/emf/EmfImportTest.cxx +++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx @@ -63,6 +63,8 @@ class Test : public test::BootstrapFixture, public XmlTestTools, public unotest: void TestSetArcDirection(); void TestDrawPolyLine16WithClip(); void TestFillRegion(); + void TestEmfPlusGetDC(); + void TestEmfPlusSave(); void TestExtTextOutOpaqueAndClipTransform(); void TestBitBltStretchBltWMF(); @@ -106,6 +108,8 @@ public: CPPUNIT_TEST(TestSetArcDirection); CPPUNIT_TEST(TestDrawPolyLine16WithClip); CPPUNIT_TEST(TestFillRegion); + CPPUNIT_TEST(TestEmfPlusGetDC); + CPPUNIT_TEST(TestEmfPlusSave); CPPUNIT_TEST(TestExtTextOutOpaqueAndClipTransform); CPPUNIT_TEST(TestBitBltStretchBltWMF); @@ -828,6 +832,68 @@ void Test::TestPolylinetoCloseStroke() assertXPath(pDocument, aXPathPrefix + "polygonhairline[2]", "color", "#000000"); } +void Test::TestEmfPlusGetDC() +{ + // tdf#147818 EMF+ records: GetDC, DrawPath, FillRects + Primitive2DSequence aSequence = parseEmf(u"/emfio/qa/cppunit/emf/data/TestEmfPlusGetDC.emf"); + CPPUNIT_ASSERT_EQUAL(1, static_cast(aSequence.getLength())); + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(Primitive2DContainer(aSequence)); + CPPUNIT_ASSERT(pDocument); + + assertXPath(pDocument, aXPathPrefix + "textsimpleportion", "text", "sd CCCCCCCCCCCCCCC"); + assertXPath(pDocument, aXPathPrefix + "textsimpleportion", "fontcolor", "#000000"); + + assertXPath(pDocument, aXPathPrefix + "group", 5); + assertXPath( + pDocument, aXPathPrefix + "group[4]/textsimpleportion", "text", + "Getttttttttttttttttttttttttttttt, uuuu: \"eeeeeeeeeeeeeeeeeeeeeee-7acd04a3953b\")"); + assertXPath(pDocument, aXPathPrefix + "group[5]/textsimpleportion", "text", + "TTTTTTTTTTTTTTTTTTTTTTTTTTTTT, trackId: 55)"); + assertXPath(pDocument, aXPathPrefix + "group[5]/textsimpleportion", "fontcolor", "#000000"); + + assertXPath(pDocument, aXPathPrefix + "polypolygoncolor", 6); + assertXPath(pDocument, aXPathPrefix + "polypolygoncolor[1]/polypolygon", "path", + "m105.78125 " + "776.111111111111h3878.64583333333l458.385416666667-493.888888888889v-176." + "388888888889h-4337.03125v670.277777777778"); + assertXPath(pDocument, aXPathPrefix + "polypolygoncolor[1]", "color", "#ffffff"); + + assertXPath(pDocument, aXPathPrefix + "polypolygoncolor[3]/polypolygon", "path", + "m2291.92708333333 4550.83333333333h317.34375v-317.5h-317.34375z"); + assertXPath(pDocument, aXPathPrefix + "polypolygoncolor[3]", "color", "#fcf2e3"); + + assertXPath(pDocument, aXPathPrefix + "polypolygoncolor[6]/polypolygon", "path", + "m19428.4895833333 6632.22222222222h317.34375v-2398.88888888889h-317.34375z"); + assertXPath(pDocument, aXPathPrefix + "polypolygoncolor[6]", "color", "#fcf2e3"); + + assertXPath(pDocument, aXPathPrefix + "polypolygonstroke", 15); +} + +void Test::TestEmfPlusSave() +{ + // tdf#147818 EMF+ records: Save, Restore, SetWorldTransform, FillRects, SetClipRegion + Primitive2DSequence aSequence = parseEmf(u"/emfio/qa/cppunit/emf/data/TestEmfPlusSave.emf"); + CPPUNIT_ASSERT_EQUAL(1, static_cast(aSequence.getLength())); + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(Primitive2DContainer(aSequence)); + CPPUNIT_ASSERT(pDocument); + + assertXPath(pDocument, aXPathPrefix + "mask/polypolygon", "path", "m0 0h33544v21311h-33544z"); + + assertXPath(pDocument, aXPathPrefix + "mask/group/mask/polypolygoncolor/polypolygon", "path", + "m327.458333333333 638.222222222222h437007.1875v295555.555555556h-437007.1875z"); + assertXPath(pDocument, aXPathPrefix + "mask/group/mask/polypolygoncolor", "color", "#ff0cad"); + + assertXPath(pDocument, aXPathPrefix + "mask/polypolygoncolor/polypolygon", "path", + "m10853.4145539602 7321.41354709201h41952690v29630720h-41952690z"); + assertXPath(pDocument, aXPathPrefix + "mask/polypolygoncolor", "color", "#00ffad"); + + assertXPath(pDocument, aXPathPrefix + "mask/polypolygonstroke/line", "color", "#000000"); + assertXPath(pDocument, aXPathPrefix + "mask/polypolygonstroke/polypolygon", "path", + "m10853.4145539602 7321.41354709201v-2413.87029012044h1979.24116969109"); +} + void Test::TestExtTextOutOpaqueAndClipTransform() { // tdf#142495 EMF records: SETBKCOLOR, SELECTOBJECT, EXTTEXTOUTW, MODIFYWORLDTRANSFORM, CREATEFONTINDIRECT. diff --git a/emfio/qa/cppunit/emf/data/TestEmfPlusGetDC.emf b/emfio/qa/cppunit/emf/data/TestEmfPlusGetDC.emf new file mode 100644 index 000000000000..665364abeefb Binary files /dev/null and b/emfio/qa/cppunit/emf/data/TestEmfPlusGetDC.emf differ diff --git a/emfio/qa/cppunit/emf/data/TestEmfPlusSave.emf b/emfio/qa/cppunit/emf/data/TestEmfPlusSave.emf new file mode 100644 index 000000000000..24662233b8cd Binary files /dev/null and b/emfio/qa/cppunit/emf/data/TestEmfPlusSave.emf differ -- cgit