attributes.rs: Removed, along with the dependency for phf

parent 1dee83d1
...@@ -99,7 +99,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" ...@@ -99,7 +99,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "0.1.7" version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
...@@ -171,7 +171,7 @@ version = "0.3.1" ...@@ -171,7 +171,7 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
...@@ -184,7 +184,7 @@ name = "crossbeam-utils" ...@@ -184,7 +184,7 @@ name = "crossbeam-utils"
version = "0.2.2" version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
...@@ -526,7 +526,7 @@ name = "log" ...@@ -526,7 +526,7 @@ name = "log"
version = "0.4.6" version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
...@@ -984,7 +984,6 @@ dependencies = [ ...@@ -984,7 +984,6 @@ dependencies = [
"pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "pango-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pangocairo 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "pangocairo 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)", "phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
...@@ -1257,7 +1256,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" ...@@ -1257,7 +1256,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum cairo-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9e09d8a818b2ccc8983f04d95a9350c3cf8d24cc456cedca3b88fa3a81fdc0e2" "checksum cairo-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9e09d8a818b2ccc8983f04d95a9350c3cf8d24cc456cedca3b88fa3a81fdc0e2"
"checksum cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3fa13914fdc013387afa771f554f2f71d6ae931f4e5be9246c337d60c3dc484" "checksum cairo-sys-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3fa13914fdc013387afa771f554f2f71d6ae931f4e5be9246c337d60c3dc484"
"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427" "checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427"
"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0363053954f3e679645fc443321ca128b7b950a6fe288cf5f9335cc22ee58394" "checksum criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0363053954f3e679645fc443321ca128b7b950a6fe288cf5f9335cc22ee58394"
......
...@@ -32,7 +32,6 @@ RUST_SRC = \ ...@@ -32,7 +32,6 @@ RUST_SRC = \
rsvg_internals/src/allowed_url.rs \ rsvg_internals/src/allowed_url.rs \
rsvg_internals/src/angle.rs \ rsvg_internals/src/angle.rs \
rsvg_internals/src/aspect_ratio.rs \ rsvg_internals/src/aspect_ratio.rs \
rsvg_internals/src/attributes.rs \
rsvg_internals/src/bbox.rs \ rsvg_internals/src/bbox.rs \
rsvg_internals/src/c_api.rs \ rsvg_internals/src/c_api.rs \
rsvg_internals/src/clip_path.rs \ rsvg_internals/src/clip_path.rs \
......
...@@ -17,9 +17,6 @@ edition = "2018" ...@@ -17,9 +17,6 @@ edition = "2018"
# regenerate librsvg/Cargo.lock, and copy the resolved version numbers # regenerate librsvg/Cargo.lock, and copy the resolved version numbers
# from there into cargo-fetcher/Cargo.toml. # from there into cargo-fetcher/Cargo.toml.
[build-dependencies]
phf_codegen = "0.7.21"
[dependencies] [dependencies]
bitflags = "1.0" bitflags = "1.0"
cairo-rs = { version="0.6.0", features=["v1_16"] } cairo-rs = { version="0.6.0", features=["v1_16"] }
......
use phf_codegen;
use std::env; use std::env;
use std::fs::File; use std::fs::File;
use std::io::{BufWriter, Write}; use std::io::{BufWriter, Write};
use std::path::Path; use std::path::Path;
fn main() { fn main() {
generate_phf_of_svg_attributes();
generate_srgb_tables(); generate_srgb_tables();
} }
/// Creates a perfect hash function (PHF) to map SVG attribute names to enum values.
fn generate_phf_of_svg_attributes() {
// (attribute name, Rust enum value)
//
#[cfg_attr(rustfmt, rustfmt_skip)]
let attribute_defs = [
( "alternate", "Alternate" ),
( "amplitude", "Amplitude" ),
( "azimuth", "Azimuth" ),
( "baseFrequency", "BaseFrequency" ),
( "baseline-shift", "BaselineShift" ),
( "bias", "Bias" ),
( "class", "Class" ),
( "clip-path", "ClipPath" ),
( "clip-rule", "ClipRule" ),
( "clipPathUnits", "ClipPathUnits" ),
( "color", "Color" ),
( "color-interpolation-filters", "ColorInterpolationFilters" ),
( "cx", "Cx" ),
( "cy", "Cy" ),
( "d", "D" ),
( "diffuseConstant", "DiffuseConstant" ),
( "direction", "Direction" ),
( "display", "Display" ),
( "divisor", "Divisor" ),
( "dx", "Dx" ),
( "dy", "Dy" ),
( "edgeMode", "EdgeMode" ),
( "elevation", "Elevation" ),
( "enable-background", "EnableBackground" ),
( "encoding", "Encoding" ),
( "exponent", "Exponent" ),
( "fill", "Fill" ),
( "fill-opacity", "FillOpacity" ),
( "fill-rule", "FillRule" ),
( "filter", "Filter" ),
( "filterUnits", "FilterUnits" ),
( "flood-color", "FloodColor" ),
( "flood-opacity", "FloodOpacity" ),
( "font-family", "FontFamily" ),
( "font-size", "FontSize" ),
( "font-stretch", "FontStretch" ),
( "font-style", "FontStyle" ),
( "font-variant", "FontVariant" ),
( "font-weight", "FontWeight" ),
( "fx", "Fx" ),
( "fy", "Fy" ),
( "gradientTransform", "GradientTransform" ),
( "gradientUnits", "GradientUnits" ),
( "height", "Height" ),
( "href", "Href" ),
( "id", "Id" ),
( "in", "In" ),
( "in2", "In2" ),
( "intercept", "Intercept" ),
( "k1", "K1" ),
( "k2", "K2" ),
( "k3", "K3" ),
( "k4", "K4" ),
( "kernelMatrix", "KernelMatrix" ),
( "kernelUnitLength", "KernelUnitLength" ),
( "letter-spacing", "LetterSpacing" ),
( "lighting-color", "LightingColor" ),
( "limitingConeAngle", "LimitingConeAngle" ),
( "marker", "Marker" ),
( "marker-end", "MarkerEnd" ),
( "marker-mid", "MarkerMid" ),
( "marker-start", "MarkerStart" ),
( "markerHeight", "MarkerHeight" ),
( "markerUnits", "MarkerUnits" ),
( "markerWidth", "MarkerWidth" ),
( "mask", "Mask" ),
( "maskContentUnits", "MaskContentUnits" ),
( "maskUnits", "MaskUnits" ),
( "mode", "Mode" ),
( "numOctaves", "NumOctaves" ),
( "offset", "Offset" ),
( "opacity", "Opacity" ),
( "operator", "Operator" ),
( "order", "Order" ),
( "orient", "Orient" ),
( "overflow", "Overflow" ),
( "parse", "Parse" ),
( "path", "Path" ),
( "patternContentUnits", "PatternContentUnits" ),
( "patternTransform", "PatternTransform" ),
( "patternUnits", "PatternUnits" ),
( "points", "Points" ),
( "pointsAtX", "PointsAtX" ),
( "pointsAtY", "PointsAtY" ),
( "pointsAtZ", "PointsAtZ" ),
( "preserveAlpha", "PreserveAlpha" ),
( "preserveAspectRatio", "PreserveAspectRatio" ),
( "primitiveUnits", "PrimitiveUnits" ),
( "r", "R" ),
( "radius", "Radius" ),
( "refX", "RefX" ),
( "refY", "RefY" ),
( "requiredExtensions", "RequiredExtensions" ),
( "requiredFeatures", "RequiredFeatures" ),
( "result", "Result" ),
( "rx", "Rx" ),
( "ry", "Ry" ),
( "scale", "Scale" ),
( "seed", "Seed" ),
( "shape-rendering", "ShapeRendering" ),
( "slope", "Slope" ),
( "specularConstant", "SpecularConstant" ),
( "specularExponent", "SpecularExponent" ),
( "spreadMethod", "SpreadMethod" ),
( "stdDeviation", "StdDeviation" ),
( "stitchTiles", "StitchTiles" ),
( "stop-color", "StopColor" ),
( "stop-opacity", "StopOpacity" ),
( "stroke", "Stroke" ),
( "stroke-dasharray", "StrokeDasharray" ),
( "stroke-dashoffset", "StrokeDashoffset" ),
( "stroke-linecap", "StrokeLinecap" ),
( "stroke-linejoin", "StrokeLinejoin" ),
( "stroke-miterlimit", "StrokeMiterlimit" ),
( "stroke-opacity", "StrokeOpacity" ),
( "stroke-width", "StrokeWidth" ),
( "style", "Style" ),
( "surfaceScale", "SurfaceScale" ),
( "systemLanguage", "SystemLanguage" ),
( "tableValues", "TableValues" ),
( "targetX", "TargetX" ),
( "targetY", "TargetY" ),
( "text-anchor", "TextAnchor" ),
( "text-decoration", "TextDecoration" ),
( "text-rendering", "TextRendering" ),
( "transform", "Transform" ),
( "type", "Type" ),
( "unicode-bidi", "UnicodeBidi" ),
( "values", "Values" ),
( "verts", "Verts" ),
( "viewBox", "ViewBox" ),
( "visibility", "Visibility" ),
( "width", "Width" ),
( "writing-mode", "WritingMode" ),
( "x", "X" ),
( "x1", "X1" ),
( "y1", "Y1" ),
( "x2", "X2" ),
( "y2", "Y2" ),
( "xChannelSelector", "XChannelSelector" ),
( "xlink:href", "XlinkHref" ),
( "xml:lang", "XmlLang" ),
( "xml:space", "XmlSpace" ),
( "y", "Y" ),
( "yChannelSelector", "YChannelSelector" ),
( "z", "Z" ),
];
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("attributes-codegen.rs");
let mut file = BufWriter::new(File::create(&path).unwrap());
writeln!(&mut file, "#[repr(C)]").unwrap();
writeln!(
&mut file,
"#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]"
)
.unwrap();
writeln!(&mut file, "pub enum Attribute {{").unwrap();
for &(_, valname) in attribute_defs.iter() {
writeln!(&mut file, " {},", valname).unwrap();
}
writeln!(&mut file, "}}").unwrap();
writeln!(
&mut file,
"static ATTRIBUTES: phf::Map<&'static str, Attribute> = "
)
.unwrap();
let mut map = phf_codegen::Map::new();
map.phf_path("phf");
for &(name, valname) in attribute_defs.iter() {
let valname = ["Attribute::", valname].concat();
map.entry(name, &valname);
}
map.build(&mut file).unwrap();
writeln!(&mut file, ";").unwrap();
}
/// Converts an sRGB color value to a linear sRGB color value (undoes the gamma correction). /// Converts an sRGB color value to a linear sRGB color value (undoes the gamma correction).
/// ///
/// The input and the output are supposed to be in the [0, 1] range. /// The input and the output are supposed to be in the [0, 1] range.
......
use phf;
use std::fmt;
use std::str::FromStr;
include!(concat!(env!("OUT_DIR"), "/attributes-codegen.rs"));
impl FromStr for Attribute {
type Err = ();
fn from_str(s: &str) -> Result<Attribute, ()> {
ATTRIBUTES.get(s).cloned().ok_or(())
}
}
impl fmt::Display for Attribute {
// This is horribly inefficient, but for now I'm too lazy to have a
// compile-time bijective mapping from attributes to names. Hopefully
// this function is only called when *printing* errors, which, uh,
// should not be done too often.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for (k, v) in ATTRIBUTES.entries() {
if *v == *self {
return write!(f, "{}", k);
}
}
unreachable!();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parses_attributes() {
assert_eq!(Attribute::from_str("width"), Ok(Attribute::Width));
}
#[test]
fn unknown_attribute_yields_error() {
assert_eq!(Attribute::from_str("foobar"), Err(()));
}
#[test]
fn converts_attributes_back_to_strings() {
assert_eq!(Attribute::ClipPath.to_string(), "clip-path");
assert_eq!(Attribute::KernelUnitLength.to_string(), "kernelUnitLength");
assert_eq!(Attribute::Offset.to_string(), "offset");
}
}
...@@ -92,7 +92,6 @@ mod property_macros; ...@@ -92,7 +92,6 @@ mod property_macros;
mod allowed_url; mod allowed_url;
mod angle; mod angle;
mod aspect_ratio; mod aspect_ratio;
mod attributes;
mod bbox; mod bbox;
mod c_api; mod c_api;
mod clip_path; mod clip_path;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment