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/svgmarkernode.hxx>
26 
27 //////////////////////////////////////////////////////////////////////////////
28 
29 namespace svgio
30 {
31     namespace svgreader
32     {
33         SvgMarkerNode::SvgMarkerNode(
34             SvgDocument& rDocument,
35             SvgNode* pParent)
36         :   SvgNode(SVGTokenMarker, rDocument, pParent),
37             aPrimitives(),
38             maSvgStyleAttributes(*this),
39             mpViewBox(0),
40             maSvgAspectRatio(),
41             maRefX(0),
42             maRefY(0),
43             maMarkerUnits(strokeWidth),
44             maMarkerWidth(3),
45             maMarkerHeight(3),
46             mfAngle(0.0),
47             mbOrientAuto(false)
48         {
49         }
50 
51         SvgMarkerNode::~SvgMarkerNode()
52         {
53             if(mpViewBox) delete mpViewBox;
54         }
55 
56         const SvgStyleAttributes* SvgMarkerNode::getSvgStyleAttributes() const
57         {
58             static rtl::OUString aClassStr(rtl::OUString::createFromAscii("marker"));
59 
60             return checkForCssStyle(aClassStr, maSvgStyleAttributes);
61         }
62 
63         void SvgMarkerNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
64         {
65             // call parent
66             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
67 
68             // read style attributes
69             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
70 
71             // parse own
72             switch(aSVGToken)
73             {
74                 case SVGTokenStyle:
75                 {
76                     readLocalCssStyle(aContent);
77                     break;
78                 }
79                 case SVGTokenViewBox:
80                 {
81                     const basegfx::B2DRange aRange(readViewBox(aContent, *this));
82 
83                     if(!aRange.isEmpty())
84                     {
85                         setViewBox(&aRange);
86                     }
87                     break;
88                 }
89                 case SVGTokenPreserveAspectRatio:
90                 {
91                     setSvgAspectRatio(readSvgAspectRatio(aContent));
92                     break;
93                 }
94                 case SVGTokenRefX:
95                 {
96                     SvgNumber aNum;
97 
98                     if(readSingleNumber(aContent, aNum))
99                     {
100                         setRefX(aNum);
101                     }
102                     break;
103                 }
104                 case SVGTokenRefY:
105                 {
106                     SvgNumber aNum;
107 
108                     if(readSingleNumber(aContent, aNum))
109                     {
110                         setRefY(aNum);
111                     }
112                     break;
113                 }
114                 case SVGTokenMarkerUnits:
115                 {
116                     if(aContent.getLength())
117                     {
118                         static rtl::OUString aStrStrokeWidth(rtl::OUString::createFromAscii("strokeWidth"));
119 
120                         if(aContent.match(aStrStrokeWidth, 0))
121                         {
122                             setMarkerUnits(strokeWidth);
123                         }
124                         else if(aContent.match(commonStrings::aStrUserSpaceOnUse, 0))
125                         {
126                             setMarkerUnits(userSpaceOnUse);
127                         }
128                     }
129                     break;
130                 }
131                 case SVGTokenMarkerWidth:
132                 {
133                     SvgNumber aNum;
134 
135                     if(readSingleNumber(aContent, aNum))
136                     {
137                         if(aNum.isPositive())
138                         {
139                             setMarkerWidth(aNum);
140                         }
141                     }
142                     break;
143                 }
144                 case SVGTokenMarkerHeight:
145                 {
146                     SvgNumber aNum;
147 
148                     if(readSingleNumber(aContent, aNum))
149                     {
150                         if(aNum.isPositive())
151                         {
152                             setMarkerHeight(aNum);
153                         }
154                     }
155                     break;
156                 }
157                 case SVGTokenOrient:
158                 {
159                     const sal_Int32 nLen(aContent.getLength());
160 
161                     if(nLen)
162                     {
163                         static rtl::OUString aStrAuto(rtl::OUString::createFromAscii("auto"));
164 
165                         if(aContent.match(aStrAuto, 0))
166                         {
167                             setOrientAuto(true);
168                         }
169                         else
170                         {
171                             sal_Int32 nPos(0);
172                             double fAngle(0.0);
173 
174                             if(readAngle(aContent, nPos, fAngle, nLen))
175                             {
176                                 setAngle(fAngle);
177                             }
178                         }
179                     }
180                     break;
181                 }
182                 default:
183                 {
184                     break;
185                 }
186             }
187         }
188 
189         const drawinglayer::primitive2d::Primitive2DSequence& SvgMarkerNode::getMarkerPrimitives() const
190         {
191             if(!aPrimitives.hasElements() && Display_none != getDisplay())
192             {
193                 decomposeSvgNode(const_cast< SvgMarkerNode* >(this)->aPrimitives, true);
194             }
195 
196             return aPrimitives;
197         }
198 
199         const basegfx::B2DRange SvgMarkerNode::getCurrentViewPort() const
200         {
201             if(getViewBox())
202             {
203                 return *(getViewBox());
204             }
205             else
206             {
207                 return SvgNode::getCurrentViewPort();
208             }
209         }
210 
211     } // end of namespace svgreader
212 } // end of namespace svgio
213 
214 //////////////////////////////////////////////////////////////////////////////
215 // eof
216