Merge #471: M4: hanging punctuation test holds for fonts that kern with x offsets (@rcoenen)

This commit is contained in:
bflatastic
2026-10-15 17:53:10 +07:00
+13 -4
View File
@@ -130,14 +130,23 @@ fn hanging_punctuation_outside_the_aligned_edge() {
t.auto_resize = TextAutoResize::Height;
let Some(plain) = laid(&t) else { return };
let open = plain.glyphs[0].advance;
// Kerning may draw a glyph off its pen position (an x offset, e.g. Helvetica Neue's "re"), so
// each hanging line is checked against the same line set flush: every glyph moves by exactly
// the hanging mark's advance, which puts the letters' pen edge on the box edge.
let moved = |a: &TextLayout, b: &TextLayout, by: f64| {
a.glyphs.len() == b.glyphs.len() && a.glyphs.iter().zip(&b.glyphs).all(|(a, b)| (a.x - b.x - by).abs() < EPS)
};
t.hanging_punctuation = true;
let l = laid(&t).unwrap();
assert!((l.glyphs[0].x + open).abs() < EPS && l.glyphs[1].x.abs() < EPS, "left: the quote hangs, Q starts the line");
assert!(plain.glyphs[0].x.abs() < EPS && moved(&l, &plain, -open), "left: the quote hangs, Q starts the line");
t.align_h = TextAlignH::Right;
t.hanging_punctuation = false;
let flush = laid(&t).unwrap();
t.hanging_punctuation = true;
let l = laid(&t).unwrap();
let last = l.glyphs.last().unwrap();
let before = &l.glyphs[l.glyphs.len() - 2];
assert!((before.x + before.advance - 400.0).abs() < EPS && last.x >= 400.0 - EPS, "right: the full stop hangs past the edge");
let stop = l.glyphs.last().unwrap().advance;
let edge = flush.lines[0].x + flush.lines[0].width;
assert!((edge - 400.0).abs() < EPS && moved(&l, &flush, stop), "right: the full stop hangs past the edge");
t.align_h = TextAlignH::Center;
let (a, b) = (laid(&t).unwrap(), {
t.hanging_punctuation = false;