Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / svgio / source / svgreader / svgmarkernode.cxx
blob444ff3266420ff459956c05b280ac2481ec5809e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svgio/svgreader/svgmarkernode.hxx>
22 //////////////////////////////////////////////////////////////////////////////
24 namespace svgio
26 namespace svgreader
28 SvgMarkerNode::SvgMarkerNode(
29 SvgDocument& rDocument,
30 SvgNode* pParent)
31 : SvgNode(SVGTokenMarker, rDocument, pParent),
32 aPrimitives(),
33 maSvgStyleAttributes(*this),
34 mpViewBox(0),
35 maSvgAspectRatio(),
36 maRefX(0),
37 maRefY(0),
38 maMarkerUnits(strokeWidth),
39 maMarkerWidth(3),
40 maMarkerHeight(3),
41 mfAngle(0.0),
42 mbOrientAuto(false)
46 SvgMarkerNode::~SvgMarkerNode()
48 if(mpViewBox) delete mpViewBox;
51 const SvgStyleAttributes* SvgMarkerNode::getSvgStyleAttributes() const
53 static rtl::OUString aClassStr(rtl::OUString::createFromAscii("marker"));
54 maSvgStyleAttributes.checkForCssStyle(aClassStr);
56 return &maSvgStyleAttributes;
59 void SvgMarkerNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
61 // call parent
62 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
64 // read style attributes
65 maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
67 // parse own
68 switch(aSVGToken)
70 case SVGTokenStyle:
72 maSvgStyleAttributes.readStyle(aContent);
73 break;
75 case SVGTokenViewBox:
77 const basegfx::B2DRange aRange(readViewBox(aContent, *this));
79 if(!aRange.isEmpty())
81 setViewBox(&aRange);
83 break;
85 case SVGTokenPreserveAspectRatio:
87 setSvgAspectRatio(readSvgAspectRatio(aContent));
88 break;
90 case SVGTokenRefX:
92 SvgNumber aNum;
94 if(readSingleNumber(aContent, aNum))
96 setRefX(aNum);
98 break;
100 case SVGTokenRefY:
102 SvgNumber aNum;
104 if(readSingleNumber(aContent, aNum))
106 setRefY(aNum);
108 break;
110 case SVGTokenMarkerUnits:
112 if(aContent.getLength())
114 static rtl::OUString aStrStrokeWidth(rtl::OUString::createFromAscii("strokeWidth"));
116 if(aContent.match(aStrStrokeWidth, 0))
118 setMarkerUnits(strokeWidth);
120 else if(aContent.match(commonStrings::aStrUserSpaceOnUse, 0))
122 setMarkerUnits(userSpaceOnUse);
125 break;
127 case SVGTokenMarkerWidth:
129 SvgNumber aNum;
131 if(readSingleNumber(aContent, aNum))
133 if(aNum.isPositive())
135 setMarkerWidth(aNum);
138 break;
140 case SVGTokenMarkerHeight:
142 SvgNumber aNum;
144 if(readSingleNumber(aContent, aNum))
146 if(aNum.isPositive())
148 setMarkerHeight(aNum);
151 break;
153 case SVGTokenOrient:
155 const sal_Int32 nLen(aContent.getLength());
157 if(nLen)
159 static rtl::OUString aStrAuto(rtl::OUString::createFromAscii("auto"));
161 if(aContent.match(aStrAuto, 0))
163 setOrientAuto(true);
165 else
167 sal_Int32 nPos(0);
168 double fAngle(0.0);
170 if(readAngle(aContent, nPos, fAngle, nLen))
172 setAngle(fAngle);
176 break;
178 default:
180 break;
185 const drawinglayer::primitive2d::Primitive2DSequence& SvgMarkerNode::getMarkerPrimitives() const
187 if(!aPrimitives.hasElements())
189 decomposeSvgNode(const_cast< SvgMarkerNode* >(this)->aPrimitives, true);
192 return aPrimitives;
195 const basegfx::B2DRange* SvgMarkerNode::getCurrentViewPort() const
197 if(getViewBox())
199 return getViewBox();
201 else
203 return SvgNode::getCurrentViewPort();
207 } // end of namespace svgreader
208 } // end of namespace svgio
210 //////////////////////////////////////////////////////////////////////////////
211 // eof
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */