[librsvg: 2/4] (#730): Incorrect text spacing when the transform is not 1:1
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/4] (#730): Incorrect text spacing when the transform is not 1:1
- Date: Tue, 25 May 2021 01:17:37 +0000 (UTC)
commit 248d3ac5e034d977f7a3488853f95228fc3d6ff0
Author: Federico Mena Quintero <federico gnome org>
Date: Mon May 24 18:34:49 2021 -0500
(#730): Incorrect text spacing when the transform is not 1:1
Three things here:
* The main one, context.set_round_glyph_positions(false) on the Pango
context. This is what was causing incorrect text spacing when the
transform does not have 1:1 scaling.
* Set HintStyle::None and HintMetrics::Off. These seem to cause
inconsistencies when the transform is not an identity matrix.
* Set the font options on the cr, not on the Pango context, as the
latter will pick up the options from the cr anyway.
Fixes https://gitlab.gnome.org/GNOME/librsvg/-/issues/730
src/drawing_ctx.rs | 24 ++++++++++++---------
.../reftests/bugs/730-font-scaling-ref.png | Bin 0 -> 14781 bytes
tests/fixtures/reftests/bugs/730-font-scaling.svg | 18 ++++++++++++++++
3 files changed, 32 insertions(+), 10 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 6355511f..7a6568a6 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -1979,8 +1979,22 @@ impl From<TextRendering> for cairo::Antialias {
impl From<&DrawingCtx> for pango::Context {
fn from(draw_ctx: &DrawingCtx) -> pango::Context {
let cr = draw_ctx.cr.clone();
+
+ let mut options = cairo::FontOptions::new();
+ if draw_ctx.testing {
+ options.set_antialias(cairo::Antialias::Gray);
+ }
+
+ options.set_hint_style(cairo::HintStyle::None);
+ options.set_hint_metrics(cairo::HintMetrics::Off);
+
+ cr.set_font_options(&options);
+
let font_map = pangocairo::FontMap::get_default().unwrap();
let context = font_map.create_context().unwrap();
+
+ context.set_round_glyph_positions(false);
+
pangocairo::functions::update_context(&cr, &context);
// Pango says this about pango_cairo_context_set_resolution():
@@ -2001,16 +2015,6 @@ impl From<&DrawingCtx> for pango::Context {
// code.
pangocairo::functions::context_set_resolution(&context, 72.0);
- if draw_ctx.testing {
- let mut options = cairo::FontOptions::new();
-
- options.set_antialias(cairo::Antialias::Gray);
- options.set_hint_style(cairo::HintStyle::Full);
- options.set_hint_metrics(cairo::HintMetrics::On);
-
- pangocairo::functions::context_set_font_options(&context, Some(&options));
- }
-
context
}
}
diff --git a/tests/fixtures/reftests/bugs/730-font-scaling-ref.png
b/tests/fixtures/reftests/bugs/730-font-scaling-ref.png
new file mode 100644
index 00000000..a4a152fd
Binary files /dev/null and b/tests/fixtures/reftests/bugs/730-font-scaling-ref.png differ
diff --git a/tests/fixtures/reftests/bugs/730-font-scaling.svg
b/tests/fixtures/reftests/bugs/730-font-scaling.svg
new file mode 100644
index 00000000..5a8ea2b8
--- /dev/null
+++ b/tests/fixtures/reftests/bugs/730-font-scaling.svg
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="500" height="200">
+ <svg x="10" y="0" width="480" height="40" viewBox="0 0 480 40">
+ <text x="0" y="25" font-size="20" font-family="sans">How vexingly quick daft zebras jump!</text>
+ </svg>
+
+ <svg x="10" y="40" width="480" height="40" viewBox="0 0 240 20">
+ <text x="0" y="12.5" font-size="10" font-family="sans">How vexingly quick daft zebras jump!</text>
+ </svg>
+
+ <svg x="10" y="80" width="480" height="40" viewBox="0 0 120 10">
+ <text x="0" y="6.25" font-size="5" font-family="sans">How vexingly quick daft zebras jump!</text>
+ </svg>
+
+ <svg x="10" y="120" width="480" height="40" viewBox="0 0 60 5">
+ <text x="0" y="3.125" font-size="2.5" font-family="sans">How vexingly quick daft zebras jump!</text>
+ </svg>
+</svg>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]