From 6d01a0bf35eb58c9f61c29b1a751261312379fcb Mon Sep 17 00:00:00 2001 From: Bartosz Kosiorek Date: Tue, 24 Nov 2020 18:53:06 +0100 Subject: EMF: tdf#138467 Fix MapMode translation Add proper translation for map mapping modes: MM_LOMETRIC = 0x02, MM_HIMETRIC = 0x03, MM_LOENGLISH = 0x04, MM_HIENGLISH = 0x05, MM_TWIPS = 0x06 according to MS-EMF documentation. Change-Id: If4c71b52e5236441837e62590797ced8acd6c80f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106251 Tested-by: Jenkins Tested-by: Xisco Fauli Reviewed-by: Xisco Fauli Reviewed-by: Bartosz Kosiorek (cherry picked from commit e179e53e3c703153bb0bb3155c1c6e2d25577fe0) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107104 --- emfio/qa/cppunit/emf/EmfImportTest.cxx | 36 +++++++++++++++++++++ .../qa/cppunit/emf/data/test_mm_hienglish_ref.emf | Bin 0 -> 3212 bytes emfio/qa/cppunit/emf/data/test_mm_himetric_ref.emf | Bin 0 -> 3212 bytes emfio/source/reader/mtftools.cxx | 28 ++++++++-------- 4 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 emfio/qa/cppunit/emf/data/test_mm_hienglish_ref.emf create mode 100644 emfio/qa/cppunit/emf/data/test_mm_himetric_ref.emf (limited to 'emfio') diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx b/emfio/qa/cppunit/emf/EmfImportTest.cxx index 29c084874b6d..e8d4833e6424 100644 --- a/emfio/qa/cppunit/emf/EmfImportTest.cxx +++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx @@ -50,6 +50,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools, public unotest: void TestDrawLine(); void TestLinearGradient(); void TestTextMapMode(); + void TestEnglishMapMode(); void TestCreatePen(); void TestPdfInEmf(); @@ -67,6 +68,7 @@ public: CPPUNIT_TEST(TestDrawLine); CPPUNIT_TEST(TestLinearGradient); CPPUNIT_TEST(TestTextMapMode); + CPPUNIT_TEST(TestEnglishMapMode); CPPUNIT_TEST(TestCreatePen); CPPUNIT_TEST(TestPdfInEmf); CPPUNIT_TEST_SUITE_END(); @@ -272,6 +274,40 @@ void Test::TestTextMapMode() assertXPath(pDocument, "/primitive2D/metafile/transform/polygonstroke[20]/line", "width", "11"); } +void Test::TestEnglishMapMode() +{ + // Check import of EMF image with records: SETMAPMODE with MM_ENGLISH MapMode, STROKEANDFILLPATH, EXTTEXTOUTW, SETTEXTALIGN, STRETCHDIBITS + // MM_LOENGLISH is mapped to 0.01 inch. Positive x is to the right; positive y is up.M + Primitive2DSequence aSequence = parseEmf("/emfio/qa/cppunit/emf/data/test_mm_hienglish_ref.emf"); + CPPUNIT_ASSERT_EQUAL(1, static_cast(aSequence.getLength())); + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer(aSequence)); + CPPUNIT_ASSERT (pDocument); + + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygon", 1); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygon[1]", "path", "m0 0h29699v20999h-29699z"); + + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor", 3); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[1]", "color", "#ffffad"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[1]/polypolygon", "path", "m-1-1h29699v21005h-29699z"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[2]/polypolygon", "path", "m1058 7937v5293h3175v-1059h-2118v-4234z"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polypolygoncolor[3]/polypolygon", "path", "m12699 1058h4234v1060h-1587v4231h-1059v-4231h-1588z"); + + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/textsimpleportion", 4); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/textsimpleportion[1]", "text", "UL"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/textsimpleportion[1]", "fontcolor", "#000000"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/textsimpleportion[1]", "x", "106"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/textsimpleportion[1]", "y", "459"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/textsimpleportion[1]", "width", "424"); + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/textsimpleportion[1]", "height", "424"); + + assertXPath(pDocument, "/primitive2D/metafile/transform/mask/polygonhairline", 3); + assertXPathContent(pDocument, "/primitive2D/metafile/transform/mask/polygonhairline[1]/polygon", "-1,-1 29698,-1 29698,21004 -1,21004"); + assertXPathContent(pDocument, "/primitive2D/metafile/transform/mask/polygonhairline[2]/polygon", "1058,7937 1058,13230 4233,13230 4233,12171 2115,12171 2115,7937"); + assertXPathContent(pDocument, "/primitive2D/metafile/transform/mask/polygonhairline[3]/polygon", "12699,1058 16933,1058 16933,2118 15346,2118 15346,6349 14287,6349 14287,2118 12699,2118"); + + +} void Test::TestCreatePen() { diff --git a/emfio/qa/cppunit/emf/data/test_mm_hienglish_ref.emf b/emfio/qa/cppunit/emf/data/test_mm_hienglish_ref.emf new file mode 100644 index 000000000000..28f4f1fc7fa0 Binary files /dev/null and b/emfio/qa/cppunit/emf/data/test_mm_hienglish_ref.emf differ diff --git a/emfio/qa/cppunit/emf/data/test_mm_himetric_ref.emf b/emfio/qa/cppunit/emf/data/test_mm_himetric_ref.emf new file mode 100644 index 000000000000..86c568fc17e7 Binary files /dev/null and b/emfio/qa/cppunit/emf/data/test_mm_himetric_ref.emf differ diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx index e376e6f501c1..9ad212b17dfa 100644 --- a/emfio/source/reader/mtftools.cxx +++ b/emfio/source/reader/mtftools.cxx @@ -320,10 +320,10 @@ namespace emfio { fX2 -= mnWinOrgX; fY2 = mnWinOrgY-fY2; - fX2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH*10; - fY2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH*10; - fX2 += mnDevOrgX; - fY2 += mnDevOrgY; + fX2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH * 10; + fY2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH * 10; + fX2 += mnDevOrgX * static_cast(mnMillX) * 100.0 / static_cast(mnPixX); + fY2 += mnDevOrgY * static_cast(mnMillY) * 100.0 / static_cast(mnPixY); } break; case MM_HIENGLISH : @@ -332,18 +332,18 @@ namespace emfio fY2 = mnWinOrgY-fY2; fX2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH; fY2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH; - fX2 += mnDevOrgX; - fY2 += mnDevOrgY; + fX2 += mnDevOrgX * static_cast(mnMillX) * 100.0 / static_cast(mnPixX); + fY2 += mnDevOrgY * static_cast(mnMillY) * 100.0 / static_cast(mnPixY); } break; case MM_TWIPS: { fX2 -= mnWinOrgX; fY2 = mnWinOrgY-fY2; - fX2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH/MILLIINCH_PER_TWIPS; - fY2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH/MILLIINCH_PER_TWIPS; - fX2 += mnDevOrgX; - fY2 += mnDevOrgY; + fX2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH / MILLIINCH_PER_TWIPS; + fY2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH / MILLIINCH_PER_TWIPS; + fX2 += mnDevOrgX * static_cast(mnMillX) * 100.0 / static_cast(mnPixX); + fY2 += mnDevOrgY * static_cast(mnMillY) * 100.0 / static_cast(mnPixY); } break; case MM_LOMETRIC : @@ -352,16 +352,16 @@ namespace emfio fY2 = mnWinOrgY-fY2; fX2 *= 10; fY2 *= 10; - fX2 += mnDevOrgX; - fY2 += mnDevOrgY; + fX2 += mnDevOrgX * static_cast(mnMillX) * 100.0 / static_cast(mnPixX); + fY2 += mnDevOrgY * static_cast(mnMillY) * 100.0 / static_cast(mnPixY); } break; case MM_HIMETRIC : // in hundredth of a millimeter { fX2 -= mnWinOrgX; fY2 = mnWinOrgY-fY2; - fX2 += mnDevOrgX; - fY2 += mnDevOrgY; + fX2 += mnDevOrgX * static_cast(mnMillX) * 100.0 / static_cast(mnPixX); + fY2 += mnDevOrgY * static_cast(mnMillY) * 100.0 / static_cast(mnPixY); } break; default : -- cgit