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/svgpolynode.hxx>
26 #include <basegfx/polygon/b2dpolygon.hxx>
27 #include <basegfx/polygon/b2dpolypolygontools.hxx>
28 #include <basegfx/polygon/b2dpolygontools.hxx>
29 
30 //////////////////////////////////////////////////////////////////////////////
31 
32 namespace svgio
33 {
34     namespace svgreader
35     {
SvgPolyNode(SvgDocument & rDocument,SvgNode * pParent,bool bIsPolyline)36         SvgPolyNode::SvgPolyNode(
37             SvgDocument& rDocument,
38             SvgNode* pParent,
39             bool bIsPolyline)
40         :   SvgNode(SVGTokenPolygon, rDocument, pParent),
41             maSvgStyleAttributes(*this),
42             mpPolygon(0),
43             mpaTransform(0),
44             mbIsPolyline(bIsPolyline)
45         {
46         }
47 
~SvgPolyNode()48         SvgPolyNode::~SvgPolyNode()
49         {
50             if(mpaTransform) delete mpaTransform;
51             if(mpPolygon) delete mpPolygon;
52         }
53 
getSvgStyleAttributes() const54         const SvgStyleAttributes* SvgPolyNode::getSvgStyleAttributes() const
55         {
56             static rtl::OUString aClassStrA(rtl::OUString::createFromAscii("polygon"));
57             static rtl::OUString aClassStrB(rtl::OUString::createFromAscii("polyline"));
58 
59             return checkForCssStyle(mbIsPolyline? aClassStrB : aClassStrA, maSvgStyleAttributes);
60         }
61 
parseAttribute(const rtl::OUString & rTokenName,SVGToken aSVGToken,const rtl::OUString & aContent)62         void SvgPolyNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
63         {
64             // call parent
65             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
66 
67             // read style attributes
68             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
69 
70             // parse own
71             switch(aSVGToken)
72             {
73                 case SVGTokenStyle:
74                 {
75                     maSvgStyleAttributes.readStyle(aContent);
76                     break;
77                 }
78                 case SVGTokenPoints:
79                 {
80                     basegfx::B2DPolygon aPath;
81 
82                     if(basegfx::tools::importFromSvgPoints(aPath, aContent))
83                     {
84                         if(aPath.count())
85                         {
86                             if(!isPolyline())
87                             {
88                                 aPath.setClosed(true);
89                             }
90 
91                             setPolygon(&aPath);
92                         }
93                     }
94                     break;
95                 }
96                 case SVGTokenTransform:
97                 {
98                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
99 
100                     if(!aMatrix.isIdentity())
101                     {
102                         setTransform(&aMatrix);
103                     }
104                     break;
105                 }
106                 default:
107                 {
108                     break;
109                 }
110             }
111         }
112 
decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence & rTarget,bool) const113         void SvgPolyNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
114         {
115             const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
116 
117             if(pStyle && getPolygon())
118             {
119                 drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
120 
121                 pStyle->add_path(basegfx::B2DPolyPolygon(*getPolygon()), aNewTarget, 0);
122 
123                 if(aNewTarget.hasElements())
124                 {
125                     pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
126                 }
127             }
128         }
129     } // end of namespace svgreader
130 } // end of namespace svgio
131 
132 //////////////////////////////////////////////////////////////////////////////
133 // eof
134