[librsvg: 2/31] Pass the Stroke to setup_cr_for_stroke
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/31] Pass the Stroke to setup_cr_for_stroke
- Date: Thu, 3 Jun 2021 02:27:09 +0000 (UTC)
commit 4641ca2a96765a07afbd3b353db4179389fb8baf
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Jun 2 11:40:15 2021 -0500
Pass the Stroke to setup_cr_for_stroke
Extract that function from DrawingCtx.
src/drawing_ctx.rs | 54 ++++++++++++++++++++++++++++++++----------------------
1 file changed, 32 insertions(+), 22 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 4e6ea53a..4905f607 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -1107,26 +1107,6 @@ impl DrawingCtx {
surface.share()
}
- fn setup_cr_for_stroke(&self, cr: &cairo::Context, values: &ComputedValues) {
- let view_params = self.get_view_params();
- let params = NormalizeParams::new(values, &view_params);
-
- let stroke = Stroke::new(values, ¶ms);
-
- cr.set_line_width(stroke.width);
- cr.set_miter_limit(stroke.miter_limit.0);
- cr.set_line_cap(cairo::LineCap::from(stroke.line_cap));
- cr.set_line_join(cairo::LineJoin::from(stroke.line_join));
-
- let total_length: f64 = stroke.dashes.iter().sum();
-
- if total_length > 0.0 {
- cr.set_dash(&stroke.dashes, stroke.dash_offset);
- } else {
- cr.set_dash(&[], 0.0);
- }
- }
-
fn stroke(
&mut self,
cr: &cairo::Context,
@@ -1209,7 +1189,14 @@ impl DrawingCtx {
}
cr.set_antialias(cairo::Antialias::from(values.shape_rendering()));
- dc.setup_cr_for_stroke(&cr, values);
+
+ {
+ let view_params = dc.get_view_params();
+ let params = NormalizeParams::new(values, &view_params);
+ let stroke = Stroke::new(values, ¶ms);
+
+ setup_cr_for_stroke(&cr, &stroke);
+ }
cr.set_fill_rule(cairo::FillRule::from(values.fill_rule()));
@@ -1353,7 +1340,15 @@ impl DrawingCtx {
let cr = saved_cr.draw_ctx.cr.clone();
cr.set_antialias(cairo::Antialias::from(values.text_rendering()));
- saved_cr.draw_ctx.setup_cr_for_stroke(&cr, &values);
+
+ {
+ let view_params = saved_cr.draw_ctx.get_view_params();
+ let params = NormalizeParams::new(values, &view_params);
+ let stroke = Stroke::new(values, ¶ms);
+
+ setup_cr_for_stroke(&cr, &stroke);
+ }
+
cr.move_to(x, y);
let rotation = gravity.to_rotation();
@@ -1886,6 +1881,21 @@ fn compute_text_box(
Some(bbox)
}
+fn setup_cr_for_stroke(cr: &cairo::Context, stroke: &Stroke) {
+ cr.set_line_width(stroke.width);
+ cr.set_miter_limit(stroke.miter_limit.0);
+ cr.set_line_cap(cairo::LineCap::from(stroke.line_cap));
+ cr.set_line_join(cairo::LineJoin::from(stroke.line_join));
+
+ let total_length: f64 = stroke.dashes.iter().sum();
+
+ if total_length > 0.0 {
+ cr.set_dash(&stroke.dashes, stroke.dash_offset);
+ } else {
+ cr.set_dash(&[], 0.0);
+ }
+}
+
// FIXME: should the pango crate provide this like PANGO_GRAVITY_IS_VERTICAL() ?
fn gravity_is_vertical(gravity: pango::Gravity) -> bool {
matches!(gravity, pango::Gravity::East | pango::Gravity::West)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]