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/svgpathnode.hxx> 26 #include <basegfx/polygon/b2dpolypolygontools.hxx> 27 28 ////////////////////////////////////////////////////////////////////////////// 29 30 namespace svgio 31 { 32 namespace svgreader 33 { 34 SvgPathNode::SvgPathNode( 35 SvgDocument& rDocument, 36 SvgNode* pParent) 37 : SvgNode(SVGTokenPath, rDocument, pParent), 38 maSvgStyleAttributes(*this), 39 mpPolyPolygon(0), 40 mpaTransform(0), 41 maPathLength() 42 { 43 } 44 45 SvgPathNode::~SvgPathNode() 46 { 47 if(mpPolyPolygon) delete mpPolyPolygon; 48 if(mpaTransform) delete mpaTransform; 49 } 50 51 const SvgStyleAttributes* SvgPathNode::getSvgStyleAttributes() const 52 { 53 static rtl::OUString aClassStr(rtl::OUString::createFromAscii("path")); 54 maSvgStyleAttributes.checkForCssStyle(aClassStr); 55 56 return &maSvgStyleAttributes; 57 } 58 59 void SvgPathNode::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 SVGTokenD: 76 { 77 basegfx::B2DPolyPolygon aPath; 78 79 if(basegfx::tools::importFromSvgD(aPath, aContent)) 80 { 81 if(aPath.count()) 82 { 83 setPath(&aPath); 84 } 85 } 86 break; 87 } 88 case SVGTokenTransform: 89 { 90 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this)); 91 92 if(!aMatrix.isIdentity()) 93 { 94 setTransform(&aMatrix); 95 } 96 break; 97 } 98 case SVGTokenPathLength: 99 { 100 SvgNumber aNum; 101 102 if(readSingleNumber(aContent, aNum)) 103 { 104 setPathLength(aNum); 105 } 106 break; 107 } 108 default: 109 { 110 break; 111 } 112 } 113 } 114 115 void SvgPathNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const 116 { 117 // fill and/or stroke needed, also a path 118 const SvgStyleAttributes* pStyle = getSvgStyleAttributes(); 119 120 if(pStyle && getPath()) 121 { 122 drawinglayer::primitive2d::Primitive2DSequence aNewTarget; 123 124 pStyle->add_path(*getPath(), aNewTarget); 125 126 if(aNewTarget.hasElements()) 127 { 128 pStyle->add_postProcess(rTarget, aNewTarget, getTransform()); 129 } 130 } 131 } 132 } // end of namespace svgreader 133 } // end of namespace svgio 134 135 ////////////////////////////////////////////////////////////////////////////// 136 // eof 137