[Libreoffice-commits] core.git: 6 commits - include/test include/tools svgio/CppunitTest_svgio.mk svgio/qa test/Library_test.mk test/source

Tomaž Vajngerl tomaz.vajngerl at collabora.com
Sat Aug 16 11:51:24 PDT 2014


 include/test/mtfxmldump.hxx         |    4 
 include/test/primitive2dxmldump.hxx |   47 +++++++
 include/test/xmlwriter.hxx          |    5 
 include/tools/stream.hxx            |    2 
 svgio/CppunitTest_svgio.mk          |    5 
 svgio/qa/cppunit/SvgImportTest.cxx  |   49 +++++--
 test/Library_test.mk                |    3 
 test/source/mtfxmldump.cxx          |  231 ++++++++++++++++--------------------
 test/source/primitive2dxmldump.cxx  |  183 ++++++++++++++++++++++++++++
 test/source/xmlwriter.cxx           |   32 ++++
 10 files changed, 420 insertions(+), 141 deletions(-)

New commits:
commit 871b196f7e7296eb4e397f84f1700db33d77bfb9
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Sat Aug 16 20:43:09 2014 +0200

    SVG test: check content of Primitive2DSequence with the XML dumper
    
    Change-Id: I12954cd52cece2d2fe99b7b4ca1e60cee3b430f0

diff --git a/svgio/CppunitTest_svgio.mk b/svgio/CppunitTest_svgio.mk
index 6c1380c..2aa4f39 100644
--- a/svgio/CppunitTest_svgio.mk
+++ b/svgio/CppunitTest_svgio.mk
@@ -14,7 +14,10 @@ $(eval $(call gb_CppunitTest_set_include,svgio_import_test,\
     -I$(SRCDIR)/svgio/inc \
 ))
 
-$(eval $(call gb_CppunitTest_use_external,svgio_import_test,boost_headers))
+$(eval $(call gb_CppunitTest_use_externals,svgio_import_test,\
+    boost_headers \
+    libxml2 \
+))
 
 $(eval $(call gb_CppunitTest_use_api,svgio_import_test,\
     offapi \
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index 5b8392d..b2ed826 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -8,7 +8,11 @@
  */
 
 #include <sal/config.h>
+
 #include <test/bootstrapfixture.hxx>
+#include <test/primitive2dxmldump.hxx>
+#include <test/xmltesttools.hxx>
+
 #include <comphelper/processfactory.hxx>
 #include <comphelper/seqstream.hxx>
 
@@ -28,8 +32,10 @@ using namespace css::io;
 using namespace css::graphic;
 using drawinglayer::primitive2d::arePrimitive2DSequencesEqual;
 
-class Test : public test::BootstrapFixture
+class Test : public test::BootstrapFixture, public XmlTestTools
 {
+    void checkRectPrimitive(Primitive2DSequence& rPrimitive);
+
     void testStyles();
 
     Primitive2DSequence parseSvg(const char* aSource);
@@ -72,28 +78,47 @@ void Test::tearDown()
     BootstrapFixture::tearDown();
 }
 
+void Test::checkRectPrimitive(Primitive2DSequence& rPrimitive)
+{
+    Primitive2dXmlDump dumper;
+    xmlDocPtr pDocument = dumper.dumpAndParse(rPrimitive);
+
+    CPPUNIT_ASSERT (pDocument);
+
+    assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#00cc00"); // rect background color
+    assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "color", "#ff0000"); // rect stroke color
+    assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "width", "3"); // rect stroke width
+
+}
+
 // Attributes for an object (like rect as in this case) can be defined
 // in different ways (directly with xml attributes, or with CSS styles),
 // however the end result should be the same.
 void Test::testStyles()
 {
-    Primitive2DSequence maSequenceRect = parseSvg("/svgio/qa/cppunit/data/Rect.svg");
-    CPPUNIT_ASSERT_EQUAL(1, (int) maSequenceRect.getLength());
+    Primitive2DSequence aSequenceRect = parseSvg("/svgio/qa/cppunit/data/Rect.svg");
+    CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRect.getLength());
+    checkRectPrimitive(aSequenceRect);
 
-    Primitive2DSequence maSequenceRectWithStyle = parseSvg("/svgio/qa/cppunit/data/RectWithStyles.svg");
-    CPPUNIT_ASSERT_EQUAL(1, (int) maSequenceRectWithStyle.getLength());
+    Primitive2DSequence aSequenceRectWithStyle = parseSvg("/svgio/qa/cppunit/data/RectWithStyles.svg");
+    CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithStyle.getLength());
+    checkRectPrimitive(aSequenceRectWithStyle);
 
-    Primitive2DSequence maSequenceRectWithParentStyle = parseSvg("/svgio/qa/cppunit/data/RectWithParentStyles.svg");
-    CPPUNIT_ASSERT_EQUAL(1, (int) maSequenceRectWithParentStyle.getLength());
+    Primitive2DSequence aSequenceRectWithParentStyle = parseSvg("/svgio/qa/cppunit/data/RectWithParentStyles.svg");
+    CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithParentStyle.getLength());
+    checkRectPrimitive(aSequenceRectWithParentStyle);
 
-    Primitive2DSequence maSequenceRectWithStylesByGroup = parseSvg("/svgio/qa/cppunit/data/RectWithStylesByGroup.svg");
-    CPPUNIT_ASSERT_EQUAL(1, (int) maSequenceRectWithStylesByGroup.getLength());
+    Primitive2DSequence aSequenceRectWithStylesByGroup = parseSvg("/svgio/qa/cppunit/data/RectWithStylesByGroup.svg");
+    CPPUNIT_ASSERT_EQUAL(1, (int) aSequenceRectWithStylesByGroup.getLength());
+    checkRectPrimitive(aSequenceRectWithStylesByGroup);
+
+    CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect, aSequenceRectWithStyle));
+    CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect, aSequenceRectWithParentStyle));
+    CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(aSequenceRect, aSequenceRectWithStylesByGroup));
 
-    CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(maSequenceRect, maSequenceRectWithStyle));
-    CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(maSequenceRect, maSequenceRectWithParentStyle));
-    CPPUNIT_ASSERT(arePrimitive2DSequencesEqual(maSequenceRect, maSequenceRectWithStylesByGroup));
 }
 
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 }
commit 4bc6484c594cd11d2f04e9918aada20d49934bee
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Sat Aug 16 20:40:50 2014 +0200

    initial implementation of XML dump for Primitive2DSequence
    
    Change-Id: I6618b18164a26553f81a1c737e009b7187b028c3

