1#[allow(missing_docs)]
9#[derive(Clone, Copy, PartialEq)]
10pub enum EId {
11 A,
12 Circle,
13 ClipPath,
14 Defs,
15 Ellipse,
16 FeBlend,
17 FeColorMatrix,
18 FeComponentTransfer,
19 FeComposite,
20 FeConvolveMatrix,
21 FeDiffuseLighting,
22 FeDisplacementMap,
23 FeDistantLight,
24 FeDropShadow,
25 FeFlood,
26 FeFuncA,
27 FeFuncB,
28 FeFuncG,
29 FeFuncR,
30 FeGaussianBlur,
31 FeImage,
32 FeMerge,
33 FeMergeNode,
34 FeMorphology,
35 FeOffset,
36 FePointLight,
37 FeSpecularLighting,
38 FeSpotLight,
39 FeTile,
40 FeTurbulence,
41 Filter,
42 G,
43 Image,
44 Line,
45 LinearGradient,
46 Marker,
47 Mask,
48 Path,
49 Pattern,
50 Polygon,
51 Polyline,
52 RadialGradient,
53 Rect,
54 Stop,
55 Style,
56 Svg,
57 Switch,
58 Symbol,
59 Text,
60 TextPath,
61 Tref,
62 Tspan,
63 Use
64}
65
66static ELEMENTS: Map<EId> = Map {
67 key: 732231254413039614,
68 disps: &[
69 (0, 12),
70 (1, 11),
71 (10, 26),
72 (2, 42),
73 (1, 19),
74 (0, 5),
75 (1, 13),
76 (8, 50),
77 (0, 0),
78 (1, 0),
79 (7, 45),
80 ],
81 entries: &[
82 ("feFlood", EId::FeFlood),
83 ("radialGradient", EId::RadialGradient),
84 ("feImage", EId::FeImage),
85 ("stop", EId::Stop),
86 ("fePointLight", EId::FePointLight),
87 ("feConvolveMatrix", EId::FeConvolveMatrix),
88 ("feComposite", EId::FeComposite),
89 ("clipPath", EId::ClipPath),
90 ("feMerge", EId::FeMerge),
91 ("defs", EId::Defs),
92 ("mask", EId::Mask),
93 ("svg", EId::Svg),
94 ("symbol", EId::Symbol),
95 ("linearGradient", EId::LinearGradient),
96 ("feSpecularLighting", EId::FeSpecularLighting),
97 ("feFuncB", EId::FeFuncB),
98 ("filter", EId::Filter),
99 ("feFuncG", EId::FeFuncG),
100 ("circle", EId::Circle),
101 ("g", EId::G),
102 ("tref", EId::Tref),
103 ("feFuncA", EId::FeFuncA),
104 ("image", EId::Image),
105 ("text", EId::Text),
106 ("line", EId::Line),
107 ("pattern", EId::Pattern),
108 ("use", EId::Use),
109 ("feDropShadow", EId::FeDropShadow),
110 ("feSpotLight", EId::FeSpotLight),
111 ("marker", EId::Marker),
112 ("style", EId::Style),
113 ("switch", EId::Switch),
114 ("tspan", EId::Tspan),
115 ("feColorMatrix", EId::FeColorMatrix),
116 ("feOffset", EId::FeOffset),
117 ("path", EId::Path),
118 ("feGaussianBlur", EId::FeGaussianBlur),
119 ("feTile", EId::FeTile),
120 ("feTurbulence", EId::FeTurbulence),
121 ("feMergeNode", EId::FeMergeNode),
122 ("feMorphology", EId::FeMorphology),
123 ("a", EId::A),
124 ("textPath", EId::TextPath),
125 ("ellipse", EId::Ellipse),
126 ("feComponentTransfer", EId::FeComponentTransfer),
127 ("feDistantLight", EId::FeDistantLight),
128 ("polyline", EId::Polyline),
129 ("polygon", EId::Polygon),
130 ("feBlend", EId::FeBlend),
131 ("feDisplacementMap", EId::FeDisplacementMap),
132 ("feDiffuseLighting", EId::FeDiffuseLighting),
133 ("rect", EId::Rect),
134 ("feFuncR", EId::FeFuncR),
135 ],
136};
137
138impl EId {
139 pub(crate) fn from_str(text: &str) -> Option<EId> {
140 ELEMENTS.get(text).cloned()
141 }
142
143 #[inline(never)]
145 pub fn to_str(self) -> &'static str {
146 ELEMENTS.key(&self)
147 }
148}
149
150impl std::fmt::Debug for EId {
151 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
152 write!(f, "{}", self.to_str())
153 }
154}
155
156impl std::fmt::Display for EId {
157 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
158 write!(f, "{:?}", self)
159 }
160}
161
162#[allow(missing_docs)]
164#[derive(Clone, Copy, PartialEq)]
165pub enum AId {
166 AlignmentBaseline,
167 Amplitude,
168 Azimuth,
169 BackgroundColor,
170 BaseFrequency,
171 BaselineShift,
172 Bias,
173 Class,
174 Clip,
175 ClipPath,
176 ClipRule,
177 ClipPathUnits,
178 Color,
179 ColorInterpolation,
180 ColorInterpolationFilters,
181 ColorProfile,
182 ColorRendering,
183 Cx,
184 Cy,
185 D,
186 DiffuseConstant,
187 Direction,
188 Display,
189 Divisor,
190 DominantBaseline,
191 Dx,
192 Dy,
193 EdgeMode,
194 Elevation,
195 EnableBackground,
196 Exponent,
197 Fill,
198 FillOpacity,
199 FillRule,
200 Filter,
201 FilterUnits,
202 FloodColor,
203 FloodOpacity,
204 Font,
205 FontFamily,
206 FontFeatureSettings,
207 FontKerning,
208 FontOpticalSizing,
209 FontSize,
210 FontSizeAdjust,
211 FontStretch,
212 FontStyle,
213 FontSynthesis,
214 FontVariant,
215 FontVariantCaps,
216 FontVariantEastAsian,
217 FontVariantLigatures,
218 FontVariantNumeric,
219 FontVariantPosition,
220 FontVariationSettings,
221 FontWeight,
222 Fr,
223 Fx,
224 Fy,
225 GlyphOrientationHorizontal,
226 GlyphOrientationVertical,
227 GradientTransform,
228 GradientUnits,
229 Height,
230 Href,
231 Id,
232 ImageRendering,
233 In,
234 In2,
235 InlineSize,
236 Intercept,
237 Isolation,
238 K1,
239 K2,
240 K3,
241 K4,
242 KernelMatrix,
243 KernelUnitLength,
244 Kerning,
245 LengthAdjust,
246 LetterSpacing,
247 LightingColor,
248 LimitingConeAngle,
249 LineHeight,
250 MarkerEnd,
251 MarkerMid,
252 MarkerStart,
253 MarkerHeight,
254 MarkerUnits,
255 MarkerWidth,
256 Mask,
257 MaskBorder,
258 MaskBorderMode,
259 MaskBorderOutset,
260 MaskBorderRepeat,
261 MaskBorderSlice,
262 MaskBorderSource,
263 MaskBorderWidth,
264 MaskClip,
265 MaskComposite,
266 MaskImage,
267 MaskMode,
268 MaskOrigin,
269 MaskPosition,
270 MaskSize,
271 MaskType,
272 MaskContentUnits,
273 MaskUnits,
274 MixBlendMode,
275 Mode,
276 NumOctaves,
277 Offset,
278 Opacity,
279 Operator,
280 Order,
281 Orient,
282 Overflow,
283 PaintOrder,
284 Path,
285 PathLength,
286 PatternContentUnits,
287 PatternTransform,
288 PatternUnits,
289 Points,
290 PointsAtX,
291 PointsAtY,
292 PointsAtZ,
293 PreserveAlpha,
294 PreserveAspectRatio,
295 PrimitiveUnits,
296 R,
297 Radius,
298 RefX,
299 RefY,
300 RequiredExtensions,
301 RequiredFeatures,
302 Result,
303 Rotate,
304 Rx,
305 Ry,
306 Scale,
307 Seed,
308 ShapeImageThreshold,
309 ShapeInside,
310 ShapeMargin,
311 ShapePadding,
312 ShapeRendering,
313 ShapeSubtract,
314 Side,
315 Slope,
316 Space,
317 SpecularConstant,
318 SpecularExponent,
319 SpreadMethod,
320 StartOffset,
321 StdDeviation,
322 StitchTiles,
323 StopColor,
324 StopOpacity,
325 Stroke,
326 StrokeDasharray,
327 StrokeDashoffset,
328 StrokeLinecap,
329 StrokeLinejoin,
330 StrokeMiterlimit,
331 StrokeOpacity,
332 StrokeWidth,
333 Style,
334 SurfaceScale,
335 SystemLanguage,
336 TableValues,
337 TargetX,
338 TargetY,
339 TextAlign,
340 TextAlignLast,
341 TextAnchor,
342 TextDecoration,
343 TextDecorationColor,
344 TextDecorationFill,
345 TextDecorationLine,
346 TextDecorationStroke,
347 TextDecorationStyle,
348 TextIndent,
349 TextOrientation,
350 TextOverflow,
351 TextRendering,
352 TextUnderlinePosition,
353 TextLength,
354 Transform,
355 TransformBox,
356 TransformOrigin,
357 Type,
358 UnicodeBidi,
359 UnicodeRange,
360 Values,
361 VectorEffect,
362 ViewBox,
363 Visibility,
364 WhiteSpace,
365 Width,
366 WordSpacing,
367 WritingMode,
368 X,
369 X1,
370 X2,
371 XChannelSelector,
372 Y,
373 Y1,
374 Y2,
375 YChannelSelector,
376 Z
377}
378
379static ATTRIBUTES: Map<AId> = Map {
380 key: 3213172566270843353,
381 disps: &[
382 (0, 63),
383 (4, 146),
384 (0, 0),
385 (3, 42),
386 (2, 197),
387 (0, 0),
388 (0, 1),
389 (0, 0),
390 (0, 0),
391 (0, 18),
392 (0, 11),
393 (1, 20),
394 (0, 8),
395 (17, 110),
396 (1, 112),
397 (1, 108),
398 (5, 94),
399 (2, 128),
400 (4, 95),
401 (0, 63),
402 (0, 96),
403 (0, 0),
404 (1, 110),
405 (0, 1),
406 (40, 30),
407 (17, 157),
408 (0, 61),
409 (0, 16),
410 (7, 16),
411 (0, 80),
412 (0, 107),
413 (6, 111),
414 (0, 153),
415 (6, 202),
416 (18, 86),
417 (0, 194),
418 (0, 0),
419 (0, 7),
420 (0, 69),
421 (0, 5),
422 (0, 19),
423 (0, 0),
424 (4, 65),
425 ],
426 entries: &[
427 ("alignment-baseline", AId::AlignmentBaseline),
428 ("fx", AId::Fx),
429 ("targetY", AId::TargetY),
430 ("clip-path", AId::ClipPath),
431 ("lengthAdjust", AId::LengthAdjust),
432 ("mask-size", AId::MaskSize),
433 ("unicode-bidi", AId::UnicodeBidi),
434 ("z", AId::Z),
435 ("font-variant-numeric", AId::FontVariantNumeric),
436 ("clip-rule", AId::ClipRule),
437 ("font", AId::Font),
438 ("gradientUnits", AId::GradientUnits),
439 ("style", AId::Style),
440 ("font-stretch", AId::FontStretch),
441 ("intercept", AId::Intercept),
442 ("mask-border-slice", AId::MaskBorderSlice),
443 ("y", AId::Y),
444 ("xChannelSelector", AId::XChannelSelector),
445 ("numOctaves", AId::NumOctaves),
446 ("x1", AId::X1),
447 ("fill-rule", AId::FillRule),
448 ("image-rendering", AId::ImageRendering),
449 ("surfaceScale", AId::SurfaceScale),
450 ("seed", AId::Seed),
451 ("mix-blend-mode", AId::MixBlendMode),
452 ("path", AId::Path),
453 ("mask-border-repeat", AId::MaskBorderRepeat),
454 ("transform", AId::Transform),
455 ("stroke", AId::Stroke),
456 ("refX", AId::RefX),
457 ("text-orientation", AId::TextOrientation),
458 ("line-height", AId::LineHeight),
459 ("display", AId::Display),
460 ("kerning", AId::Kerning),
461 ("transform-origin", AId::TransformOrigin),
462 ("shape-subtract", AId::ShapeSubtract),
463 ("width", AId::Width),
464 ("stroke-miterlimit", AId::StrokeMiterlimit),
465 ("dy", AId::Dy),
466 ("text-decoration-color", AId::TextDecorationColor),
467 ("white-space", AId::WhiteSpace),
468 ("diffuseConstant", AId::DiffuseConstant),
469 ("text-decoration-stroke", AId::TextDecorationStroke),
470 ("values", AId::Values),
471 ("font-size", AId::FontSize),
472 ("shape-image-threshold", AId::ShapeImageThreshold),
473 ("href", AId::Href),
474 ("cy", AId::Cy),
475 ("mask-image", AId::MaskImage),
476 ("unicode-range", AId::UnicodeRange),
477 ("specularConstant", AId::SpecularConstant),
478 ("baseline-shift", AId::BaselineShift),
479 ("k3", AId::K3),
480 ("text-anchor", AId::TextAnchor),
481 ("mask-border-mode", AId::MaskBorderMode),
482 ("requiredFeatures", AId::RequiredFeatures),
483 ("color-rendering", AId::ColorRendering),
484 ("amplitude", AId::Amplitude),
485 ("mask-border-width", AId::MaskBorderWidth),
486 ("stroke-linecap", AId::StrokeLinecap),
487 ("paint-order", AId::PaintOrder),
488 ("lighting-color", AId::LightingColor),
489 ("dx", AId::Dx),
490 ("markerWidth", AId::MarkerWidth),
491 ("scale", AId::Scale),
492 ("id", AId::Id),
493 ("color", AId::Color),
494 ("in2", AId::In2),
495 ("targetX", AId::TargetX),
496 ("direction", AId::Direction),
497 ("pointsAtX", AId::PointsAtX),
498 ("stitchTiles", AId::StitchTiles),
499 ("patternUnits", AId::PatternUnits),
500 ("shape-padding", AId::ShapePadding),
501 ("k2", AId::K2),
502 ("font-optical-sizing", AId::FontOpticalSizing),
503 ("k4", AId::K4),
504 ("vector-effect", AId::VectorEffect),
505 ("mask-composite", AId::MaskComposite),
506 ("stroke-width", AId::StrokeWidth),
507 ("font-variation-settings", AId::FontVariationSettings),
508 ("mask-border-outset", AId::MaskBorderOutset),
509 ("in", AId::In),
510 ("stroke-linejoin", AId::StrokeLinejoin),
511 ("stop-opacity", AId::StopOpacity),
512 ("inline-size", AId::InlineSize),
513 ("mask-type", AId::MaskType),
514 ("filterUnits", AId::FilterUnits),
515 ("color-profile", AId::ColorProfile),
516 ("space", AId::Space),
517 ("text-decoration-fill", AId::TextDecorationFill),
518 ("font-kerning", AId::FontKerning),
519 ("offset", AId::Offset),
520 ("pointsAtZ", AId::PointsAtZ),
521 ("text-align", AId::TextAlign),
522 ("clip", AId::Clip),
523 ("y1", AId::Y1),
524 ("mask-origin", AId::MaskOrigin),
525 ("mask-mode", AId::MaskMode),
526 ("yChannelSelector", AId::YChannelSelector),
527 ("font-variant-caps", AId::FontVariantCaps),
528 ("marker-mid", AId::MarkerMid),
529 ("shape-rendering", AId::ShapeRendering),
530 ("text-rendering", AId::TextRendering),
531 ("fill-opacity", AId::FillOpacity),
532 ("word-spacing", AId::WordSpacing),
533 ("fill", AId::Fill),
534 ("mask-clip", AId::MaskClip),
535 ("font-feature-settings", AId::FontFeatureSettings),
536 ("radius", AId::Radius),
537 ("kernelMatrix", AId::KernelMatrix),
538 ("kernelUnitLength", AId::KernelUnitLength),
539 ("mask-border-source", AId::MaskBorderSource),
540 ("k1", AId::K1),
541 ("mask", AId::Mask),
542 ("opacity", AId::Opacity),
543 ("markerUnits", AId::MarkerUnits),
544 ("visibility", AId::Visibility),
545 ("spreadMethod", AId::SpreadMethod),
546 ("pointsAtY", AId::PointsAtY),
547 ("d", AId::D),
548 ("slope", AId::Slope),
549 ("side", AId::Side),
550 ("tableValues", AId::TableValues),
551 ("order", AId::Order),
552 ("text-align-last", AId::TextAlignLast),
553 ("font-size-adjust", AId::FontSizeAdjust),
554 ("rotate", AId::Rotate),
555 ("shape-margin", AId::ShapeMargin),
556 ("limitingConeAngle", AId::LimitingConeAngle),
557 ("font-weight", AId::FontWeight),
558 ("text-decoration-line", AId::TextDecorationLine),
559 ("stop-color", AId::StopColor),
560 ("requiredExtensions", AId::RequiredExtensions),
561 ("enable-background", AId::EnableBackground),
562 ("systemLanguage", AId::SystemLanguage),
563 ("clipPathUnits", AId::ClipPathUnits),
564 ("stroke-dashoffset", AId::StrokeDashoffset),
565 ("ry", AId::Ry),
566 ("overflow", AId::Overflow),
567 ("class", AId::Class),
568 ("mask-border", AId::MaskBorder),
569 ("specularExponent", AId::SpecularExponent),
570 ("text-decoration", AId::TextDecoration),
571 ("startOffset", AId::StartOffset),
572 ("stroke-dasharray", AId::StrokeDasharray),
573 ("fr", AId::Fr),
574 ("mask-position", AId::MaskPosition),
575 ("writing-mode", AId::WritingMode),
576 ("font-synthesis", AId::FontSynthesis),
577 ("isolation", AId::Isolation),
578 ("rx", AId::Rx),
579 ("bias", AId::Bias),
580 ("markerHeight", AId::MarkerHeight),
581 ("edgeMode", AId::EdgeMode),
582 ("r", AId::R),
583 ("stroke-opacity", AId::StrokeOpacity),
584 ("maskContentUnits", AId::MaskContentUnits),
585 ("height", AId::Height),
586 ("font-variant-position", AId::FontVariantPosition),
587 ("operator", AId::Operator),
588 ("font-family", AId::FontFamily),
589 ("fy", AId::Fy),
590 ("dominant-baseline", AId::DominantBaseline),
591 ("y2", AId::Y2),
592 ("shape-inside", AId::ShapeInside),
593 ("letter-spacing", AId::LetterSpacing),
594 ("azimuth", AId::Azimuth),
595 ("stdDeviation", AId::StdDeviation),
596 ("flood-color", AId::FloodColor),
597 ("flood-opacity", AId::FloodOpacity),
598 ("type", AId::Type),
599 ("font-variant-east-asian", AId::FontVariantEastAsian),
600 ("points", AId::Points),
601 ("refY", AId::RefY),
602 ("text-underline-position", AId::TextUnderlinePosition),
603 ("patternContentUnits", AId::PatternContentUnits),
604 ("baseFrequency", AId::BaseFrequency),
605 ("color-interpolation", AId::ColorInterpolation),
606 ("font-variant-ligatures", AId::FontVariantLigatures),
607 ("font-style", AId::FontStyle),
608 ("filter", AId::Filter),
609 ("text-decoration-style", AId::TextDecorationStyle),
610 ("preserveAlpha", AId::PreserveAlpha),
611 ("mode", AId::Mode),
612 ("divisor", AId::Divisor),
613 ("cx", AId::Cx),
614 ("patternTransform", AId::PatternTransform),
615 ("background-color", AId::BackgroundColor),
616 ("preserveAspectRatio", AId::PreserveAspectRatio),
617 ("gradientTransform", AId::GradientTransform),
618 ("x2", AId::X2),
619 ("pathLength", AId::PathLength),
620 ("marker-start", AId::MarkerStart),
621 ("glyph-orientation-horizontal", AId::GlyphOrientationHorizontal),
622 ("maskUnits", AId::MaskUnits),
623 ("textLength", AId::TextLength),
624 ("viewBox", AId::ViewBox),
625 ("text-overflow", AId::TextOverflow),
626 ("glyph-orientation-vertical", AId::GlyphOrientationVertical),
627 ("result", AId::Result),
628 ("primitiveUnits", AId::PrimitiveUnits),
629 ("exponent", AId::Exponent),
630 ("x", AId::X),
631 ("font-variant", AId::FontVariant),
632 ("elevation", AId::Elevation),
633 ("color-interpolation-filters", AId::ColorInterpolationFilters),
634 ("text-indent", AId::TextIndent),
635 ("marker-end", AId::MarkerEnd),
636 ("transform-box", AId::TransformBox),
637 ("orient", AId::Orient),
638 ],
639};
640
641impl AId {
642 pub(crate) fn from_str(text: &str) -> Option<AId> {
643 ATTRIBUTES.get(text).cloned()
644 }
645
646 #[inline(never)]
648 pub fn to_str(self) -> &'static str {
649 ATTRIBUTES.key(&self)
650 }
651}
652
653impl std::fmt::Debug for AId {
654 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
655 write!(f, "{}", self.to_str())
656 }
657}
658
659impl std::fmt::Display for AId {
660 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
661 write!(f, "{:?}", self)
662 }
663}
664
665struct Map<V: 'static> {
670 pub key: u64,
671 pub disps: &'static [(u32, u32)],
672 pub entries: &'static [(&'static str, V)],
673}
674
675impl<V: PartialEq> Map<V> {
676 fn get(&self, key: &str) -> Option<&V> {
677 let hash = hash(key, self.key);
678 let index = get_index(hash, self.disps, self.entries.len());
679 let entry = &self.entries[index as usize];
680 let b = entry.0;
681 if b == key {
682 Some(&entry.1)
683 } else {
684 None
685 }
686 }
687
688 fn key(&self, value: &V) -> &'static str {
689 self.entries.iter().find(|kv| kv.1 == *value).unwrap().0
690 }
691}
692
693#[inline]
694fn hash(x: &str, key: u64) -> u64 {
695 use std::hash::Hasher;
696
697 let mut hasher = siphasher::sip::SipHasher13::new_with_keys(0, key);
698 hasher.write(x.as_bytes());
699 hasher.finish()
700}
701
702#[inline]
703fn get_index(hash: u64, disps: &[(u32, u32)], len: usize) -> u32 {
704 let (g, f1, f2) = split(hash);
705 let (d1, d2) = disps[(g % (disps.len() as u32)) as usize];
706 displace(f1, f2, d1, d2) % (len as u32)
707}
708
709#[inline]
710fn split(hash: u64) -> (u32, u32, u32) {
711 const BITS: u32 = 21;
712 const MASK: u64 = (1 << BITS) - 1;
713
714 ((hash & MASK) as u32,
715 ((hash >> BITS) & MASK) as u32,
716 ((hash >> (2 * BITS)) & MASK) as u32)
717}
718
719#[inline]
720fn displace(f1: u32, f2: u32, d1: u32, d2: u32) -> u32 {
721 d2 + f1 * d1 + f2
722}