[librsvg/wip/euclid] Use Transform in more places



commit ad4b0ea0c0fdca21443108e2474cd01ef5545b78
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Dec 1 19:00:08 2019 +0100

    Use Transform in more places

 rsvg_internals/src/filter.rs          |  7 +++--
 rsvg_internals/src/filters/bounds.rs  |  9 +++---
 rsvg_internals/src/filters/context.rs | 53 +++++++++++++++++------------------
 rsvg_internals/src/gradient.rs        |  9 +++---
 rsvg_internals/src/marker.rs          |  8 +++---
 rsvg_internals/src/pattern.rs         | 10 +++----
 6 files changed, 47 insertions(+), 49 deletions(-)
---
diff --git a/rsvg_internals/src/filter.rs b/rsvg_internals/src/filter.rs
index a1494fe4..175c336d 100644
--- a/rsvg_internals/src/filter.rs
+++ b/rsvg_internals/src/filter.rs
@@ -10,6 +10,7 @@ use crate::node::{NodeResult, NodeTrait, RsvgNode};
 use crate::parsers::{Parse, ParseError, ParseValue};
 use crate::properties::ComputedValues;
 use crate::property_bag::PropertyBag;
+use crate::transform::Transform;
 
 /// The <filter> node.
 pub struct Filter {
@@ -49,14 +50,14 @@ impl Filter {
         &self,
         computed_from_target_node: &ComputedValues,
         draw_ctx: &mut DrawingCtx,
-        affine: cairo::Matrix,
+        affine: Transform,
         width: f64,
         height: f64,
     ) -> BoundingBox {
         // Filters use the properties of the target node.
         let values = computed_from_target_node;
 
-        let mut bbox = BoundingBox::new(&cairo::Matrix::identity());
+        let mut bbox = BoundingBox::new(&Transform::identity());
 
         // affine is set up in FilterContext::new() in such a way that for
         // filterunits == ObjectBoundingBox affine includes scaling to correct width, height and
@@ -104,7 +105,7 @@ impl Filter {
             width,
             height,
         };
-        let other_bbox = BoundingBox::new(&cairo::Matrix::identity()).with_rect(Some(rect));
+        let other_bbox = BoundingBox::new(&Transform::identity()).with_rect(Some(rect));
         bbox.clip(&other_bbox);
 
         bbox
diff --git a/rsvg_internals/src/filters/bounds.rs b/rsvg_internals/src/filters/bounds.rs
index 10094f9d..754a48d1 100644
--- a/rsvg_internals/src/filters/bounds.rs
+++ b/rsvg_internals/src/filters/bounds.rs
@@ -1,10 +1,9 @@
 //! Filter primitive subregion computation.
-use cairo;
-
 use crate::bbox::BoundingBox;
 use crate::drawing_ctx::DrawingCtx;
 use crate::length::*;
 use crate::rect::IRect;
+use crate::transform::Transform;
 
 use super::context::{FilterContext, FilterInput};
 
@@ -64,8 +63,8 @@ impl<'a> BoundsBuilder<'a> {
                 self.standard_input_was_referenced = true;
             }
             FilterInput::PrimitiveOutput(ref output) => {
-                let input_bbox = BoundingBox::new(&cairo::Matrix::identity())
-                    .with_rect(Some(output.bounds.into()));
+                let input_bbox =
+                    BoundingBox::new(&Transform::identity()).with_rect(Some(output.bounds.into()));
                 self.bbox.insert(&input_bbox);
             }
         }
@@ -128,7 +127,7 @@ impl<'a> BoundsBuilder<'a> {
         }
 
         // Convert into the surface coordinate system.
-        let mut bbox = BoundingBox::new(&cairo::Matrix::identity());
+        let mut bbox = BoundingBox::new(&Transform::identity());
         bbox.insert(&self.bbox);
         bbox
     }
diff --git a/rsvg_internals/src/filters/context.rs b/rsvg_internals/src/filters/context.rs
index 1dd8a886..364c3447 100644
--- a/rsvg_internals/src/filters/context.rs
+++ b/rsvg_internals/src/filters/context.rs
@@ -13,6 +13,7 @@ use crate::paint_server::PaintServer;
 use crate::properties::ComputedValues;
 use crate::rect::IRect;
 use crate::surface_utils::shared_surface::{SharedImageSurface, SurfaceType};
