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     {
SvgGNode(SVGToken aType,SvgDocument & rDocument,SvgNode * pParent)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 
~SvgGNode()46         SvgGNode::~SvgGNode()
47         {
48             if(mpaTransform) delete mpaTransform;
49         }
50 
getSvgStyleAttributes() const51         const SvgStyleAttributes* SvgGNode::getSvgStyleAttributes() const
52         {
53             if(SVGTokenDefs == getType())
54             {
55                 // #125258# call parent for SVGTokenDefs
56                 return SvgNode::getSvgStyleAttributes();
57             }
58             else
59             {
60                 // #125258# for SVGTokenG take CssStyles into account
61                 static rtl::OUString aClassStr(rtl::OUString::createFromAscii("g"));
62 
63                 return checkForCssStyle(aClassStr, maSvgStyleAttributes);
64             }
65         }
66 
parseAttribute(const rtl::OUString & rTokenName,SVGToken aSVGToken,const rtl::OUString & aContent)67         void SvgGNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
68         {
69             // call parent
70             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
71 
72             // read style attributes
73             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
74 
75             // parse own
76             switch(aSVGToken)
77             {
78                 case SVGTokenStyle:
79                 {
80                     maSvgStyleAttributes.readStyle(aContent);
81                     break;
82                 }
83                 case SVGTokenTransform:
84                 {
85                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
86 
87                     if(!aMatrix.isIdentity())
88                     {
89                         setTransform(&aMatrix);
90                     }
91                     break;
92                 }
93                 default:
94                 {
95                     break;
96                 }
97             }
98         }
99 
decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence & rTarget,bool bReferenced) const100         void SvgGNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const
101         {
102             if(SVGTokenDefs == getType())
103             {
104                 // #125258# no decompose needed for defs element, call parent for SVGTokenDefs
105                 SvgNode::decomposeSvgNode(rTarget, bReferenced);
106             }
107             else
108             {
109                 // #125258# for SVGTokenG decompose childs
110                 const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
111 
112                 if(pStyle)
113                 {
114                     const double fOpacity(pStyle->getOpacity().getNumber());
115 
116                     if(fOpacity > 0.0 && Display_none != getDisplay())
117                     {
118                         drawinglayer::primitive2d::Primitive2DSequence aContent;
119 
120                         // decompose childs
121                         SvgNode::decomposeSvgNode(aContent, bReferenced);
122 
123                         if(aContent.hasElements())
124                         {
125                             pStyle->add_postProcess(rTarget, aContent, getTransform());
126                         }
127                     }
128                 }
129             }
130         }
131     } // end of namespace svgreader
132 } // end of namespace svgio
133 
134 //////////////////////////////////////////////////////////////////////////////
135 // eof
136