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/svgpolynode.hxx> 26 #include <basegfx/polygon/b2dpolygon.hxx> 27 #include <basegfx/polygon/b2dpolypolygontools.hxx> 28 29 ////////////////////////////////////////////////////////////////////////////// 30 31 namespace svgio 32 { 33 namespace svgreader 34 { 35 SvgPolyNode::SvgPolyNode( 36 SvgDocument& rDocument, 37 SvgNode* pParent, 38 bool bIsPolyline) 39 : SvgNode(SVGTokenPolygon, rDocument, pParent), 40 maSvgStyleAttributes(*this), 41 mpPolygon(0), 42 mpaTransform(0), 43 mbIsPolyline(bIsPolyline) 44 { 45 } 46 47 SvgPolyNode::~SvgPolyNode() 48 { 49 if(mpaTransform) delete mpaTransform; 50 if(mpPolygon) delete mpPolygon; 51 } 52 53 const SvgStyleAttributes* SvgPolyNode::getSvgStyleAttributes() const 54 { 55 static rtl::OUString aClassStr(rtl::OUString::createFromAscii("poly")); 56 maSvgStyleAttributes.checkForCssStyle(aClassStr); 57 58 return &maSvgStyleAttributes; 59 } 60 61 void SvgPolyNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent) 62 { 63 // call parent 64 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent); 65 66 // read style attributes 67 maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent); 68 69 // parse own 70 switch(aSVGToken) 71 { 72 case SVGTokenStyle: 73 { 74 maSvgStyleAttributes.readStyle(aContent); 75 break; 76 } 77 case SVGTokenPoints: 78 { 79 basegfx::B2DPolygon aPath; 80 81 if(basegfx::tools::importFromSvgPoints(aPath, aContent)) 82 { 83 if(aPath.count()) 84 { 85 if(!isPolyline()) 86 { 87 aPath.setClosed(true); 88 } 89 90 setPolygon(&aPath); 91 } 92 } 93 break; 94 } 95 case SVGTokenTransform: 96 { 97 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this)); 98 99 if(!aMatrix.isIdentity()) 100 { 101 setTransform(&aMatrix); 102 } 103 break; 104 } 105 } 106 } 107 108 void SvgPolyNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const 109 { 110 const SvgStyleAttributes* pStyle = getSvgStyleAttributes(); 111 112 if(pStyle && getPolygon()) 113 { 114 drawinglayer::primitive2d::Primitive2DSequence aNewTarget; 115 116 pStyle->add_path(basegfx::B2DPolyPolygon(*getPolygon()), aNewTarget); 117 118 if(aNewTarget.hasElements()) 119 { 120 pStyle->add_postProcess(rTarget, aNewTarget, getTransform()); 121 } 122 } 123 } 124 } // end of namespace svgreader 125 } // end of namespace svgio 126 127 ////////////////////////////////////////////////////////////////////////////// 128 // eof 129