+use crate::transform::{Transform, TransformExt};
 use crate::unit_interval::UnitInterval;
 
 use super::error::FilterError;
@@ -86,12 +87,12 @@ pub struct FilterContext {
     /// This is to be used in conjunction with setting the viewbox size to account for the scaling.
     /// For `filterUnits == userSpaceOnUse`, the viewbox will have the actual resolution size, and
     /// for `filterUnits == objectBoundingBox`, the viewbox will have the size of 1, 1.
-    _affine: cairo::Matrix,
+    _affine: Transform,
 
     /// The filter primitive affine matrix.
     ///
     /// See the comments for `_affine`, they largely apply here.
-    paffine: cairo::Matrix,
+    paffine: Transform,
 }
 
 impl FilterContext {
@@ -119,32 +120,26 @@ impl FilterContext {
 
         let affine = match filter.get_filter_units() {
             CoordUnits::UserSpaceOnUse => cr_affine,
-            CoordUnits::ObjectBoundingBox => {
-                let affine = cairo::Matrix::new(
-                    bbox_rect.width,
-                    0f64,
-                    0f64,
-                    bbox_rect.height,
-                    bbox_rect.x,
-                    bbox_rect.y,
-                );
-                cairo::Matrix::multiply(&affine, &cr_affine)
-            }
+            CoordUnits::ObjectBoundingBox => cr_affine.pre_transform(&Transform::new(
+                bbox_rect.width,
+                0.0,
+                0.0,
+                bbox_rect.height,
+                bbox_rect.x,
+                bbox_rect.y,
+            )),
         };
 
         let paffine = match filter.get_primitive_units() {
             CoordUnits::UserSpaceOnUse => cr_affine,
-            CoordUnits::ObjectBoundingBox => {
-                let affine = cairo::Matrix::new(
-                    bbox_rect.width,
-                    0f64,
-                    0f64,
-                    bbox_rect.height,
-                    bbox_rect.x,
-                    bbox_rect.y,
-                );
-                cairo::Matrix::multiply(&affine, &cr_affine)
-            }
+            CoordUnits::ObjectBoundingBox => cr_affine.pre_transform(&Transform::new(
+                bbox_rect.width,
+                0.0,
+                0.0,
+                bbox_rect.height,
+                bbox_rect.x,
+                bbox_rect.y,
+            )),
         };
 
         let width = source_surface.width();
@@ -232,7 +227,11 @@ impl FilterContext {
         );
 
         // Return the only existing reference as immutable.
-        bg.as_ref().unwrap().as_ref().map(|surf| surf.clone()).map_err(|&s| s)
+        bg.as_ref()
+            .unwrap()
+            .as_ref()
+            .map(|surf| surf.clone())
+            .map_err(|&s| s)
     }
 
     /// Returns the surface containing the background image snapshot alpha.
@@ -288,9 +287,9 @@ impl FilterContext {
         Ok(())
     }
 
-    /// Returns the paffine matrix.
+    /// Returns the paffine transform.
     #[inline]
-    pub fn paffine(&self) -> cairo::Matrix {
+    pub fn paffine(&self) -> Transform {
         self.paffine
     }
 
diff --git a/rsvg_internals/src/gradient.rs b/rsvg_internals/src/gradient.rs
index e30ad815..e73f2b2b 100644
--- a/rsvg_internals/src/gradient.rs
+++ b/rsvg_internals/src/gradient.rs
@@ -16,6 +16,7 @@ use crate::properties::ComputedValues;
 use crate::property_bag::PropertyBag;
 use crate::property_defs::StopColor;
 use crate::rect::RectangleExt;
+use crate::transform::Transform;
 use crate::unit_interval::UnitInterval;
 
 /// Contents of a <stop> element for gradient color stops
@@ -316,7 +317,7 @@ impl Variant {
 #[derive(Default)]
 struct Common {
     units: Option<GradientUnits>,
-    affine: Option<cairo::Matrix>,
+    affine: Option<Transform>,
     spread: Option<SpreadMethod>,
 
     fallback: Option<Fragment>,
@@ -353,7 +354,7 @@ pub struct RadialGradient {
 /// field was specified.
 struct UnresolvedGradient {
     units: Option<GradientUnits>,
-    affine: Option<cairo::Matrix>,
+    affine: Option<Transform>,
     spread: Option<SpreadMethod>,
     stops: Option<Vec<ColorStop>>,
 
@@ -364,7 +365,7 @@ struct UnresolvedGradient {
 #[derive(Clone)]
 pub struct Gradient {
     units: GradientUnits,
-    affine: cairo::Matrix,
+    affine: Transform,
     spread: SpreadMethod,
     stops: Vec<ColorStop>,
 
@@ -489,7 +490,7 @@ impl UnresolvedGradient {
 
     fn resolve_from_defaults(&self) -> UnresolvedGradient {
         let units = self.units.or_else(|| Some(GradientUnits::default()));
-        let affine = self.affine.or_else(|| Some(cairo::Matrix::identity()));
+        let affine = self.affine.or_else(|| Some(Transform::identity()));
         let spread = self.spread.or_else(|| Some(SpreadMethod::default()));
         let stops = self.stops.clone().or_else(|| Some(Vec::<ColorStop>::new()));
         let variant = self.variant.resolve_from_defaults();
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index 1dbc41b7..a34b25cc 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -1143,14 +1143,14 @@ mod marker_tests {
 
         assert!(emit_markers_for_path_builder(
             &builder,
-            BoundingBox::new(&cairo::Matrix::identity()),
+            BoundingBox::new(&Transform::identity()),
             &mut |marker_type: MarkerType,
                   x: f64,
                   y: f64,
                   computed_angle: Angle|
              -> Result<BoundingBox, RenderingError> {
                 v.push((marker_type, x, y, computed_angle));
-                Ok(BoundingBox::new(&cairo::Matrix::identity()))
+                Ok(BoundingBox::new(&Transform::identity()))
             }
         )
         .is_ok());
@@ -1179,14 +1179,14 @@ mod marker_tests {
 
         assert!(emit_markers_for_path_builder(
             &builder,
-            BoundingBox::new(&cairo::Matrix::identity()),
+            BoundingBox::new(&Transform::identity()),
             &mut |marker_type: MarkerType,
                   x: f64,
                   y: f64,
                   computed_angle: Angle|
              -> Result<BoundingBox, RenderingError> {
                 v.push((marker_type, x, y, computed_angle));
-                Ok(BoundingBox::new(&cairo::Matrix::identity()))
+                Ok(BoundingBox::new(&Transform::identity()))
             }
         )
         .is_ok());
diff --git a/rsvg_internals/src/pattern.rs b/rsvg_internals/src/pattern.rs
index f4383700..89fca26d 100644
--- a/rsvg_internals/src/pattern.rs
+++ b/rsvg_internals/src/pattern.rs
@@ -17,6 +17,7 @@ use crate::parsers::ParseValue;
 use crate::properties::ComputedValues;
 use crate::property_bag::PropertyBag;
 use crate::rect::RectangleExt;
+use crate::transform::Transform;
 use crate::unit_interval::UnitInterval;
 use crate::viewbox::*;
 
@@ -33,7 +34,7 @@ struct Common {
     // In that case, the fully resolved pattern will have a .vbox=Some(None) value.
     vbox: Option<Option<ViewBox>>,
     preserve_aspect_ratio: Option<AspectRatio>,
-    affine: Option<cairo::Matrix>,
+    affine: Option<Transform>,
     x: Option<Length<Horizontal>>,
     y: Option<Length<Vertical>>,
     width: Option<Length<Horizontal>>,
@@ -97,7 +98,7 @@ pub struct ResolvedPattern {
     // In that case, the fully resolved pattern will have a .vbox=Some(None) value.
     vbox: Option<ViewBox>,
     preserve_aspect_ratio: AspectRatio,
-    affine: cairo::Matrix,
+    affine: Transform,
     x: Length<Horizontal>,
     y: Length<Vertical>,
     width: Length<Horizontal>,
@@ -475,10 +476,7 @@ impl UnresolvedPattern {
             .common
             .preserve_aspect_ratio
             .or_else(|| Some(AspectRatio::default()));
-        let affine = self
-            .common
-            .affine
-            .or_else(|| Some(cairo::Matrix::identity()));
+        let affine = self.common.affine.or_else(|| Some(Transform::identity()));
         let x = self.common.x.or_else(|| Some(Default::default()));
         let y = self.common.y.or_else(|| Some(Default::default()));
         let width = self.common.width.or_else(|| Some(Default::default()));


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