[librsvg] paint_server.rs: New file with a PaintServerUnits enum
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] paint_server.rs: New file with a PaintServerUnits enum
- Date: Tue, 21 Mar 2017 22:57:43 +0000 (UTC)
commit 69903c259ec2f52538ef9b5e4f044afb9a3f9b62
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Mar 21 14:06:54 2017 -0600
paint_server.rs: New file with a PaintServerUnits enum
This has the userSpaceOnUse and objectBoundingBox values from the SVG
spec. We'll use this enum instead of boolean values for obj_bbox and
similar.
rust/src/lib.rs | 1 +
rust/src/paint_server.rs | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index d3456de..7ae50cb 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -112,6 +112,7 @@ mod gradient;
mod length;
mod marker;
mod node;
+mod paint_server;
mod parsers;
mod path_builder;
mod path_parser;
diff --git a/rust/src/paint_server.rs b/rust/src/paint_server.rs
new file mode 100644
index 0000000..ecdb216
--- /dev/null
+++ b/rust/src/paint_server.rs
@@ -0,0 +1,42 @@
+use std::str::FromStr;
+
+use parsers::ParseError;
+
+/// Defines the units to be used for scaling paint servers, per the [svg specification].
+///
+/// [svg spec]: https://www.w3.org/TR/SVG/pservers.html
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
+pub enum PaintServerUnits {
+ UserSpaceOnUse,
+ ObjectBoundingBox
+}
+
+impl FromStr for PaintServerUnits {
+ type Err = ParseError;
+
+ fn from_str (s: &str) -> Result<PaintServerUnits, ParseError> {
+ match s {
+ "userSpaceOnUse" => Ok (PaintServerUnits::UserSpaceOnUse),
+ "objectBoundingBox" => Ok (PaintServerUnits::ObjectBoundingBox),
+ _ => Err (ParseError::new ("expected 'userSpaceOnUse' or 'objectBoundingBox'"))
+ }
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use std::str::FromStr;
+
+ #[test]
+ fn parsing_invalid_strings_yields_error () {
+ assert! (PaintServerUnits::from_str ("").is_err ());
+ assert! (PaintServerUnits::from_str ("foo").is_err ());
+ }
+
+ #[test]
+ fn parses_paint_server_units () {
+ assert_eq! (PaintServerUnits::from_str ("userSpaceOnUse"), Ok (PaintServerUnits::UserSpaceOnUse));
+ assert_eq! (PaintServerUnits::from_str ("objectBoundingBox"), Ok
(PaintServerUnits::ObjectBoundingBox));
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]