[librsvg/librsvg-2.50] (#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/librsvg-2.50] (#730): Incorrect text spacing when the transform is not 1:1
- Date: Tue, 25 May 2021 19:04:38 +0000 (UTC)
commit afba7f2fcae0505113450198f74c8bf95c3cc13c
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
rsvg_internals/src/drawing_ctx.rs | 36 +++++++++++++++------
.../reftests/bugs/730-font-scaling-ref.png | Bin 0 -> 14781 bytes
tests/fixtures/reftests/bugs/730-font-scaling.svg | 18 +++++++++++
3 files changed, 44 insertions(+), 10 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index f7da9675..e176e691 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -1,8 +1,11 @@
//! The main context structure which drives the drawing process.
use float_cmp::approx_eq;
+use glib::translate::*;
+use glib_sys::gboolean;
use once_cell::sync::Lazy;
use pango::FontMapExt;
+use pango_sys::PangoContext;
use regex::{Captures, Regex};
use std::borrow::Cow;
use std::cell::RefCell;
@@ -2054,8 +2057,31 @@ 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();
+
+ unsafe {
+ extern "C" {
+ fn pango_context_set_round_glyph_positions(
+ context: *mut PangoContext,
+ round_positions: gboolean,
+ );
+ }
+
+ pango_context_set_round_glyph_positions(context.to_glib_none().0, false.to_glib());
+ }
+
pangocairo::functions::update_context(&cr, &context);
// Pango says this about pango_cairo_context_set_resolution():
@@ -2076,16 +2102,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]