LibreOffice Module svgio (master) 1
svgmarkernode.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <svgmarkernode.hxx>
21#include <o3tl/string_view.hxx>
22
23namespace svgio::svgreader
24{
26 SvgDocument& rDocument,
27 SvgNode* pParent)
28 : SvgNode(SVGToken::Marker, rDocument, pParent),
29 maSvgStyleAttributes(*this),
30 maRefX(0),
31 maRefY(0),
32 maMarkerUnits(MarkerUnits::strokeWidth),
33 maMarkerWidth(3),
34 maMarkerHeight(3),
35 mfAngle(0.0),
36 maMarkerOrient(MarkerOrient::notset)
37 {
38 }
39
41 {
42 }
43
45 {
47 }
48
49 void SvgMarkerNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
50 {
51 // call parent
52 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
53
54 // read style attributes
55 maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
56
57 // parse own
58 switch(aSVGToken)
59 {
60 case SVGToken::Style:
61 {
62 readLocalCssStyle(aContent);
63 break;
64 }
66 {
67 const basegfx::B2DRange aRange(readViewBox(aContent, *this));
68
69 if(!aRange.isEmpty())
70 {
71 setViewBox(&aRange);
72 }
73 break;
74 }
76 {
78 break;
79 }
80 case SVGToken::RefX:
81 {
82 SvgNumber aNum;
83
84 if(readSingleNumber(aContent, aNum))
85 {
86 maRefX = aNum;
87 }
88 break;
89 }
90 case SVGToken::RefY:
91 {
92 SvgNumber aNum;
93
94 if(readSingleNumber(aContent, aNum))
95 {
96 maRefY = aNum;
97 }
98 break;
99 }
101 {
102 if(!aContent.isEmpty())
103 {
104 if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"strokeWidth"))
105 {
107 }
109 {
111 }
112 }
113 break;
114 }
116 {
117 SvgNumber aNum;
118
119 if(readSingleNumber(aContent, aNum))
120 {
121 if(aNum.isPositive())
122 {
123 maMarkerWidth = aNum;
124 }
125 }
126 break;
127 }
129 {
130 SvgNumber aNum;
131
132 if(readSingleNumber(aContent, aNum))
133 {
134 if(aNum.isPositive())
135 {
136 maMarkerHeight = aNum;
137 }
138 }
139 break;
140 }
141 case SVGToken::Orient:
142 {
143 const sal_Int32 nLen(aContent.getLength());
144
145 if(nLen)
146 {
147 if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"auto"))
148 {
150 }
151 else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"auto-start-reverse"))
152 {
154 }
155 else
156 {
157 sal_Int32 nPos(0);
158 double fAngle(0.0);
159
160 if(readAngle(aContent, nPos, fAngle, nLen))
161 {
162 setAngle(fAngle);
163 }
164 }
165 }
166 break;
167 }
168 default:
169 {
170 break;
171 }
172 }
173 }
174
176 {
177 if(aPrimitives.empty() && Display::None != getDisplay())
178 {
179 decomposeSvgNode(const_cast< SvgMarkerNode* >(this)->aPrimitives, true);
180 }
181
182 return aPrimitives;
183 }
184
186 {
187 if(getViewBox())
188 {
189 return *(getViewBox());
190 }
191 else
192 {
194 }
195 }
196
197} // end of namespace svgio::svgreader
198
199/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isEmpty() const
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent) override
virtual ~SvgMarkerNode() override
SvgStyleAttributes maSvgStyleAttributes
use styles
void setViewBox(const basegfx::B2DRange *pViewBox)
void setMarkerUnits(const MarkerUnits aMarkerUnits)
virtual basegfx::B2DRange getCurrentViewPort() const override
InfoProvider support for % values.
const drawinglayer::primitive2d::Primitive2DContainer & getMarkerPrimitives() const
get marker primitives buffered, uses decomposeSvgNode internally
drawinglayer::primitive2d::Primitive2DContainer aPrimitives
buffered decomposition
const basegfx::B2DRange * getViewBox() const
viewBox content
void setMarkerOrient(const MarkerOrient aMarkerOrient)
virtual const SvgStyleAttributes * getSvgStyleAttributes() const override
SvgMarkerNode(SvgDocument &rDocument, SvgNode *pParent)
Display getDisplay() const
Display access #i121656#.
Definition: svgnode.hxx:182
virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer &rTarget, bool bReferenced) const
Definition: svgnode.cxx:584
const SvgStyleAttributes * checkForCssStyle(const SvgStyleAttributes &rOriginal) const
helper to evtl. link to css style
Definition: svgnode.cxx:335
virtual basegfx::B2DRange getCurrentViewPort() const override
InfoProvider support for %, em and ex values.
Definition: svgnode.cxx:702
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent)
Definition: svgnode.cxx:534
void readLocalCssStyle(std::u16string_view aContent)
scan helper to read and interpret a local CssStyle to mpLocalCssStyle
Definition: svgnode.cxx:412
void parseStyleAttribute(SVGToken aSVGToken, const OUString &rContent)
local attribute scanner
float u
sal_uInt16 nPos
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
bool readSingleNumber(std::u16string_view rCandidate, SvgNumber &aNum)
Definition: svgtools.cxx:1076
bool readAngle(std::u16string_view rCandidate, sal_Int32 &nPos, double &fAngle, const sal_Int32 nLen)
Definition: svgtools.cxx:559
SvgAspectRatio readSvgAspectRatio(std::u16string_view rCandidate)
Definition: svgtools.cxx:1197
basegfx::B2DRange readViewBox(std::u16string_view rCandidate, InfoProvider const &rInfoProvider)
Definition: svgtools.cxx:808
static constexpr OUStringLiteral aStrUserSpaceOnUse
Definition: svgtools.hxx:38