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/svgpathnode.hxx>
26 #include <basegfx/polygon/b2dpolypolygontools.hxx>
27 
28 //////////////////////////////////////////////////////////////////////////////
29 
30 namespace svgio
31 {
32     namespace svgreader
33     {
SvgPathNode(SvgDocument & rDocument,SvgNode * pParent)34         SvgPathNode::SvgPathNode(
35             SvgDocument& rDocument,
36             SvgNode* pParent)
37         :   SvgNode(SVGTokenPath, rDocument, pParent),
38             maSvgStyleAttributes(*this),
39             mpPolyPolygon(0),
40             mpaTransform(0),
41             maPathLength()
42         {
43         }
44 
~SvgPathNode()45         SvgPathNode::~SvgPathNode()
46         {
47             if(mpPolyPolygon) delete mpPolyPolygon;
48             if(mpaTransform) delete mpaTransform;
49         }
50 
getSvgStyleAttributes() const51         const SvgStyleAttributes* SvgPathNode::getSvgStyleAttributes() const
52         {
53             static rtl::OUString aClassStr(rtl::OUString::createFromAscii("path"));
54 
55             return checkForCssStyle(aClassStr, maSvgStyleAttributes);
56         }
57 
parseAttribute(const rtl::OUString & rTokenName,SVGToken aSVGToken,const rtl::OUString & aContent)58         void SvgPathNode::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 SVGTokenD:
75                 {
76                     basegfx::B2DPolyPolygon aPath;
77 
78                     if(basegfx::tools::importFromSvgD(aPath, aContent, false, &maHelpPointIndices))
79                     {
80                         if(aPath.count())
81                         {
82                             setPath(&aPath);
83                         }
84                     }
85                     break;
86                 }
87                 case SVGTokenTransform:
88                 {
89                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
90 
91                     if(!aMatrix.isIdentity())
92                     {
93                         setTransform(&aMatrix);
94                     }
95                     break;
96                 }
97                 case SVGTokenPathLength:
98                 {
99                     SvgNumber aNum;
100 
101                     if(readSingleNumber(aContent, aNum))
102                     {
103                         setPathLength(aNum);
104                     }
105                     break;
106                 }
107                 default:
108                 {
109                     break;
110                 }
111             }
112         }
113 
decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence & rTarget,bool) const114         void SvgPathNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
115         {
116             // fill and/or stroke needed, also a path
117             const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
118 
119             if(pStyle && getPath())
120             {
121                 drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
122 
123                 pStyle->add_path(*getPath(), aNewTarget, &maHelpPointIndices);
124 
125                 if(aNewTarget.hasElements())
126                 {
127                     pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
128                 }
129             }
130         }
131     } // end of namespace svgreader
132 } // end of namespace svgio
133 
134 //////////////////////////////////////////////////////////////////////////////
135 // eof
136