[librsvg] Rename PaintServerUnits to CoordUnits



commit a30570a8cefa37d61c0fbee99e3b85f0b745bea6
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Nov 30 20:37:59 2017 -0600

    Rename PaintServerUnits to CoordUnits

 rust/src/clip_path.rs    |    6 +++---
 rust/src/gradient.rs     |   14 +++++++-------
 rust/src/paint_server.rs |   26 ++++++++++++++------------
 rust/src/pattern.rs      |   30 +++++++++++++++---------------
 4 files changed, 39 insertions(+), 37 deletions(-)
---
diff --git a/rust/src/clip_path.rs b/rust/src/clip_path.rs
index 039f6c7..6f7a819 100644
--- a/rust/src/clip_path.rs
+++ b/rust/src/clip_path.rs
@@ -4,7 +4,7 @@ use std::cell::Cell;
 use drawing_ctx::RsvgDrawingCtx;
 use handle::RsvgHandle;
 use node::{NodeResult, NodeTrait, NodeType, RsvgCNodeImpl, RsvgNode, boxed_node_new};
-use paint_server::PaintServerUnits;
+use paint_server::CoordUnits;
 use pattern::PatternContentUnits;
 use property_bag::{self, RsvgPropertyBag};
 
@@ -17,7 +17,7 @@ struct NodeClipPath {
 impl NodeClipPath {
     fn new() -> NodeClipPath {
         NodeClipPath {
-            units: Cell::new(PatternContentUnits::from(PaintServerUnits::UserSpaceOnUse))
+            units: Cell::new(PatternContentUnits::from(CoordUnits::UserSpaceOnUse))
         }
     }
 }
@@ -46,7 +46,7 @@ pub extern fn rsvg_node_clip_path_new(_: *const libc::c_char, raw_parent: *const
 }
 
 #[no_mangle]
-pub extern fn rsvg_node_clip_path_get_units(raw_node: *const RsvgNode) -> PaintServerUnits {
+pub extern fn rsvg_node_clip_path_get_units(raw_node: *const RsvgNode) -> CoordUnits {
     assert! (!raw_node.is_null ());
     let node: &RsvgNode = unsafe { & *raw_node };
 
diff --git a/rust/src/gradient.rs b/rust/src/gradient.rs
index e02b248..d4fa8e3 100644
--- a/rust/src/gradient.rs
+++ b/rust/src/gradient.rs
@@ -33,7 +33,7 @@ pub struct ColorStop {
  */
 #[derive(Clone)]
 pub struct GradientCommon {
-    pub units:    Option<PaintServerUnits>,
+    pub units:    Option<CoordUnits>,
     pub affine:   Option<cairo::Matrix>,
     pub spread:   Option<PaintServerSpread>,
     pub fallback: Option<String>,
@@ -118,7 +118,7 @@ impl GradientCommon {
     fn resolve_from_defaults (&mut self) {
         /* These are per the spec */
 
-        fallback_to! (self.units,  Some (PaintServerUnits::default ()));
+        fallback_to! (self.units,  Some (CoordUnits::default ()));
         fallback_to! (self.affine, Some (cairo::Matrix::identity ()));
         fallback_to! (self.spread, Some (PaintServerSpread::default ()));
         fallback_to! (self.stops,  Some (Vec::<ColorStop>::new ())); // empty array of color stops
@@ -362,7 +362,7 @@ fn set_common_on_pattern<P: cairo::Pattern + cairo::Gradient> (gradient: &Gradie
 
     let units = gradient.common.units.unwrap ();
 
-    if units == PaintServerUnits::ObjectBoundingBox {
+    if units == CoordUnits::ObjectBoundingBox {
         let bbox_matrix = cairo::Matrix::new (bbox.rect.width, 0.0,
                                               0.0, bbox.rect.height,
                                               bbox.rect.x, bbox.rect.y);
@@ -385,7 +385,7 @@ fn set_linear_gradient_on_pattern (gradient: &Gradient,
     if let GradientVariant::Linear { x1, y1, x2, y2 } = gradient.variant {
         let units = gradient.common.units.unwrap ();
 
-        if units == PaintServerUnits::ObjectBoundingBox {
+        if units == CoordUnits::ObjectBoundingBox {
             drawing_ctx::push_view_box (draw_ctx, 1.0, 1.0);
         }
 
@@ -394,7 +394,7 @@ fn set_linear_gradient_on_pattern (gradient: &Gradient,
                                                       x2.as_ref ().unwrap ().normalize (draw_ctx),
                                                       y2.as_ref ().unwrap ().normalize (draw_ctx));
 
-        if units == PaintServerUnits::ObjectBoundingBox {
+        if units == CoordUnits::ObjectBoundingBox {
             drawing_ctx::pop_view_box (draw_ctx);
         }
 
@@ -467,7 +467,7 @@ fn set_radial_gradient_on_pattern (gradient: &Gradient,
     if let GradientVariant::Radial { cx, cy, r, fx, fy } = gradient.variant {
         let units = gradient.common.units.unwrap ();
 
-        if units == PaintServerUnits::ObjectBoundingBox {
+        if units == CoordUnits::ObjectBoundingBox {
             drawing_ctx::push_view_box (draw_ctx, 1.0, 1.0);
         }
 
@@ -481,7 +481,7 @@ fn set_radial_gradient_on_pattern (gradient: &Gradient,
 
         let mut pattern = cairo::RadialGradient::new (new_fx, new_fy, 0.0, n_cx, n_cy, n_r);
 
-        if units == PaintServerUnits::ObjectBoundingBox {
+        if units == CoordUnits::ObjectBoundingBox {
             drawing_ctx::pop_view_box (draw_ctx);
         }
 
diff --git a/rust/src/paint_server.rs b/rust/src/paint_server.rs
index 6d2808c..10f4d8b 100644
--- a/rust/src/paint_server.rs
+++ b/rust/src/paint_server.rs
@@ -7,29 +7,31 @@ 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
+///
+/// Keep in sync with rsvg-private.h:RsvgCoordUnits
 #[repr(C)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq)]
-pub enum PaintServerUnits {
+pub enum CoordUnits {
     UserSpaceOnUse,
     ObjectBoundingBox
 }
 
-impl Parse for PaintServerUnits {
+impl Parse for CoordUnits {
     type Data = ();
     type Err = AttributeError;
 
-    fn parse (s: &str, _: ()) -> Result<PaintServerUnits, AttributeError> {
+    fn parse (s: &str, _: ()) -> Result<CoordUnits, AttributeError> {
         match s {
-            "userSpaceOnUse"    => Ok (PaintServerUnits::UserSpaceOnUse),
-            "objectBoundingBox" => Ok (PaintServerUnits::ObjectBoundingBox),
+            "userSpaceOnUse"    => Ok (CoordUnits::UserSpaceOnUse),
+            "objectBoundingBox" => Ok (CoordUnits::ObjectBoundingBox),
             _                   => Err (AttributeError::Parse (ParseError::new ("expected 'userSpaceOnUse' 
or 'objectBoundingBox'")))
         }
     }
 }
 
-impl Default for PaintServerUnits {
-    fn default () -> PaintServerUnits {
-        PaintServerUnits::ObjectBoundingBox
+impl Default for CoordUnits {
+    fn default () -> CoordUnits {
+        CoordUnits::ObjectBoundingBox
     }
 }
 
@@ -62,14 +64,14 @@ mod tests {
 
     #[test]
     fn parsing_invalid_strings_yields_error () {
-        assert! (PaintServerUnits::parse ("", ()).is_err ());
-        assert! (PaintServerUnits::parse ("foo", ()).is_err ());
+        assert! (CoordUnits::parse ("", ()).is_err ());
+        assert! (CoordUnits::parse ("foo", ()).is_err ());
     }
 
     #[test]
     fn parses_paint_server_units () {
-        assert_eq! (PaintServerUnits::parse ("userSpaceOnUse", ()), Ok (PaintServerUnits::UserSpaceOnUse));
-        assert_eq! (PaintServerUnits::parse ("objectBoundingBox", ()), Ok 
(PaintServerUnits::ObjectBoundingBox));
+        assert_eq! (CoordUnits::parse ("userSpaceOnUse", ()), Ok (CoordUnits::UserSpaceOnUse));
+        assert_eq! (CoordUnits::parse ("objectBoundingBox", ()), Ok (CoordUnits::ObjectBoundingBox));
     }
 
     #[test]
diff --git a/rust/src/pattern.rs b/rust/src/pattern.rs
index 9978a7d..79ce689 100644
--- a/rust/src/pattern.rs
+++ b/rust/src/pattern.rs
@@ -26,7 +26,7 @@ use viewbox::*;
 
 #[derive(Clone)]
 pub struct Pattern {
-    pub units:                 Option<PaintServerUnits>,
+    pub units:                 Option<CoordUnits>,
     pub content_units:         Option<PatternContentUnits>,
     // This Option<Option<ViewBox>> is a bit strange.  We want a field
     // with value None to mean, "this field isn't resolved yet".  However,
@@ -67,19 +67,19 @@ impl Default for Pattern {
 // system relative to the x/y/width/height of the Pattern.  However, patterns also
 // have a patternContentUnits attribute, which refers to the pattern's contents (i.e. the
 // objects which it references.  We define PatternContentUnits as a newtype, so that
-// it can have its own default value, different from the one in PaintServerUnits.
+// it can have its own default value, different from the one in CoordUnits.
 #[derive(Debug, Copy, Clone, PartialEq, Eq)]
-pub struct PatternContentUnits(pub PaintServerUnits);
+pub struct PatternContentUnits(pub CoordUnits);
 
-impl From<PaintServerUnits> for PatternContentUnits {
-    fn from (units: PaintServerUnits) -> PatternContentUnits {
+impl From<CoordUnits> for PatternContentUnits {
+    fn from (units: CoordUnits) -> PatternContentUnits {
         PatternContentUnits(units)
     }
 }
 
 impl Default for PatternContentUnits {
     fn default () -> PatternContentUnits {
-        PatternContentUnits (PaintServerUnits::UserSpaceOnUse)
+        PatternContentUnits (CoordUnits::UserSpaceOnUse)
     }
 }
 
@@ -88,7 +88,7 @@ impl Parse for PatternContentUnits {
     type Err = AttributeError;
 
     fn parse (s: &str, _: ()) -> Result<PatternContentUnits, AttributeError> {
-        Ok (PatternContentUnits::from (PaintServerUnits::parse (s, ())?))
+        Ok (PatternContentUnits::from (CoordUnits::parse (s, ())?))
     }
 }
 
@@ -144,7 +144,7 @@ impl Pattern {
     fn resolve_from_defaults (&mut self) {
         /* These are per the spec */
 
-        fallback_to! (self.units,                 Some (PaintServerUnits::default ()));
+        fallback_to! (self.units,                 Some (CoordUnits::default ()));
         fallback_to! (self.content_units,         Some (PatternContentUnits::default ()));
         fallback_to! (self.vbox,                  Some (None));
         fallback_to! (self.preserve_aspect_ratio, Some (AspectRatio::default ()));
@@ -305,7 +305,7 @@ fn set_pattern_on_draw_context (pattern: &Pattern,
     let vbox                  = pattern.vbox.unwrap ();
     let preserve_aspect_ratio = pattern.preserve_aspect_ratio.unwrap ();
 
-    if units == PaintServerUnits::ObjectBoundingBox {
+    if units == CoordUnits::ObjectBoundingBox {
         drawing_ctx::push_view_box (draw_ctx, 1.0, 1.0);
     }
 
@@ -314,7 +314,7 @@ fn set_pattern_on_draw_context (pattern: &Pattern,
     let pattern_width  = pattern.width.unwrap ().normalize (draw_ctx);
     let pattern_height = pattern.height.unwrap ().normalize (draw_ctx);
 
-    if units == PaintServerUnits::ObjectBoundingBox {
+    if units == CoordUnits::ObjectBoundingBox {
         drawing_ctx::pop_view_box (draw_ctx);
     }
 
@@ -324,12 +324,12 @@ fn set_pattern_on_draw_context (pattern: &Pattern,
     let bbhscale: f64;
 
     match units {
-        PaintServerUnits::ObjectBoundingBox => {
+        CoordUnits::ObjectBoundingBox => {
             bbwscale = bbox.rect.width;
             bbhscale = bbox.rect.height;
         },
 
-        PaintServerUnits::UserSpaceOnUse => {
+        CoordUnits::UserSpaceOnUse => {
             bbwscale = 1.0;
             bbhscale = 1.0;
         }
@@ -358,12 +358,12 @@ fn set_pattern_on_draw_context (pattern: &Pattern,
 
     // Create the pattern coordinate system
     match units {
-        PaintServerUnits::ObjectBoundingBox => {
+        CoordUnits::ObjectBoundingBox => {
             affine.translate (bbox.rect.x + pattern_x * bbox.rect.width,
                               bbox.rect.y + pattern_y * bbox.rect.height);
         },
 
-        PaintServerUnits::UserSpaceOnUse => {
+        CoordUnits::UserSpaceOnUse => {
             affine.translate (pattern_x, pattern_y);
         }
     }
@@ -397,7 +397,7 @@ fn set_pattern_on_draw_context (pattern: &Pattern,
 
         drawing_ctx::push_view_box (draw_ctx, vbox.0.width, vbox.0.height);
         pushed_view_box = true;
-    } else if content_units == PatternContentUnits (PaintServerUnits::ObjectBoundingBox) {
+    } else if content_units == PatternContentUnits (CoordUnits::ObjectBoundingBox) {
         // If coords are in terms of the bounding box, use them
 
         caffine = cairo::Matrix::identity ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]