Stop leaking all ScPostIt instances.
[LibreOffice.git] / svgio / source / svgreader / svgcirclenode.cxx
blobf462a07e3284e086af74da049154d34361204ba7
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/svgcirclenode.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
24 //////////////////////////////////////////////////////////////////////////////
26 namespace svgio
28 namespace svgreader
30 SvgCircleNode::SvgCircleNode(
31 SvgDocument& rDocument,
32 SvgNode* pParent)
33 : SvgNode(SVGTokenCircle, rDocument, pParent),
34 maSvgStyleAttributes(*this),
35 maCx(0),
36 maCy(0),
37 maR(0),
38 mpaTransform(0)
42 SvgCircleNode::~SvgCircleNode()
44 if(mpaTransform) delete mpaTransform;
47 const SvgStyleAttributes* SvgCircleNode::getSvgStyleAttributes() const
49 static OUString aClassStr(OUString::createFromAscii("circle"));
50 return checkForCssStyle(aClassStr, maSvgStyleAttributes);
53 void SvgCircleNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
55 // call parent
56 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
58 // read style attributes
59 maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
61 // parse own
62 switch(aSVGToken)
64 case SVGTokenStyle:
66 maSvgStyleAttributes.readStyle(aContent);
67 break;
69 case SVGTokenCx:
71 SvgNumber aNum;
73 if(readSingleNumber(aContent, aNum))
75 setCx(aNum);
77 break;
79 case SVGTokenCy:
81 SvgNumber aNum;
83 if(readSingleNumber(aContent, aNum))
85 setCy(aNum);
87 break;
89 case SVGTokenR:
91 SvgNumber aNum;
93 if(readSingleNumber(aContent, aNum))
95 if(aNum.isPositive())
97 setR(aNum);
100 break;
102 case SVGTokenTransform:
104 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
106 if(!aMatrix.isIdentity())
108 setTransform(&aMatrix);
110 break;
112 default:
114 break;
119 void SvgCircleNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
121 const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
123 if(pStyle && getR().isSet())
125 const double fR(getR().solve(*this, length));
127 if(fR > 0.0)
129 const basegfx::B2DPolygon aPath(
130 basegfx::tools::createPolygonFromCircle(
131 basegfx::B2DPoint(
132 getCx().isSet() ? getCx().solve(*this, xcoordinate) : 0.0,
133 getCy().isSet() ? getCy().solve(*this, ycoordinate) : 0.0),
134 fR));
136 drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
138 pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, 0);
140 if(aNewTarget.hasElements())
142 pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
147 } // end of namespace svgreader
148 } // end of namespace svgio
150 //////////////////////////////////////////////////////////////////////////////
151 // eof
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */