[librsvg] drawing_ctx: use early return for readability
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] drawing_ctx: use early return for readability
- Date: Sun, 5 Apr 2020 10:37:41 +0000 (UTC)
commit e1d612a581c2f9bf5d1f9c418ae00eba8748a2a4
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Apr 5 12:34:03 2020 +0200
drawing_ctx: use early return for readability
Return early if there is no clip node.
rsvg_internals/src/drawing_ctx.rs | 73 ++++++++++++++++++++-------------------
1 file changed, 37 insertions(+), 36 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index ee143f25..4470c469 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -318,50 +318,51 @@ impl DrawingCtx {
acquired_nodes: &mut AcquiredNodes,
bbox: &BoundingBox,
) -> Result<(), RenderingError> {
- if let Some(node) = clip_node {
- let units = node.borrow_element().get_impl::<ClipPath>().get_units();
+ if clip_node.is_none() {
+ return Ok(());
+ }
- if units == CoordUnits::ObjectBoundingBox && bbox.rect.is_none() {
- // The node being clipped is empty / doesn't have a
- // bounding box, so there's nothing to clip!
- return Ok(());
- }
+ let node = clip_node.as_ref().unwrap();
+ let units = node.borrow_element().get_impl::<ClipPath>().get_units();
- let cascaded = CascadedValues::new_from_node(node);
+ if units == CoordUnits::ObjectBoundingBox && bbox.rect.is_none() {
+ // The node being clipped is empty / doesn't have a
+ // bounding box, so there's nothing to clip!
+ return Ok(());
+ }
- let transform = if units == CoordUnits::ObjectBoundingBox {
- let bbox_rect = bbox.rect.as_ref().unwrap();
+ let cascaded = CascadedValues::new_from_node(node);
- Some(Transform::new(
- bbox_rect.width(),
- 0.0,
- 0.0,
- bbox_rect.height(),
- bbox_rect.x0,
- bbox_rect.y0,
- ))
- } else {
- None
- };
+ let transform = if units == CoordUnits::ObjectBoundingBox {
+ let bbox_rect = bbox.rect.as_ref().unwrap();
+
+ Some(Transform::new(
+ bbox_rect.width(),
+ 0.0,
+ 0.0,
+ bbox_rect.height(),
+ bbox_rect.x0,
+ bbox_rect.y0,
+ ))
+ } else {
+ None
+ };
- self.with_saved_transform(transform, &mut |dc| {
- let cr = dc.get_cairo_context();
+ self.with_saved_transform(transform, &mut |dc| {
+ let cr = dc.get_cairo_context();
- // here we don't push a layer because we are clipping
- let res = node.draw_children(acquired_nodes, &cascaded, dc, true);
+ // here we don't push a layer because we are clipping
+ let res = node.draw_children(acquired_nodes, &cascaded, dc, true);
- cr.clip();
+ cr.clip();
- res
- })
- .and_then(|_bbox|
- // Clipping paths do not contribute to bounding boxes (they should,
- // but we need Real Computational Geometry(tm), so ignore the
- // bbox from the clip path.
- Ok(()))
- } else {
- Ok(())
- }
+ res
+ })
+ .and_then(|_bbox|
+ // Clipping paths do not contribute to bounding boxes (they should,
+ // but we need Real Computational Geometry(tm), so ignore the
+ // bbox from the clip path.
+ Ok(()))
}
fn generate_cairo_mask(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]