Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / svgio / source / svgreader / svgellipsenode.cxx
blobf34edb244f4a1d1e29de1874d6da8911ac084859
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/svgellipsenode.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
24 //////////////////////////////////////////////////////////////////////////////
26 namespace svgio
28 namespace svgreader
30 SvgEllipseNode::SvgEllipseNode(
31 SvgDocument& rDocument,
32 SvgNode* pParent)
33 : SvgNode(SVGTokenEllipse, rDocument, pParent),
34 maSvgStyleAttributes(*this),
35 maCx(0),
36 maCy(0),
37 maRx(0),
38 maRy(0),
39 mpaTransform(0)
43 SvgEllipseNode::~SvgEllipseNode()
45 if(mpaTransform) delete mpaTransform;
48 const SvgStyleAttributes* SvgEllipseNode::getSvgStyleAttributes() const
50 static rtl::OUString aClassStr(rtl::OUString::createFromAscii("ellipse"));
51 maSvgStyleAttributes.checkForCssStyle(aClassStr);
53 return &maSvgStyleAttributes;
56 void SvgEllipseNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
58 // call parent
59 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
61 // read style attributes
62 maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
64 // parse own
65 switch(aSVGToken)
67 case SVGTokenStyle:
69 maSvgStyleAttributes.readStyle(aContent);
70 break;
72 case SVGTokenCx:
74 SvgNumber aNum;
76 if(readSingleNumber(aContent, aNum))
78 setCx(aNum);
80 break;
82 case SVGTokenCy:
84 SvgNumber aNum;
86 if(readSingleNumber(aContent, aNum))
88 setCy(aNum);
90 break;
92 case SVGTokenRx:
94 SvgNumber aNum;
96 if(readSingleNumber(aContent, aNum))
98 if(aNum.isPositive())
100 setRx(aNum);
103 break;
105 case SVGTokenRy:
107 SvgNumber aNum;
109 if(readSingleNumber(aContent, aNum))
111 if(aNum.isPositive())
113 setRy(aNum);
116 break;
118 case SVGTokenTransform:
120 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
122 if(!aMatrix.isIdentity())
124 setTransform(&aMatrix);
126 break;
128 default:
130 break;
135 void SvgEllipseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
137 const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
139 if(pStyle && getRx().isSet() && getRy().isSet())
141 const double fRx(getRx().solve(*this, xcoordinate));
142 const double fRy(getRy().solve(*this, ycoordinate));
144 if(fRx > 0.0 && fRy > 0.0)
146 const basegfx::B2DPolygon aPath(
147 basegfx::tools::createPolygonFromEllipse(
148 basegfx::B2DPoint(
149 getCx().isSet() ? getCx().solve(*this, xcoordinate) : 0.0,
150 getCy().isSet() ? getCy().solve(*this, ycoordinate) : 0.0),
151 fRx, fRy));
153 drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
155 pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget);
157 if(aNewTarget.hasElements())
159 pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
164 } // end of namespace svgreader
165 } // end of namespace svgio
167 //////////////////////////////////////////////////////////////////////////////
168 // eof
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */