address review: keep the metrics box as a second hit test for Type 3 glyphs

This commit is contained in:
Dylan M. Taylor
2026-11-04 01:44:56 +00:00
parent 48e9e6b7a2
commit 39bc948e67
+5 -4
View File
@@ -696,11 +696,11 @@ fn show(scope: &Scope<'_>, gs: &Gs, tm: &mut Matrix, items: &[Object]) -> (Vec<O
let w0 = f.width(code);
let spacing = gs.char_spacing + if f.is_space(code, len) { gs.word_spacing } else { 0.0 };
let trm = Matrix([size * gs.scale, 0.0, 0.0, size, 0.0, gs.rise]).then(tm).then(&gs.ctm);
let b = trm.bbox([0.0, f.descent, w0, f.ascent]);
let metrics = trm.bbox([0.0, f.descent, w0, f.ascent]);
// A Type 3 glyph paints where its whole font matrix puts it: the box covers both.
let b = gs.glyph_box.map_or(b, |g| {
let b = gs.glyph_box.map_or(metrics, |g| {
let p = trm.bbox(g);
[b[0].min(p[0]), b[1].min(p[1]), b[2].max(p[2]), b[3].max(p[3])]
[metrics[0].min(p[0]), metrics[1].min(p[1]), metrics[2].max(p[2]), metrics[3].max(p[3])]
});
let origin = trm.apply(0.0, 0.0);
let advance = w0 * size + spacing;
@@ -710,7 +710,8 @@ fn show(scope: &Scope<'_>, gs: &Gs, tm: &mut Matrix, items: &[Object]) -> (Vec<O
let degenerate = b[2] - b[0] < 0.01 && b[3] - b[1] < 0.01;
matches!(gs.render_mode, 3 | 7) || !(overlaps(page, b, 0.0) || degenerate)
}
None => scope.glyph_hit(b, origin),
// (the metrics box is a second test: the union's overlap threshold is wider than a narrow glyph's own)
None => scope.glyph_hit(b, origin) || scope.glyph_hit(metrics, origin),
};
glyphs.push(Glyph { bytes: pos..pos + len, advance, hit });
*tm = Matrix::translate(advance * gs.scale, 0.0).then(tm);