[librsvg: 34/90] image.rs: use DrawingCtx.with_saved_cr()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 34/90] image.rs: use DrawingCtx.with_saved_cr()
- Date: Tue, 26 Mar 2019 19:14:55 +0000 (UTC)
commit 52341991431a9d925079bedd755545df17dff549
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Mar 13 18:17:56 2019 -0600
image.rs: use DrawingCtx.with_saved_cr()
rsvg_internals/src/image.rs | 66 +++++++++++++++++++++++----------------------
1 file changed, 34 insertions(+), 32 deletions(-)
---
diff --git a/rsvg_internals/src/image.rs b/rsvg_internals/src/image.rs
index 7d723820..98a22a84 100644
--- a/rsvg_internals/src/image.rs
+++ b/rsvg_internals/src/image.rs
@@ -124,39 +124,41 @@ impl NodeTrait for NodeImage {
},
));
- let cr = dc.get_cairo_context();
- cr.save();
-
- let image_width = f64::from(image_width);
- let image_height = f64::from(image_height);
-
- if let Some(_params) = dc.push_new_viewport(
- Some(ViewBox::new(0.0, 0.0, image_width, image_height)),
- &Rectangle::new(x, y, w, h),
- aspect,
- clip_mode,
- ) {
- // We need to set extend appropriately, so can't use cr.set_source_surface().
- //
- // If extend is left at its default value (None), then bilinear scaling uses
- // transparency outside of the image producing incorrect results.
- // For example, in svg1.1/filters-blend-01-b.svgthere's a completely
- // opaque 100×1 image of a gradient scaled to 100×98 which ends up
- // transparent almost everywhere without this fix (which it shouldn't).
- let ptn = surface.to_cairo_pattern();
- ptn.set_extend(cairo::Extend::Pad);
- cr.set_source(&ptn);
-
- // Clip is needed due to extend being set to pad.
- cr.rectangle(0.0, 0.0, image_width, image_height);
- cr.clip();
-
- cr.paint();
- }
+ dc.with_saved_cr(&mut |dc| {
+ let cr = dc.get_cairo_context();
+
+ let image_width = f64::from(image_width);
+ let image_height = f64::from(image_height);
+
+ if let Some(_params) = dc.push_new_viewport(
+ Some(ViewBox::new(0.0, 0.0, image_width, image_height)),
+ &Rectangle::new(x, y, w, h),
+ aspect,
+ clip_mode,
+ ) {
+ // We need to set extend appropriately, so can't use cr.set_source_surface().
+ //
+ // If extend is left at its default value (None), then bilinear scaling uses
+ // transparency outside of the image producing incorrect results.
+ // For example, in svg1.1/filters-blend-01-b.svgthere's a completely
+ // opaque 100×1 image of a gradient scaled to 100×98 which ends up
+ // transparent almost everywhere without this fix (which it shouldn't).
+ let ptn = surface.to_cairo_pattern();
+ ptn.set_extend(cairo::Extend::Pad);
+ cr.set_source(&ptn);
+
+ // Clip is needed due to extend being set to pad.
+ cr.rectangle(0.0, 0.0, image_width, image_height);
+ cr.clip();
+
+ cr.paint();
+ }
- cr.restore();
- dc.insert_bbox(&bbox);
- Ok(())
+ Ok(())
+ }).and_then(|()| {
+ dc.insert_bbox(&bbox);
+ Ok(())
+ })
})
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]