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/svggnode.hxx> 26 #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 27 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx> 28 29 ////////////////////////////////////////////////////////////////////////////// 30 31 namespace svgio 32 { 33 namespace svgreader 34 { 35 SvgGNode::SvgGNode( 36 SVGToken aType, 37 SvgDocument& rDocument, 38 SvgNode* pParent) 39 : SvgNode(aType, rDocument, pParent), 40 maSvgStyleAttributes(*this), 41 mpaTransform(0) 42 { 43 OSL_ENSURE(aType == SVGTokenDefs || aType == SVGTokenG, "SvgGNode should ony be used for Group and Defs (!)"); 44 } 45 46 SvgGNode::~SvgGNode() 47 { 48 if(mpaTransform) delete mpaTransform; 49 } 50 51 const SvgStyleAttributes* SvgGNode::getSvgStyleAttributes() const 52 { 53 static rtl::OUString aClassStr(rtl::OUString::createFromAscii("g")); 54 maSvgStyleAttributes.checkForCssStyle(aClassStr); 55 56 return &maSvgStyleAttributes; 57 } 58 59 void SvgGNode::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 SVGTokenTransform: 76 { 77 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this)); 78 79 if(!aMatrix.isIdentity()) 80 { 81 setTransform(&aMatrix); 82 } 83 break; 84 } 85 default: 86 { 87 break; 88 } 89 } 90 } 91 92 void SvgGNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const 93 { 94 const SvgStyleAttributes* pStyle = getSvgStyleAttributes(); 95 96 if(pStyle) 97 { 98 const double fOpacity(pStyle->getOpacity().getNumber()); 99 100 if(fOpacity > 0.0) 101 { 102 drawinglayer::primitive2d::Primitive2DSequence aContent; 103 104 // decompose childs 105 SvgNode::decomposeSvgNode(aContent, bReferenced); 106 107 if(aContent.hasElements()) 108 { 109 pStyle->add_postProcess(rTarget, aContent, getTransform()); 110 } 111 } 112 } 113 } 114 } // end of namespace svgreader 115 } // end of namespace svgio 116 117 ////////////////////////////////////////////////////////////////////////////// 118 // eof 119