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 { SvgCircleNode(SvgDocument & rDocument,SvgNode * pParent)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 ~SvgCircleNode()47 SvgCircleNode::~SvgCircleNode() 48 { 49 if(mpaTransform) delete mpaTransform; 50 } 51 getSvgStyleAttributes() const52 const SvgStyleAttributes* SvgCircleNode::getSvgStyleAttributes() const 53 { 54 static rtl::OUString aClassStr(rtl::OUString::createFromAscii("circle")); 55 56 return checkForCssStyle(aClassStr, maSvgStyleAttributes); 57 } 58 parseAttribute(const rtl::OUString & rTokenName,SVGToken aSVGToken,const rtl::OUString & aContent)59 void SvgCircleNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent) 60 { 61 // call parent 62 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent); 63 64 // read style attributes 65 maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent); 66 67 // parse own 68 switch(aSVGToken) 69 { 70 case SVGTokenStyle: 71 { 72 maSvgStyleAttributes.readStyle(aContent); 73 break; 74 } 75 case SVGTokenCx: 76 { 77 SvgNumber aNum; 78 79 if(readSingleNumber(aContent, aNum)) 80 { 81 setCx(aNum); 82 } 83 break; 84 } 85 case SVGTokenCy: 86 { 87 SvgNumber aNum; 88 89 if(readSingleNumber(aContent, aNum)) 90 { 91 setCy(aNum); 92 } 93 break; 94 } 95 case SVGTokenR: 96 { 97 SvgNumber aNum; 98 99 if(readSingleNumber(aContent, aNum)) 100 { 101 if(aNum.isPositive()) 102 { 103 setR(aNum); 104 } 105 } 106 break; 107 } 108 case SVGTokenTransform: 109 { 110 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this)); 111 112 if(!aMatrix.isIdentity()) 113 { 114 setTransform(&aMatrix); 115 } 116 break; 117 } 118 default: 119 { 120 break; 121 } 122 } 123 } 124 decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence & rTarget,bool) const125 void SvgCircleNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const 126 { 127 const SvgStyleAttributes* pStyle = getSvgStyleAttributes(); 128 129 if(pStyle && getR().isSet()) 130 { 131 const double fR(getR().solve(*this, length)); 132 133 if(fR > 0.0) 134 { 135 const basegfx::B2DPolygon aPath( 136 basegfx::tools::createPolygonFromCircle( 137 basegfx::B2DPoint( 138 getCx().isSet() ? getCx().solve(*this, xcoordinate) : 0.0, 139 getCy().isSet() ? getCy().solve(*this, ycoordinate) : 0.0), 140 fR)); 141 142 drawinglayer::primitive2d::Primitive2DSequence aNewTarget; 143 144 pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, 0); 145 146 if(aNewTarget.hasElements()) 147 { 148 pStyle->add_postProcess(rTarget, aNewTarget, getTransform()); 149 } 150 } 151 } 152 } 153 } // end of namespace svgreader 154 } // end of namespace svgio 155 156 ////////////////////////////////////////////////////////////////////////////// 157 // eof 158