#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq)]
pub enum ElementId {
A,
Circle,
ClipPath,
Defs,
Ellipse,
FeBlend,
FeColorMatrix,
FeComponentTransfer,
FeComposite,
FeConvolveMatrix,
FeDiffuseLighting,
FeDisplacementMap,
FeDistantLight,
FeDropShadow,
FeFlood,
FeFuncA,
FeFuncB,
FeFuncG,
FeFuncR,
FeGaussianBlur,
FeImage,
FeMerge,
FeMergeNode,
FeMorphology,
FeOffset,
FePointLight,
FeSpecularLighting,
FeSpotLight,
FeTile,
FeTurbulence,
Filter,
G,
Image,
Line,
LinearGradient,
Marker,
Mask,
Path,
Pattern,
Polygon,
Polyline,
RadialGradient,
Rect,
Stop,
Style,
Svg,
Switch,
Symbol,
Text,
TextPath,
Tref,
Tspan,
Use
}
static ELEMENTS: Map<ElementId> = Map {
key: 732231254413039614,
disps: &[
(0, 12),
(1, 11),
(10, 26),
(2, 42),
(1, 19),
(0, 5),
(1, 13),
(8, 50),
(0, 0),
(1, 0),
(7, 45),
],
entries: &[
("feFlood", ElementId::FeFlood),
("radialGradient", ElementId::RadialGradient),
("feImage", ElementId::FeImage),
("stop", ElementId::Stop),
("fePointLight", ElementId::FePointLight),
("feConvolveMatrix", ElementId::FeConvolveMatrix),
("feComposite", ElementId::FeComposite),
("clipPath", ElementId::ClipPath),
("feMerge", ElementId::FeMerge),
("defs", ElementId::Defs),
("mask", ElementId::Mask),
("svg", ElementId::Svg),
("symbol", ElementId::Symbol),
("linearGradient", ElementId::LinearGradient),
("feSpecularLighting", ElementId::FeSpecularLighting),
("feFuncB", ElementId::FeFuncB),
("filter", ElementId::Filter),
("feFuncG", ElementId::FeFuncG),
("circle", ElementId::Circle),
("g", ElementId::G),
("tref", ElementId::Tref),
("feFuncA", ElementId::FeFuncA),
("image", ElementId::Image),
("text", ElementId::Text),
("line", ElementId::Line),
("pattern", ElementId::Pattern),
("use", ElementId::Use),
("feDropShadow", ElementId::FeDropShadow),
("feSpotLight", ElementId::FeSpotLight),
("marker", ElementId::Marker),
("style", ElementId::Style),
("switch", ElementId::Switch),
("tspan", ElementId::Tspan),
("feColorMatrix", ElementId::FeColorMatrix),
("feOffset", ElementId::FeOffset),
("path", ElementId::Path),
("feGaussianBlur", ElementId::FeGaussianBlur),
("feTile", ElementId::FeTile),
("feTurbulence", ElementId::FeTurbulence),
("feMergeNode", ElementId::FeMergeNode),
("feMorphology", ElementId::FeMorphology),
("a", ElementId::A),
("textPath", ElementId::TextPath),
("ellipse", ElementId::Ellipse),
("feComponentTransfer", ElementId::FeComponentTransfer),
("feDistantLight", ElementId::FeDistantLight),
("polyline", ElementId::Polyline),
("polygon", ElementId::Polygon),
("feBlend", ElementId::FeBlend),
("feDisplacementMap", ElementId::FeDisplacementMap),
("feDiffuseLighting", ElementId::FeDiffuseLighting),
("rect", ElementId::Rect),
("feFuncR", ElementId::FeFuncR),
],
};
impl ElementId {
pub(crate) fn from_str(text: &str) -> Option<ElementId> {
ELEMENTS.get(text).cloned()
}
#[inline(never)]
pub fn to_str(self) -> &'static str {
ELEMENTS.key(&self)
}
}
impl std::fmt::Debug for ElementId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.to_str())
}
}
impl std::fmt::Display for ElementId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq)]
pub enum AttributeId {
AlignmentBaseline,
Amplitude,
Azimuth,
BaseFrequency,
BaselineShift,
Bias,
Class,
Clip,
ClipPath,
ClipRule,
ClipPathUnits,
Color,
ColorInterpolation,
ColorInterpolationFilters,
ColorProfile,
ColorRendering,
Cx,
Cy,
D,
DiffuseConstant,
Direction,
Display,
Divisor,
DominantBaseline,
Dx,
Dy,
EdgeMode,
Elevation,
EnableBackground,
Exponent,
Fill,
FillOpacity,
FillRule,
Filter,
FilterUnits,
FloodColor,
FloodOpacity,
Font,
FontFamily,
FontFeatureSettings,
FontKerning,
FontSize,
FontSizeAdjust,
FontStretch,
FontStyle,
FontSynthesis,
FontVariant,
FontVariantCaps,
FontVariantEastAsian,
FontVariantLigatures,
FontVariantNumeric,
FontVariantPosition,
FontWeight,
Fx,
Fy,
GlyphOrientationHorizontal,
GlyphOrientationVertical,
GradientTransform,
GradientUnits,
Height,
Href,
Id,
ImageRendering,
In,
In2,
InlineSize,
Intercept,
Isolation,
K1,
K2,
K3,
K4,
KernelMatrix,
KernelUnitLength,
Kerning,
LengthAdjust,
LetterSpacing,
LightingColor,
LimitingConeAngle,
LineHeight,
MarkerEnd,
MarkerMid,
MarkerStart,
MarkerHeight,
MarkerUnits,
MarkerWidth,
Mask,
MaskContentUnits,
MaskUnits,
MixBlendMode,
Mode,
NumOctaves,
Offset,
Opacity,
Operator,
Order,
Orient,
Overflow,
PaintOrder,
Path,
PathLength,
PatternContentUnits,
PatternTransform,
PatternUnits,
Points,
PointsAtX,
PointsAtY,
PointsAtZ,
PreserveAlpha,
PreserveAspectRatio,
PrimitiveUnits,
R,
Radius,
RefX,
RefY,
RequiredExtensions,
RequiredFeatures,
Result,
Rotate,
Rx,
Ry,
Scale,
Seed,
ShapeImageThreshold,
ShapeInside,
ShapeMargin,
ShapePadding,
ShapeRendering,
ShapeSubtract,
Side,
Slope,
Space,
SpecularConstant,
SpecularExponent,
SpreadMethod,
StartOffset,
StdDeviation,
StitchTiles,
StopColor,
StopOpacity,
Stroke,
StrokeDasharray,
StrokeDashoffset,
StrokeLinecap,
StrokeLinejoin,
StrokeMiterlimit,
StrokeOpacity,
StrokeWidth,
Style,
SurfaceScale,
SystemLanguage,
TableValues,
TargetX,
TargetY,
TextAlign,
TextAlignLast,
TextAnchor,
TextDecoration,
TextDecorationColor,
TextDecorationFill,
TextDecorationLine,
TextDecorationStroke,
TextDecorationStyle,
TextIndent,
TextOrientation,
TextOverflow,
TextRendering,
TextUnderlinePosition,
TextLength,
Transform,
TransformBox,
TransformOrigin,
Type,
UnicodeBidi,
UnicodeRange,
Values,
VectorEffect,
ViewBox,
Visibility,
WhiteSpace,
Width,
WordSpacing,
WritingMode,
X,
X1,
X2,
XChannelSelector,
Y,
Y1,
Y2,
YChannelSelector,
Z
}
static ATTRIBUTES: Map<AttributeId> = Map {
key: 732231254413039614,
disps: &[
(0, 103),
(1, 31),
(0, 1),
(0, 2),
(0, 31),
(3, 20),
(0, 164),
(0, 97),
(0, 2),
(0, 4),
(0, 12),
(0, 166),
(0, 1),
(4, 174),
(2, 158),
(0, 13),
(0, 18),
(0, 0),
(0, 138),
(7, 16),
(1, 100),
(5, 19),
(10, 59),
(0, 5),
(0, 146),
(0, 44),
(0, 72),
(0, 26),
(0, 1),
(3, 147),
(0, 7),
(0, 11),
(0, 10),
(5, 91),
(0, 74),
(4, 37),
(0, 138),
(0, 3),
(6, 164),
],
entries: &[
("color-interpolation", AttributeId::ColorInterpolation),
("id", AttributeId::Id),
("inline-size", AttributeId::InlineSize),
("flood-opacity", AttributeId::FloodOpacity),
("kernelMatrix", AttributeId::KernelMatrix),
("font-stretch", AttributeId::FontStretch),
("mask", AttributeId::Mask),
("order", AttributeId::Order),
("kerning", AttributeId::Kerning),
("font-size-adjust", AttributeId::FontSizeAdjust),
("limitingConeAngle", AttributeId::LimitingConeAngle),
("azimuth", AttributeId::Azimuth),
("k4", AttributeId::K4),
("fill", AttributeId::Fill),
("intercept", AttributeId::Intercept),
("text-align-last", AttributeId::TextAlignLast),
("text-decoration-fill", AttributeId::TextDecorationFill),
("textLength", AttributeId::TextLength),
("patternUnits", AttributeId::PatternUnits),
("space", AttributeId::Space),
("side", AttributeId::Side),
("line-height", AttributeId::LineHeight),
("stroke-linejoin", AttributeId::StrokeLinejoin),
("xChannelSelector", AttributeId::XChannelSelector),
("kernelUnitLength", AttributeId::KernelUnitLength),
("k3", AttributeId::K3),
("font-feature-settings", AttributeId::FontFeatureSettings),
("fill-opacity", AttributeId::FillOpacity),
("transform-box", AttributeId::TransformBox),
("lengthAdjust", AttributeId::LengthAdjust),
("marker-end", AttributeId::MarkerEnd),
("y1", AttributeId::Y1),
("specularExponent", AttributeId::SpecularExponent),
("direction", AttributeId::Direction),
("stroke-linecap", AttributeId::StrokeLinecap),
("display", AttributeId::Display),
("text-overflow", AttributeId::TextOverflow),
("text-decoration-color", AttributeId::TextDecorationColor),
("transform-origin", AttributeId::TransformOrigin),
("lighting-color", AttributeId::LightingColor),
("systemLanguage", AttributeId::SystemLanguage),
("pointsAtZ", AttributeId::PointsAtZ),
("cy", AttributeId::Cy),
("k2", AttributeId::K2),
("specularConstant", AttributeId::SpecularConstant),
("tableValues", AttributeId::TableValues),
("dominant-baseline", AttributeId::DominantBaseline),
("stroke-width", AttributeId::StrokeWidth),
("dx", AttributeId::Dx),
("font-variant-caps", AttributeId::FontVariantCaps),
("shape-subtract", AttributeId::ShapeSubtract),
("shape-image-threshold", AttributeId::ShapeImageThreshold),
("gradientTransform", AttributeId::GradientTransform),
("pointsAtX", AttributeId::PointsAtX),
("cx", AttributeId::Cx),
("filterUnits", AttributeId::FilterUnits),
("image-rendering", AttributeId::ImageRendering),
("fx", AttributeId::Fx),
("gradientUnits", AttributeId::GradientUnits),
("text-orientation", AttributeId::TextOrientation),
("exponent", AttributeId::Exponent),
("rotate", AttributeId::Rotate),
("d", AttributeId::D),
("mix-blend-mode", AttributeId::MixBlendMode),
("rx", AttributeId::Rx),
("text-rendering", AttributeId::TextRendering),
("glyph-orientation-horizontal", AttributeId::GlyphOrientationHorizontal),
("enable-background", AttributeId::EnableBackground),
("scale", AttributeId::Scale),
("in", AttributeId::In),
("font-variant-numeric", AttributeId::FontVariantNumeric),
("font-variant-east-asian", AttributeId::FontVariantEastAsian),
("text-anchor", AttributeId::TextAnchor),
("glyph-orientation-vertical", AttributeId::GlyphOrientationVertical),
("dy", AttributeId::Dy),
("color-interpolation-filters", AttributeId::ColorInterpolationFilters),
("clip-rule", AttributeId::ClipRule),
("stroke-miterlimit", AttributeId::StrokeMiterlimit),
("isolation", AttributeId::Isolation),
("transform", AttributeId::Transform),
("stroke-dashoffset", AttributeId::StrokeDashoffset),
("z", AttributeId::Z),
("refX", AttributeId::RefX),
("width", AttributeId::Width),
("requiredExtensions", AttributeId::RequiredExtensions),
("font-synthesis", AttributeId::FontSynthesis),
("radius", AttributeId::Radius),
("white-space", AttributeId::WhiteSpace),
("patternTransform", AttributeId::PatternTransform),
("maskContentUnits", AttributeId::MaskContentUnits),
("stop-color", AttributeId::StopColor),
("amplitude", AttributeId::Amplitude),
("visibility", AttributeId::Visibility),
("yChannelSelector", AttributeId::YChannelSelector),
("color-rendering", AttributeId::ColorRendering),
("diffuseConstant", AttributeId::DiffuseConstant),
("stroke", AttributeId::Stroke),
("text-decoration-style", AttributeId::TextDecorationStyle),
("y2", AttributeId::Y2),
("operator", AttributeId::Operator),
("font-variant", AttributeId::FontVariant),
("clip-path", AttributeId::ClipPath),
("edgeMode", AttributeId::EdgeMode),
("text-indent", AttributeId::TextIndent),
("numOctaves", AttributeId::NumOctaves),
("font-size", AttributeId::FontSize),
("alignment-baseline", AttributeId::AlignmentBaseline),
("stroke-opacity", AttributeId::StrokeOpacity),
("class", AttributeId::Class),
("refY", AttributeId::RefY),
("stitchTiles", AttributeId::StitchTiles),
("x2", AttributeId::X2),
("unicode-bidi", AttributeId::UnicodeBidi),
("targetY", AttributeId::TargetY),
("vector-effect", AttributeId::VectorEffect),
("fy", AttributeId::Fy),
("clipPathUnits", AttributeId::ClipPathUnits),
("href", AttributeId::Href),
("x1", AttributeId::X1),
("result", AttributeId::Result),
("fill-rule", AttributeId::FillRule),
("color-profile", AttributeId::ColorProfile),
("font", AttributeId::Font),
("font-weight", AttributeId::FontWeight),
("shape-padding", AttributeId::ShapePadding),
("primitiveUnits", AttributeId::PrimitiveUnits),
("height", AttributeId::Height),
("bias", AttributeId::Bias),
("maskUnits", AttributeId::MaskUnits),
("pointsAtY", AttributeId::PointsAtY),
("paint-order", AttributeId::PaintOrder),
("text-decoration-line", AttributeId::TextDecorationLine),
("preserveAlpha", AttributeId::PreserveAlpha),
("shape-rendering", AttributeId::ShapeRendering),
("text-underline-position", AttributeId::TextUnderlinePosition),
("stroke-dasharray", AttributeId::StrokeDasharray),
("ry", AttributeId::Ry),
("preserveAspectRatio", AttributeId::PreserveAspectRatio),
("markerWidth", AttributeId::MarkerWidth),
("letter-spacing", AttributeId::LetterSpacing),
("font-variant-position", AttributeId::FontVariantPosition),
("y", AttributeId::Y),
("style", AttributeId::Style),
("requiredFeatures", AttributeId::RequiredFeatures),
("text-align", AttributeId::TextAlign),
("divisor", AttributeId::Divisor),
("offset", AttributeId::Offset),
("overflow", AttributeId::Overflow),
("font-kerning", AttributeId::FontKerning),
("slope", AttributeId::Slope),
("marker-mid", AttributeId::MarkerMid),
("mode", AttributeId::Mode),
("x", AttributeId::X),
("elevation", AttributeId::Elevation),
("k1", AttributeId::K1),
("startOffset", AttributeId::StartOffset),
("clip", AttributeId::Clip),
("surfaceScale", AttributeId::SurfaceScale),
("points", AttributeId::Points),
("targetX", AttributeId::TargetX),
("text-decoration", AttributeId::TextDecoration),
("font-style", AttributeId::FontStyle),
("seed", AttributeId::Seed),
("stop-opacity", AttributeId::StopOpacity),
("values", AttributeId::Values),
("stdDeviation", AttributeId::StdDeviation),
("spreadMethod", AttributeId::SpreadMethod),
("flood-color", AttributeId::FloodColor),
("color", AttributeId::Color),
("shape-inside", AttributeId::ShapeInside),
("marker-start", AttributeId::MarkerStart),
("text-decoration-stroke", AttributeId::TextDecorationStroke),
("patternContentUnits", AttributeId::PatternContentUnits),
("word-spacing", AttributeId::WordSpacing),
("orient", AttributeId::Orient),
("in2", AttributeId::In2),
("unicode-range", AttributeId::UnicodeRange),
("opacity", AttributeId::Opacity),
("baseFrequency", AttributeId::BaseFrequency),
("path", AttributeId::Path),
("markerHeight", AttributeId::MarkerHeight),
("pathLength", AttributeId::PathLength),
("r", AttributeId::R),
("writing-mode", AttributeId::WritingMode),
("shape-margin", AttributeId::ShapeMargin),
("viewBox", AttributeId::ViewBox),
("font-family", AttributeId::FontFamily),
("filter", AttributeId::Filter),
("markerUnits", AttributeId::MarkerUnits),
("type", AttributeId::Type),
("baseline-shift", AttributeId::BaselineShift),
("font-variant-ligatures", AttributeId::FontVariantLigatures),
],
};
impl AttributeId {
pub(crate) fn from_str(text: &str) -> Option<AttributeId> {
ATTRIBUTES.get(text).cloned()
}
#[inline(never)]
pub fn to_str(self) -> &'static str {
ATTRIBUTES.key(&self)
}
}
impl std::fmt::Debug for AttributeId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.to_str())
}
}
impl std::fmt::Display for AttributeId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
struct Map<V: 'static> {
pub key: u64,
pub disps: &'static [(u32, u32)],
pub entries: &'static[(&'static str, V)],
}
impl<V: PartialEq> Map<V> {
fn get(&self, key: &str) -> Option<&V> {
use std::borrow::Borrow;
let hash = hash(key, self.key);
let index = get_index(hash, &*self.disps, self.entries.len());
let entry = &self.entries[index as usize];
let b = entry.0.borrow();
if b == key {
Some(&entry.1)
} else {
None
}
}
fn key(&self, value: &V) -> &'static str {
self.entries.iter().find(|kv| kv.1 == *value).unwrap().0
}
}
#[inline]
fn hash(x: &str, key: u64) -> u64 {
use std::hash::Hasher;
let mut hasher = siphasher::sip::SipHasher13::new_with_keys(0, key);
hasher.write(x.as_bytes());
hasher.finish()
}
#[inline]
fn get_index(hash: u64, disps: &[(u32, u32)], len: usize) -> u32 {
let (g, f1, f2) = split(hash);
let (d1, d2) = disps[(g % (disps.len() as u32)) as usize];
displace(f1, f2, d1, d2) % (len as u32)
}
#[inline]
fn split(hash: u64) -> (u32, u32, u32) {
const BITS: u32 = 21;
const MASK: u64 = (1 << BITS) - 1;
((hash & MASK) as u32,
((hash >> BITS) & MASK) as u32,
((hash >> (2 * BITS)) & MASK) as u32)
}
#[inline]
fn displace(f1: u32, f2: u32, d1: u32, d2: u32) -> u32 {
d2 + f1 * d1 + f2
}