DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Hidden characters test: in canvas/tests.rs, out of the canvas paint function
moppeeer1698f69d683e
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 5c0926b44..1b1e10d13 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -194,38 +194,6 @@ fn paint_render(app: &DesignApp, painter: &egui::Painter, xf: &Xf, doc: &Documenpainter.add(egui::Shape::mesh(mesh));}}-- /// As InDesign: an end-of-story # in every cell (after its text), a ¶ where a cell paragraph- /// ends, and the table paragraph's ¶ just after the table's bottom right corner.- #[test]- fn table_cells_show_their_hidden_characters() {- let mut d = Document::new(&designcraft_doc::build::NewDocument::default());- let lid = d.default_layer();- let (_, sid) = d.add_text_frame(SpreadRef::Doc(0), DRect::new(0.0, 0.0, 300.0, 300.0), lid, "", Default::default()).unwrap();- let data = vec![vec!["Name:".to_string(), "".into()], vec!["a\nb".into(), "".into()]];- let t = designcraft_doc::Table::from_strings(d.alloc(), &data, 200.0, &Default::default(), &Default::default());- d.story_mut(sid).unwrap().insert_table(0, t);- let cs = compose::compose_story(&d, sid, &compose::ComposeOptions::default());- let frag = &cs.frames[0].tables[0];- // The whole frame: the table's own line adds no second ¶; the story's last paragraph- // (after the table) has its #.- let story = d.story(sid).unwrap().text.clone();- let all = frame_hidden_marks(&story, &cs.frames[0]);- let marks: Vec<_> = all.iter().filter(|m| frag.rect.inflate(2.0, 2.0).contains(m.0)).cloned().collect();- let ends = |m: &str| marks.iter().filter(|x| x.1 == m).count();- assert_eq!(ends("#"), 4, "one per cell: {marks:?}");- assert_eq!(ends("¶"), 2, "the cell's first paragraph and the table's, once: {marks:?}");- assert_eq!(all.iter().filter(|m| m.1 == "¶" && m.3 > 20.0).count(), 0, "no ¶ the size of the table: {all:?}");- // Each # is inside its cell, after the cell's text.- for c in &frag.cells {- let inside = marks.iter().filter(|m| m.1 == "#" && c.rect.contains(m.0)).count();- assert_eq!(inside, 1, "cell {},{}: {marks:?}", c.row, c.col);- }- let name = frag.cell(0, 0).unwrap();- assert!(marks.iter().any(|m| m.1 == "#" && name.rect.contains(m.0) && m.0.x > name.origin.x + 20.0), "after Name:");- let last = marks.last().unwrap();- assert_eq!((last.0, last.1), (designcraft_geom::Point::new(frag.rect.x1 + 1.0, frag.rect.y1), "¶"));- }}/// Presentation: a click shows the next spread, Shift-click the previous one.diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rsindex 01300bdd0..f36269479 100644--- a/crates/ui-egui/src/canvas/tests.rs+++ b/crates/ui-egui/src/canvas/tests.rs@@ -2837,3 +2837,35 @@ fn trailing_spaces_show_dots_before_the_paragraph_mark() {assert!(para_x >= space.x + space.adv, "{mark} at {para_x} overlaps the last space");}}++/// As InDesign: an end-of-story # in every cell (after its text), a ¶ where a cell paragraph+/// ends, and the table paragraph's ¶ just after the table's bottom right corner.+#[test]+fn table_cells_show_their_hidden_characters() {+ let mut d = Document::new(&designcraft_doc::build::NewDocument::default());+ let lid = d.default_layer();+ let (_, sid) = d.add_text_frame(SpreadRef::Doc(0), DRect::new(0.0, 0.0, 300.0, 300.0), lid, "", Default::default()).unwrap();+ let data = vec![vec!["Name:".to_string(), "".into()], vec!["a\nb".into(), "".into()]];+ let t = designcraft_doc::Table::from_strings(d.alloc(), &data, 200.0, &Default::default(), &Default::default());+ d.story_mut(sid).unwrap().insert_table(0, t);+ let cs = compose::compose_story(&d, sid, &compose::ComposeOptions::default());+ let frag = &cs.frames[0].tables[0];+ // The whole frame: the table's own line adds no second ¶; the story's last paragraph+ // (after the table) has its #.+ let story = d.story(sid).unwrap().text.clone();+ let all = frame_hidden_marks(&story, &cs.frames[0]);+ let marks: Vec<_> = all.iter().filter(|m| frag.rect.inflate(2.0, 2.0).contains(m.0)).cloned().collect();+ let ends = |m: &str| marks.iter().filter(|x| x.1 == m).count();+ assert_eq!(ends("#"), 4, "one per cell: {marks:?}");+ assert_eq!(ends("¶"), 2, "the cell's first paragraph and the table's, once: {marks:?}");+ assert_eq!(all.iter().filter(|m| m.1 == "¶" && m.3 > 20.0).count(), 0, "no ¶ the size of the table: {all:?}");+ // Each # is inside its cell, after the cell's text.+ for c in &frag.cells {+ let inside = marks.iter().filter(|m| m.1 == "#" && c.rect.contains(m.0)).count();+ assert_eq!(inside, 1, "cell {},{}: {marks:?}", c.row, c.col);+ }+ let name = frag.cell(0, 0).unwrap();+ assert!(marks.iter().any(|m| m.1 == "#" && name.rect.contains(m.0) && m.0.x > name.origin.x + 20.0), "after Name:");+ let last = marks.last().unwrap();+ assert_eq!((last.0, last.1), (designcraft_geom::Point::new(frag.rect.x1 + 1.0, frag.rect.y1), "¶"));+}