[librsvg: 2/3] (#799): Don't leave active points in the current Cairo path after drawing text
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/3] (#799): Don't leave active points in the current Cairo path after drawing text
- Date: Tue, 5 Oct 2021 16:34:16 +0000 (UTC)
commit 31c5024678e58d2807749cb6fe71257c3f72b9b9
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Oct 4 21:15:45 2021 -0500
(#799): Don't leave active points in the current Cairo path after drawing text
Pangocairo's show_layout family of functions use the cr's current
point as the starting point for the text. Librsvg does a lone
cr.move_to() to establish this point.
However, Pangocairo does not consume that point; it tries to leave the
current path alone. Also, the current path (and current point) are
not part of cairo's gstate - if on does cairo_save(), then sets the
path, then cairo_restore(), the latter function call will not remove
the current path. So, having a <text> element as the last renderable
element in an SVG would cause librsvg to leave a lone point as part of
the cr that the caller passed in.
This commit resets the current subpath after text operations to avoid
that.
Fixes https://gitlab.gnome.org/GNOME/librsvg/-/issues/799
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/598>
src/drawing_ctx.rs | 4 ++++
tests/src/api.rs | 31 +++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index a68484fe..92ba431b 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -1418,6 +1418,8 @@ impl DrawingCtx {
pangocairo::functions::show_layout(&self.cr, &span.layout);
self.cr.set_matrix(matrix);
+
+ self.cr.new_path();
}
}
@@ -1447,6 +1449,8 @@ impl DrawingCtx {
self.cr.stroke()?;
self.cr.set_matrix(matrix);
+
+ self.cr.new_path();
}
}
diff --git a/tests/src/api.rs b/tests/src/api.rs
index d67814e1..4d099ba4 100644
--- a/tests/src/api.rs
+++ b/tests/src/api.rs
@@ -219,3 +219,34 @@ fn set_stylesheet() {
.compare(&output_surf)
.evaluate(&output_surf, "set_stylesheet");
}
+
+// https://gitlab.gnome.org/GNOME/librsvg/-/issues/799
+#[test]
+fn text_doesnt_leave_points_in_current_path() {
+ let svg = load_svg(
+ br##"<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
+ <text>Hello world!</text>
+</svg>
+"##,
+ )
+ .unwrap();
+
+ let renderer = CairoRenderer::new(&svg);
+
+ let output = cairo::ImageSurface::create(cairo::Format::ARgb32, 100, 100).unwrap();
+ let cr = cairo::Context::new(&output).unwrap();
+
+ assert!(!cr.has_current_point().unwrap());
+
+ let viewport = cairo::Rectangle {
+ x: 0.0,
+ y: 0.0,
+ width: 100.0,
+ height: 100.0,
+ };
+
+ renderer.render_document(&cr, &viewport).unwrap();
+
+ assert!(!cr.has_current_point().unwrap());
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]