[librsvg: 1/6] drawing-ctx: move clip() method to the draw ctx
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/6] drawing-ctx: move clip() method to the draw ctx
- Date: Tue, 26 Jun 2018 02:03:09 +0000 (UTC)
commit 981e2e20c6cf4965695e342fd708eade7b8a0b2b
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Jun 23 11:01:38 2018 +0200
drawing-ctx: move clip() method to the draw ctx
Also move the set_affine_on_cr helper, for now it is public since
other functions need it
rsvg_internals/src/draw.rs | 37 +++----------------------------------
rsvg_internals/src/drawing_ctx.rs | 25 +++++++++++++++++++++++++
rsvg_internals/src/image.rs | 4 ++--
rsvg_internals/src/marker.rs | 5 ++---
rsvg_internals/src/mask.rs | 6 ++----
rsvg_internals/src/viewport.rs | 5 ++---
6 files changed, 36 insertions(+), 46 deletions(-)
---
diff --git a/rsvg_internals/src/draw.rs b/rsvg_internals/src/draw.rs
index 92ae4410..abd7b7cb 100644
--- a/rsvg_internals/src/draw.rs
+++ b/rsvg_internals/src/draw.rs
@@ -25,22 +25,6 @@ use state::{
TextRendering,
};
-fn set_affine_on_cr(draw_ctx: &DrawingCtx, cr: &cairo::Context) {
- let (x0, y0) = draw_ctx.get_offset();
-
- let affine = cr.get_matrix();
-
- let matrix = cairo::Matrix::new(
- affine.xx,
- affine.yx,
- affine.xy,
- affine.yy,
- affine.x0 + x0,
- affine.y0 + y0,
- );
- cr.set_matrix(matrix);
-}
-
pub fn draw_path_builder(
draw_ctx: &mut DrawingCtx,
values: &ComputedValues,
@@ -49,8 +33,7 @@ pub fn draw_path_builder(
) {
let cr = draw_ctx.get_cairo_context();
- set_affine_on_cr(draw_ctx, &cr);
-
+ draw_ctx.set_affine_on_cr(&cr);
builder.to_cairo(&cr);
if clipping {
@@ -294,7 +277,7 @@ pub fn draw_pango_layout(
let cr = draw_ctx.get_cairo_context();
cr.save();
- set_affine_on_cr(draw_ctx, &cr);
+ draw_ctx.set_affine_on_cr(&cr);
let affine = cr.get_matrix();
@@ -443,7 +426,7 @@ pub fn draw_surface(
height: h,
}));
- set_affine_on_cr(draw_ctx, &cr);
+ draw_ctx.set_affine_on_cr(&cr);
cr.scale(w / width, h / height);
let x = x * width / w;
let y = y * height / h;
@@ -473,17 +456,3 @@ pub fn draw_surface(
draw_ctx.insert_bbox(&bbox);
}
-
-/// Adds a clipping rectangle to the curent Cairo context
-pub fn add_clipping_rect(draw_ctx: &mut DrawingCtx, x: f64, y: f64, w: f64, h: f64) {
- let cr = draw_ctx.get_cairo_context();
-
- let save_affine = cr.get_matrix();
-
- set_affine_on_cr(draw_ctx, &cr);
-
- cr.rectangle(x, y, w, h);
- cr.clip();
-
- cr.set_matrix(save_affine);
-}
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index f3f4f02f..f800601c 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -407,6 +407,31 @@ impl<'a> DrawingCtx {
context
}
+ pub fn set_affine_on_cr(&self, cr: &cairo::Context) {
+ let (x0, y0) = self.get_offset();
+ let affine = cr.get_matrix();
+ let matrix = cairo::Matrix::new(
+ affine.xx,
+ affine.yx,
+ affine.xy,
+ affine.yy,
+ affine.x0 + x0,
+ affine.y0 + y0,
+ );
+ cr.set_matrix(matrix);
+ }
+
+ pub fn clip(&mut self, x: f64, y: f64, w: f64, h: f64) {
+ let cr = self.get_cairo_context();
+ let save_affine = cr.get_matrix();
+
+ self.set_affine_on_cr(&cr);
+
+ cr.rectangle(x, y, w, h);
+ cr.clip();
+ cr.set_matrix(save_affine);
+ }
+
pub fn draw_node_on_surface(
&mut self,
node: &RsvgNode,
diff --git a/rsvg_internals/src/image.rs b/rsvg_internals/src/image.rs
index 9f5173bf..d98226bd 100644
--- a/rsvg_internals/src/image.rs
+++ b/rsvg_internals/src/image.rs
@@ -9,7 +9,7 @@ use std::ptr;
use aspect_ratio::AspectRatio;
use attributes::Attribute;
-use draw::{add_clipping_rect, draw_surface};
+use draw::draw_surface;
use drawing_ctx::DrawingCtx;
use handle::RsvgHandle;
use length::*;
@@ -122,7 +122,7 @@ impl NodeTrait for NodeImage {
let aspect = self.aspect.get();
if !values.is_overflow() && aspect.is_slice() {
- add_clipping_rect(dc, x, y, w, h);
+ dc.clip(x, y, w, h);
}
let (x, y, w, h) = aspect.compute(
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index 3307bc5b..f041fb20 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -6,7 +6,6 @@ use cssparser::{CowRcStr, Parser, Token};
use aspect_ratio::*;
use attributes::Attribute;
-use draw::add_clipping_rect;
use drawing_ctx::DrawingCtx;
use error::*;
use float_eq_cairo::ApproxEqCairo;
@@ -185,9 +184,9 @@ impl NodeMarker {
if !values.is_overflow() {
if let Some(vbox) = self.vbox.get() {
- add_clipping_rect(draw_ctx, vbox.0.x, vbox.0.y, vbox.0.width, vbox.0.height);
+ draw_ctx.clip(vbox.0.x, vbox.0.y, vbox.0.width, vbox.0.height);
} else {
- add_clipping_rect(draw_ctx, 0.0, 0.0, marker_width, marker_height);
+ draw_ctx.clip(0.0, 0.0, marker_width, marker_height);
}
}
diff --git a/rsvg_internals/src/mask.rs b/rsvg_internals/src/mask.rs
index 79efde2e..24efcf01 100644
--- a/rsvg_internals/src/mask.rs
+++ b/rsvg_internals/src/mask.rs
@@ -5,7 +5,6 @@ use std::cell::Cell;
use attributes::Attribute;
use coord_units::CoordUnits;
-use draw;
use drawing_ctx::DrawingCtx;
use handle::RsvgHandle;
use length::{LengthDir, RsvgLength};
@@ -108,15 +107,14 @@ impl NodeMask {
bbox.rect.unwrap()
};
- draw::add_clipping_rect(
- draw_ctx,
+ draw_ctx.clip(
x * rect.width + rect.x,
y * rect.height + rect.y,
w * rect.width,
h * rect.height,
);
} else {
- draw::add_clipping_rect(draw_ctx, x, y, w, h);
+ draw_ctx.clip(x, y, w, h);
}
if content_units == CoordUnits::ObjectBoundingBox {
diff --git a/rsvg_internals/src/viewport.rs b/rsvg_internals/src/viewport.rs
index 2291a281..61a1fb59 100644
--- a/rsvg_internals/src/viewport.rs
+++ b/rsvg_internals/src/viewport.rs
@@ -2,7 +2,6 @@ use cairo;
use cairo::MatrixTrait;
use aspect_ratio::AspectRatio;
-use draw::add_clipping_rect;
use drawing_ctx::DrawingCtx;
use float_eq_cairo::ApproxEqCairo;
use node::RsvgNode;
@@ -44,7 +43,7 @@ pub fn draw_in_viewport(
draw_ctx.with_discrete_layer(node, values, clipping, &mut |dc| {
if do_clip && clip_mode == ClipMode::ClipToViewport {
dc.get_cairo_context().set_matrix(affine);
- add_clipping_rect(dc, vx, vy, vw, vh);
+ dc.clip(vx, vy, vw, vh);
}
if let Some(vbox) = vbox {
@@ -69,7 +68,7 @@ pub fn draw_in_viewport(
dc.get_cairo_context().set_matrix(affine);
if do_clip && clip_mode == ClipMode::ClipToVbox {
- add_clipping_rect(dc, vbox.0.x, vbox.0.y, vbox.0.width, vbox.0.height);
+ dc.clip(vbox.0.x, vbox.0.y, vbox.0.width, vbox.0.height);
}
} else {
dc.push_view_box(vw, vh);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]