nss: upgrade to release 3.73
[LibreOffice.git] / svgio / source / svgreader / svgtoken.cxx
blob3bb517d42021518e01ad2fc68ee79944abd6fdd5
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 <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 const char aSVGStrTitle[] = "title";
95 const char aSVGStrDesc[] = "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, SVGTokenWidth },
172 { aSVGStrHeight, SVGTokenHeight },
173 { aSVGStrViewBox, SVGTokenViewBox },
174 { aSVGStrTransform, SVGTokenTransform },
175 { aSVGStrStyle, SVGTokenStyle },
176 { aSVGStrDisplay, SVGTokenDisplay }, // #i121656#
177 { aSVGStrD, SVGTokenD },
178 { aSVGStrX, SVGTokenX },
179 { aSVGStrY, SVGTokenY },
180 { aSVGStrXmlns, SVGTokenXmlns },
181 { aSVGStrVersion, SVGTokenVersion },
182 { aSVGStrId, SVGTokenId },
183 { aSVGStrRx, SVGTokenRx },
184 { aSVGStrRy, SVGTokenRy },
185 { aSVGStrPoints, SVGTokenPoints },
186 { aSVGStrDx, SVGTokenDx },
187 { aSVGStrDy, SVGTokenDy },
188 { aSVGStrRotate, SVGTokenRotate },
189 { aSVGStrTextLength, SVGTokenTextLength },
190 { aSVGStrLengthAdjust, SVGTokenLengthAdjust },
191 { aSVGStrFont, SVGTokenFont },
192 { aSVGStrFontFamily, SVGTokenFontFamily },
193 { aSVGStrFontSize, SVGTokenFontSize },
194 { aSVGStrFontSizeAdjust, SVGTokenFontSizeAdjust },
195 { aSVGStrFontStretch, SVGTokenFontStretch },
196 { aSVGStrFontStyle, SVGTokenFontStyle },
197 { aSVGStrFontVariant, SVGTokenFontVariant },
198 { aSVGStrFontWeight, SVGTokenFontWeight },
199 { aSVGStrDirection, SVGTokenDirection },
200 { aSVGStrLetterSpacing, SVGTokenLetterSpacing },
201 { aSVGStrTextDecoration, SVGTokenTextDecoration },
202 { aSVGStrUnicodeBidi, SVGTokenUnicodeBidi },
203 { aSVGStrWordSpacing, SVGTokenWordSpacing },
204 { aSVGStrTspan, SVGTokenTspan },
205 { aSVGStrTref, SVGTokenTref },
206 { aSVGStrTextPath, SVGTokenTextPath },
207 { aSVGStrStartOffset, SVGTokenStartOffset },
208 { aSVGStrMethod, SVGTokenMethod },
209 { aSVGStrSpacing, SVGTokenSpacing },
210 { aSVGStrTextAlign, SVGTokenTextAlign },
211 { aSVGStrPathLength, SVGTokenPathLength },
212 { aSVGStrType, SVGTokenType },
213 { aSVGStrClass, SVGTokenClass },
214 { aSVGStrTextAnchor, SVGTokenTextAnchor },
215 { aSVGStrXmlSpace, SVGTokenXmlSpace },
216 { aSVGStrColor, SVGTokenColor },
217 { aSVGStrClipPathNode, SVGTokenClipPathNode },
218 { aSVGStrClipPathProperty, SVGTokenClipPathProperty },
219 { aSVGStrMask, SVGTokenMask },
220 { aSVGStrClipPathUnits, SVGTokenClipPathUnits },
221 { aSVGStrMaskUnits, SVGTokenMaskUnits },
222 { aSVGStrMaskContentUnits, SVGTokenMaskContentUnits },
223 { aSVGStrClipRule, SVGTokenClipRule },
224 { aSVGStrMarker, SVGTokenMarker },
225 { aSVGStrMarkerStart, SVGTokenMarkerStart },
226 { aSVGStrMarkerMid, SVGTokenMarkerMid },
227 { aSVGStrMarkerEnd, SVGTokenMarkerEnd },
228 { aSVGStrRefX, SVGTokenRefX },
229 { aSVGStrRefY, SVGTokenRefY },
230 { aSVGStrMarkerUnits, SVGTokenMarkerUnits },
231 { aSVGStrMarkerWidth, SVGTokenMarkerWidth },
232 { aSVGStrMarkerHeight, SVGTokenMarkerHeight },
233 { aSVGStrOrient, SVGTokenOrient },
234 { aSVGStrPattern, SVGTokenPattern },
235 { aSVGStrPatternUnits, SVGTokenPatternUnits },
236 { aSVGStrPatternContentUnits, SVGTokenPatternContentUnits },
237 { aSVGStrPatternTransform, SVGTokenPatternTransform },
238 { aSVGStrOpacity, SVGTokenOpacity },
239 { aSVGStrVisibility, SVGTokenVisibility },
240 { aSVGStrTitle, SVGTokenTitle },
241 { aSVGStrDesc, SVGTokenDesc },
243 { aSVGStrPreserveAspectRatio, SVGTokenPreserveAspectRatio },
244 { aSVGStrDefer, SVGTokenDefer },
245 { aSVGStrNone, SVGTokenNone },
246 { aSVGStrXMinYMin, SVGTokenXMinYMin },
247 { aSVGStrXMidYMin, SVGTokenXMidYMin },
248 { aSVGStrXMaxYMin, SVGTokenXMaxYMin },
249 { aSVGStrXMinYMid, SVGTokenXMinYMid },
250 { aSVGStrXMidYMid, SVGTokenXMidYMid },
251 { aSVGStrXMaxYMid, SVGTokenXMaxYMid },
252 { aSVGStrXMinYMax, SVGTokenXMinYMax },
253 { aSVGStrXMidYMax, SVGTokenXMidYMax },
254 { aSVGStrXMaxYMax, SVGTokenXMaxYMax },
255 { aSVGStrMeet, SVGTokenMeet },
256 { aSVGStrSlice, SVGTokenSlice },
258 { aSVGStrDefs, SVGTokenDefs },
259 { aSVGStrG, SVGTokenG },
260 { aSVGStrSvg, SVGTokenSvg },
261 { aSVGStrSymbol, SVGTokenSymbol },
262 { aSVGStrUse, SVGTokenUse },
263 { aSVGStrA, SVGTokenA },
265 { aSVGStrCircle, SVGTokenCircle },
266 { aSVGStrEllipse, SVGTokenEllipse },
267 { aSVGStrLine, SVGTokenLine },
268 { aSVGStrPath, SVGTokenPath },
269 { aSVGStrPolygon, SVGTokenPolygon },
270 { aSVGStrPolyline, SVGTokenPolyline },
271 { aSVGStrRect, SVGTokenRect },
272 { aSVGStrImage, SVGTokenImage },
274 { aSVGStrLinearGradient, SVGTokenLinearGradient },
275 { aSVGStrRadialGradient, SVGTokenRadialGradient },
276 { aSVGStrStop, SVGTokenStop },
277 { aSVGStrOffset, SVGTokenOffset },
278 { aSVGStrX1, SVGTokenX1 },
279 { aSVGStrY1, SVGTokenY1 },
280 { aSVGStrX2, SVGTokenX2 },
281 { aSVGStrY2, SVGTokenY2 },
282 { aSVGStrCx, SVGTokenCx },
283 { aSVGStrCy, SVGTokenCy },
284 { aSVGStrFx, SVGTokenFx },
285 { aSVGStrFy, SVGTokenFy },
286 { aSVGStrR, SVGTokenR },
287 { aSVGStrGradientUnits, SVGTokenGradientUnits },
288 { aSVGStrGradientTransform, SVGTokenGradientTransform },
289 { aSVGStrSpreadMethod, SVGTokenSpreadMethod },
290 { aSVGStrXlinkHref, SVGTokenXlinkHref },
291 { aSVGStrStopColor, SVGTokenStopColor },
292 { aSVGStrStopOpacity, SVGTokenStopOpacity },
294 { aSVGStrFill, SVGTokenFill },
295 { aSVGStrFillOpacity, SVGTokenFillOpacity },
296 { aSVGStrFillRule, SVGTokenFillRule },
298 { aSVGStrStroke, SVGTokenStroke },
299 { aSVGStrStrokeDasharray, SVGTokenStrokeDasharray },
300 { aSVGStrStrokeDashoffset, SVGTokenStrokeDashoffset },
301 { aSVGStrStrokeLinecap, SVGTokenStrokeLinecap },
302 { aSVGStrStrokeLinejoin, SVGTokenStrokeLinejoin },
303 { aSVGStrStrokeMiterlimit, SVGTokenStrokeMiterlimit },
304 { aSVGStrStrokeOpacity, SVGTokenStrokeOpacity },
305 { aSVGStrStrokeWidth, SVGTokenStrokeWidth },
307 { aSVGStrText, SVGTokenText },
308 { aSVGStrBaselineShift, SVGTokenBaselineShift },
309 { aSVGStrFlowRoot, SVGTokenFlowRoot }
312 const SVGTokenMapper::const_iterator aResult(aSVGTokenMapperList.find(rStr.startsWith("svg:") ? rStr.copy(4) : rStr));
314 if(aResult == aSVGTokenMapperList.end())
316 if(bCaseIndependent)
318 static SVGTokenMapper aCaseLindependentSVGTokenMapperList;
320 if(aCaseLindependentSVGTokenMapperList.empty())
322 for(const auto& rCurrent : aSVGTokenMapperList)
324 aCaseLindependentSVGTokenMapperList.insert(
325 SVGTokenValueType(
326 rCurrent.first.toAsciiLowerCase(),
327 rCurrent.second));
331 const SVGTokenMapper::const_iterator aResult2(aCaseLindependentSVGTokenMapperList.find(rStr.toAsciiLowerCase()));
333 if(aResult2 == aCaseLindependentSVGTokenMapperList.end())
335 return SVGTokenUnknown;
337 else
339 return aResult2->second;
343 return SVGTokenUnknown;
345 else
347 return aResult->second;
351 OUString getStrTitle()
353 return aSVGStrTitle;
356 OUString getStrDesc()
358 return aSVGStrDesc;
360 } // end of namespace svgio
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */