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 aClassStrA(rtl::OUString::createFromAscii("polygon")); 56 static rtl::OUString aClassStrB(rtl::OUString::createFromAscii("polyline")); 57 maSvgStyleAttributes.checkForCssStyle(mbIsPolyline? aClassStrB : aClassStrA); 58 59 return &maSvgStyleAttributes; 60 } 61 62 void SvgPolyNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent) 63 { 64 // call parent 65 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent); 66 67 // read style attributes 68 maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent); 69 70 // parse own 71 switch(aSVGToken) 72 { 73 case SVGTokenStyle: 74 { 75 maSvgStyleAttributes.readStyle(aContent); 76 break; 77 } 78 case SVGTokenPoints: 79 { 80 basegfx::B2DPolygon aPath; 81 82 if(basegfx::tools::importFromSvgPoints(aPath, aContent)) 83 { 84 if(aPath.count()) 85 { 86 if(!isPolyline()) 87 { 88 aPath.setClosed(true); 89 } 90 91 setPolygon(&aPath); 92 } 93 } 94 break; 95 } 96 case SVGTokenTransform: 97 { 98 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this)); 99 100 if(!aMatrix.isIdentity()) 101 { 102 setTransform(&aMatrix); 103 } 104 break; 105 } 106 default: 107 { 108 break; 109 } 110 } 111 } 112 113 void SvgPolyNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const 114 { 115 const SvgStyleAttributes* pStyle = getSvgStyleAttributes(); 116 117 if(pStyle && getPolygon()) 118 { 119 drawinglayer::primitive2d::Primitive2DSequence aNewTarget; 120 121 pStyle->add_path(basegfx::B2DPolyPolygon(*getPolygon()), aNewTarget); 122 123 if(aNewTarget.hasElements()) 124 { 125 pStyle->add_postProcess(rTarget, aNewTarget, getTransform()); 126 } 127 } 128 } 129 } // end of namespace svgreader 130 } // end of namespace svgio 131 132 ////////////////////////////////////////////////////////////////////////////// 133 // eof 134