Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / svgio / source / svgreader / svgpolynode.cxx
bloba814402d46f89fc95c35079c19301639802af24c
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svgio/svgreader/svgpolynode.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolypolygontools.hxx>
24 //////////////////////////////////////////////////////////////////////////////
26 namespace svgio
28 namespace svgreader
30 SvgPolyNode::SvgPolyNode(
31 SvgDocument& rDocument,
32 SvgNode* pParent,
33 bool bIsPolyline)
34 : SvgNode(SVGTokenPolygon, rDocument, pParent),
35 maSvgStyleAttributes(*this),
36 mpPolygon(0),
37 mpaTransform(0),
38 mbIsPolyline(bIsPolyline)
42 SvgPolyNode::~SvgPolyNode()
44 if(mpaTransform) delete mpaTransform;
45 if(mpPolygon) delete mpPolygon;
48 const SvgStyleAttributes* SvgPolyNode::getSvgStyleAttributes() const
50 static rtl::OUString aClassStrA(rtl::OUString::createFromAscii("polygon"));
51 static rtl::OUString aClassStrB(rtl::OUString::createFromAscii("polyline"));
52 maSvgStyleAttributes.checkForCssStyle(mbIsPolyline? aClassStrB : aClassStrA);
54 return &maSvgStyleAttributes;
57 void SvgPolyNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
59 // call parent
60 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
62 // read style attributes
63 maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
65 // parse own
66 switch(aSVGToken)
68 case SVGTokenStyle:
70 maSvgStyleAttributes.readStyle(aContent);
71 break;
73 case SVGTokenPoints:
75 basegfx::B2DPolygon aPath;
77 if(basegfx::tools::importFromSvgPoints(aPath, aContent))
79 if(aPath.count())
81 if(!isPolyline())
83 aPath.setClosed(true);
86 setPolygon(&aPath);
89 break;
91 case SVGTokenTransform:
93 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
95 if(!aMatrix.isIdentity())
97 setTransform(&aMatrix);
99 break;
101 default:
103 break;
108 void SvgPolyNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
110 const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
112 if(pStyle && getPolygon())
114 drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
116 pStyle->add_path(basegfx::B2DPolyPolygon(*getPolygon()), aNewTarget);
118 if(aNewTarget.hasElements())
120 pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
124 } // end of namespace svgreader
125 } // end of namespace svgio
127 //////////////////////////////////////////////////////////////////////////////
128 // eof
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */