Branch libreoffice-5-0-4
[LibreOffice.git] / test / source / primitive2dxmldump.cxx
blobe1be527f96a57089eff05a17f227a63242a13730
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <test/primitive2dxmldump.hxx>
11 #include <test/xmltesttools.hxx>
13 #include <vcl/metaact.hxx>
14 #include <rtl/string.hxx>
15 #include <rtl/strbuf.hxx>
17 #include <boost/scoped_ptr.hpp>
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>
25 #include <drawinglayer/attribute/lineattribute.hxx>
27 #include <basegfx/polygon/b2dpolypolygontools.hxx>
28 #include <basegfx/polygon/b2dpolygontools.hxx>
30 using namespace drawinglayer::primitive2d;
32 namespace
35 const size_t constMaxActionType = 513;
37 OUString convertColorToString(const basegfx::BColor& rColor)
39 OUString aRGBString = Color(rColor).AsRGBHexString();
40 return "#" + aRGBString;
43 } // anonymous namespace
45 Primitive2dXmlDump::Primitive2dXmlDump() :
46 maFilter(constMaxActionType, false)
49 Primitive2dXmlDump::~Primitive2dXmlDump()
52 void Primitive2dXmlDump::filterActionType(const sal_uInt16 nActionType, bool bShouldFilter)
54 maFilter[nActionType] = bShouldFilter;
57 void Primitive2dXmlDump::filterAllActionTypes()
59 maFilter.assign(constMaxActionType, true);
62 xmlDocPtr Primitive2dXmlDump::dumpAndParse(
63 const drawinglayer::primitive2d::Primitive2DSequence& rPrimitive2DSequence,
64 const OUString& rTempStreamName)
66 boost::scoped_ptr<SvStream> pStream;
68 if (rTempStreamName.isEmpty())
69 pStream.reset(new SvMemoryStream());
70 else
71 pStream.reset(new SvFileStream(rTempStreamName, STREAM_STD_READWRITE | StreamMode::TRUNC));
73 XmlWriter aWriter(pStream.get());
74 aWriter.startDocument();
75 aWriter.startElement("primitive2D");
77 decomposeAndWrite(rPrimitive2DSequence, aWriter);
79 aWriter.endElement();
80 aWriter.endDocument();
82 pStream->Seek(STREAM_SEEK_TO_BEGIN);
84 xmlDocPtr pDoc = XmlTestTools::parseXmlStream(pStream.get());
86 return pDoc;
89 void Primitive2dXmlDump::decomposeAndWrite(
90 const drawinglayer::primitive2d::Primitive2DSequence& rPrimitive2DSequence,
91 XmlWriter& rWriter)
93 for (int i = 0; i < rPrimitive2DSequence.getLength(); i++)
95 drawinglayer::primitive2d::Primitive2DReference xPrimitive2DReference = rPrimitive2DSequence[i];
96 const BasePrimitive2D* pBasePrimitive = dynamic_cast<const BasePrimitive2D* >(xPrimitive2DReference.get());
97 if (!pBasePrimitive)
98 continue;
99 sal_uInt32 nId = pBasePrimitive->getPrimitive2DID();
100 if (maFilter[nId])
101 continue;
103 OUString sCurrentElementTag = drawinglayer::primitive2d::idToString(nId);
105 switch (nId)
107 case PRIMITIVE2D_ID_HIDDENGEOMETRYPRIMITIVE2D:
109 const HiddenGeometryPrimitive2D* pHiddenGeometryPrimitive2D = dynamic_cast<const HiddenGeometryPrimitive2D*>(pBasePrimitive);
110 rWriter.startElement("hiddengeometry");
111 decomposeAndWrite(pHiddenGeometryPrimitive2D->getChildren(), rWriter);
112 rWriter.endElement();
114 break;
116 case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D:
118 const TransformPrimitive2D* pTransformPrimitive2D = dynamic_cast<const TransformPrimitive2D*>(pBasePrimitive);
119 rWriter.startElement("transform");
120 //pTransformPrimitive2D->getTransformation()
121 decomposeAndWrite(pTransformPrimitive2D->getChildren(), rWriter);
122 rWriter.endElement();
124 break;
126 case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D:
128 const PolyPolygonColorPrimitive2D* pPolyPolygonColorPrimitive2D = dynamic_cast<const PolyPolygonColorPrimitive2D*>(pBasePrimitive);
130 rWriter.startElement("polypolygoncolor");
131 rWriter.attribute("color", convertColorToString(pPolyPolygonColorPrimitive2D->getBColor()));
132 rWriter.startElement("polypolygon");
133 rWriter.content(basegfx::tools::exportToSvgD(pPolyPolygonColorPrimitive2D->getB2DPolyPolygon(), true, true, false));
134 rWriter.endElement();
135 rWriter.endElement();
137 break;
139 case PRIMITIVE2D_ID_POLYPOLYGONSTROKEPRIMITIVE2D:
141 const PolyPolygonStrokePrimitive2D* pPolyPolygonStrokePrimitive2D = dynamic_cast<const PolyPolygonStrokePrimitive2D*>(pBasePrimitive);
142 rWriter.startElement("polypolygonstroke");
144 rWriter.startElement("line");
145 drawinglayer::attribute::LineAttribute aLineAttribute = pPolyPolygonStrokePrimitive2D->getLineAttribute();
146 rWriter.attribute("color", convertColorToString(aLineAttribute.getColor()));
147 rWriter.attribute("width", aLineAttribute.getWidth());
148 //rWriter.attribute("linejoin", aLineAttribute.getLineJoin());
149 //rWriter.attribute("linecap", aLineAttribute.getLineCap());
150 rWriter.endElement();
152 //getStrokeAttribute()
154 rWriter.startElement("polypolygon");
155 rWriter.content(basegfx::tools::exportToSvgD(pPolyPolygonStrokePrimitive2D->getB2DPolyPolygon(), true, true, false));
156 rWriter.endElement();
158 rWriter.endElement();
160 break;
162 case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D:
164 const PolygonHairlinePrimitive2D* pPolygonHairlinePrimitive2D = dynamic_cast<const PolygonHairlinePrimitive2D*>(pBasePrimitive);
165 rWriter.startElement("polygonhairline");
167 rWriter.attribute("color", convertColorToString(pPolygonHairlinePrimitive2D->getBColor()));
169 rWriter.startElement("polygon");
170 rWriter.content(basegfx::tools::exportToSvgPoints(pPolygonHairlinePrimitive2D->getB2DPolygon()));
171 rWriter.endElement();
174 rWriter.endElement();
176 break;
178 default:
180 rWriter.element(OUStringToOString(sCurrentElementTag, RTL_TEXTENCODING_UTF8));
182 break;
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */