tdf#159660: Add support for feMerge and feMergeNode
[libreoffice.git] / svgio / source / svgreader / svgtoken.cxx
blob3a1f2eb3e2513bc61bb20fe4ee2f533fb93dd56c
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 <frozen/bits/defines.h>
22 #include <frozen/bits/elsa_std.h>
23 #include <frozen/unordered_map.h>
24 #include <o3tl/string_view.hxx>
26 namespace svgio::svgreader
29 constexpr auto aSVGTokenMap = frozen::make_unordered_map<std::u16string_view, SVGToken>(
31 { u"width", SVGToken::Width },
32 { u"height", SVGToken::Height },
33 { u"viewBox", SVGToken::ViewBox },
34 { u"transform", SVGToken::Transform },
35 { u"style", SVGToken::Style },
36 { u"display", SVGToken::Display }, // #i121656#
37 { u"d", SVGToken::D },
38 { u"x", SVGToken::X },
39 { u"y", SVGToken::Y },
40 { u"xmlns", SVGToken::Xmlns },
41 { u"version", SVGToken::Version },
42 { u"id", SVGToken::Id },
43 { u"in", SVGToken::In },
44 { u"result", SVGToken::Result },
45 { u"rx", SVGToken::Rx },
46 { u"ry", SVGToken::Ry },
47 { u"points", SVGToken::Points },
48 { u"dx", SVGToken::Dx },
49 { u"dy", SVGToken::Dy },
50 { u"rotate", SVGToken::Rotate },
51 { u"textLength", SVGToken::TextLength },
52 { u"lengthAdjust", SVGToken::LengthAdjust },
53 { u"font", SVGToken::Font },
54 { u"font-family", SVGToken::FontFamily },
55 { u"font-size", SVGToken::FontSize },
56 { u"font-size-adjust", SVGToken::FontSizeAdjust },
57 { u"font-stretch", SVGToken::FontStretch },
58 { u"font-style", SVGToken::FontStyle },
59 { u"font-variant", SVGToken::FontVariant },
60 { u"font-weight", SVGToken::FontWeight },
61 { u"direction", SVGToken::Direction },
62 { u"letter-spacing", SVGToken::LetterSpacing },
63 { u"text-decoration", SVGToken::TextDecoration },
64 { u"unicode-bidi", SVGToken::UnicodeBidi },
65 { u"word-spacing", SVGToken::WordSpacing },
66 { u"tspan", SVGToken::Tspan },
67 { u"tref", SVGToken::Tref },
68 { u"textPath", SVGToken::TextPath },
69 { u"startOffset", SVGToken::StartOffset },
70 { u"method", SVGToken::Method },
71 { u"spacing", SVGToken::Spacing },
72 { u"stdDeviation", SVGToken::StdDeviation },
73 { u"text-align", SVGToken::TextAlign },
74 { u"pathLength", SVGToken::PathLength },
75 { u"type", SVGToken::Type },
76 { u"class", SVGToken::Class },
77 { u"text-anchor", SVGToken::TextAnchor },
78 { u"xml:space", SVGToken::XmlSpace },
79 { u"color", SVGToken::Color },
80 { u"clipPath", SVGToken::ClipPathNode },
81 { u"clip-path", SVGToken::ClipPathProperty },
82 { u"feColorMatrix", SVGToken::FeColorMatrix },
83 { u"feDropShadow", SVGToken::FeDropShadow },
84 { u"feFlood", SVGToken::FeFlood },
85 { u"feImage", SVGToken::FeImage },
86 { u"feGaussianBlur", SVGToken::FeGaussianBlur },
87 { u"feMerge", SVGToken::FeMerge },
88 { u"feMergeNode", SVGToken::FeMergeNode },
89 { u"feOffset", SVGToken::FeOffset },
90 { u"filter", SVGToken::Filter },
91 { u"flood-color", SVGToken::FloodColor },
92 { u"flood-opacity", SVGToken::FloodOpacity },
93 { u"mask", SVGToken::Mask },
94 { u"clipPathUnits", SVGToken::ClipPathUnits },
95 { u"maskUnits", SVGToken::MaskUnits },
96 { u"maskContentUnits", SVGToken::MaskContentUnits },
97 { u"clip-rule", SVGToken::ClipRule },
98 { u"marker", SVGToken::Marker },
99 { u"marker-start", SVGToken::MarkerStart },
100 { u"marker-mid", SVGToken::MarkerMid },
101 { u"marker-end", SVGToken::MarkerEnd },
102 { u"refX", SVGToken::RefX },
103 { u"refY", SVGToken::RefY },
104 { u"markerUnits", SVGToken::MarkerUnits },
105 { u"markerWidth", SVGToken::MarkerWidth },
106 { u"markerHeight", SVGToken::MarkerHeight },
107 { u"orient", SVGToken::Orient },
108 { u"pattern", SVGToken::Pattern },
109 { u"patternUnits", SVGToken::PatternUnits },
110 { u"patternContentUnits", SVGToken::PatternContentUnits },
111 { u"patternTransform", SVGToken::PatternTransform },
112 { u"opacity", SVGToken::Opacity },
113 { u"visibility", SVGToken::Visibility },
114 { u"title", SVGToken::Title },
115 { u"desc", SVGToken::Desc },
116 { u"overflow", SVGToken::Overflow },
117 { u"preserveAspectRatio", SVGToken::PreserveAspectRatio },
118 { u"defer", SVGToken::Defer },
119 { u"none", SVGToken::None },
120 { u"xMinYMin", SVGToken::XMinYMin },
121 { u"xMidYMin", SVGToken::XMidYMin },
122 { u"xMaxYMin", SVGToken::XMaxYMin },
123 { u"xMinYMid", SVGToken::XMinYMid },
124 { u"xMidYMid", SVGToken::XMidYMid },
125 { u"xMaxYMid", SVGToken::XMaxYMid },
126 { u"xMinYMax", SVGToken::XMinYMax },
127 { u"xMidYMax", SVGToken::XMidYMax },
128 { u"xMaxYMax", SVGToken::XMaxYMax },
129 { u"meet", SVGToken::Meet },
130 { u"slice", SVGToken::Slice },
131 { u"values", SVGToken::Values },
133 { u"defs", SVGToken::Defs },
134 { u"g", SVGToken::G },
135 { u"svg", SVGToken::Svg },
136 { u"symbol", SVGToken::Symbol },
137 { u"switch", SVGToken::Switch },
138 { u"use", SVGToken::Use },
139 { u"a", SVGToken::A },
141 { u"circle", SVGToken::Circle },
142 { u"ellipse", SVGToken::Ellipse },
143 { u"line", SVGToken::Line },
144 { u"path", SVGToken::Path },
145 { u"polygon", SVGToken::Polygon },
146 { u"polyline", SVGToken::Polyline },
147 { u"rect", SVGToken::Rect },
148 { u"image", SVGToken::Image },
150 { u"linearGradient", SVGToken::LinearGradient },
151 { u"radialGradient", SVGToken::RadialGradient },
152 { u"stop", SVGToken::Stop },
153 { u"offset", SVGToken::Offset },
154 { u"x1", SVGToken::X1 },
155 { u"y1", SVGToken::Y1 },
156 { u"x2", SVGToken::X2 },
157 { u"y2", SVGToken::Y2 },
158 { u"cx", SVGToken::Cx },
159 { u"cy", SVGToken::Cy },
160 { u"fx", SVGToken::Fx },
161 { u"fy", SVGToken::Fy },
162 { u"r", SVGToken::R },
163 { u"gradientUnits", SVGToken::GradientUnits },
164 { u"gradientTransform", SVGToken::GradientTransform },
165 { u"spreadMethod", SVGToken::SpreadMethod },
166 { u"href", SVGToken::Href },
167 { u"xlink:href", SVGToken::XlinkHref },
168 { u"stop-color", SVGToken::StopColor },
169 { u"stop-opacity", SVGToken::StopOpacity },
171 { u"fill", SVGToken::Fill },
172 { u"fill-opacity", SVGToken::FillOpacity },
173 { u"fill-rule", SVGToken::FillRule },
175 { u"stroke", SVGToken::Stroke },
176 { u"stroke-dasharray", SVGToken::StrokeDasharray },
177 { u"stroke-dashoffset", SVGToken::StrokeDashoffset },
178 { u"stroke-linecap", SVGToken::StrokeLinecap },
179 { u"stroke-linejoin", SVGToken::StrokeLinejoin },
180 { u"stroke-miterlimit", SVGToken::StrokeMiterlimit },
181 { u"stroke-opacity", SVGToken::StrokeOpacity },
182 { u"stroke-width", SVGToken::StrokeWidth },
184 { u"text", SVGToken::Text },
185 { u"baseline-shift", SVGToken::BaselineShift },
186 { u"dominant-baseline", SVGToken::DominantBaseline }
189 SVGToken StrToSVGToken(std::u16string_view rStr, bool bIgnoreCase)
191 std::u16string_view aStr = rStr.starts_with(u"svg:") ? rStr.substr(4) : rStr;
193 // TODO: a better alternative to the bIgnoreCase would be separate maps for SVG and CSS,
194 // the latter using case-insensitive hasher and comparator, with separate search functions.
196 auto it = bIgnoreCase ? std::find_if(aSVGTokenMap.begin(), aSVGTokenMap.end(),
197 [aStr](const auto& el)
198 { return o3tl::equalsIgnoreAsciiCase(el.first, aStr); })
199 : aSVGTokenMap.find(aStr);
200 if (it != aSVGTokenMap.end())
201 return it->second;
203 return SVGToken::Unknown;
206 OUString SVGTokenToStr(const SVGToken& rToken)
208 auto it = std::find_if(aSVGTokenMap.begin(), aSVGTokenMap.end(),
209 [rToken](const auto& el) { return el.second == rToken; });
210 if (it != aSVGTokenMap.end())
211 return OUString(it->first);
213 return OUString();
216 } // end of namespace svgio
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */