1ddde725dSArmin Le Grand /**************************************************************
2ddde725dSArmin Le Grand  *
3ddde725dSArmin Le Grand  * Licensed to the Apache Software Foundation (ASF) under one
4ddde725dSArmin Le Grand  * or more contributor license agreements.  See the NOTICE file
5ddde725dSArmin Le Grand  * distributed with this work for additional information
6ddde725dSArmin Le Grand  * regarding copyright ownership.  The ASF licenses this file
7ddde725dSArmin Le Grand  * to you under the Apache License, Version 2.0 (the
8ddde725dSArmin Le Grand  * "License"); you may not use this file except in compliance
9ddde725dSArmin Le Grand  * with the License.  You may obtain a copy of the License at
10ddde725dSArmin Le Grand  *
11ddde725dSArmin Le Grand  *   http://www.apache.org/licenses/LICENSE-2.0
12ddde725dSArmin Le Grand  *
13ddde725dSArmin Le Grand  * Unless required by applicable law or agreed to in writing,
14ddde725dSArmin Le Grand  * software distributed under the License is distributed on an
15ddde725dSArmin Le Grand  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ddde725dSArmin Le Grand  * KIND, either express or implied.  See the License for the
17ddde725dSArmin Le Grand  * specific language governing permissions and limitations
18ddde725dSArmin Le Grand  * under the License.
19ddde725dSArmin Le Grand  *
20ddde725dSArmin Le Grand  *************************************************************/
21ddde725dSArmin Le Grand 
22ddde725dSArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove
23ddde725dSArmin Le Grand #include "precompiled_svgio.hxx"
24ddde725dSArmin Le Grand 
25ddde725dSArmin Le Grand #include <svgio/svgreader/svggnode.hxx>
26ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
27ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
28ddde725dSArmin Le Grand 
29ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
30ddde725dSArmin Le Grand 
31ddde725dSArmin Le Grand namespace svgio
32ddde725dSArmin Le Grand {
33ddde725dSArmin Le Grand     namespace svgreader
34ddde725dSArmin Le Grand     {
SvgGNode(SVGToken aType,SvgDocument & rDocument,SvgNode * pParent)35ddde725dSArmin Le Grand         SvgGNode::SvgGNode(
36ddde725dSArmin Le Grand             SVGToken aType,
37ddde725dSArmin Le Grand             SvgDocument& rDocument,
38ddde725dSArmin Le Grand             SvgNode* pParent)
39ddde725dSArmin Le Grand         :   SvgNode(aType, rDocument, pParent),
40ddde725dSArmin Le Grand             maSvgStyleAttributes(*this),
41ddde725dSArmin Le Grand             mpaTransform(0)
42ddde725dSArmin Le Grand         {
43ddde725dSArmin Le Grand             OSL_ENSURE(aType == SVGTokenDefs || aType == SVGTokenG, "SvgGNode should ony be used for Group and Defs (!)");
44ddde725dSArmin Le Grand         }
45ddde725dSArmin Le Grand 
~SvgGNode()46ddde725dSArmin Le Grand         SvgGNode::~SvgGNode()
47ddde725dSArmin Le Grand         {
48ddde725dSArmin Le Grand             if(mpaTransform) delete mpaTransform;
49ddde725dSArmin Le Grand         }
50ddde725dSArmin Le Grand 
getSvgStyleAttributes() const51ddde725dSArmin Le Grand         const SvgStyleAttributes* SvgGNode::getSvgStyleAttributes() const
52ddde725dSArmin Le Grand         {
534374d266SArmin Le Grand             if(SVGTokenDefs == getType())
544374d266SArmin Le Grand             {
554374d266SArmin Le Grand                 // #125258# call parent for SVGTokenDefs
564374d266SArmin Le Grand                 return SvgNode::getSvgStyleAttributes();
574374d266SArmin Le Grand             }
584374d266SArmin Le Grand             else
594374d266SArmin Le Grand             {
604374d266SArmin Le Grand                 // #125258# for SVGTokenG take CssStyles into account
614374d266SArmin Le Grand                 static rtl::OUString aClassStr(rtl::OUString::createFromAscii("g"));
62ddde725dSArmin Le Grand 
634374d266SArmin Le Grand                 return checkForCssStyle(aClassStr, maSvgStyleAttributes);
644374d266SArmin Le Grand             }
65ddde725dSArmin Le Grand         }
66ddde725dSArmin Le Grand 
parseAttribute(const rtl::OUString & rTokenName,SVGToken aSVGToken,const rtl::OUString & aContent)67ddde725dSArmin Le Grand         void SvgGNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
68ddde725dSArmin Le Grand         {
69ddde725dSArmin Le Grand             // call parent
70ddde725dSArmin Le Grand             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
71ddde725dSArmin Le Grand 
72ddde725dSArmin Le Grand             // read style attributes
73*52cb04b8SArmin Le Grand             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent, false);
74ddde725dSArmin Le Grand 
75ddde725dSArmin Le Grand             // parse own
76ddde725dSArmin Le Grand             switch(aSVGToken)
77ddde725dSArmin Le Grand             {
78ddde725dSArmin Le Grand                 case SVGTokenStyle:
79ddde725dSArmin Le Grand                 {
809d01bcdeSArmin Le Grand                     readLocalCssStyle(aContent);
81ddde725dSArmin Le Grand                     break;
82ddde725dSArmin Le Grand                 }
83ddde725dSArmin Le Grand                 case SVGTokenTransform:
84ddde725dSArmin Le Grand                 {
85ddde725dSArmin Le Grand                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
86ddde725dSArmin Le Grand 
87ddde725dSArmin Le Grand                     if(!aMatrix.isIdentity())
88ddde725dSArmin Le Grand                     {
89ddde725dSArmin Le Grand                         setTransform(&aMatrix);
90ddde725dSArmin Le Grand                     }
91ddde725dSArmin Le Grand                     break;
92ddde725dSArmin Le Grand                 }
93e2bf1e9dSArmin Le Grand                 default:
94e2bf1e9dSArmin Le Grand                 {
95e2bf1e9dSArmin Le Grand                     break;
96e2bf1e9dSArmin Le Grand                 }
97ddde725dSArmin Le Grand             }
98ddde725dSArmin Le Grand         }
99ddde725dSArmin Le Grand 
decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence & rTarget,bool bReferenced) const100ddde725dSArmin Le Grand         void SvgGNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const
101ddde725dSArmin Le Grand         {
1024374d266SArmin Le Grand             if(SVGTokenDefs == getType())
103ddde725dSArmin Le Grand             {
1044374d266SArmin Le Grand                 // #125258# no decompose needed for defs element, call parent for SVGTokenDefs
1054374d266SArmin Le Grand                 SvgNode::decomposeSvgNode(rTarget, bReferenced);
1064374d266SArmin Le Grand             }
1074374d266SArmin Le Grand             else
1084374d266SArmin Le Grand             {
1094374d266SArmin Le Grand                 // #125258# for SVGTokenG decompose childs
1104374d266SArmin Le Grand                 const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
111ddde725dSArmin Le Grand 
1124374d266SArmin Le Grand                 if(pStyle)
113ddde725dSArmin Le Grand                 {
1144374d266SArmin Le Grand                     const double fOpacity(pStyle->getOpacity().getNumber());
115ddde725dSArmin Le Grand 
1164374d266SArmin Le Grand                     if(fOpacity > 0.0 && Display_none != getDisplay())
117ddde725dSArmin Le Grand                     {
1184374d266SArmin Le Grand                         drawinglayer::primitive2d::Primitive2DSequence aContent;
1194374d266SArmin Le Grand 
1204374d266SArmin Le Grand                         // decompose childs
1214374d266SArmin Le Grand                         SvgNode::decomposeSvgNode(aContent, bReferenced);
1224374d266SArmin Le Grand 
1234374d266SArmin Le Grand                         if(aContent.hasElements())
1244374d266SArmin Le Grand                         {
1254374d266SArmin Le Grand                             pStyle->add_postProcess(rTarget, aContent, getTransform());
1264374d266SArmin Le Grand                         }
127ddde725dSArmin Le Grand                     }
128ddde725dSArmin Le Grand                 }
129ddde725dSArmin Le Grand             }
130ddde725dSArmin Le Grand         }
131ddde725dSArmin Le Grand     } // end of namespace svgreader
132ddde725dSArmin Le Grand } // end of namespace svgio
133ddde725dSArmin Le Grand 
134ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
135ddde725dSArmin Le Grand // eof
136