mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-21 09:37:26 +00:00
Merge #828: Compose: spaces at the end of a paragraph take no room on the line
# Conflicts: # crates/compose/src/tests.rs
This commit is contained in:
commit
c24f658ab6
2 files changed
+24
No files matched your search
@@ -369,8 +369,17 @@ fn items(glyphs: &[Glyph], hyph_after: &[bool], emergency_after: &[bool], sp: &S
|
||||
let n = glyphs.len();
|
||||
let mut hy_cache = Vec::new();
|
||||
let mut last_space = NONE;
|
||||
// Spaces before the paragraph end or a forced break hang: they take no room on the line (as
|
||||
// in InDesign, where "2 VOOR " fits a frame as wide as "2 VOOR").
|
||||
let mut hangs = vec![false; n];
|
||||
for i in (0..n).rev() {
|
||||
hangs[i] = glyphs[i].is_space() && glyphs.get(i + 1).is_none_or(|nx| hangs[i + 1] || is_forced(nx.ch));
|
||||
}
|
||||
for (i, g) in glyphs.iter().enumerate() {
|
||||
let prev_hang = if i > 0 { right_hang(&glyphs[i - 1], sp) } else { 0.0 };
|
||||
if hangs[i] {
|
||||
continue;
|
||||
}
|
||||
if is_forced(g.ch) {
|
||||
it.push(Item::glue(0.0, INF, 0.0));
|
||||
ig.push(i);
|
||||
|
||||
@@ -7052,3 +7052,18 @@ fn cache_recomposes_page_numbers_when_a_section_is_renumbered() {
|
||||
assert!(!Arc::ptr_eq(&a, &b));
|
||||
assert_eq!(b.frames[0].lines[0].glyphs.len(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spaces_at_the_end_of_a_paragraph_take_no_room() {
|
||||
// A frame as wide as "2 VOOR" also holds "2 VOOR " on one line: the trailing space hangs.
|
||||
let (d, sid, _) = doc_with("2 VOOR", Rect::new(0.0, 0.0, 500.0, 100.0), ParaAttrs::default());
|
||||
let cs = compose_story(&d, sid, &ComposeOptions::default());
|
||||
let l = all_lines(&cs)[0];
|
||||
let width = l.end_x - l.x0;
|
||||
for text in ["2 VOOR ", "2 VOOR ", "2 VOOR \u{2028}more"] {
|
||||
let (d, sid, _) = doc_with(text, Rect::new(0.0, 0.0, width + 0.02, 100.0), ParaAttrs::default());
|
||||
let cs = compose_story(&d, sid, &ComposeOptions::default());
|
||||
let first = all_lines(&cs)[0];
|
||||
assert_eq!(&text[first.range.clone()].trim_end(), &"2 VOOR", "{text:?}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user