Extract trim_weak_spacing function (#6797)

This commit is contained in:
Laurenz 2025-08-21 15:17:16 +02:00 committed by GitHub
parent eb93294171
commit c163c46b3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -168,6 +168,9 @@ pub fn line<'a>(
shaped.push_hyphen(engine, p.config.fallback);
}
// Ensure that there is no weak spacing at the start and end of the line.
trim_weak_spacing(&mut items);
// Deal with CJ characters at line boundaries.
adjust_cj_at_line_boundaries(p, full, &mut items);
@ -203,6 +206,18 @@ fn collect_items<'a>(
}
});
// Add fallback text to expand the line height, if necessary.
if !items.iter().any(|item| matches!(item, Item::Text(_)))
&& let Some(fallback) = fallback
{
items.push(fallback, usize::MAX);
}
items
}
/// Trims weak spacing from the start and end of the line.
fn trim_weak_spacing(items: &mut Items) {
// Trim weak spacing at the start of the line.
let prefix = items
.iter()
@ -216,15 +231,6 @@ fn collect_items<'a>(
while matches!(items.last(), Some(Item::Absolute(_, true))) {
items.pop();
}
// Add fallback text to expand the line height, if necessary.
if !items.iter().any(|item| matches!(item, Item::Text(_)))
&& let Some(fallback) = fallback
{
items.push(fallback, usize::MAX);
}
items
}
/// Calls `f` for the BiDi-reordered ranges of a line.