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>
(cherry picked from commit e179e53e3c703153bb0bb3155c1c6e2d25577fe0)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107105
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx b/emfio/qa/cppunit/emf/EmfImportTest.cxx
index 7a3e659..8ec6166 100644
--- a/emfio/qa/cppunit/emf/EmfImportTest.cxx
+++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx
@@ -49,6 +49,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools, public unotest:
    void TestDrawLine();
    void TestLinearGradient();
    void TestTextMapMode();
    void TestEnglishMapMode();
    void TestCreatePen();
    void TestPdfInEmf();

@@ -66,6 +67,7 @@ public:
    CPPUNIT_TEST(TestDrawLine);
    CPPUNIT_TEST(TestLinearGradient);
    CPPUNIT_TEST(TestTextMapMode);
    CPPUNIT_TEST(TestEnglishMapMode);
    CPPUNIT_TEST(TestCreatePen);
    CPPUNIT_TEST(TestPdfInEmf);
    CPPUNIT_TEST_SUITE_END();
@@ -271,6 +273,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::tools::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 e90ced5..59f016c 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -319,10 +319,16 @@ 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;
                        double nDevOrgX = mnDevOrgX;
                        if (mnPixX)
                            nDevOrgX *= static_cast<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
                        fX2 += nDevOrgX;
                        double nDevOrgY = mnDevOrgY;
                        if (mnPixY)
                            nDevOrgY *= static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
                        fY2 += nDevOrgY;
                    }
                    break;
                    case MM_HIENGLISH :
@@ -331,18 +337,30 @@ namespace emfio
                        fY2  = mnWinOrgY-fY2;
                        fX2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH;
                        fY2 *= HUNDREDTH_MILLIMETERS_PER_MILLIINCH;
                        fX2 += mnDevOrgX;
                        fY2 += mnDevOrgY;
                        double nDevOrgX = mnDevOrgX;
                        if (mnPixX)
                            nDevOrgX *= static_cast<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
                        fX2 += nDevOrgX;
                        double nDevOrgY = mnDevOrgY;
                        if (mnPixY)
                            nDevOrgY *= static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
                        fY2 += nDevOrgY;
                    }
                    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;
                        double nDevOrgX = mnDevOrgX;
                        if (mnPixX)
                            nDevOrgX *= static_cast<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
                        fX2 += nDevOrgX;
                        double nDevOrgY = mnDevOrgY;
                        if (mnPixY)
                            nDevOrgY *= static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
                        fY2 += nDevOrgY;
                    }
                    break;
                    case MM_LOMETRIC :
@@ -351,16 +369,28 @@ namespace emfio
                        fY2  = mnWinOrgY-fY2;
                        fX2 *= 10;
                        fY2 *= 10;
                        fX2 += mnDevOrgX;
                        fY2 += mnDevOrgY;
                        double nDevOrgX = mnDevOrgX;
                        if (mnPixX)
                            nDevOrgX *= static_cast<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
                        fX2 += nDevOrgX;
                        double nDevOrgY = mnDevOrgY;
                        if (mnPixY)
                            nDevOrgY *= static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
                        fY2 += nDevOrgY;
                    }
                    break;
                    case MM_HIMETRIC : // in hundredth of a millimeter
                    {
                        fX2 -= mnWinOrgX;
                        fY2  = mnWinOrgY-fY2;
                        fX2 += mnDevOrgX;
                        fY2 += mnDevOrgY;
                        double nDevOrgX = mnDevOrgX;
                        if (mnPixX)
                            nDevOrgX *= static_cast<double>(mnMillX) * 100.0 / static_cast<double>(mnPixX);
                        fX2 += nDevOrgX;
                        double nDevOrgY = mnDevOrgY;
                        if (mnPixY)
                            nDevOrgY *= static_cast<double>(mnMillY) * 100.0 / static_cast<double>(mnPixY);
                        fY2 += nDevOrgY;
                    }
                    break;
                    default :