calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / svgio / source / svgreader / svgtoken.cxx
blob0b03e2c3f0cd890c7be29a2bfcf2247fbce9eb93
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 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 aSVGStrHref[] = "href";
145 const char aSVGStrXlinkHref[] = "xlink:href";
146 const char aSVGStrStopColor[] = "stop-color";
147 const char aSVGStrStopOpacity[] = "stop-opacity";
149 const char aSVGStrFill[] = "fill";
150 const char aSVGStrFillOpacity[] = "fill-opacity";
151 const char aSVGStrFillRule[] = "fill-rule";
153 const char aSVGStrStroke[] = "stroke";
154 const char aSVGStrStrokeDasharray[] = "stroke-dasharray";
155 const char aSVGStrStrokeDashoffset[] = "stroke-dashoffset";
156 const char aSVGStrStrokeLinecap[] = "stroke-linecap";
157 const char aSVGStrStrokeLinejoin[] = "stroke-linejoin";
158 const char aSVGStrStrokeMiterlimit[] = "stroke-miterlimit";
159 const char aSVGStrStrokeOpacity[] = "stroke-opacity";
160 const char aSVGStrStrokeWidth[] = "stroke-width";
162 const char aSVGStrText[] = "text";
163 const char aSVGStrBaselineShift[] = "baseline-shift";
165 const char aSVGStrFlowRoot[] = "flowRoot";
167 SVGToken StrToSVGToken(const OUString& rStr, bool bCaseIndependent)
169 typedef std::unordered_map< OUString, SVGToken > SVGTokenMapper;
170 typedef std::pair< OUString, SVGToken > SVGTokenValueType;
171 static SVGTokenMapper aSVGTokenMapperList {
172 { aSVGStrWidth, SVGToken::Width },
173 { aSVGStrHeight, SVGToken::Height },
174 { aSVGStrViewBox, SVGToken::ViewBox },
175 { aSVGStrTransform, SVGToken::Transform },
176 { aSVGStrStyle, SVGToken::Style },
177 { aSVGStrDisplay, SVGToken::Display }, // #i121656#
178 { aSVGStrD, SVGToken::D },
179 { aSVGStrX, SVGToken::X },
180 { aSVGStrY, SVGToken::Y },
181 { aSVGStrXmlns, SVGToken::Xmlns },
182 { aSVGStrVersion, SVGToken::Version },
183 { aSVGStrId, SVGToken::Id },
184 { aSVGStrRx, SVGToken::Rx },
185 { aSVGStrRy, SVGToken::Ry },
186 { aSVGStrPoints, SVGToken::Points },
187 { aSVGStrDx, SVGToken::Dx },
188 { aSVGStrDy, SVGToken::Dy },
189 { aSVGStrRotate, SVGToken::Rotate },
190 { aSVGStrTextLength, SVGToken::TextLength },
191 { aSVGStrLengthAdjust, SVGToken::LengthAdjust },
192 { aSVGStrFont, SVGToken::Font },
193 { aSVGStrFontFamily, SVGToken::FontFamily },
194 { aSVGStrFontSize, SVGToken::FontSize },
195 { aSVGStrFontSizeAdjust, SVGToken::FontSizeAdjust },
196 { aSVGStrFontStretch, SVGToken::FontStretch },
197 { aSVGStrFontStyle, SVGToken::FontStyle },
198 { aSVGStrFontVariant, SVGToken::FontVariant },
199 { aSVGStrFontWeight, SVGToken::FontWeight },
200 { aSVGStrDirection, SVGToken::Direction },
201 { aSVGStrLetterSpacing, SVGToken::LetterSpacing },
202 { aSVGStrTextDecoration, SVGToken::TextDecoration },
203 { aSVGStrUnicodeBidi, SVGToken::UnicodeBidi },
204 { aSVGStrWordSpacing, SVGToken::WordSpacing },
205 { aSVGStrTspan, SVGToken::Tspan },
206 { aSVGStrTref, SVGToken::Tref },
207 { aSVGStrTextPath, SVGToken::TextPath },
208 { aSVGStrStartOffset, SVGToken::StartOffset },
209 { aSVGStrMethod, SVGToken::Method },
210 { aSVGStrSpacing, SVGToken::Spacing },
211 { aSVGStrTextAlign, SVGToken::TextAlign },
212 { aSVGStrPathLength, SVGToken::PathLength },
213 { aSVGStrType, SVGToken::Type },
214 { aSVGStrClass, SVGToken::Class },
215 { aSVGStrTextAnchor, SVGToken::TextAnchor },
216 { aSVGStrXmlSpace, SVGToken::XmlSpace },
217 { aSVGStrColor, SVGToken::Color },
218 { aSVGStrClipPathNode, SVGToken::ClipPathNode },
219 { aSVGStrClipPathProperty, SVGToken::ClipPathProperty },
220 { aSVGStrMask, SVGToken::Mask },
221 { aSVGStrClipPathUnits, SVGToken::ClipPathUnits },
222 { aSVGStrMaskUnits, SVGToken::MaskUnits },
223 { aSVGStrMaskContentUnits, SVGToken::MaskContentUnits },
224 { aSVGStrClipRule, SVGToken::ClipRule },
225 { aSVGStrMarker, SVGToken::Marker },
226 { aSVGStrMarkerStart, SVGToken::MarkerStart },
227 { aSVGStrMarkerMid, SVGToken::MarkerMid },
228 { aSVGStrMarkerEnd, SVGToken::MarkerEnd },
229 { aSVGStrRefX, SVGToken::RefX },
230 { aSVGStrRefY, SVGToken::RefY },
231 { aSVGStrMarkerUnits, SVGToken::MarkerUnits },
232 { aSVGStrMarkerWidth, SVGToken::MarkerWidth },
233 { aSVGStrMarkerHeight, SVGToken::MarkerHeight },
234 { aSVGStrOrient, SVGToken::Orient },
235 { aSVGStrPattern, SVGToken::Pattern },
236 { aSVGStrPatternUnits, SVGToken::PatternUnits },
237 { aSVGStrPatternContentUnits, SVGToken::PatternContentUnits },
238 { aSVGStrPatternTransform, SVGToken::PatternTransform },
239 { aSVGStrOpacity, SVGToken::Opacity },
240 { aSVGStrVisibility, SVGToken::Visibility },
241 { aSVGStrTitle, SVGToken::Title },
242 { aSVGStrDesc, SVGToken::Desc },
244 { aSVGStrPreserveAspectRatio, SVGToken::PreserveAspectRatio },
245 { aSVGStrDefer, SVGToken::Defer },
246 { aSVGStrNone, SVGToken::None },
247 { aSVGStrXMinYMin, SVGToken::XMinYMin },
248 { aSVGStrXMidYMin, SVGToken::XMidYMin },
249 { aSVGStrXMaxYMin, SVGToken::XMaxYMin },
250 { aSVGStrXMinYMid, SVGToken::XMinYMid },
251 { aSVGStrXMidYMid, SVGToken::XMidYMid },
252 { aSVGStrXMaxYMid, SVGToken::XMaxYMid },
253 { aSVGStrXMinYMax, SVGToken::XMinYMax },
254 { aSVGStrXMidYMax, SVGToken::XMidYMax },
255 { aSVGStrXMaxYMax, SVGToken::XMaxYMax },
256 { aSVGStrMeet, SVGToken::Meet },
257 { aSVGStrSlice, SVGToken::Slice },
259 { aSVGStrDefs, SVGToken::Defs },
260 { aSVGStrG, SVGToken::G },
261 { aSVGStrSvg, SVGToken::Svg },
262 { aSVGStrSymbol, SVGToken::Symbol },
263 { aSVGStrUse, SVGToken::Use },
264 { aSVGStrA, SVGToken::A },
266 { aSVGStrCircle, SVGToken::Circle },
267 { aSVGStrEllipse, SVGToken::Ellipse },
268 { aSVGStrLine, SVGToken::Line },
269 { aSVGStrPath, SVGToken::Path },
270 { aSVGStrPolygon, SVGToken::Polygon },
271 { aSVGStrPolyline, SVGToken::Polyline },
272 { aSVGStrRect, SVGToken::Rect },
273 { aSVGStrImage, SVGToken::Image },
275 { aSVGStrLinearGradient, SVGToken::LinearGradient },
276 { aSVGStrRadialGradient, SVGToken::RadialGradient },
277 { aSVGStrStop, SVGToken::Stop },
278 { aSVGStrOffset, SVGToken::Offset },
279 { aSVGStrX1, SVGToken::X1 },
280 { aSVGStrY1, SVGToken::Y1 },
281 { aSVGStrX2, SVGToken::X2 },
282 { aSVGStrY2, SVGToken::Y2 },
283 { aSVGStrCx, SVGToken::Cx },
284 { aSVGStrCy, SVGToken::Cy },
285 { aSVGStrFx, SVGToken::Fx },
286 { aSVGStrFy, SVGToken::Fy },
287 { aSVGStrR, SVGToken::R },
288 { aSVGStrGradientUnits, SVGToken::GradientUnits },
289 { aSVGStrGradientTransform, SVGToken::GradientTransform },
290 { aSVGStrSpreadMethod, SVGToken::SpreadMethod },
291 { aSVGStrHref, SVGToken::Href },
292 { aSVGStrXlinkHref, SVGToken::XlinkHref },
293 { aSVGStrStopColor, SVGToken::StopColor },
294 { aSVGStrStopOpacity, SVGToken::StopOpacity },
296 { aSVGStrFill, SVGToken::Fill },
297 { aSVGStrFillOpacity, SVGToken::FillOpacity },
298 { aSVGStrFillRule, SVGToken::FillRule },
300 { aSVGStrStroke, SVGToken::Stroke },
301 { aSVGStrStrokeDasharray, SVGToken::StrokeDasharray },
302 { aSVGStrStrokeDashoffset, SVGToken::StrokeDashoffset },
303 { aSVGStrStrokeLinecap, SVGToken::StrokeLinecap },
304 { aSVGStrStrokeLinejoin, SVGToken::StrokeLinejoin },
305 { aSVGStrStrokeMiterlimit, SVGToken::StrokeMiterlimit },
306 { aSVGStrStrokeOpacity, SVGToken::StrokeOpacity },
307 { aSVGStrStrokeWidth, SVGToken::StrokeWidth },
309 { aSVGStrText, SVGToken::Text },
310 { aSVGStrBaselineShift, SVGToken::BaselineShift },
311 { aSVGStrFlowRoot, SVGToken::FlowRoot }
314 const SVGTokenMapper::const_iterator aResult(aSVGTokenMapperList.find(rStr.startsWith("svg:") ? rStr.copy(4) : rStr));
316 if(aResult == aSVGTokenMapperList.end())
318 if(bCaseIndependent)
320 static SVGTokenMapper aCaseLindependentSVGTokenMapperList;
322 if(aCaseLindependentSVGTokenMapperList.empty())
324 for(const auto& rCurrent : aSVGTokenMapperList)
326 aCaseLindependentSVGTokenMapperList.insert(
327 SVGTokenValueType(
328 rCurrent.first.toAsciiLowerCase(),
329 rCurrent.second));
333 const SVGTokenMapper::const_iterator aResult2(aCaseLindependentSVGTokenMapperList.find(rStr.toAsciiLowerCase()));
335 if(aResult2 == aCaseLindependentSVGTokenMapperList.end())
337 return SVGToken::Unknown;
339 else
341 return aResult2->second;
345 return SVGToken::Unknown;
347 else
349 return aResult->second;
353 OUString getStrTitle()
355 return aSVGStrTitle;
358 OUString getStrDesc()
360 return aSVGStrDesc;
362 } // end of namespace svgio
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */