LCOV - code coverage report
Current view: top level - test/source - primitive2dxmldump.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 70 81 86.4 %
Date: 2015-06-13 12:38:46 Functions: 7 10 70.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include <test/primitive2dxmldump.hxx>
      11             : #include <test/xmltesttools.hxx>
      12             : 
      13             : #include <vcl/metaact.hxx>
      14             : #include <rtl/string.hxx>
      15             : #include <rtl/strbuf.hxx>
      16             : 
      17             : #include <boost/scoped_ptr.hpp>
      18             : 
      19             : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
      20             : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
      21             : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      22             : #include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
      23             : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      24             : 
      25             : #include <drawinglayer/attribute/lineattribute.hxx>
      26             : 
      27             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      28             : #include <basegfx/polygon/b2dpolygontools.hxx>
      29             : 
      30             : using namespace drawinglayer::primitive2d;
      31             : 
      32             : namespace
      33             : {
      34             : 
      35             : const size_t constMaxActionType = 513;
      36             : 
      37          12 : OUString convertColorToString(const basegfx::BColor& rColor)
      38             : {
      39          12 :     OUString aRGBString = Color(rColor).AsRGBHexString();
      40          12 :     return "#" + aRGBString;
      41             : }
      42             : 
      43             : } // anonymous namespace
      44             : 
      45           4 : Primitive2dXmlDump::Primitive2dXmlDump() :
      46           4 :     maFilter(constMaxActionType, false)
      47           4 : {}
      48             : 
      49           4 : Primitive2dXmlDump::~Primitive2dXmlDump()
      50           4 : {}
      51             : 
      52           0 : void Primitive2dXmlDump::filterActionType(const sal_uInt16 nActionType, bool bShouldFilter)
      53             : {
      54           0 :     maFilter[nActionType] = bShouldFilter;
      55           0 : }
      56             : 
      57           0 : void Primitive2dXmlDump::filterAllActionTypes()
      58             : {
      59           0 :     maFilter.assign(constMaxActionType, true);
      60           0 : }
      61             : 
      62           4 : xmlDocPtr Primitive2dXmlDump::dumpAndParse(
      63             :     const drawinglayer::primitive2d::Primitive2DSequence& rPrimitive2DSequence,
      64             :     const OUString& rTempStreamName)
      65             : {
      66           4 :     boost::scoped_ptr<SvStream> pStream;
      67             : 
      68           4 :     if (rTempStreamName.isEmpty())
      69           4 :         pStream.reset(new SvMemoryStream());
      70             :     else
      71           0 :         pStream.reset(new SvFileStream(rTempStreamName, STREAM_STD_READWRITE | StreamMode::TRUNC));
      72             : 
      73           8 :     XmlWriter aWriter(pStream.get());
      74           4 :     aWriter.startDocument();
      75           4 :     aWriter.startElement("primitive2D");
      76             : 
      77           4 :     decomposeAndWrite(rPrimitive2DSequence, aWriter);
      78             : 
      79           4 :     aWriter.endElement();
      80           4 :     aWriter.endDocument();
      81             : 
      82           4 :     pStream->Seek(STREAM_SEEK_TO_BEGIN);
      83             : 
      84           4 :     xmlDocPtr pDoc = XmlTestTools::parseXmlStream(pStream.get());
      85             : 
      86           8 :     return pDoc;
      87             : }
      88             : 
      89          12 : void Primitive2dXmlDump::decomposeAndWrite(
      90             :     const drawinglayer::primitive2d::Primitive2DSequence& rPrimitive2DSequence,
      91             :     XmlWriter& rWriter)
      92             : {
      93          32 :     for (int i = 0; i < rPrimitive2DSequence.getLength(); i++)
      94             :     {
      95          20 :         drawinglayer::primitive2d::Primitive2DReference xPrimitive2DReference = rPrimitive2DSequence[i];
      96          20 :         const BasePrimitive2D* pBasePrimitive = dynamic_cast<const BasePrimitive2D* >(xPrimitive2DReference.get());
      97          20 :         if (!pBasePrimitive)
      98           0 :             continue;
      99          20 :         sal_uInt32 nId = pBasePrimitive->getPrimitive2DID();
     100          20 :         if (maFilter[nId])
     101           0 :             continue;
     102             : 
     103          40 :         OUString sCurrentElementTag = drawinglayer::primitive2d::idToString(nId);
     104             : 
     105          20 :         switch (nId)
     106             :         {
     107             :             case PRIMITIVE2D_ID_HIDDENGEOMETRYPRIMITIVE2D:
     108             :             {
     109           4 :                 const HiddenGeometryPrimitive2D* pHiddenGeometryPrimitive2D = dynamic_cast<const HiddenGeometryPrimitive2D*>(pBasePrimitive);
     110           4 :                 rWriter.startElement("hiddengeometry");
     111           4 :                 decomposeAndWrite(pHiddenGeometryPrimitive2D->getChildren(), rWriter);
     112           4 :                 rWriter.endElement();
     113             :             }
     114           4 :             break;
     115             : 
     116             :             case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D:
     117             :             {
     118           4 :                 const TransformPrimitive2D* pTransformPrimitive2D = dynamic_cast<const TransformPrimitive2D*>(pBasePrimitive);
     119           4 :                 rWriter.startElement("transform");
     120             :                 //pTransformPrimitive2D->getTransformation()
     121           4 :                 decomposeAndWrite(pTransformPrimitive2D->getChildren(), rWriter);
     122           4 :                 rWriter.endElement();
     123             :             }
     124           4 :             break;
     125             : 
     126             :             case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D:
     127             :             {
     128           4 :                 const PolyPolygonColorPrimitive2D* pPolyPolygonColorPrimitive2D = dynamic_cast<const PolyPolygonColorPrimitive2D*>(pBasePrimitive);
     129             : 
     130           4 :                 rWriter.startElement("polypolygoncolor");
     131           4 :                 rWriter.attribute("color", convertColorToString(pPolyPolygonColorPrimitive2D->getBColor()));
     132           4 :                 rWriter.startElement("polypolygon");
     133           4 :                 rWriter.content(basegfx::tools::exportToSvgD(pPolyPolygonColorPrimitive2D->getB2DPolyPolygon(), true, true, false));
     134           4 :                 rWriter.endElement();
     135           4 :                 rWriter.endElement();
     136             :             }
     137           4 :             break;
     138             : 
     139             :             case PRIMITIVE2D_ID_POLYPOLYGONSTROKEPRIMITIVE2D:
     140             :             {
     141           4 :                 const PolyPolygonStrokePrimitive2D* pPolyPolygonStrokePrimitive2D = dynamic_cast<const PolyPolygonStrokePrimitive2D*>(pBasePrimitive);
     142           4 :                 rWriter.startElement("polypolygonstroke");
     143             : 
     144           4 :                 rWriter.startElement("line");
     145           4 :                 drawinglayer::attribute::LineAttribute aLineAttribute = pPolyPolygonStrokePrimitive2D->getLineAttribute();
     146           4 :                 rWriter.attribute("color", convertColorToString(aLineAttribute.getColor()));
     147           4 :                 rWriter.attribute("width", aLineAttribute.getWidth());
     148             :                 //rWriter.attribute("linejoin", aLineAttribute.getLineJoin());
     149             :                 //rWriter.attribute("linecap", aLineAttribute.getLineCap());
     150           4 :                 rWriter.endElement();
     151             : 
     152             :                 //getStrokeAttribute()
     153             : 
     154           4 :                 rWriter.startElement("polypolygon");
     155           4 :                 rWriter.content(basegfx::tools::exportToSvgD(pPolyPolygonStrokePrimitive2D->getB2DPolyPolygon(), true, true, false));
     156           4 :                 rWriter.endElement();
     157             : 
     158           4 :                 rWriter.endElement();
     159             :             }
     160           4 :             break;
     161             : 
     162             :             case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D:
     163             :             {
     164           4 :                 const PolygonHairlinePrimitive2D* pPolygonHairlinePrimitive2D = dynamic_cast<const PolygonHairlinePrimitive2D*>(pBasePrimitive);
     165           4 :                 rWriter.startElement("polygonhairline");
     166             : 
     167           4 :                 rWriter.attribute("color", convertColorToString(pPolygonHairlinePrimitive2D->getBColor()));
     168             : 
     169           4 :                 rWriter.startElement("polygon");
     170           4 :                 rWriter.content(basegfx::tools::exportToSvgPoints(pPolygonHairlinePrimitive2D->getB2DPolygon()));
     171           4 :                 rWriter.endElement();
     172             : 
     173             : 
     174           4 :                 rWriter.endElement();
     175             :             }
     176           4 :             break;
     177             : 
     178             :             default:
     179             :             {
     180           0 :                 rWriter.element(OUStringToOString(sCurrentElementTag, RTL_TEXTENCODING_UTF8));
     181             :             }
     182           0 :             break;
     183             :         }
     184             : 
     185          20 :     }
     186         384 : }
     187             : 
     188             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11