[librsvg: 2/3] bbox: tweak construction API
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/3] bbox: tweak construction API
- Date: Fri, 27 Dec 2019 04:20:35 +0000 (UTC)
commit f5f4a100fa6dd86676366ebfd7b156834e09263c
Author: Paolo Borelli <pborelli gnome org>
Date: Thu Dec 26 21:31:33 2019 +0100
bbox: tweak construction API
Construct bbox with an identity matrix by default since
that is a common case.
rsvg_internals/src/bbox.rs | 8 ++++++--
rsvg_internals/src/drawing_ctx.rs | 20 +++++++++++++-------
rsvg_internals/src/filter.rs | 6 +++---
rsvg_internals/src/filters/bounds.rs | 9 +++------
rsvg_internals/src/marker.rs | 8 ++++----
rsvg_internals/src/text.rs | 11 +++++++----
6 files changed, 36 insertions(+), 26 deletions(-)
---
diff --git a/rsvg_internals/src/bbox.rs b/rsvg_internals/src/bbox.rs
index 85238e9d..c62e4011 100644
--- a/rsvg_internals/src/bbox.rs
+++ b/rsvg_internals/src/bbox.rs
@@ -12,14 +12,18 @@ pub struct BoundingBox {
}
impl BoundingBox {
- pub fn new(affine: &cairo::Matrix) -> BoundingBox {
+ pub fn new() -> BoundingBox {
BoundingBox {
- affine: *affine,
+ affine: cairo::Matrix::identity(),
rect: None,
ink_rect: None,
}
}
+ pub fn with_affine(self, affine: cairo::Matrix) -> BoundingBox {
+ BoundingBox { affine, ..self }
+ }
+
pub fn with_rect(self, rect: Rect) -> BoundingBox {
BoundingBox {
rect: Some(rect),
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index e6fa8846..faeecd57 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -186,7 +186,7 @@ impl DrawingCtx {
}
pub fn empty_bbox(&self) -> BoundingBox {
- BoundingBox::new(&self.cr.get_matrix())
+ BoundingBox::new().with_affine(self.cr.get_matrix())
}
// FIXME: Usage of this function is more less a hack... The caller
@@ -454,7 +454,7 @@ impl DrawingCtx {
let bbox = if let Ok(ref bbox) = res {
*bbox
} else {
- BoundingBox::new(&affines.for_temporary_surface)
+ BoundingBox::new().with_affine(affines.for_temporary_surface)
};
// Filter
@@ -556,7 +556,7 @@ impl DrawingCtx {
self.cr.set_matrix(matrix);
if let Ok(bbox) = res {
- let mut orig_matrix_bbox = BoundingBox::new(&matrix);
+ let mut orig_matrix_bbox = BoundingBox::new().with_affine(matrix);
orig_matrix_bbox.insert(&bbox);
Ok(orig_matrix_bbox)
} else {
@@ -947,7 +947,7 @@ impl CompositingAffines {
fn compute_stroke_and_fill_box(cr: &cairo::Context, values: &ComputedValues) -> BoundingBox {
let affine = cr.get_matrix();
- let mut bbox = BoundingBox::new(&affine);
+ let mut bbox = BoundingBox::new().with_affine(affine);
// Dropping the precision of cairo's bezier subdivision, yielding 2x
// _rendering_ time speedups, are these rather expensive operations
@@ -964,21 +964,27 @@ fn compute_stroke_and_fill_box(cr: &cairo::Context, values: &ComputedValues) ->
// rectangle's extents, even when it has no fill nor stroke.
let (x0, y0, x1, y1) = cr.fill_extents();
- let fb = BoundingBox::new(&affine).with_ink_rect(Rect::new(x0, y0, x1, y1));
+ let fb = BoundingBox::new()
+ .with_affine(affine)
+ .with_ink_rect(Rect::new(x0, y0, x1, y1));
bbox.insert(&fb);
// Bounding box for stroke
if values.stroke.0 != PaintServer::None {
let (x0, y0, x1, y1) = cr.stroke_extents();
- let sb = BoundingBox::new(&affine).with_ink_rect(Rect::new(x0, y0, x1, y1));
+ let sb = BoundingBox::new()
+ .with_affine(affine)
+ .with_ink_rect(Rect::new(x0, y0, x1, y1));
bbox.insert(&sb);
}
// objectBoundingBox
let (x0, y0, x1, y1) = cr.path_extents();
- let ob = BoundingBox::new(&affine).with_rect(Rect::new(x0, y0, x1, y1));
+ let ob = BoundingBox::new()
+ .with_affine(affine)
+ .with_rect(Rect::new(x0, y0, x1, y1));
bbox.insert(&ob);
// restore tolerance
diff --git a/rsvg_internals/src/filter.rs b/rsvg_internals/src/filter.rs
index 16e813e7..0b18310b 100644
--- a/rsvg_internals/src/filter.rs
+++ b/rsvg_internals/src/filter.rs
@@ -59,7 +59,7 @@ impl Filter {
// 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();
// affine is set up in FilterContext::new() in such a way that for
// filterunits == ObjectBoundingBox affine includes scaling to correct width, height and
@@ -95,7 +95,7 @@ impl Filter {
};
let rect = Rect::new(x, y, x + w, y + h);
- let other_bbox = BoundingBox::new(&affine).with_rect(rect);
+ let other_bbox = BoundingBox::new().with_affine(affine).with_rect(rect);
// At this point all of the previous viewbox and matrix business gets converted to pixel
// coordinates in the final surface, because bbox is created with an identity affine.
@@ -103,7 +103,7 @@ impl Filter {
// Finally, clip to the width and height of our surface.
let rect = Rect::from_size(width, height);
- let other_bbox = BoundingBox::new(&cairo::Matrix::identity()).with_rect(rect);
+ let other_bbox = BoundingBox::new().with_rect(rect);
bbox.clip(&other_bbox);
bbox
diff --git a/rsvg_internals/src/filters/bounds.rs b/rsvg_internals/src/filters/bounds.rs
index bc26962e..2c3e57b3 100644
--- a/rsvg_internals/src/filters/bounds.rs
+++ b/rsvg_internals/src/filters/bounds.rs
@@ -1,6 +1,4 @@
//! Filter primitive subregion computation.
-use cairo;
-
use crate::bbox::BoundingBox;
use crate::drawing_ctx::DrawingCtx;
use crate::length::*;
@@ -40,7 +38,7 @@ impl<'a> BoundsBuilder<'a> {
Self {
ctx,
// The matrix is paffine because we're using that fact in apply_properties().
- bbox: BoundingBox::new(&ctx.paffine()),
+ bbox: BoundingBox::new().with_affine(ctx.paffine()),
standard_input_was_referenced: false,
x,
y,
@@ -64,8 +62,7 @@ impl<'a> BoundsBuilder<'a> {
self.standard_input_was_referenced = true;
}
FilterInput::PrimitiveOutput(ref output) => {
- let input_bbox =
- BoundingBox::new(&cairo::Matrix::identity()).with_rect(output.bounds.into());
+ let input_bbox = BoundingBox::new().with_rect(output.bounds.into());
self.bbox.insert(&input_bbox);
}
}
@@ -136,7 +133,7 @@ impl<'a> BoundsBuilder<'a> {
}
// Convert into the surface coordinate system.
- let mut bbox = BoundingBox::new(&cairo::Matrix::identity());
+ let mut bbox = BoundingBox::new();
bbox.insert(&self.bbox);
bbox
}
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index fe903137..05e7c17d 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -1120,14 +1120,14 @@ mod marker_tests {
assert!(emit_markers_for_path_builder(
&builder,
- BoundingBox::new(&cairo::Matrix::identity()),
+ BoundingBox::new(),
&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())
}
)
.is_ok());
@@ -1156,14 +1156,14 @@ mod marker_tests {
assert!(emit_markers_for_path_builder(
&builder,
- BoundingBox::new(&cairo::Matrix::identity()),
+ BoundingBox::new(),
&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())
}
)
.is_ok());
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index ff10295f..3ad422ea 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -286,7 +286,7 @@ impl PositionedSpan {
let affine = cr.get_matrix();
let gravity = self.layout.get_context().unwrap().get_gravity();
- let bbox = self.compute_text_bbox(&affine, gravity);
+ let bbox = self.compute_text_bbox(affine, gravity);
if bbox.is_none() {
return Ok(dc.empty_bbox());
}
@@ -355,7 +355,7 @@ impl PositionedSpan {
if !clipping {
let (x0, y0, x1, y1) = cr.stroke_extents();
let r = Rect::new(x0, y0, x1, y1);
- let ib = BoundingBox::new(&affine).with_ink_rect(r);
+ let ib = BoundingBox::new().with_affine(affine).with_ink_rect(r);
cr.stroke();
bbox.insert(&ib);
}
@@ -368,7 +368,7 @@ impl PositionedSpan {
fn compute_text_bbox(
&self,
- affine: &cairo::Matrix,
+ affine: cairo::Matrix,
gravity: pango::Gravity,
) -> Option<BoundingBox> {
let (ink, _) = self.layout.get_extents();
@@ -400,7 +400,10 @@ impl PositionedSpan {
};
let r = Rect::new(x, y, x + w, y + h);
- let bbox = BoundingBox::new(affine).with_rect(r).with_ink_rect(r);
+ let bbox = BoundingBox::new()
+ .with_affine(affine)
+ .with_rect(r)
+ .with_ink_rect(r);
Some(bbox)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]