LCOV - code coverage report
Current view: top level - test/source - primitive2dxmldump.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 70 81 86.4 %
Date: 2014-11-03 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          24 : OUString convertColorToString(basegfx::BColor aColor)
      38             : {
      39          24 :     OUString aRGBString = Color(aColor).AsRGBHexString();
      40          24 :     return "#" + aRGBString;
      41             : }
      42             : 
      43             : } // anonymous namespace
      44             : 
      45           8 : Primitive2dXmlDump::Primitive2dXmlDump() :
      46           8 :     maFilter(constMaxActionType, false)
      47           8 : {}
      48             : 
      49           8 : Primitive2dXmlDump::~Primitive2dXmlDump()
      50           8 : {}
      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           8 : xmlDocPtr Primitive2dXmlDump::dumpAndParse(
      63             :     const drawinglayer::primitive2d::Primitive2DSequence& rPrimitive2DSequence,
      64             :     const OUString& rTempStreamName)
      65             : {
      66           8 :     boost::scoped_ptr<SvStream> pStream;
      67             : 
      68           8 :     if (rTempStreamName.isEmpty())
      69           8 :         pStream.reset(new SvMemoryStream());
      70             :     else
      71           0 :         pStream.reset(new SvFileStream(rTempStreamName, STREAM_STD_READWRITE | STREAM_TRUNC));
      72             : 
      73          16 :     XmlWriter aWriter(pStream.get());
      74           8 :     aWriter.startDocument();
      75           8 :     aWriter.startElement("primitive2D");
      76             : 
      77           8 :     decomposeAndWrite(rPrimitive2DSequence, aWriter);
      78             : 
      79           8 :     aWriter.endElement();
      80           8 :     aWriter.endDocument();
      81             : 
      82           8 :     pStream->Seek(STREAM_SEEK_TO_BEGIN);
      83             : 
      84           8 :     xmlDocPtr pDoc = XmlTestTools::parseXmlStream(pStream.get());
      85             : 
      86          16 :     return pDoc;
      87             : }
      88             : 
      89          24 : void Primitive2dXmlDump::decomposeAndWrite(
      90             :     const drawinglayer::primitive2d::Primitive2DSequence& rPrimitive2DSequence,
      91             :     XmlWriter& rWriter)
      92             : {
      93          64 :     for (int i = 0; i < rPrimitive2DSequence.getLength(); i++)
      94             :     {
      95          40 :         drawinglayer::primitive2d::Primitive2DReference xPrimitive2DReference = rPrimitive2DSequence[i];
      96          40 :         const BasePrimitive2D* pBasePrimitive = dynamic_cast<const BasePrimitive2D* >(xPrimitive2DReference.get());
      97          40 :         if (!pBasePrimitive)
      98           0 :             continue;
      99          40 :         sal_uInt32 nId = pBasePrimitive->getPrimitive2DID();
     100          40 :         if (maFilter[nId])
     101           0 :             continue;
     102             : 
     103          80 :         OUString sCurrentElementTag = drawinglayer::primitive2d::idToString(nId);
     104             : 
     105          40 :         switch (nId)
     106             :         {
     107             :             case PRIMITIVE2D_ID_HIDDENGEOMETRYPRIMITIVE2D:
     108             :             {
     109           8 :                 const HiddenGeometryPrimitive2D* pHiddenGeometryPrimitive2D = dynamic_cast<const HiddenGeometryPrimitive2D*>(pBasePrimitive);
     110           8 :                 rWriter.startElement("hiddengeometry");
     111           8 :                 decomposeAndWrite(pHiddenGeometryPrimitive2D->getChildren(), rWriter);
     112           8 :                 rWriter.endElement();
     113             :             }
     114           8 :             break;
     115             : 
     116             :             case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D:
     117             :             {
     118           8 :                 const TransformPrimitive2D* pTransformPrimitive2D = dynamic_cast<const TransformPrimitive2D*>(pBasePrimitive);
     119           8 :                 rWriter.startElement("transform");
     120             :                 //pTransformPrimitive2D->getTransformation()
     121           8 :                 decomposeAndWrite(pTransformPrimitive2D->getChildren(), rWriter);
     122           8 :                 rWriter.endElement();
     123             :             }
     124           8 :             break;
     125             : 
     126             :             case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D:
     127             :             {
     128           8 :                 const PolyPolygonColorPrimitive2D* pPolyPolygonColorPrimitive2D = dynamic_cast<const PolyPolygonColorPrimitive2D*>(pBasePrimitive);
     129             : 
     130           8 :                 rWriter.startElement("polypolygoncolor");
     131           8 :                 rWriter.attribute("color", convertColorToString(pPolyPolygonColorPrimitive2D->getBColor()));
     132           8 :                 rWriter.startElement("polypolygon");
     133           8 :                 rWriter.content(basegfx::tools::exportToSvgD(pPolyPolygonColorPrimitive2D->getB2DPolyPolygon(), true, true, false));
     134           8 :                 rWriter.endElement();
     135           8 :                 rWriter.endElement();
     136             :             }
     137           8 :             break;
     138             : 
     139             :             case PRIMITIVE2D_ID_POLYPOLYGONSTROKEPRIMITIVE2D:
     140             :             {
     141           8 :                 const PolyPolygonStrokePrimitive2D* pPolyPolygonStrokePrimitive2D = dynamic_cast<const PolyPolygonStrokePrimitive2D*>(pBasePrimitive);
     142           8 :                 rWriter.startElement("polypolygonstroke");
     143             : 
     144           8 :                 rWriter.startElement("line");
     145           8 :                 drawinglayer::attribute::LineAttribute aLineAttribute = pPolyPolygonStrokePrimitive2D->getLineAttribute();
     146           8 :                 rWriter.attribute("color", convertColorToString(aLineAttribute.getColor()));
     147           8 :                 rWriter.attribute("width", aLineAttribute.getWidth());
     148             :                 //rWriter.attribute("linejoin", aLineAttribute.getLineJoin());
     149             :                 //rWriter.attribute("linecap", aLineAttribute.getLineCap());
     150           8 :                 rWriter.endElement();
     151             : 
     152             :                 //getStrokeAttribute()
     153             : 
     154           8 :                 rWriter.startElement("polypolygon");
     155           8 :                 rWriter.content(basegfx::tools::exportToSvgD(pPolyPolygonStrokePrimitive2D->getB2DPolyPolygon(), true, true, false));
     156           8 :                 rWriter.endElement();
     157             : 
     158           8 :                 rWriter.endElement();
     159             :             }
     160           8 :             break;
     161             : 
     162             :             case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D:
     163             :             {
     164           8 :                 const PolygonHairlinePrimitive2D* pPolygonHairlinePrimitive2D = dynamic_cast<const PolygonHairlinePrimitive2D*>(pBasePrimitive);
     165           8 :                 rWriter.startElement("polygonhairline");
     166             : 
     167           8 :                 rWriter.attribute("color", convertColorToString(pPolygonHairlinePrimitive2D->getBColor()));
     168             : 
     169           8 :                 rWriter.startElement("polygon");
     170           8 :                 rWriter.content(basegfx::tools::exportToSvgPoints(pPolygonHairlinePrimitive2D->getB2DPolygon()));
     171           8 :                 rWriter.endElement();
     172             : 
     173             : 
     174           8 :                 rWriter.endElement();
     175             :             }
     176           8 :             break;
     177             : 
     178             :             default:
     179             :             {
     180           0 :                 rWriter.element(OUStringToOString(sCurrentElementTag, RTL_TEXTENCODING_UTF8));
     181             :             }
     182           0 :             break;
     183             :         }
     184             : 
     185          40 :     }
     186         666 : }
     187             : 
     188             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10