1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <svgtoken.hxx>
21 #include <unordered_map>
23 namespace svgio::svgreader
25 const char aSVGStrWidth
[] = "width";
26 const char aSVGStrHeight
[] = "height";
27 const char aSVGStrViewBox
[] = "viewBox";
28 const char aSVGStrTransform
[] = "transform";
29 const char aSVGStrStyle
[] = "style";
30 const char aSVGStrDisplay
[] = "display"; // #i121656#
31 const char aSVGStrD
[] = "d";
32 const char aSVGStrX
[] = "x";
33 const char aSVGStrY
[] = "y";
34 const char aSVGStrXmlns
[] = "xmlns";
35 const char aSVGStrVersion
[] = "version";
36 const char aSVGStrId
[] = "id";
37 const char aSVGStrRx
[] = "rx";
38 const char aSVGStrRy
[] = "ry";
39 const char aSVGStrPoints
[] = "points";
40 const char aSVGStrDx
[] = "dx";
41 const char aSVGStrDy
[] = "dy";
42 const char aSVGStrRotate
[] = "rotate";
43 const char aSVGStrTextLength
[] = "textLength";
44 const char aSVGStrLengthAdjust
[] = "lengthAdjust";
45 const char aSVGStrFont
[] = "font";
46 const char aSVGStrFontFamily
[] = "font-family";
47 const char aSVGStrFontSize
[] = "font-size";
48 const char aSVGStrFontSizeAdjust
[] = "font-size-adjust";
49 const char aSVGStrFontStretch
[] = "font-stretch";
50 const char aSVGStrFontStyle
[] = "font-style";
51 const char aSVGStrFontVariant
[] = "font-variant";
52 const char aSVGStrFontWeight
[] = "font-weight";
53 const char aSVGStrDirection
[] = "direction";
54 const char aSVGStrLetterSpacing
[] = "letter-spacing";
55 const char aSVGStrTextDecoration
[] = "text-decoration";
56 const char aSVGStrUnicodeBidi
[] = "unicode-bidi";
57 const char aSVGStrWordSpacing
[] = "word-spacing";
58 const char aSVGStrTspan
[] = "tspan";
59 const char aSVGStrTref
[] = "tref";
60 const char aSVGStrTextPath
[] = "textPath";
61 const char aSVGStrStartOffset
[] = "startOffset";
62 const char aSVGStrMethod
[] = "method";
63 const char aSVGStrSpacing
[] = "spacing";
64 const char aSVGStrTextAlign
[] = "text-align";
65 const char aSVGStrPathLength
[] = "pathLength";
66 const char aSVGStrType
[] = "type";
67 const char aSVGStrClass
[] = "class";
68 const char aSVGStrTextAnchor
[] = "text-anchor";
69 const char aSVGStrXmlSpace
[] = "xml:space";
70 const char aSVGStrColor
[] = "color";
71 const char aSVGStrClipPathNode
[] = "clipPath";
72 const char aSVGStrClipPathProperty
[] = "clip-path";
73 const char aSVGStrMask
[] = "mask";
74 const char aSVGStrClipPathUnits
[] = "clipPathUnits";
75 const char aSVGStrMaskUnits
[] = "maskUnits";
76 const char aSVGStrMaskContentUnits
[] = "maskContentUnits";
77 const char aSVGStrClipRule
[] = "clip-rule";
78 const char aSVGStrMarker
[] = "marker";
79 const char aSVGStrMarkerStart
[] = "marker-start";
80 const char aSVGStrMarkerMid
[] = "marker-mid";
81 const char aSVGStrMarkerEnd
[] = "marker-end";
82 const char aSVGStrRefX
[] = "refX";
83 const char aSVGStrRefY
[] = "refY";
84 const char aSVGStrMarkerUnits
[] = "markerUnits";
85 const char aSVGStrMarkerWidth
[] = "markerWidth";
86 const char aSVGStrMarkerHeight
[] = "markerHeight";
87 const char aSVGStrOrient
[] = "orient";
88 const char aSVGStrPattern
[] = "pattern";
89 const char aSVGStrPatternUnits
[] = "patternUnits";
90 const char aSVGStrPatternContentUnits
[] = "patternContentUnits";
91 const char aSVGStrPatternTransform
[] = "patternTransform";
92 const char aSVGStrOpacity
[] = "opacity";
93 const char aSVGStrVisibility
[] = "visibility";
94 constexpr OUStringLiteral aSVGStrTitle
= u
"title";
95 constexpr OUStringLiteral aSVGStrDesc
= u
"desc";
97 const char aSVGStrPreserveAspectRatio
[] = "preserveAspectRatio";
98 const char aSVGStrDefer
[] = "defer";
99 const char aSVGStrNone
[] = "none";
100 const char aSVGStrXMinYMin
[] = "xMinYMin";
101 const char aSVGStrXMidYMin
[] = "xMidYMin";
102 const char aSVGStrXMaxYMin
[] = "xMaxYMin";
103 const char aSVGStrXMinYMid
[] = "xMinYMid";
104 const char aSVGStrXMidYMid
[] = "xMidYMid";
105 const char aSVGStrXMaxYMid
[] = "xMaxYMid";
106 const char aSVGStrXMinYMax
[] = "xMinYMax";
107 const char aSVGStrXMidYMax
[] = "xMidYMax";
108 const char aSVGStrXMaxYMax
[] = "xMaxYMax";
109 const char aSVGStrMeet
[] = "meet";
110 const char aSVGStrSlice
[] = "slice";
112 const char aSVGStrDefs
[] = "defs";
113 const char aSVGStrG
[] = "g";
114 const char aSVGStrSvg
[] = "svg";
115 const char aSVGStrSymbol
[] = "symbol";
116 const char aSVGStrUse
[] = "use";
117 const char aSVGStrA
[] = "a";
119 const char aSVGStrCircle
[] = "circle";
120 const char aSVGStrEllipse
[] = "ellipse";
121 const char aSVGStrLine
[] = "line";
122 const char aSVGStrPath
[] = "path";
123 const char aSVGStrPolygon
[] = "polygon";
124 const char aSVGStrPolyline
[] = "polyline";
125 const char aSVGStrRect
[] = "rect";
126 const char aSVGStrImage
[] = "image";
128 const char aSVGStrLinearGradient
[] = "linearGradient";
129 const char aSVGStrRadialGradient
[] = "radialGradient";
130 const char aSVGStrStop
[] = "stop";
131 const char aSVGStrOffset
[] = "offset";
132 const char aSVGStrX1
[] = "x1";
133 const char aSVGStrY1
[] = "y1";
134 const char aSVGStrX2
[] = "x2";
135 const char aSVGStrY2
[] = "y2";
136 const char aSVGStrCx
[] = "cx";
137 const char aSVGStrCy
[] = "cy";
138 const char aSVGStrFx
[] = "fx";
139 const char aSVGStrFy
[] = "fy";
140 const char aSVGStrR
[] = "r";
141 const char aSVGStrGradientUnits
[] = "gradientUnits";
142 const char aSVGStrGradientTransform
[] = "gradientTransform";
143 const char aSVGStrSpreadMethod
[] = "spreadMethod";
144 const char aSVGStrXlinkHref
[] = "xlink:href";
145 const char aSVGStrStopColor
[] = "stop-color";
146 const char aSVGStrStopOpacity
[] = "stop-opacity";
148 const char aSVGStrFill
[] = "fill";
149 const char aSVGStrFillOpacity
[] = "fill-opacity";
150 const char aSVGStrFillRule
[] = "fill-rule";
152 const char aSVGStrStroke
[] = "stroke";
153 const char aSVGStrStrokeDasharray
[] = "stroke-dasharray";
154 const char aSVGStrStrokeDashoffset
[] = "stroke-dashoffset";
155 const char aSVGStrStrokeLinecap
[] = "stroke-linecap";
156 const char aSVGStrStrokeLinejoin
[] = "stroke-linejoin";
157 const char aSVGStrStrokeMiterlimit
[] = "stroke-miterlimit";
158 const char aSVGStrStrokeOpacity
[] = "stroke-opacity";
159 const char aSVGStrStrokeWidth
[] = "stroke-width";
161 const char aSVGStrText
[] = "text";
162 const char aSVGStrBaselineShift
[] = "baseline-shift";
164 const char aSVGStrFlowRoot
[] = "flowRoot";
166 SVGToken
StrToSVGToken(const OUString
& rStr
, bool bCaseIndependent
)
168 typedef std::unordered_map
< OUString
, SVGToken
> SVGTokenMapper
;
169 typedef std::pair
< OUString
, SVGToken
> SVGTokenValueType
;
170 static SVGTokenMapper aSVGTokenMapperList
{
171 { aSVGStrWidth
, SVGToken::Width
},
172 { aSVGStrHeight
, SVGToken::Height
},
173 { aSVGStrViewBox
, SVGToken::ViewBox
},
174 { aSVGStrTransform
, SVGToken::Transform
},
175 { aSVGStrStyle
, SVGToken::Style
},
176 { aSVGStrDisplay
, SVGToken::Display
}, // #i121656#
177 { aSVGStrD
, SVGToken::D
},
178 { aSVGStrX
, SVGToken::X
},
179 { aSVGStrY
, SVGToken::Y
},
180 { aSVGStrXmlns
, SVGToken::Xmlns
},
181 { aSVGStrVersion
, SVGToken::Version
},
182 { aSVGStrId
, SVGToken::Id
},
183 { aSVGStrRx
, SVGToken::Rx
},
184 { aSVGStrRy
, SVGToken::Ry
},
185 { aSVGStrPoints
, SVGToken::Points
},
186 { aSVGStrDx
, SVGToken::Dx
},
187 { aSVGStrDy
, SVGToken::Dy
},
188 { aSVGStrRotate
, SVGToken::Rotate
},
189 { aSVGStrTextLength
, SVGToken::TextLength
},
190 { aSVGStrLengthAdjust
, SVGToken::LengthAdjust
},
191 { aSVGStrFont
, SVGToken::Font
},
192 { aSVGStrFontFamily
, SVGToken::FontFamily
},
193 { aSVGStrFontSize
, SVGToken::FontSize
},
194 { aSVGStrFontSizeAdjust
, SVGToken::FontSizeAdjust
},
195 { aSVGStrFontStretch
, SVGToken::FontStretch
},
196 { aSVGStrFontStyle
, SVGToken::FontStyle
},
197 { aSVGStrFontVariant
, SVGToken::FontVariant
},
198 { aSVGStrFontWeight
, SVGToken::FontWeight
},
199 { aSVGStrDirection
, SVGToken::Direction
},
200 { aSVGStrLetterSpacing
, SVGToken::LetterSpacing
},
201 { aSVGStrTextDecoration
, SVGToken::TextDecoration
},
202 { aSVGStrUnicodeBidi
, SVGToken::UnicodeBidi
},
203 { aSVGStrWordSpacing
, SVGToken::WordSpacing
},
204 { aSVGStrTspan
, SVGToken::Tspan
},
205 { aSVGStrTref
, SVGToken::Tref
},
206 { aSVGStrTextPath
, SVGToken::TextPath
},
207 { aSVGStrStartOffset
, SVGToken::StartOffset
},
208 { aSVGStrMethod
, SVGToken::Method
},
209 { aSVGStrSpacing
, SVGToken::Spacing
},
210 { aSVGStrTextAlign
, SVGToken::TextAlign
},
211 { aSVGStrPathLength
, SVGToken::PathLength
},
212 { aSVGStrType
, SVGToken::Type
},
213 { aSVGStrClass
, SVGToken::Class
},
214 { aSVGStrTextAnchor
, SVGToken::TextAnchor
},
215 { aSVGStrXmlSpace
, SVGToken::XmlSpace
},
216 { aSVGStrColor
, SVGToken::Color
},
217 { aSVGStrClipPathNode
, SVGToken::ClipPathNode
},
218 { aSVGStrClipPathProperty
, SVGToken::ClipPathProperty
},
219 { aSVGStrMask
, SVGToken::Mask
},
220 { aSVGStrClipPathUnits
, SVGToken::ClipPathUnits
},
221 { aSVGStrMaskUnits
, SVGToken::MaskUnits
},
222 { aSVGStrMaskContentUnits
, SVGToken::MaskContentUnits
},
223 { aSVGStrClipRule
, SVGToken::ClipRule
},
224 { aSVGStrMarker
, SVGToken::Marker
},
225 { aSVGStrMarkerStart
, SVGToken::MarkerStart
},
226 { aSVGStrMarkerMid
, SVGToken::MarkerMid
},
227 { aSVGStrMarkerEnd
, SVGToken::MarkerEnd
},
228 { aSVGStrRefX
, SVGToken::RefX
},
229 { aSVGStrRefY
, SVGToken::RefY
},
230 { aSVGStrMarkerUnits
, SVGToken::MarkerUnits
},
231 { aSVGStrMarkerWidth
, SVGToken::MarkerWidth
},
232 { aSVGStrMarkerHeight
, SVGToken::MarkerHeight
},
233 { aSVGStrOrient
, SVGToken::Orient
},
234 { aSVGStrPattern
, SVGToken::Pattern
},
235 { aSVGStrPatternUnits
, SVGToken::PatternUnits
},
236 { aSVGStrPatternContentUnits
, SVGToken::PatternContentUnits
},
237 { aSVGStrPatternTransform
, SVGToken::PatternTransform
},
238 { aSVGStrOpacity
, SVGToken::Opacity
},
239 { aSVGStrVisibility
, SVGToken::Visibility
},
240 { aSVGStrTitle
, SVGToken::Title
},
241 { aSVGStrDesc
, SVGToken::Desc
},
243 { aSVGStrPreserveAspectRatio
, SVGToken::PreserveAspectRatio
},
244 { aSVGStrDefer
, SVGToken::Defer
},
245 { aSVGStrNone
, SVGToken::None
},
246 { aSVGStrXMinYMin
, SVGToken::XMinYMin
},
247 { aSVGStrXMidYMin
, SVGToken::XMidYMin
},
248 { aSVGStrXMaxYMin
, SVGToken::XMaxYMin
},
249 { aSVGStrXMinYMid
, SVGToken::XMinYMid
},
250 { aSVGStrXMidYMid
, SVGToken::XMidYMid
},
251 { aSVGStrXMaxYMid
, SVGToken::XMaxYMid
},
252 { aSVGStrXMinYMax
, SVGToken::XMinYMax
},
253 { aSVGStrXMidYMax
, SVGToken::XMidYMax
},
254 { aSVGStrXMaxYMax
, SVGToken::XMaxYMax
},
255 { aSVGStrMeet
, SVGToken::Meet
},
256 { aSVGStrSlice
, SVGToken::Slice
},
258 { aSVGStrDefs
, SVGToken::Defs
},
259 { aSVGStrG
, SVGToken::G
},
260 { aSVGStrSvg
, SVGToken::Svg
},
261 { aSVGStrSymbol
, SVGToken::Symbol
},
262 { aSVGStrUse
, SVGToken::Use
},
263 { aSVGStrA
, SVGToken::A
},
265 { aSVGStrCircle
, SVGToken::Circle
},
266 { aSVGStrEllipse
, SVGToken::Ellipse
},
267 { aSVGStrLine
, SVGToken::Line
},
268 { aSVGStrPath
, SVGToken::Path
},
269 { aSVGStrPolygon
, SVGToken::Polygon
},
270 { aSVGStrPolyline
, SVGToken::Polyline
},
271 { aSVGStrRect
, SVGToken::Rect
},
272 { aSVGStrImage
, SVGToken::Image
},
274 { aSVGStrLinearGradient
, SVGToken::LinearGradient
},
275 { aSVGStrRadialGradient
, SVGToken::RadialGradient
},
276 { aSVGStrStop
, SVGToken::Stop
},
277 { aSVGStrOffset
, SVGToken::Offset
},
278 { aSVGStrX1
, SVGToken::X1
},
279 { aSVGStrY1
, SVGToken::Y1
},
280 { aSVGStrX2
, SVGToken::X2
},
281 { aSVGStrY2
, SVGToken::Y2
},
282 { aSVGStrCx
, SVGToken::Cx
},
283 { aSVGStrCy
, SVGToken::Cy
},
284 { aSVGStrFx
, SVGToken::Fx
},
285 { aSVGStrFy
, SVGToken::Fy
},
286 { aSVGStrR
, SVGToken::R
},
287 { aSVGStrGradientUnits
, SVGToken::GradientUnits
},
288 { aSVGStrGradientTransform
, SVGToken::GradientTransform
},
289 { aSVGStrSpreadMethod
, SVGToken::SpreadMethod
},
290 { aSVGStrXlinkHref
, SVGToken::XlinkHref
},
291 { aSVGStrStopColor
, SVGToken::StopColor
},
292 { aSVGStrStopOpacity
, SVGToken::StopOpacity
},
294 { aSVGStrFill
, SVGToken::Fill
},
295 { aSVGStrFillOpacity
, SVGToken::FillOpacity
},
296 { aSVGStrFillRule
, SVGToken::FillRule
},
298 { aSVGStrStroke
, SVGToken::Stroke
},
299 { aSVGStrStrokeDasharray
, SVGToken::StrokeDasharray
},
300 { aSVGStrStrokeDashoffset
, SVGToken::StrokeDashoffset
},
301 { aSVGStrStrokeLinecap
, SVGToken::StrokeLinecap
},
302 { aSVGStrStrokeLinejoin
, SVGToken::StrokeLinejoin
},
303 { aSVGStrStrokeMiterlimit
, SVGToken::StrokeMiterlimit
},
304 { aSVGStrStrokeOpacity
, SVGToken::StrokeOpacity
},
305 { aSVGStrStrokeWidth
, SVGToken::StrokeWidth
},
307 { aSVGStrText
, SVGToken::Text
},
308 { aSVGStrBaselineShift
, SVGToken::BaselineShift
},
309 { aSVGStrFlowRoot
, SVGToken::FlowRoot
}
312 const SVGTokenMapper::const_iterator
aResult(aSVGTokenMapperList
.find(rStr
.startsWith("svg:") ? rStr
.copy(4) : rStr
));
314 if(aResult
== aSVGTokenMapperList
.end())
318 static SVGTokenMapper aCaseLindependentSVGTokenMapperList
;
320 if(aCaseLindependentSVGTokenMapperList
.empty())
322 for(const auto& rCurrent
: aSVGTokenMapperList
)
324 aCaseLindependentSVGTokenMapperList
.insert(
326 rCurrent
.first
.toAsciiLowerCase(),
331 const SVGTokenMapper::const_iterator
aResult2(aCaseLindependentSVGTokenMapperList
.find(rStr
.toAsciiLowerCase()));
333 if(aResult2
== aCaseLindependentSVGTokenMapperList
.end())
335 return SVGToken::Unknown
;
339 return aResult2
->second
;
343 return SVGToken::Unknown
;
347 return aResult
->second
;
351 OUString
getStrTitle()
356 OUString
getStrDesc()
360 } // end of namespace svgio
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */