usvg/parser/svgtree/
names.rs

1// Copyright 2019 the Resvg Authors
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4// This file is autogenerated. Do not edit it!
5// See ./codegen for details.
6
7/// An element ID.
8#[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    /// Returns the original string.
144    #[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/// An attribute ID.
163#[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    FontSize,
209    FontSizeAdjust,
210    FontStretch,
211    FontStyle,
212    FontSynthesis,
213    FontVariant,
214    FontVariantCaps,
215    FontVariantEastAsian,
216    FontVariantLigatures,
217    FontVariantNumeric,
218    FontVariantPosition,
219    FontWeight,
220    Fr,
221    Fx,
222    Fy,
223    GlyphOrientationHorizontal,
224    GlyphOrientationVertical,
225    GradientTransform,
226    GradientUnits,
227    Height,
228    Href,
229    Id,
230    ImageRendering,
231    In,
232    In2,
233    InlineSize,
234    Intercept,
235    Isolation,
236    K1,
237    K2,
238    K3,
239    K4,
240    KernelMatrix,
241    KernelUnitLength,
242    Kerning,
243    LengthAdjust,
244    LetterSpacing,
245    LightingColor,
246    LimitingConeAngle,
247    LineHeight,
248    MarkerEnd,
249    MarkerMid,
250    MarkerStart,
251    MarkerHeight,
252    MarkerUnits,
253    MarkerWidth,
254    Mask,
255    MaskBorder,
256    MaskBorderMode,
257    MaskBorderOutset,
258    MaskBorderRepeat,
259    MaskBorderSlice,
260    MaskBorderSource,
261    MaskBorderWidth,
262    MaskClip,
263    MaskComposite,
264    MaskImage,
265    MaskMode,
266    MaskOrigin,
267    MaskPosition,
268    MaskSize,
269    MaskType,
270    MaskContentUnits,
271    MaskUnits,
272    MixBlendMode,
273    Mode,
274    NumOctaves,
275    Offset,
276    Opacity,
277    Operator,
278    Order,
279    Orient,
280    Overflow,
281    PaintOrder,
282    Path,
283    PathLength,
284    PatternContentUnits,
285    PatternTransform,
286    PatternUnits,
287    Points,
288    PointsAtX,
289    PointsAtY,
290    PointsAtZ,
291    PreserveAlpha,
292    PreserveAspectRatio,
293    PrimitiveUnits,
294    R,
295    Radius,
296    RefX,
297    RefY,
298    RequiredExtensions,
299    RequiredFeatures,
300    Result,
301    Rotate,
302    Rx,
303    Ry,
304    Scale,
305    Seed,
306    ShapeImageThreshold,
307    ShapeInside,
308    ShapeMargin,
309    ShapePadding,
310    ShapeRendering,
311    ShapeSubtract,
312    Side,
313    Slope,
314    Space,
315    SpecularConstant,
316    SpecularExponent,
317    SpreadMethod,
318    StartOffset,
319    StdDeviation,
320    StitchTiles,
321    StopColor,
322    StopOpacity,
323    Stroke,
324    StrokeDasharray,
325    StrokeDashoffset,
326    StrokeLinecap,
327    StrokeLinejoin,
328    StrokeMiterlimit,
329    StrokeOpacity,
330    StrokeWidth,
331    Style,
332    SurfaceScale,
333    SystemLanguage,
334    TableValues,
335    TargetX,
336    TargetY,
337    TextAlign,
338    TextAlignLast,
339    TextAnchor,
340    TextDecoration,
341    TextDecorationColor,
342    TextDecorationFill,
343    TextDecorationLine,
344    TextDecorationStroke,
345    TextDecorationStyle,
346    TextIndent,
347    TextOrientation,
348    TextOverflow,
349    TextRendering,
350    TextUnderlinePosition,
351    TextLength,
352    Transform,
353    TransformBox,
354    TransformOrigin,
355    Type,
356    UnicodeBidi,
357    UnicodeRange,
358    Values,
359    VectorEffect,
360    ViewBox,
361    Visibility,
362    WhiteSpace,
363    Width,
364    WordSpacing,
365    WritingMode,
366    X,
367    X1,
368    X2,
369    XChannelSelector,
370    Y,
371    Y1,
372    Y2,
373    YChannelSelector,
374    Z
375}
376
377static ATTRIBUTES: Map<AId> = Map {
378    key: 3347381344252206323,
379    disps: &[
380        (0, 111),
381        (0, 2),
382        (0, 45),
383        (0, 5),
384        (0, 1),
385        (2, 56),
386        (0, 5),
387        (2, 99),
388        (13, 198),
389        (0, 61),
390        (0, 52),
391        (1, 29),
392        (0, 21),
393        (0, 70),
394        (0, 164),
395        (2, 60),
396        (3, 52),
397        (0, 1),
398        (0, 86),
399        (0, 10),
400        (0, 0),
401        (0, 4),
402        (2, 175),
403        (6, 59),
404        (1, 14),
405        (0, 13),
406        (3, 175),
407        (1, 10),
408        (2, 76),
409        (0, 53),
410        (0, 24),
411        (123, 202),
412        (0, 14),
413        (0, 30),
414        (0, 62),
415        (0, 98),
416        (11, 193),
417        (8, 79),
418        (0, 17),
419        (22, 5),
420        (36, 106),
421        (1, 1),
422    ],
423    entries: &[
424        ("mask-border-source", AId::MaskBorderSource),
425        ("stop-opacity", AId::StopOpacity),
426        ("stroke-linejoin", AId::StrokeLinejoin),
427        ("dominant-baseline", AId::DominantBaseline),
428        ("spreadMethod", AId::SpreadMethod),
429        ("order", AId::Order),
430        ("stroke", AId::Stroke),
431        ("stitchTiles", AId::StitchTiles),
432        ("height", AId::Height),
433        ("font-size", AId::FontSize),
434        ("background-color", AId::BackgroundColor),
435        ("tableValues", AId::TableValues),
436        ("x1", AId::X1),
437        ("y", AId::Y),
438        ("width", AId::Width),
439        ("text-indent", AId::TextIndent),
440        ("fill-opacity", AId::FillOpacity),
441        ("word-spacing", AId::WordSpacing),
442        ("cy", AId::Cy),
443        ("scale", AId::Scale),
444        ("x2", AId::X2),
445        ("lengthAdjust", AId::LengthAdjust),
446        ("glyph-orientation-horizontal", AId::GlyphOrientationHorizontal),
447        ("opacity", AId::Opacity),
448        ("mask-border", AId::MaskBorder),
449        ("font-stretch", AId::FontStretch),
450        ("stroke-dashoffset", AId::StrokeDashoffset),
451        ("fill", AId::Fill),
452        ("space", AId::Space),
453        ("baseline-shift", AId::BaselineShift),
454        ("text-align-last", AId::TextAlignLast),
455        ("font-variant-east-asian", AId::FontVariantEastAsian),
456        ("mask-border-mode", AId::MaskBorderMode),
457        ("font-variant-caps", AId::FontVariantCaps),
458        ("gradientUnits", AId::GradientUnits),
459        ("exponent", AId::Exponent),
460        ("text-decoration-color", AId::TextDecorationColor),
461        ("refX", AId::RefX),
462        ("enable-background", AId::EnableBackground),
463        ("mask-border-width", AId::MaskBorderWidth),
464        ("numOctaves", AId::NumOctaves),
465        ("kerning", AId::Kerning),
466        ("mix-blend-mode", AId::MixBlendMode),
467        ("mask-clip", AId::MaskClip),
468        ("mask-mode", AId::MaskMode),
469        ("type", AId::Type),
470        ("class", AId::Class),
471        ("font", AId::Font),
472        ("mask-border-repeat", AId::MaskBorderRepeat),
473        ("stroke-miterlimit", AId::StrokeMiterlimit),
474        ("text-decoration-stroke", AId::TextDecorationStroke),
475        ("z", AId::Z),
476        ("dx", AId::Dx),
477        ("clip-path", AId::ClipPath),
478        ("markerHeight", AId::MarkerHeight),
479        ("text-underline-position", AId::TextUnderlinePosition),
480        ("stdDeviation", AId::StdDeviation),
481        ("id", AId::Id),
482        ("paint-order", AId::PaintOrder),
483        ("elevation", AId::Elevation),
484        ("specularConstant", AId::SpecularConstant),
485        ("result", AId::Result),
486        ("font-size-adjust", AId::FontSizeAdjust),
487        ("mask-origin", AId::MaskOrigin),
488        ("direction", AId::Direction),
489        ("font-variant-numeric", AId::FontVariantNumeric),
490        ("startOffset", AId::StartOffset),
491        ("maskUnits", AId::MaskUnits),
492        ("font-variant", AId::FontVariant),
493        ("text-orientation", AId::TextOrientation),
494        ("amplitude", AId::Amplitude),
495        ("rx", AId::Rx),
496        ("mask-type", AId::MaskType),
497        ("filter", AId::Filter),
498        ("in", AId::In),
499        ("display", AId::Display),
500        ("seed", AId::Seed),
501        ("unicode-range", AId::UnicodeRange),
502        ("color-profile", AId::ColorProfile),
503        ("x", AId::X),
504        ("href", AId::Href),
505        ("font-feature-settings", AId::FontFeatureSettings),
506        ("fill-rule", AId::FillRule),
507        ("fr", AId::Fr),
508        ("font-variant-ligatures", AId::FontVariantLigatures),
509        ("text-decoration-style", AId::TextDecorationStyle),
510        ("radius", AId::Radius),
511        ("xChannelSelector", AId::XChannelSelector),
512        ("orient", AId::Orient),
513        ("isolation", AId::Isolation),
514        ("gradientTransform", AId::GradientTransform),
515        ("transform-box", AId::TransformBox),
516        ("pointsAtY", AId::PointsAtY),
517        ("text-decoration-line", AId::TextDecorationLine),
518        ("requiredFeatures", AId::RequiredFeatures),
519        ("patternContentUnits", AId::PatternContentUnits),
520        ("shape-padding", AId::ShapePadding),
521        ("text-overflow", AId::TextOverflow),
522        ("clipPathUnits", AId::ClipPathUnits),
523        ("azimuth", AId::Azimuth),
524        ("line-height", AId::LineHeight),
525        ("viewBox", AId::ViewBox),
526        ("preserveAspectRatio", AId::PreserveAspectRatio),
527        ("path", AId::Path),
528        ("k4", AId::K4),
529        ("systemLanguage", AId::SystemLanguage),
530        ("stroke-width", AId::StrokeWidth),
531        ("specularExponent", AId::SpecularExponent),
532        ("writing-mode", AId::WritingMode),
533        ("transform-origin", AId::TransformOrigin),
534        ("stroke-linecap", AId::StrokeLinecap),
535        ("points", AId::Points),
536        ("style", AId::Style),
537        ("pointsAtZ", AId::PointsAtZ),
538        ("targetX", AId::TargetX),
539        ("font-synthesis", AId::FontSynthesis),
540        ("maskContentUnits", AId::MaskContentUnits),
541        ("text-align", AId::TextAlign),
542        ("cx", AId::Cx),
543        ("alignment-baseline", AId::AlignmentBaseline),
544        ("font-kerning", AId::FontKerning),
545        ("requiredExtensions", AId::RequiredExtensions),
546        ("clip-rule", AId::ClipRule),
547        ("mask-border-outset", AId::MaskBorderOutset),
548        ("primitiveUnits", AId::PrimitiveUnits),
549        ("textLength", AId::TextLength),
550        ("text-decoration-fill", AId::TextDecorationFill),
551        ("fy", AId::Fy),
552        ("mask-size", AId::MaskSize),
553        ("k3", AId::K3),
554        ("marker-start", AId::MarkerStart),
555        ("mode", AId::Mode),
556        ("k1", AId::K1),
557        ("refY", AId::RefY),
558        ("y1", AId::Y1),
559        ("shape-rendering", AId::ShapeRendering),
560        ("operator", AId::Operator),
561        ("mask-image", AId::MaskImage),
562        ("marker-end", AId::MarkerEnd),
563        ("rotate", AId::Rotate),
564        ("limitingConeAngle", AId::LimitingConeAngle),
565        ("surfaceScale", AId::SurfaceScale),
566        ("intercept", AId::Intercept),
567        ("font-variant-position", AId::FontVariantPosition),
568        ("clip", AId::Clip),
569        ("fx", AId::Fx),
570        ("visibility", AId::Visibility),
571        ("shape-margin", AId::ShapeMargin),
572        ("font-style", AId::FontStyle),
573        ("y2", AId::Y2),
574        ("dy", AId::Dy),
575        ("yChannelSelector", AId::YChannelSelector),
576        ("ry", AId::Ry),
577        ("color-rendering", AId::ColorRendering),
578        ("white-space", AId::WhiteSpace),
579        ("patternUnits", AId::PatternUnits),
580        ("shape-subtract", AId::ShapeSubtract),
581        ("markerWidth", AId::MarkerWidth),
582        ("d", AId::D),
583        ("shape-inside", AId::ShapeInside),
584        ("preserveAlpha", AId::PreserveAlpha),
585        ("shape-image-threshold", AId::ShapeImageThreshold),
586        ("image-rendering", AId::ImageRendering),
587        ("marker-mid", AId::MarkerMid),
588        ("filterUnits", AId::FilterUnits),
589        ("bias", AId::Bias),
590        ("mask-border-slice", AId::MaskBorderSlice),
591        ("pointsAtX", AId::PointsAtX),
592        ("kernelMatrix", AId::KernelMatrix),
593        ("color-interpolation", AId::ColorInterpolation),
594        ("glyph-orientation-vertical", AId::GlyphOrientationVertical),
595        ("color", AId::Color),
596        ("patternTransform", AId::PatternTransform),
597        ("kernelUnitLength", AId::KernelUnitLength),
598        ("markerUnits", AId::MarkerUnits),
599        ("font-weight", AId::FontWeight),
600        ("overflow", AId::Overflow),
601        ("stop-color", AId::StopColor),
602        ("r", AId::R),
603        ("k2", AId::K2),
604        ("text-anchor", AId::TextAnchor),
605        ("inline-size", AId::InlineSize),
606        ("unicode-bidi", AId::UnicodeBidi),
607        ("font-family", AId::FontFamily),
608        ("color-interpolation-filters", AId::ColorInterpolationFilters),
609        ("slope", AId::Slope),
610        ("baseFrequency", AId::BaseFrequency),
611        ("transform", AId::Transform),
612        ("text-rendering", AId::TextRendering),
613        ("divisor", AId::Divisor),
614        ("edgeMode", AId::EdgeMode),
615        ("letter-spacing", AId::LetterSpacing),
616        ("flood-color", AId::FloodColor),
617        ("in2", AId::In2),
618        ("side", AId::Side),
619        ("mask-composite", AId::MaskComposite),
620        ("offset", AId::Offset),
621        ("values", AId::Values),
622        ("vector-effect", AId::VectorEffect),
623        ("mask", AId::Mask),
624        ("pathLength", AId::PathLength),
625        ("lighting-color", AId::LightingColor),
626        ("mask-position", AId::MaskPosition),
627        ("stroke-dasharray", AId::StrokeDasharray),
628        ("text-decoration", AId::TextDecoration),
629        ("stroke-opacity", AId::StrokeOpacity),
630        ("targetY", AId::TargetY),
631        ("flood-opacity", AId::FloodOpacity),
632        ("diffuseConstant", AId::DiffuseConstant),
633    ],
634};
635
636impl AId {
637    pub(crate) fn from_str(text: &str) -> Option<AId> {
638        ATTRIBUTES.get(text).cloned()
639    }
640
641    /// Returns the original string.
642    #[inline(never)]
643    pub fn to_str(self) -> &'static str {
644        ATTRIBUTES.key(&self)
645    }
646}
647
648impl std::fmt::Debug for AId {
649    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
650        write!(f, "{}", self.to_str())
651    }
652}
653
654impl std::fmt::Display for AId {
655    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
656        write!(f, "{:?}", self)
657    }
658}
659
660// A stripped down `phf` crate fork.
661//
662// https://github.com/sfackler/rust-phf
663
664struct Map<V: 'static> {
665    pub key: u64,
666    pub disps: &'static [(u32, u32)],
667    pub entries: &'static [(&'static str, V)],
668}
669
670impl<V: PartialEq> Map<V> {
671    fn get(&self, key: &str) -> Option<&V> {
672        let hash = hash(key, self.key);
673        let index = get_index(hash, self.disps, self.entries.len());
674        let entry = &self.entries[index as usize];
675        let b = entry.0;
676        if b == key {
677            Some(&entry.1)
678        } else {
679            None
680        }
681    }
682
683    fn key(&self, value: &V) -> &'static str {
684        self.entries.iter().find(|kv| kv.1 == *value).unwrap().0
685    }
686}
687
688#[inline]
689fn hash(x: &str, key: u64) -> u64 {
690    use std::hash::Hasher;
691
692    let mut hasher = siphasher::sip::SipHasher13::new_with_keys(0, key);
693    hasher.write(x.as_bytes());
694    hasher.finish()
695}
696
697#[inline]
698fn get_index(hash: u64, disps: &[(u32, u32)], len: usize) -> u32 {
699    let (g, f1, f2) = split(hash);
700    let (d1, d2) = disps[(g % (disps.len() as u32)) as usize];
701    displace(f1, f2, d1, d2) % (len as u32)
702}
703
704#[inline]
705fn split(hash: u64) -> (u32, u32, u32) {
706    const BITS: u32 = 21;
707    const MASK: u64 = (1 << BITS) - 1;
708
709    ((hash & MASK) as u32,
710     ((hash >> BITS) & MASK) as u32,
711     ((hash >> (2 * BITS)) & MASK) as u32)
712}
713
714#[inline]
715fn displace(f1: u32, f2: u32, d1: u32, d2: u32) -> u32 {
716    d2 + f1 * d1 + f2
717}