DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge #828: Compose: spaces at the end of a paragraph take no room on the line
aionggc24f658ab612
diff --cc crates/compose/src/tests.rsindex e8391db99,fd7484fce..546986087--- a/crates/compose/src/tests.rs+++ b/crates/compose/src/tests.rs@@@ -7009,46 -2930,17 +7009,61 @@@ fn degenerate_frame_outlines_compose_wi}}+#[test]+fn cache_recomposes_when_the_baseline_grid_changes() {+ let para = ParaAttrs { grid_align: Some(GridAlign::AllLines), ..Default::default() };+ let (mut d, sid, _) = doc_with(LOREM, Rect::new(0.0, 0.0, 200.0, 600.0), para);+ let cache = Cache::new();+ let a = cache.get(&d, sid, None);+ d.settings.baseline_grid.increment = 30.0;+ let b = cache.get(&d, sid, None);+ assert!(!Arc::ptr_eq(&a, &b));+ let (la, lb) = (&a.frames[0].lines[1], &b.frames[0].lines[1]);+ assert!((la.baseline - lb.baseline).abs() > 1.0, "{} {}", la.baseline, lb.baseline);+}++#[test]+fn cache_recomposes_when_a_wrap_layer_is_hidden() {+ let (mut d, sid, _) = doc_with(&[LOREM; 2].join(" "), Rect::new(0.0, 0.0, 300.0, 800.0), ParaAttrs::default());+ let lid = d.default_layer();+ let id = ItemId(d.alloc());+ let mut it =+ designcraft_doc::Item::new(id, lid, designcraft_doc::Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(0.0, 0.0, 120.0, 60.0)));+ it.wrap.mode = WrapMode::BoundingBox;+ d.insert_item(SpreadRef::Doc(0), it, None).unwrap();+ let cache = Cache::new();+ let a = cache.get(&d, sid, None);+ assert!(a.frames[0].lines[0].x0 >= 120.0 - 1e-6);+ d.layer_mut(lid).unwrap().visible = false;+ let b = cache.get(&d, sid, None);+ assert!(!Arc::ptr_eq(&a, &b));+ assert!(b.frames[0].lines[0].x0 < 1.0, "{}", b.frames[0].lines[0].x0);+}++#[test]+fn cache_recomposes_page_numbers_when_a_section_is_renumbered() {+ let text = story::PAGE_NUMBER.to_string();+ let (mut d, sid, _) = doc_with(&text, Rect::new(0.0, 0.0, 300.0, 100.0), ParaAttrs::default());+ let cache = Cache::new();+ let a = cache.get(&d, sid, None);+ assert_eq!(a.frames[0].lines[0].glyphs.len(), 1);+ d.sections[0].start_number = Some(1000);+ let b = cache.get(&d, sid, None);+ 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:?}");+ }+ }