address review: a collapsed line break keeps its measured leading in tiny type

This commit is contained in:
Dylan M. Taylor
2026-11-11 06:15:32 +00:00
parent b3c0ad039e
commit 059d3cc21a
2 changed files with 12 additions and 1 deletions
+3 -1
View File
@@ -950,7 +950,9 @@ fn lines(
// A line's characters take its spacing as leading unless it is their auto leading.
for (k, b) in breaks.iter().enumerate() {
let end = breaks.get(k + 1).map_or(n, |nb| nb.at);
if cells[b.at..end].iter().any(|c| (c.style.effective_leading() - b.leading).abs() > 0.01) {
// 0.01 absolute, but never more than a thousandth of the spacing itself (tiny type has tiny gaps).
let tolerance = 0.01_f64.min(b.leading.abs() * 1e-3);
if cells[b.at..end].iter().any(|c| (c.style.effective_leading() - b.leading).abs() > tolerance) {
for c in &mut cells[b.at..end] {
c.style.leading = Some(b.leading);
}
+9
View File
@@ -232,6 +232,15 @@ fn per_character_positions_with_middle_anchor() {
assert!(close(mid(0), 50.0, 0.05) && close(mid(1), 100.0, 0.05), "{} {}", mid(0), mid(1));
}
#[test]
fn a_small_line_gap_in_tiny_type_keeps_its_leading() {
// 0.0085 against an auto leading of 0.006 differs by less than 0.01 but is not a whole multiple of it.
let d = open(r#"<text x="1" y="1" font-size="0.005">One<tspan x="1" dy="0.0085">Two</tspan></text>"#);
let t = only_text(&d);
let two = t.runs.iter().find(|r| r.text.contains("Two")).unwrap().style.leading;
assert!(two.is_some_and(|l| close(l, 0.0085, 1e-9)), "{two:?}");
}
#[test]
fn tspan_lines_dx_and_baseline_shift() {
let d = open(