Updated core
[LibreOffice.git] / svgio / source / svgreader / svgpolynode.cxx
blob5edd74696dee44670ac858e6880ab9318c57affb
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>
23 #include <basegfx/polygon/b2dpolygontools.hxx>
25 namespace svgio
27 namespace svgreader
29 SvgPolyNode::SvgPolyNode(
30 SvgDocument& rDocument,
31 SvgNode* pParent,
32 bool bIsPolyline)
33 : SvgNode(SVGTokenPolygon, rDocument, pParent),
34 maSvgStyleAttributes(*this),
35 mpPolygon(0),
36 mpaTransform(0),
37 mbIsPolyline(bIsPolyline)
41 SvgPolyNode::~SvgPolyNode()
43 if(mpaTransform) delete mpaTransform;
44 if(mpPolygon) delete mpPolygon;
47 const SvgStyleAttributes* SvgPolyNode::getSvgStyleAttributes() const
49 return checkForCssStyle(mbIsPolyline? OUString("polyline") : OUString("polygon"), maSvgStyleAttributes);
52 void SvgPolyNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
54 // call parent
55 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
57 // read style attributes
58 maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent, false);
60 // parse own
61 switch(aSVGToken)
63 case SVGTokenStyle:
65 readLocalCssStyle(aContent);
66 break;
68 case SVGTokenPoints:
70 basegfx::B2DPolygon aPath;
72 if(basegfx::tools::importFromSvgPoints(aPath, aContent))
74 if(aPath.count())
76 if(!isPolyline())
78 aPath.setClosed(true);
81 setPolygon(&aPath);
84 break;
86 case SVGTokenTransform:
88 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
90 if(!aMatrix.isIdentity())
92 setTransform(&aMatrix);
94 break;
96 default:
98 break;
103 void SvgPolyNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
105 const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
107 if(pStyle && getPolygon())
109 drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
111 pStyle->add_path(basegfx::B2DPolyPolygon(*getPolygon()), aNewTarget, 0);
113 if(aNewTarget.hasElements())
115 pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
119 } // end of namespace svgreader
120 } // end of namespace svgio
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */