[Libreoffice-commits] core.git: emfio/qa test/source

Patrick Jaap patrick.jaap at tu-dresden.de
Thu Aug 24 15:16:34 UTC 2017


 emfio/qa/cppunit/emf/EmfImportTest.cxx       |   42 +++++++++++++++++++++++++++
 emfio/qa/cppunit/emf/data/TestDrawLine.emf   |binary
 emfio/qa/cppunit/emf/data/TestDrawString.emf |binary
 test/source/primitive2dxmldump.cxx           |   18 +++++++++++
 4 files changed, 60 insertions(+)

New commits:
commit 8d1dc9a662d2e1bc833d5488f3f0013f98e7f3fd
Author: Patrick Jaap <patrick.jaap at tu-dresden.de>
Date:   Tue Aug 22 12:31:15 2017 +0200

    emfio: unit test for the EMF+ renderer
    
    Two unit tests, which test the EMF+ records DrawString and DrawLine
    independently.
    To this end, a fixed view decomposition of metafiles is implemented.
    
    The chosen primitives should be optimal, even for future extensions
    of the EMF+ parser.
    
    Change-Id: I12672d3b294ff0fdae63c7a5ce211517ef8f763c
    Reviewed-on: https://gerrit.libreoffice.org/41425
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx b/emfio/qa/cppunit/emf/EmfImportTest.cxx
index ca766b8b67f3..bc14c4bd3062 100644
--- a/emfio/qa/cppunit/emf/EmfImportTest.cxx
+++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx
@@ -39,12 +39,16 @@ class Test : public test::BootstrapFixture, public XmlTestTools
     void checkRectPrimitive(Primitive2DSequence const & rPrimitive);
 
     void testWorking();
+    void TestDrawString();
+    void TestDrawLine();
 
     Primitive2DSequence parseEmf(const OUString& aSource);
 
 public:
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(testWorking);
+    CPPUNIT_TEST(TestDrawString);
+    CPPUNIT_TEST(TestDrawLine);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -88,6 +92,44 @@ void Test::testWorking()
     checkRectPrimitive(aSequenceRect);
 }
 
+void Test::TestDrawString()
+{
+    // This unit checks for a correct import of an EMF+ file with only one DrawString Record
+    // Since the text is undecorated the optimal choice is a simpletextportion primitive
+
+    // first, get the sequence of primitives and dump it
+    Primitive2DSequence aSequence = parseEmf("/emfio/qa/cppunit/emf/data/TestDrawString.emf");
+    CPPUNIT_ASSERT_EQUAL(1, (int) aSequence.getLength());
+    Primitive2dXmlDump dumper;
+    xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequence));
+    CPPUNIT_ASSERT (pDocument);
+
+    // check correct import of the DrawString: height, position, text, color and font
+    assertXPath(pDocument, "/primitive2D/metafile/transform/textsimpleportion", "height", "276");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/textsimpleportion", "x", "25");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/textsimpleportion", "y", "323");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/textsimpleportion", "text", "TEST");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/textsimpleportion", "fontcolor", "#000000");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/textsimpleportion", "familyname", "CALIBRI");
+}
+
+void Test::TestDrawLine()
+{
+    // This unit checks for a correct import of an EMF+ file with only one DrawLine Record
+    // The line is colored and has a specified width, therefore a polypolygonstroke primitive is the optimal choice
+
+    // first, get the sequence of primitives and dump it
+    Primitive2DSequence aSequence = parseEmf("/emfio/qa/cppunit/emf/data/TestDrawLine.emf");
+    CPPUNIT_ASSERT_EQUAL(1, (int) aSequence.getLength());
+    Primitive2dXmlDump dumper;
+    xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequence));
+    CPPUNIT_ASSERT (pDocument);
+
+    // check correct import of the DrawLine: color and width of the line
+    assertXPath(pDocument, "/primitive2D/metafile/transform/polypolygonstroke/line", "color", "#000000");
+    assertXPath(pDocument, "/primitive2D/metafile/transform/polypolygonstroke/line", "width", "33");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 }
diff --git a/emfio/qa/cppunit/emf/data/TestDrawLine.emf b/emfio/qa/cppunit/emf/data/TestDrawLine.emf
new file mode 100644
index 000000000000..89946c523f98
Binary files /dev/null and b/emfio/qa/cppunit/emf/data/TestDrawLine.emf differ
diff --git a/emfio/qa/cppunit/emf/data/TestDrawString.emf b/emfio/qa/cppunit/emf/data/TestDrawString.emf
new file mode 100644
index 000000000000..c7976f53b3c0
Binary files /dev/null and b/emfio/qa/cppunit/emf/data/TestDrawString.emf differ
diff --git a/test/source/primitive2dxmldump.cxx b/test/source/primitive2dxmldump.cxx
index 6523c4c0c971..563fb75acc19 100644
--- a/test/source/primitive2dxmldump.cxx
+++ b/test/source/primitive2dxmldump.cxx
@@ -26,6 +26,9 @@
 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
 #include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
 #include <drawinglayer/primitive2d/svggradientprimitive2d.hxx>
+#include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
+#include <drawinglayer/geometry/viewinformation2d.hxx>
+
 
 #include <drawinglayer/attribute/lineattribute.hxx>
 #include <drawinglayer/attribute/fontattribute.hxx>
@@ -190,6 +193,8 @@ void Primitive2dXmlDump::decomposeAndWrite(
                 {
                     rWriter.attribute("height", aScale.getY());
                 }
+                rWriter.attribute("x", aTranslate.getX());
+                rWriter.attribute("y", aTranslate.getY());
                 rWriter.attribute("text", rTextSimplePortionPrimitive2D.getText());
                 rWriter.attribute("fontcolor", convertColorToString(rTextSimplePortionPrimitive2D.getFontColor()));
 
@@ -244,6 +249,19 @@ void Primitive2dXmlDump::decomposeAndWrite(
             }
             break;
 
+            case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D:
+            {
+                const MetafilePrimitive2D& rMetafilePrimitive2D = dynamic_cast<const MetafilePrimitive2D&>(*pBasePrimitive);
+                rWriter.startElement("metafile");
+                drawinglayer::primitive2d::Primitive2DContainer aPrimitiveContainer;
+                // since the graphic is not rendered in a document, we do not need a concrete view information
+                rMetafilePrimitive2D.get2DDecomposition(aPrimitiveContainer, drawinglayer::geometry::ViewInformation2D());
+                decomposeAndWrite(aPrimitiveContainer,rWriter);
+                rWriter.endElement();
+            }
+
+            break;
+
             default:
             {
                 rWriter.element(OUStringToOString(sCurrentElementTag, RTL_TEXTENCODING_UTF8));


More information about the Libreoffice-commits mailing list