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 <xiscofauli@libreoffice.org>
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx b/emfio/qa/cppunit/emf/EmfImportTest.cxx
index 29c0848..e8d4833 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<int>(aSequence.getLength()));
drawinglayer::Primitive2dXmlDump dumper;
xmlDocUniquePtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(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 0000000..28f4f1f
--- /dev/null
+++ b/emfio/qa/cppunit/emf/data/test_mm_hienglish_ref.emf
Binary files 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 0000000..86c568f
--- /dev/null
+++ b/emfio/qa/cppunit/emf/data/test_mm_himetric_ref.emf
Binary files differ
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index e376e6f..9ad212b 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<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
fY2 += mnDevOrgY * static_cast<double>(mnMillY) * 100.0 / static_cast<double>(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<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
fY2 += mnDevOrgY * static_cast<double>(mnMillY) * 100.0 / static_cast<double>(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<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
fY2 += mnDevOrgY * static_cast<double>(mnMillY) * 100.0 / static_cast<double>(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<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
fY2 += mnDevOrgY * static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
}
break;
case MM_HIMETRIC : // in hundredth of a millimeter
{
fX2 -= mnWinOrgX;
fY2 = mnWinOrgY-fY2;
fX2 += mnDevOrgX;
fY2 += mnDevOrgY;
fX2 += mnDevOrgX * static_cast<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
fY2 += mnDevOrgY * static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
}
break;
default :