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