[librsvg] Replace FilterContext::with_primitive_units() by a get_view_params()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Replace FilterContext::with_primitive_units() by a get_view_params()
- Date: Tue, 22 Jan 2019 01:48:11 +0000 (UTC)
commit bbb1e285208a04ddf2df14c2dbc23f70a186f3e8
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Jan 21 17:09:28 2019 -0600
Replace FilterContext::with_primitive_units() by a get_view_params()
Similar to the function from DrawingCtx; hopefully this is more legible.
rsvg_internals/src/filters/bounds.rs | 37 ++++++++++++++++++-----------------
rsvg_internals/src/filters/context.rs | 28 +++++++++-----------------
2 files changed, 28 insertions(+), 37 deletions(-)
---
diff --git a/rsvg_internals/src/filters/bounds.rs b/rsvg_internals/src/filters/bounds.rs
index 94a3c305..685fbeba 100644
--- a/rsvg_internals/src/filters/bounds.rs
+++ b/rsvg_internals/src/filters/bounds.rs
@@ -115,24 +115,25 @@ impl<'a> BoundsBuilder<'a> {
// If any of the properties were specified, we need to respect them.
if self.x.is_some() || self.y.is_some() || self.width.is_some() || self.height.is_some() {
- self.ctx.with_primitive_units(draw_ctx, |normalize| {
- // These replacements are correct only because self.bbox is used with the paffine
- // matrix.
- let rect = self.bbox.rect.as_mut().unwrap();
-
- if let Some(x) = self.x {
- rect.x = normalize(&x);
- }
- if let Some(y) = self.y {
- rect.y = normalize(&y);
- }
- if let Some(width) = self.width {
- rect.width = normalize(&width);
- }
- if let Some(height) = self.height {
- rect.height = normalize(&height);
- }
- });
+ let params = self.ctx.get_view_params(draw_ctx);
+ let values = self.ctx.get_computed_values_from_node_being_filtered();
+
+ // These replacements are correct only because self.bbox is used with the paffine
+ // matrix.
+ let rect = self.bbox.rect.as_mut().unwrap();
+
+ if let Some(x) = self.x {
+ rect.x = x.normalize(values, ¶ms);
+ }
+ if let Some(y) = self.y {
+ rect.y = y.normalize(values, ¶ms);
+ }
+ if let Some(width) = self.width {
+ rect.width = width.normalize(values, ¶ms);
+ }
+ if let Some(height) = self.height {
+ rect.height = height.normalize(values, ¶ms);
+ }
}
// Convert into the surface coordinate system.
diff --git a/rsvg_internals/src/filters/context.rs b/rsvg_internals/src/filters/context.rs
index 92e8479b..ab063d5e 100644
--- a/rsvg_internals/src/filters/context.rs
+++ b/rsvg_internals/src/filters/context.rs
@@ -6,8 +6,7 @@ use cairo::{self, MatrixTrait};
use bbox::BoundingBox;
use coord_units::CoordUnits;
-use drawing_ctx::DrawingCtx;
-use length::Length;
+use drawing_ctx::{DrawingCtx, ViewParams};
use node::RsvgNode;
use paint_server::PaintServer;
use properties::ComputedValues;
@@ -366,28 +365,19 @@ impl FilterContext {
self.effects_region
}
- /// Calls the given function with correct behavior for the value of `primitiveUnits`.
- pub fn with_primitive_units<F, T>(&self, draw_ctx: &mut DrawingCtx, f: F) -> T
- // TODO: Get rid of this Box? Can't just impl Trait because Rust cannot do higher-ranked types.
- where
- for<'b> F: FnOnce(Box<Fn(&Length) -> f64 + 'b>) -> T,
- {
+ pub fn get_computed_from_node_being_filtered(&self) -> &ComputedValues {
+ &self.computed_from_node_being_filtered
+ }
+
+ /// Pushes the viewport size based on the value of `primitiveUnits`.
+ pub fn get_view_params(&self, draw_ctx: &mut DrawingCtx) -> ViewParams {
let filter = self.node.get_impl::<NodeFilter>().unwrap();
// See comments in compute_effects_region() for how this works.
if filter.primitiveunits.get() == CoordUnits::ObjectBoundingBox {
- let _params = draw_ctx.push_view_box(1.0, 1.0);
- let rv = f(Box::new(Length::get_unitless));
-
- rv
+ draw_ctx.push_view_box(1.0, 1.0)
} else {
- f(Box::new(|length: &Length| {
- // Filters use the properties of the target node.
- length.normalize(
- &self.computed_from_node_being_filtered,
- &draw_ctx.get_view_params(),
- )
- }))
+ draw_ctx.get_view_params()
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]