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 
55             return checkForCssStyle(aClassStr, maSvgStyleAttributes);
56         }
57 
58         void SvgGNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
59         {
60             // call parent
61             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
62 
63             // read style attributes
64             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
65 
66             // parse own
67             switch(aSVGToken)
68             {
69                 case SVGTokenStyle:
70                 {
71                     maSvgStyleAttributes.readStyle(aContent);
72                     break;
73                 }
74                 case SVGTokenTransform:
75                 {
76                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
77 
78                     if(!aMatrix.isIdentity())
79                     {
80                         setTransform(&aMatrix);
81                     }
82                     break;
83                 }
84                 default:
85                 {
86                     break;
87                 }
88             }
89         }
90 
91         void SvgGNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const
92         {
93             const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
94 
95             if(pStyle)
96             {
97                 const double fOpacity(pStyle->getOpacity().getNumber());
98 
99                 if(fOpacity > 0.0 && Display_none != getDisplay())
100                 {
101                     drawinglayer::primitive2d::Primitive2DSequence aContent;
102 
103                     // decompose childs
104                     SvgNode::decomposeSvgNode(aContent, bReferenced);
105 
106                     if(aContent.hasElements())
107                     {
108                         pStyle->add_postProcess(rTarget, aContent, getTransform());
109                     }
110                 }
111             }
112         }
113     } // end of namespace svgreader
114 } // end of namespace svgio
115 
116 //////////////////////////////////////////////////////////////////////////////
117 // eof
118