diff options
author | Bartosz Kosiorek <gang65@poczta.onet.pl> | 2021-05-24 20:05:19 +0200 |
---|---|---|
committer | Bartosz Kosiorek <gang65@poczta.onet.pl> | 2021-05-28 21:47:40 +0200 |
commit | 3a9027609e7ee0c7af457b06426093782ca295a8 (patch) | |
tree | 4f0f6aa86cccc2326e55196d412fe5d02daa8375 /emfio/qa | |
parent | d90aa314961ea4a6893144cd6be66dd71cc2cca1 (diff) |
tdf#53004 tdf#142495 WMF EMF Fix displaying Text with OPAQUE and CLIPPED
With OPAQUE option enabled, the rectangle need to be drawn,
before drawing text.
With CLIPPED option enabled, the text needs to be drawn
only inside rectangle.
In previous implementation, the rectangle read was skipped and
it was not drawn (for OPAQUE).
For CLIPPED the rectangle was read but Clip was not applied
to text drawing
This commit fix that issues, and allow to draw rectangle correctly,
with BGColor (background color), and add support for Text Clipping
according to [MS-WMF] and [MS-EMF] specification.
The fix applied to EMR_EXTTEXTOUTW, EMR_EXTTEXTOUTA and EXTTEXTOUT records
Change-Id: I0f6248bb9465e6d5f797cddb53f058afb0815a2d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116072
Tested-by: Jenkins
Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
Diffstat (limited to 'emfio/qa')
-rw-r--r-- | emfio/qa/cppunit/emf/EmfImportTest.cxx | 113 | ||||
-rw-r--r-- | emfio/qa/cppunit/emf/data/TestExtTextOutOpaqueAndClipTransform.emf | bin | 0 -> 1232 bytes | |||
-rw-r--r-- | emfio/qa/cppunit/wmf/data/TestExtTextOutOpaqueAndClip.wmf | bin | 0 -> 328 bytes | |||
-rw-r--r-- | emfio/qa/cppunit/wmf/wmfimporttest.cxx | 18 |
4 files changed, 125 insertions, 6 deletions
diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx b/emfio/qa/cppunit/emf/EmfImportTest.cxx index 5de9faa36714..1b134551c7ff 100644 --- a/emfio/qa/cppunit/emf/EmfImportTest.cxx +++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx @@ -60,6 +60,9 @@ class Test : public test::BootstrapFixture, public XmlTestTools, public unotest: void TestEllipseXformIntersectClipRect(); void TestDrawPolyLine16WithClip(); void TestFillRegion(); + void TestExtTextOutOpaqueAndClipTransform(); + + void TestExtTextOutOpaqueAndClipWMF(); void TestPaletteWMF(); void TestRoundrectWMF(); void TestPolylinetoCloseStroke(); @@ -91,6 +94,8 @@ public: CPPUNIT_TEST(TestEllipseXformIntersectClipRect); CPPUNIT_TEST(TestDrawPolyLine16WithClip); CPPUNIT_TEST(TestFillRegion); + CPPUNIT_TEST(TestExtTextOutOpaqueAndClipTransform); + CPPUNIT_TEST(TestExtTextOutOpaqueAndClipWMF); CPPUNIT_TEST(TestPaletteWMF); CPPUNIT_TEST(TestRoundrectWMF); CPPUNIT_TEST(TestPolylinetoCloseStroke); @@ -504,6 +509,114 @@ void Test::TestPolylinetoCloseStroke() "color", "#000000"); } + +void Test::TestExtTextOutOpaqueAndClipTransform() +{ + // tdf#142495 EMF records: SETBKCOLOR, SELECTOBJECT, EXTTEXTOUTW, MODIFYWORLDTRANSFORM, CREATEFONTINDIRECT. + Primitive2DSequence aSequence = parseEmf(u"/emfio/qa/cppunit/emf/data/TestExtTextOutOpaqueAndClipTransform.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/textsimpleportion", + "text", "No_rect- DLP-"); + assertXPath(pDocument, "/primitive2D/metafile/transform/textsimpleportion", + "fontcolor", "#000000"); + + assertXPath(pDocument, "/primitive2D/metafile/transform/polypolygoncolor", 2); + assertXPath(pDocument, "/primitive2D/metafile/transform/polypolygoncolor[1]/polypolygon", + "path", "m966 490-477-275-84 147 476 275z"); + assertXPath(pDocument, "/primitive2D/metafile/transform/polypolygoncolor[1]", + "color", "#ff0000"); + + assertXPath(pDocument, "/primitive2D/metafile/transform/polypolygoncolor[2]/polypolygon", + "path", "m251 713 623 361-148 257-623-361z"); + assertXPath(pDocument, "/primitive2D/metafile/transform/polypolygoncolor[2]", + "color", "#0080ff"); + + assertXPath(pDocument, "/primitive2D/metafile/transform/group", 3); + assertXPath(pDocument, "/primitive2D/metafile/transform/group[1]/polypolygoncolor", + "color", "#ff0000"); + assertXPath(pDocument, "/primitive2D/metafile/transform/group[1]/textsimpleportion", + "text", "Opaque - DLP-"); + assertXPath(pDocument, "/primitive2D/metafile/transform/group[1]/textsimpleportion", + "fontcolor", "#000000"); + + assertXPath(pDocument, "/primitive2D/metafile/transform/group[2]/mask/group/polypolygoncolor", + "color", "#00ff00"); + assertXPath(pDocument, "/primitive2D/metafile/transform/group[2]/mask/polypolygon", + "path", "m320 508 586 340-169 293-586-339z"); + assertXPath(pDocument, "/primitive2D/metafile/transform/group[2]/mask/group/textsimpleportion", + "text", "Clip - DLP-"); + assertXPath(pDocument, "/primitive2D/metafile/transform/group[2]/mask/group/textsimpleportion", + "fontcolor", "#000000"); + + assertXPath(pDocument, "/primitive2D/metafile/transform/group[3]/mask/group/polypolygoncolor", + "color", "#0080ff"); + assertXPath(pDocument, "/primitive2D/metafile/transform/group[3]/mask/polypolygon", + "path", "m251 713 623 361-148 257-623-361z"); + assertXPath(pDocument, "/primitive2D/metafile/transform/group[3]/mask/group/textsimpleportion", + "text", "Opaque ClipP-"); + assertXPath(pDocument, "/primitive2D/metafile/transform/group[3]/mask/group/textsimpleportion", + "fontcolor", "#000000"); +} + +void Test::TestExtTextOutOpaqueAndClipWMF() +{ + // tdf#53004 WMF records: SETBKCOLOR, SELECTOBJECT, EXTTEXTOUT, CREATEBRUSHINDIRECT. + Primitive2DSequence aSequence = parseEmf(u"/emfio/qa/cppunit/wmf/data/TestExtTextOutOpaqueAndClip.wmf"); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength())); + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequence)); + CPPUNIT_ASSERT (pDocument); + +#ifdef MACOSX + // On some operating systems (Linux on LO Jenkins CI), the `/mask/` string is not added to XPath + // As a result tests are failing. On my Ubuntu 20.04 the `/mask/` string was added + // I would leave this test case for macOS to make sure there is no regression at least on one platform. + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor", 5); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[1]/polypolygon", + "path", "m7219 1825h319v3608h-319z"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[1]", + "color", "#ff0000"); + + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[2]/polypolygon", + "path", "m7219 5942h319v318h-319z"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[2]", + "color", "#00ff00"); + + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[3]/polypolygon", + "path", "m10149 5942h319v318h-319z"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[3]", + "color", "#8080ff"); + + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/group", 5); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/group[1]/polypolygoncolor", + "color", "#00ff00"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/group[1]/textsimpleportion", + "text", "ABCD"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/group[1]/textsimpleportion", + "fontcolor", "#000000"); + + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/group[2]/polypolygoncolor", + "color", "#8080ff"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/group[2]/textsimpleportion", + "text", "MMMM"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/group[2]/textsimpleportion", + "fontcolor", "#000000"); + + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/group[3]/mask/group/polypolygoncolor", + "color", "#ff8000"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/group[3]/mask/group/polypolygoncolor/polypolygon", + "path", "m1062 1061h1270v473h-1270z"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/group[3]/mask/group/textsimpleportion", + "text", "OOOO"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/group[3]/mask/group/textsimpleportion", + "fontcolor", "#000000"); +#endif +} + void Test::TestPaletteWMF() { // WMF import with records: CREATEPALETTE, SELECTOBJECT, CREATEPENINDIRECT, CREATEBRUSHINDIRECT, ELLIPSE. diff --git a/emfio/qa/cppunit/emf/data/TestExtTextOutOpaqueAndClipTransform.emf b/emfio/qa/cppunit/emf/data/TestExtTextOutOpaqueAndClipTransform.emf Binary files differnew file mode 100644 index 000000000000..7d59ac3e5bd2 --- /dev/null +++ b/emfio/qa/cppunit/emf/data/TestExtTextOutOpaqueAndClipTransform.emf diff --git a/emfio/qa/cppunit/wmf/data/TestExtTextOutOpaqueAndClip.wmf b/emfio/qa/cppunit/wmf/data/TestExtTextOutOpaqueAndClip.wmf Binary files differnew file mode 100644 index 000000000000..fb6fd20f0cb4 --- /dev/null +++ b/emfio/qa/cppunit/wmf/data/TestExtTextOutOpaqueAndClip.wmf diff --git a/emfio/qa/cppunit/wmf/wmfimporttest.cxx b/emfio/qa/cppunit/wmf/wmfimporttest.cxx index 41c15e3989f8..62a669fe3676 100644 --- a/emfio/qa/cppunit/wmf/wmfimporttest.cxx +++ b/emfio/qa/cppunit/wmf/wmfimporttest.cxx @@ -206,7 +206,7 @@ void WmfTest::testWorldTransformFontSize() CPPUNIT_ASSERT(pDoc); - assertXPath(pDoc, "/metafile/font", 8); + assertXPath(pDoc, "/metafile/font", 9); assertXPath(pDoc, "/metafile/font[1]", "color", "#595959"); assertXPath(pDoc, "/metafile/font[1]", "width", "0"); @@ -214,13 +214,19 @@ void WmfTest::testWorldTransformFontSize() assertXPath(pDoc, "/metafile/font[1]", "orientation", "0"); assertXPath(pDoc, "/metafile/font[1]", "weight", "bold"); - // World transform should not affect font size. Rotating text for 90 degrees - // should not exchange font width and height. assertXPath(pDoc, "/metafile/font[3]", "color", "#000000"); assertXPath(pDoc, "/metafile/font[3]", "width", "0"); - assertXPath(pDoc, "/metafile/font[3]", "height", "530"); - assertXPath(pDoc, "/metafile/font[3]", "orientation", "900"); - assertXPath(pDoc, "/metafile/font[3]", "weight", "normal"); + assertXPath(pDoc, "/metafile/font[3]", "height", "389"); + assertXPath(pDoc, "/metafile/font[3]", "orientation", "0"); + assertXPath(pDoc, "/metafile/font[3]", "weight", "bold"); + + // World transform should not affect font size. Rotating text for 90 degrees + // should not exchange font width and height. + assertXPath(pDoc, "/metafile/font[4]", "color", "#000000"); + assertXPath(pDoc, "/metafile/font[4]", "width", "0"); + assertXPath(pDoc, "/metafile/font[4]", "height", "530"); + assertXPath(pDoc, "/metafile/font[4]", "orientation", "900"); + assertXPath(pDoc, "/metafile/font[4]", "weight", "normal"); } void WmfTest::testTdf93750() |