diff --git a/include/test/primitive2dxmldump.hxx b/include/test/primitive2dxmldump.hxx
new file mode 100644
index 0000000..6a94960
--- /dev/null
+++ b/include/test/primitive2dxmldump.hxx
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_TEST_PRIMITIVE2DXMLDUMP_HXX
+#define INCLUDED_TEST_PRIMITIVE2DXMLDUMP_HXX
+
+#include <sal/config.h>
+#include <test/testdllapi.hxx>
+#include <test/xmlwriter.hxx>
+
+#include <libxml/tree.h>
+#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
+
+#include <vector>
+
+class OOO_DLLPUBLIC_TEST Primitive2dXmlDump
+{
+private:
+    std::vector<bool> maFilter;
+    void decomposeAndWrite(const drawinglayer::primitive2d::Primitive2DSequence& rPrimitive2DSequence, XmlWriter& rWriter);
+
+public:
+    Primitive2dXmlDump();
+    virtual ~Primitive2dXmlDump();
+
+    void filterActionType(const sal_uInt16 nActionType, bool bShouldFilter);
+    void filterAllActionTypes();
+
+    /** The actual result that will be used for testing.
+
+        This function normally uses a SvMemoryStream for its operation; but
+        can use a physical file when a filename is specified in
+        pTempStreamName - this is useful when creating the test, to dump the
+        file for examination.
+    */
+    xmlDocPtr dumpAndParse(drawinglayer::primitive2d::Primitive2DSequence aPrimitive2DSequence, const OUString& rTempStreamName = OUString());
+};
+
+#endif // INCLUDED_TEST_PRIMITIVE2DXMLDUMP_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/Library_test.mk b/test/Library_test.mk
index 585c7eb..2c8d854 100644
--- a/test/Library_test.mk
+++ b/test/Library_test.mk
@@ -22,6 +22,7 @@ $(eval $(call gb_Library_use_externals,test,\
 ))
 
 $(eval $(call gb_Library_use_libraries,test,\
+    basegfx \
     comphelper \
     cppu \
     cppuhelper \
@@ -32,6 +33,7 @@ $(eval $(call gb_Library_use_libraries,test,\
 	utl \
 	unotest \
 	vcl \
+	drawinglayer \
 	$(gb_UWINAPI) \
 ))
 
@@ -42,6 +44,7 @@ $(eval $(call gb_Library_add_exception_objects,test,\
     test/source/htmltesttools \
     test/source/mtfxmldump \
     test/source/xmlwriter \
+    test/source/primitive2dxmldump \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/test/source/primitive2dxmldump.cxx b/test/source/primitive2dxmldump.cxx
new file mode 100644
index 0000000..ea12562
--- /dev/null
+++ b/test/source/primitive2dxmldump.cxx
@@ -0,0 +1,183 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/primitive2dxmldump.hxx>
+#include <test/xmltesttools.hxx>
+
+#include <vcl/metaact.hxx>
+#include <rtl/string.hxx>
+#include <rtl/strbuf.hxx>
+
+#include <boost/scoped_ptr.hpp>
+
+#include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
+#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
+#include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
+#include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
+#include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
+
+#include <drawinglayer/attribute/lineattribute.hxx>
+
+#include <basegfx/polygon/b2dpolypolygontools.hxx>
+#include <basegfx/polygon/b2dpolygontools.hxx>
+
+using namespace drawinglayer::primitive2d;
+
+namespace
+{
+
+const size_t constMaxActionType = 513;
+
+OUString convertColorToString(basegfx::BColor aColor)
+{
+    OUString aRGBString = Color(aColor).AsRGBHexString();
+    return "#" + aRGBString;
+}
+
+} // anonymous namespace
+
+Primitive2dXmlDump::Primitive2dXmlDump() :
+    maFilter(constMaxActionType, false)
+{}
+
+Primitive2dXmlDump::~Primitive2dXmlDump()
+{}
+
+void Primitive2dXmlDump::filterActionType(const sal_uInt16 nActionType, bool bShouldFilter)
+{
+    maFilter[nActionType] = bShouldFilter;
+}
+
+void Primitive2dXmlDump::filterAllActionTypes()
+{
+    maFilter.assign(constMaxActionType, true);
+}
+
+xmlDocPtr Primitive2dXmlDump::dumpAndParse(Primitive2DSequence aPrimitive2DSequence, const OUString& rTempStreamName)
+{
+    boost::scoped_ptr<SvStream> pStream;
+
+    if (rTempStreamName.isEmpty())
+        pStream.reset(new SvMemoryStream());
+    else
+        pStream.reset(new SvFileStream(rTempStreamName, STREAM_STD_READWRITE | STREAM_TRUNC));
+
+    XmlWriter aWriter(pStream.get());
+    aWriter.startDocument();
+    aWriter.startElement("primitive2D");
+
+    decomposeAndWrite(aPrimitive2DSequence, aWriter);
+
+    aWriter.endElement();
+    aWriter.endDocument();
+
+    pStream->Seek(STREAM_SEEK_TO_BEGIN);
+
+    xmlDocPtr pDoc = XmlTestTools::parseXmlStream(pStream.get());
+
+    return pDoc;
+}
+
+void Primitive2dXmlDump::decomposeAndWrite(const Primitive2DSequence& rPrimitive2DSequence, XmlWriter& rWriter)
+{
+    for (int i = 0; i < rPrimitive2DSequence.getLength(); i++)
+    {
+        Primitive2DReference xPrimitive2DReference = rPrimitive2DSequence[i];
+        const BasePrimitive2D* pBasePrimitive = dynamic_cast<const BasePrimitive2D* >(xPrimitive2DReference.get());
+
+        sal_uInt32 nId = pBasePrimitive->getPrimitive2DID();
+        if (maFilter[nId])
+            continue;
+
+        OUString sCurrentElementTag = drawinglayer::primitive2d::idToString(nId);
+
+        switch (nId)
+        {
+            case PRIMITIVE2D_ID_HIDDENGEOMETRYPRIMITIVE2D:
+            {
+                const HiddenGeometryPrimitive2D* pHiddenGeometryPrimitive2D = dynamic_cast<const HiddenGeometryPrimitive2D*>(pBasePrimitive);
+                rWriter.startElement("hiddengeometry");
+                decomposeAndWrite(pHiddenGeometryPrimitive2D->getChildren(), rWriter);
+                rWriter.endElement();
+            }
+            break;
+
+            case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D:
+            {
+                const TransformPrimitive2D* pTransformPrimitive2D = dynamic_cast<const TransformPrimitive2D*>(pBasePrimitive);
+                rWriter.startElement("transform");
+                //pTransformPrimitive2D->getTransformation()
+                decomposeAndWrite(pTransformPrimitive2D->getChildren(), rWriter);
+                rWriter.endElement();
+            }
+            break;
+
+            case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D:
+            {
+                const PolyPolygonColorPrimitive2D* pPolyPolygonColorPrimitive2D = dynamic_cast<const PolyPolygonColorPrimitive2D*>(pBasePrimitive);
+
+                rWriter.startElement("polypolygoncolor");
+                rWriter.attribute("color", convertColorToString(pPolyPolygonColorPrimitive2D->getBColor()));
+                rWriter.startElement("polypolygon");
+                rWriter.content(basegfx::tools::exportToSvgD(pPolyPolygonColorPrimitive2D->getB2DPolyPolygon(), true, true, false));
+                rWriter.endElement();
+                rWriter.endElement();
+            }
+            break;
+
+            case PRIMITIVE2D_ID_POLYPOLYGONSTROKEPRIMITIVE2D:
+            {
+                const PolyPolygonStrokePrimitive2D* pPolyPolygonStrokePrimitive2D = dynamic_cast<const PolyPolygonStrokePrimitive2D*>(pBasePrimitive);
+                rWriter.startElement("polypolygonstroke");
+
+                rWriter.startElement("line");
+                drawinglayer::attribute::LineAttribute aLineAttribute = pPolyPolygonStrokePrimitive2D->getLineAttribute();
+                rWriter.attribute("color", convertColorToString(aLineAttribute.getColor()));
+                rWriter.attribute("width", aLineAttribute.getWidth());
+                //rWriter.attribute("linejoin", aLineAttribute.getLineJoin());
+                //rWriter.attribute("linecap", aLineAttribute.getLineCap());
+                rWriter.endElement();
+
+                //getStrokeAttribute()
+
+                rWriter.startElement("polypolygon");
+                rWriter.content(basegfx::tools::exportToSvgD(pPolyPolygonStrokePrimitive2D->getB2DPolyPolygon(), true, true, false));
+                rWriter.endElement();
+
+                rWriter.endElement();
+            }
+            break;
+
+            case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D:
+            {
+                const PolygonHairlinePrimitive2D* pPolygonHairlinePrimitive2D = dynamic_cast<const PolygonHairlinePrimitive2D*>(pBasePrimitive);
+                rWriter.startElement("polygonhairline");
+
+                rWriter.attribute("color", convertColorToString(pPolygonHairlinePrimitive2D->getBColor()));
+
+                rWriter.startElement("polygon");
+                rWriter.content(basegfx::tools::exportToSvgPoints(pPolygonHairlinePrimitive2D->getB2DPolygon()));
+                rWriter.endElement();
+
+
+                rWriter.endElement();
+            }
+            break;
+
+            default:
+            {
+                rWriter.element(OUStringToOString(sCurrentElementTag, RTL_TEXTENCODING_UTF8));
+            }
+            break;
+        }
+
+    }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit d3a59629f79da913b4a3ee367cdf70d0f5167416
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Sat Aug 16 20:30:18 2014 +0200

    XmlWriter: simplify and take SvStream* as input
    
    Change-Id: I56b2fa6887f7971604a2dcf34497ecda9cea8937

diff --git a/include/test/xmlwriter.hxx b/include/test/xmlwriter.hxx
index b640639..243b7fc 100644
--- a/include/test/xmlwriter.hxx
+++ b/include/test/xmlwriter.hxx
@@ -16,13 +16,16 @@
 #include <rtl/ustring.hxx>
 #include <rtl/string.hxx>
 
+#include <tools/stream.hxx>
+
 class OOO_DLLPUBLIC_TEST XmlWriter
 {
 private:
+    SvStream* mpStream;
     xmlTextWriterPtr mpWriter;
 
 public:
-    XmlWriter(xmlTextWriterPtr pWriter);
+    XmlWriter(SvStream* pStream);
     virtual ~XmlWriter();
 
     void startDocument();
diff --git a/test/source/mtfxmldump.cxx b/test/source/mtfxmldump.cxx
index f50a5ed..1a12912 100644
--- a/test/source/mtfxmldump.cxx
+++ b/test/source/mtfxmldump.cxx
@@ -22,19 +22,6 @@ namespace
 
 const size_t constMaxActionType = 513;
 
-int lclWriteCallback(void* pContext, const char* sBuffer, int nLen)
-{
-    SvStream* pStream = static_cast<SvStream*>(pContext);
-    return (int) pStream->Write(sBuffer, nLen);
-}
-
-int lclCloseCallback(void* pContext)
-{
-    SvStream* pStream = static_cast<SvStream*>(pContext);
-    pStream->Flush();
-    return 0; // 0 or -1 in case of error
-}
-
 OUString flagToString(sal_uInt16 nFlag)
 {
     if (nFlag & PUSH_LINECOLOR)
@@ -253,10 +240,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString&
     else
         pStream.reset(new SvFileStream(rTempStreamName, STREAM_STD_READWRITE | STREAM_TRUNC));
 
-    xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(lclWriteCallback, lclCloseCallback, pStream.get(), NULL);
-    xmlTextWriterPtr xmlWriter = xmlNewTextWriter(xmlOutBuffer);
-
-    XmlWriter aWriter(xmlWriter);
+    XmlWriter aWriter(pStream.get());
     aWriter.startDocument();
     aWriter.startElement("metafile");
 
diff --git a/test/source/xmlwriter.cxx b/test/source/xmlwriter.cxx
index c3ac40e..de3b901 100644
--- a/test/source/xmlwriter.cxx
+++ b/test/source/xmlwriter.cxx
@@ -20,8 +20,27 @@
 #include <libxml/xmlstring.h>
 #include <test/xmlwriter.hxx>
 
-XmlWriter::XmlWriter(xmlTextWriterPtr pWriter) :
-    mpWriter(pWriter)
+namespace
+{
+
+int lclWriteCallback(void* pContext, const char* sBuffer, int nLen)
+{
+    SvStream* pStream = static_cast<SvStream*>(pContext);
+    return (int) pStream->Write(sBuffer, nLen);
+}
+
+int lclCloseCallback(void* pContext)
+{
+    SvStream* pStream = static_cast<SvStream*>(pContext);
+    pStream->Flush();
+    return 0; // 0 or -1 in case of error
+}
+
+} // anonymous namespace
+
+XmlWriter::XmlWriter(SvStream* pStream) :
+    mpStream(pStream),
+    mpWriter(NULL)
 {}
 
 XmlWriter::~XmlWriter()
@@ -29,8 +48,13 @@ XmlWriter::~XmlWriter()
 
 void XmlWriter::startDocument()
 {
-    xmlTextWriterSetIndent(mpWriter, 1);
-    xmlTextWriterStartDocument(mpWriter, NULL, "UTF-8", NULL);
+    if (mpWriter == NULL && mpStream != NULL)
+    {
+        xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(lclWriteCallback, lclCloseCallback, mpStream, NULL);
+        mpWriter = xmlNewTextWriter(xmlOutBuffer);
+        xmlTextWriterSetIndent(mpWriter, 1);
+        xmlTextWriterStartDocument(mpWriter, NULL, "UTF-8", NULL);
+    }
 }
 
 void XmlWriter::endDocument()
commit 8a3a2e888bf805c602c217733510114e0521eedf
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Sat Aug 16 20:25:49 2014 +0200

    mtfxmldump: move XML writing into its own function
    
    Change-Id: I82954177fe9d4934e69b33c1c985304add09e089

diff --git a/include/test/mtfxmldump.hxx b/include/test/mtfxmldump.hxx
index e91eb6b..997d023 100644
--- a/include/test/mtfxmldump.hxx
+++ b/include/test/mtfxmldump.hxx
@@ -17,10 +17,14 @@
 #include <vcl/gdimtf.hxx>
 #include <vector>
 
+class XmlWriter;
+
 class OOO_DLLPUBLIC_TEST MetafileXmlDump
 {
     std::vector<bool> maFilter;
 
+    void writeXml(GDIMetaFile& rMetaFile, XmlWriter& rWriter);
+
 public:
     MetafileXmlDump();
     virtual ~MetafileXmlDump();
diff --git a/test/source/mtfxmldump.cxx b/test/source/mtfxmldump.cxx
index aa92777..f50a5ed 100644
--- a/test/source/mtfxmldump.cxx
+++ b/test/source/mtfxmldump.cxx
@@ -260,6 +260,20 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString&
     aWriter.startDocument();
     aWriter.startElement("metafile");
 
+    writeXml(rMetaFile, aWriter);
+
+    aWriter.endElement();
+    aWriter.endDocument();
+
+    pStream->Seek(STREAM_SEEK_TO_BEGIN);
+
+    xmlDocPtr pDoc = XmlTestTools::parseXmlStream(pStream.get());
+
+    return pDoc;
+}
+
+void MetafileXmlDump::writeXml(GDIMetaFile& rMetaFile, XmlWriter& rWriter)
+{
     for(MetaAction* pAction = rMetaFile.FirstAction(); pAction != NULL; pAction = rMetaFile.NextAction())
     {
         const sal_uInt16 nActionType = pAction->GetType();
@@ -273,281 +287,271 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString&
             case META_LINE_ACTION:
             {
                 MetaLineAction* pMetaLineAction = static_cast<MetaLineAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
-                aWriter.attribute("startx", pMetaLineAction->GetStartPoint().X());
-                aWriter.attribute("starty", pMetaLineAction->GetStartPoint().Y());
-                aWriter.attribute("endx", pMetaLineAction->GetEndPoint().X());
-                aWriter.attribute("endy", pMetaLineAction->GetEndPoint().Y());
+                rWriter.attribute("startx", pMetaLineAction->GetStartPoint().X());
+                rWriter.attribute("starty", pMetaLineAction->GetStartPoint().Y());
+                rWriter.attribute("endx", pMetaLineAction->GetEndPoint().X());
+                rWriter.attribute("endy", pMetaLineAction->GetEndPoint().Y());
 
                 LineInfo aLineInfo = pMetaLineAction->GetLineInfo();
-                aWriter.attribute("style", convertLineStyleToString(aLineInfo.GetStyle()));
-                aWriter.attribute("width", aLineInfo.GetWidth());
-                aWriter.attribute("dashlen", aLineInfo.GetDashLen());
-                aWriter.attribute("dotlen", aLineInfo.GetDotLen());
-                aWriter.attribute("distance", aLineInfo.GetDistance());
+                rWriter.attribute("style", convertLineStyleToString(aLineInfo.GetStyle()));
+                rWriter.attribute("width", aLineInfo.GetWidth());
+                rWriter.attribute("dashlen", aLineInfo.GetDashLen());
+                rWriter.attribute("dotlen", aLineInfo.GetDotLen());
+                rWriter.attribute("distance", aLineInfo.GetDistance());
 
-                aWriter.endElement();
+                rWriter.endElement();
             }
             break;
 
             case META_PUSH_ACTION:
             {
                 MetaPushAction* pMetaPushAction = static_cast<MetaPushAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
-                aWriter.attribute("flags", collectPushFlags(pMetaPushAction->GetFlags()));
+                rWriter.attribute("flags", collectPushFlags(pMetaPushAction->GetFlags()));
             }
             break;
 
             case META_POP_ACTION:
             {
-                aWriter.endElement();
+                rWriter.endElement();
             }
             break;
 
             case META_RASTEROP_ACTION:
             {
                 MetaRasterOpAction* pMetaRasterOpAction = static_cast<MetaRasterOpAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
                 if (pMetaRasterOpAction->GetRasterOp() != ROP_OVERPAINT)
                 {
-                    aWriter.attribute("operation", convertRopToString(pMetaRasterOpAction->GetRasterOp()));
+                    rWriter.attribute("operation", convertRopToString(pMetaRasterOpAction->GetRasterOp()));
                 }
-                aWriter.endElement();
+                rWriter.endElement();
             }
             break;
 
             case META_TEXTLINECOLOR_ACTION:
             {
                 MetaTextLineColorAction* pMetaTextLineColorAction = static_cast<MetaTextLineColorAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
-                aWriter.attribute("color", convertColorToString(pMetaTextLineColorAction->GetColor()));
-                aWriter.endElement();
+                rWriter.attribute("color", convertColorToString(pMetaTextLineColorAction->GetColor()));
+                rWriter.endElement();
             }
             break;
 
             case META_TEXTFILLCOLOR_ACTION:
             {
                 MetaTextFillColorAction* pMetaTextFillColorAction = static_cast<MetaTextFillColorAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
-                aWriter.attribute("color", convertColorToString(pMetaTextFillColorAction->GetColor()));
+                rWriter.attribute("color", convertColorToString(pMetaTextFillColorAction->GetColor()));
 
                 if (pMetaTextFillColorAction->IsSetting())
-                    aWriter.attribute("setting", OUString("true"));
+                    rWriter.attribute("setting", OUString("true"));
 
-                aWriter.endElement();
+                rWriter.endElement();
             }
             break;
 
             case META_FONT_ACTION:
             {
                 MetaFontAction* pMetaFontAction = static_cast<MetaFontAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
                 Font aFont = pMetaFontAction->GetFont();
 
-                aWriter.attribute("color", convertColorToString(aFont.GetColor()));
-                aWriter.attribute("fillcolor", convertColorToString(aFont.GetFillColor()));
-                aWriter.attribute("name", aFont.GetName());
-                aWriter.attribute("stylename", aFont.GetStyleName());
-                aWriter.attribute("width", aFont.GetSize().Width());
-                aWriter.attribute("height", aFont.GetSize().Height());
-                aWriter.attribute("orientation", aFont.GetOrientation());
-                aWriter.attribute("weight", convertFontWeigthToString(aFont.GetWeight()));
+                rWriter.attribute("color", convertColorToString(aFont.GetColor()));
+                rWriter.attribute("fillcolor", convertColorToString(aFont.GetFillColor()));
+                rWriter.attribute("name", aFont.GetName());
+                rWriter.attribute("stylename", aFont.GetStyleName());
+                rWriter.attribute("width", aFont.GetSize().Width());
+                rWriter.attribute("height", aFont.GetSize().Height());
+                rWriter.attribute("orientation", aFont.GetOrientation());
+                rWriter.attribute("weight", convertFontWeigthToString(aFont.GetWeight()));
 
-                aWriter.endElement();
+                rWriter.endElement();
             }
             break;
 
             case META_TEXTALIGN_ACTION:
             {
                 MetaTextAlignAction* pMetaTextAlignAction = static_cast<MetaTextAlignAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
                 OUString sAlign = convertTextAlignToString(pMetaTextAlignAction->GetTextAlign());
                 if (!sAlign.isEmpty())
-                    aWriter.attribute("align", sAlign);
-                aWriter.endElement();
+                    rWriter.attribute("align", sAlign);
+                rWriter.endElement();
             }
             break;
 
             case META_TEXTCOLOR_ACTION:
             {
                 MetaTextColorAction* pMetaTextColorAction = static_cast<MetaTextColorAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
-                aWriter.attribute("color", convertColorToString(pMetaTextColorAction->GetColor()));
-                aWriter.endElement();
+                rWriter.attribute("color", convertColorToString(pMetaTextColorAction->GetColor()));
+                rWriter.endElement();
             }
             break;
 
             case META_TEXTARRAY_ACTION:
             {
                 MetaTextArrayAction* pMetaTextArrayAction = static_cast<MetaTextArrayAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
                 sal_Int32 aIndex = pMetaTextArrayAction->GetIndex();
                 sal_Int32 aLength = pMetaTextArrayAction->GetLen();
 
-                aWriter.attribute("x", pMetaTextArrayAction->GetPoint().X());
-                aWriter.attribute("y", pMetaTextArrayAction->GetPoint().Y());
-                aWriter.attribute("index", aIndex);
-                aWriter.attribute("length", aLength);
+                rWriter.attribute("x", pMetaTextArrayAction->GetPoint().X());
+                rWriter.attribute("y", pMetaTextArrayAction->GetPoint().Y());
+                rWriter.attribute("index", aIndex);
+                rWriter.attribute("length", aLength);
 
-                aWriter.startElement("dxarray");
+                rWriter.startElement("dxarray");
                 OUString sDxLengthString;
                 for (sal_Int32 i = 0; i < aLength; ++i)
                 {
                     sDxLengthString += OUString::number(pMetaTextArrayAction->GetDXArray()[aIndex+i]);
                     sDxLengthString += " ";
                 }
-                aWriter.content(sDxLengthString);
-                aWriter.endElement();
+                rWriter.content(sDxLengthString);
+                rWriter.endElement();
 
-                aWriter.startElement("text");
-                aWriter.content(pMetaTextArrayAction->GetText());
-                aWriter.endElement();
+                rWriter.startElement("text");
+                rWriter.content(pMetaTextArrayAction->GetText());
+                rWriter.endElement();
 
-                aWriter.endElement();
+                rWriter.endElement();
             }
             break;
 
             case META_LINECOLOR_ACTION:
             {
                 MetaLineColorAction* pMetaLineColorAction = static_cast<MetaLineColorAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
-                aWriter.attribute("color", convertColorToString(pMetaLineColorAction->GetColor()));
-                aWriter.endElement();
+                rWriter.attribute("color", convertColorToString(pMetaLineColorAction->GetColor()));
+                rWriter.endElement();
             }
             break;
 
             case META_FILLCOLOR_ACTION:
             {
                 MetaFillColorAction* pMetaFillColorAction = static_cast<MetaFillColorAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
-                aWriter.attribute("color", convertColorToString(pMetaFillColorAction->GetColor()));
-                aWriter.endElement();
+                rWriter.attribute("color", convertColorToString(pMetaFillColorAction->GetColor()));
+                rWriter.endElement();
             }
             break;
 
             case META_CLIPREGION_ACTION:
             {
                 const MetaClipRegionAction* pA = static_cast< const MetaClipRegionAction* >(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
                 // FIXME for now we dump only the bounding box; this is
                 // enough for the tests we have, but may need extending to
                 // dumping the real polypolygon in the future
                 Rectangle aRectangle = pA->GetRegion().GetBoundRect();
-                aWriter.attribute("top",    aRectangle.Top());
-                aWriter.attribute("left",   aRectangle.Left());
-                aWriter.attribute("bottom", aRectangle.Bottom());
-                aWriter.attribute("right",  aRectangle.Right());
+                rWriter.attribute("top",    aRectangle.Top());
+                rWriter.attribute("left",   aRectangle.Left());
+                rWriter.attribute("bottom", aRectangle.Bottom());
+                rWriter.attribute("right",  aRectangle.Right());
 
-                aWriter.endElement();
+                rWriter.endElement();
             }
             break;
 
             case META_ISECTRECTCLIPREGION_ACTION:
             {
                 MetaISectRectClipRegionAction* pMetaISectRectClipRegionAction = static_cast<MetaISectRectClipRegionAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
                 Rectangle aRectangle = pMetaISectRectClipRegionAction->GetRect();
-                aWriter.attribute("top",    aRectangle.Top());
-                aWriter.attribute("left",   aRectangle.Left());
-                aWriter.attribute("bottom", aRectangle.Bottom());
-                aWriter.attribute("right",  aRectangle.Right());
+                rWriter.attribute("top",    aRectangle.Top());
+                rWriter.attribute("left",   aRectangle.Left());
+                rWriter.attribute("bottom", aRectangle.Bottom());
+                rWriter.attribute("right",  aRectangle.Right());
 
-                aWriter.endElement();
+                rWriter.endElement();
             }
             break;
 
             case META_POLYLINE_ACTION:
             {
                 MetaPolyLineAction* pMetaPolyLineAction = static_cast<MetaPolyLineAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
                 Polygon aPolygon = pMetaPolyLineAction->GetPolygon();
                 for (sal_uInt16 i = 0; i < aPolygon.GetSize(); i++)
                 {
-                    aWriter.startElement("point");
-                    aWriter.attribute("x", aPolygon[i].X());
-                    aWriter.attribute("y", aPolygon[i].Y());
-                    aWriter.endElement();
+                    rWriter.startElement("point");
+                    rWriter.attribute("x", aPolygon[i].X());
+                    rWriter.attribute("y", aPolygon[i].Y());
+                    rWriter.endElement();
                 }
 
                 LineInfo aLineInfo = pMetaPolyLineAction->GetLineInfo();
-                aWriter.attribute("style", convertLineStyleToString(aLineInfo.GetStyle()));
-                aWriter.attribute("width", aLineInfo.GetWidth());
-                aWriter.attribute("dashlen", aLineInfo.GetDashLen());
-                aWriter.attribute("dotlen", aLineInfo.GetDotLen());
-                aWriter.attribute("distance", aLineInfo.GetDistance());
+                rWriter.attribute("style", convertLineStyleToString(aLineInfo.GetStyle()));
+                rWriter.attribute("width", aLineInfo.GetWidth());
+                rWriter.attribute("dashlen", aLineInfo.GetDashLen());
+                rWriter.attribute("dotlen", aLineInfo.GetDotLen());
+                rWriter.attribute("distance", aLineInfo.GetDistance());
 
-                aWriter.endElement();
+                rWriter.endElement();
             }
             break;
 
             case META_POLYGON_ACTION:
             {
                 MetaPolygonAction* pMetaPolygonAction = static_cast<MetaPolygonAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
                 Polygon aPolygon = pMetaPolygonAction->GetPolygon();
                 for (sal_uInt16 i = 0; i < aPolygon.GetSize(); i++)
                 {
-                    aWriter.startElement("point");
-                    aWriter.attribute("x", aPolygon[i].X());
-                    aWriter.attribute("y", aPolygon[i].Y());
-                    aWriter.endElement();
+                    rWriter.startElement("point");
+                    rWriter.attribute("x", aPolygon[i].X());
+                    rWriter.attribute("y", aPolygon[i].Y());
+                    rWriter.endElement();
                 }
 
-                aWriter.endElement();
+                rWriter.endElement();
             }
             break;
 
             case META_COMMENT_ACTION:
             {
                 MetaCommentAction* pMetaCommentAction = static_cast<MetaCommentAction*>(pAction);
-                aWriter.startElement(sCurrentElementTag);
+                rWriter.startElement(sCurrentElementTag);
 
                 if (pMetaCommentAction->GetDataSize() > 0)
                 {
-                    aWriter.attribute("datasize", pMetaCommentAction->GetDataSize());
+                    rWriter.attribute("datasize", pMetaCommentAction->GetDataSize());
                 }
                 if (!pMetaCommentAction->GetComment().isEmpty())
                 {
-                    aWriter.startElement("comment");
-                    aWriter.content(pMetaCommentAction->GetComment());
-                    aWriter.endElement();
+                    rWriter.startElement("comment");
+                    rWriter.content(pMetaCommentAction->GetComment());
+                    rWriter.endElement();
                 }
 
-                aWriter.endElement();
+                rWriter.endElement();
             }
             break;
 
             default:
             {
-                aWriter.element(sCurrentElementTag);
+                rWriter.element(sCurrentElementTag);
             }
             break;
         }
-
     }
-
-    aWriter.endElement();
-    aWriter.endDocument();
-
-    pStream->Seek(STREAM_SEEK_TO_BEGIN);
-
-    xmlDocPtr pDoc = XmlTestTools::parseXmlStream(pStream.get());
-
-    return pDoc;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 20d8a3474b0570997d8d241a55244228f0e38ce3
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Sat Aug 16 18:42:23 2014 +0200

    No need to write '
    
    Change-Id: I0562defc6fc60ee83bc73b901caf46b1283a9df9

diff --git a/test/source/mtfxmldump.cxx b/test/source/mtfxmldump.cxx
index 87588c1..aa92777 100644
--- a/test/source/mtfxmldump.cxx
+++ b/test/source/mtfxmldump.cxx
@@ -25,15 +25,14 @@ const size_t constMaxActionType = 513;
 int lclWriteCallback(void* pContext, const char* sBuffer, int nLen)
 {
     SvStream* pStream = static_cast<SvStream*>(pContext);
-    pStream->Write(sBuffer, nLen);
-    return nLen;
+    return (int) pStream->Write(sBuffer, nLen);
 }
 
 int lclCloseCallback(void* pContext)
 {
     SvStream* pStream = static_cast<SvStream*>(pContext);
-    pStream->WriteChar('\0');
-    return 0;
+    pStream->Flush();
+    return 0; // 0 or -1 in case of error
 }
 
 OUString flagToString(sal_uInt16 nFlag)
commit e97997f1e56731b97d469f775994ef3d05f17d35
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Sat Aug 16 18:31:07 2014 +0200

    SvMemoryStream.remainingSize ret. size to end of data not buffer
    
    SvMemoryStream remainingSize returned the size from current
    position to internal buffer size instead to end of data. This
    was not consistent with what remainingSize description says on
    SvStream (and other SvStream implementations work) and what the
    user expects.
    
    Change-Id: I7ff391754a386c5f067a4bd4eed2ee7f2d7fd77e

diff --git a/include/tools/stream.hxx b/include/tools/stream.hxx
index 181a9ce..920b1bf 100644
--- a/include/tools/stream.hxx
+++ b/include/tools/stream.hxx
@@ -736,7 +736,7 @@ public:
     bool            IsObjectMemoryOwner() { return bOwnsData; }
     void            SetResizeOffset( sal_Size nNewResize ) { nResize = nNewResize; }
     sal_Size        GetResizeOffset() const { return nResize; }
-    virtual sal_uInt64 remainingSize() SAL_OVERRIDE { return GetBufSize() - Tell(); }
+    virtual sal_uInt64 remainingSize() SAL_OVERRIDE { return GetEndOfData() - Tell(); }
 };
 
 class TOOLS_DLLPUBLIC SvScriptStream: public SvStream


More information about the Libreoffice-commits mailing list