1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_svgio.hxx"
24 
25 #include <svgio/svgreader/svgcirclenode.hxx>
26 #include <basegfx/polygon/b2dpolygon.hxx>
27 #include <basegfx/polygon/b2dpolygontools.hxx>
28 
29 //////////////////////////////////////////////////////////////////////////////
30 
31 namespace svgio
32 {
33     namespace svgreader
34     {
35         SvgCircleNode::SvgCircleNode(
36             SvgDocument& rDocument,
37             SvgNode* pParent)
38         :   SvgNode(SVGTokenCircle, rDocument, pParent),
39             maSvgStyleAttributes(*this),
40             maCx(0),
41             maCy(0),
42             maR(0),
43             mpaTransform(0)
44         {
45         }
46 
47         SvgCircleNode::~SvgCircleNode()
48         {
49             if(mpaTransform) delete mpaTransform;
50         }
51 
52         const SvgStyleAttributes* SvgCircleNode::getSvgStyleAttributes() const
53         {
54             static rtl::OUString aClassStr(rtl::OUString::createFromAscii("circle"));
55             maSvgStyleAttributes.checkForCssStyle(aClassStr);
56 
57             return &maSvgStyleAttributes;
58         }
59 
60         void SvgCircleNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
61         {
62             // call parent
63             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
64 
65             // read style attributes
66             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
67 
68             // parse own
69             switch(aSVGToken)
70             {
71                 case SVGTokenStyle:
72                 {
73                     maSvgStyleAttributes.readStyle(aContent);
74                     break;
75                 }
76                 case SVGTokenCx:
77                 {
78                     SvgNumber aNum;
79 
80                     if(readSingleNumber(aContent, aNum))
81                     {
82                         setCx(aNum);
83                     }
84                     break;
85                 }
86                 case SVGTokenCy:
87                 {
88                     SvgNumber aNum;
89 
90                     if(readSingleNumber(aContent, aNum))
91                     {
92                         setCy(aNum);
93                     }
94                     break;
95                 }
96                 case SVGTokenR:
97                 {
98                     SvgNumber aNum;
99 
100                     if(readSingleNumber(aContent, aNum))
101                     {
102                         if(aNum.isPositive())
103                         {
104                             setR(aNum);
105                         }
106                     }
107                     break;
108                 }
109                 case SVGTokenTransform:
110                 {
111                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
112 
113                     if(!aMatrix.isIdentity())
114                     {
115                         setTransform(&aMatrix);
116                     }
117                     break;
118                 }
119             }
120         }
121 
122         void SvgCircleNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const
123         {
124             const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
125 
126             if(pStyle && getR().isSet())
127             {
128                 const double fR(getR().solve(*this, xcoordinate));
129 
130                 if(fR > 0.0)
131                 {
132                     const basegfx::B2DPolygon aPath(
133                         basegfx::tools::createPolygonFromCircle(
134                             basegfx::B2DPoint(
135                                 getCx().isSet() ? getCx().solve(*this, xcoordinate) : 0.0,
136                                 getCy().isSet() ? getCy().solve(*this, ycoordinate) : 0.0),
137                             fR));
138 
139                     drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
140 
141                     pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget);
142 
143                     if(aNewTarget.hasElements())
144                     {
145                         pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
146                     }
147                 }
148             }
149         }
150     } // end of namespace svgreader
151 } // end of namespace svgio
152 
153 //////////////////////////////////////////////////////////////////////////////
154 // eof
155