DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Text: Indent to Here in a drop cap or a list label indents the later lines too (#2080)
ljkx8013118a4477
diff --git a/crates/compose/src/lib.rs b/crates/compose/src/lib.rsindex 0e32881d9..c84cb6e27 100644--- a/crates/compose/src/lib.rs+++ b/crates/compose/src/lib.rs@@ -2123,7 +2123,7 @@ fn place_paragraph_lines(shared: PlacementShared<'_, '_>, paragraph: ParagraphLi}ruby::annotate(db, styles_tab, &story.text, &mut placed, doc.settings.glyph_fallback, f.vertical);kenten::annotate(db, styles_tab, &mut placed, doc.settings.glyph_fallback);- let here_props = indent_here(line_glyphs, &placed, pp, x0, x1, rtl);+ let here_props = indent_here(&placed, pp, x0, x1, rtl);let range_end = if last { prange.end } else { glyphs.get(g0 + b.next).map(|g| g.byte).unwrap_or(prange.end) };let range_start = glyphs.get(s).map(|g| g.byte).unwrap_or(prange.start).min(range_end);let range_start = if line_no == 0 { prange.start } else { range_start };@@ -4966,21 +4966,15 @@ fn distribute(line: &[Glyph], spaces: &[usize], extra: f64, sp: &Spacing, add: &}}-/// The paragraph settings for the lines after `line` when it holds an Indent to Here character-/// (the last one, if several): the start-side indent reaches the character, measured from the-/// start edge of the line's segment `x0..x1`. Like the paragraph's own indents it then applies-/// from each later line's segment, so beside a text wrap it starts at the wrap's edge. `None`-/// when there is none or the indent is unchanged.-fn indent_here(- line: &[Glyph],- placed: &[PlacedGlyph],- pp: &designcraft_doc::ParaProps,- x0: f64,- x1: f64,- rtl: bool,-) -> Option<designcraft_doc::ParaProps> {- let byte = line.iter().rev().find(|g| g.ch == story::INDENT_HERE)?.byte;- let x = placed.iter().find(|g| g.byte == byte && g.len > 0)?.x;+/// The paragraph settings for the lines after the `placed` line when it holds an Indent to Here+/// character (the last one, if several): the start-side indent reaches the character, measured+/// from the start edge of the line's segment `x0..x1`. Like the paragraph's own indents it then+/// applies from each later line's segment, so beside a text wrap it starts at the wrap's edge.+/// `None` when there is none or the indent is unchanged.+fn indent_here(placed: &[PlacedGlyph], pp: &designcraft_doc::ParaProps, x0: f64, x1: f64, rtl: bool) -> Option<designcraft_doc::ParaProps> {+ // The placed glyphs stay in text order (bidi only moves them) and include the drop cap's+ // and a list label's, so a character in either counts too.+ let x = placed.iter().rev().find(|g| g.rendered_char == story::INDENT_HERE)?.x;let indent = if rtl { x1 - x } else { x - x0 };if !indent.is_finite() {return None;diff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rsindex 7867d2ec8..9e9dd354a 100644--- a/crates/compose/src/tests.rs+++ b/crates/compose/src/tests.rs@@ -1967,6 +1967,39 @@ fn indent_to_here_beside_a_drop_cap_is_not_indented_by_the_drop_cap_again() {}}+#[test]+fn indent_to_here_inside_the_drop_cap_indents_the_lines_below_it() {+ // A two-character drop cap whose second character is Indent to Here: the lines beside the+ // drop cap and the ones below it all start at the character, at the drop cap's edge.+ let (here, starts) = indent_to_here_starts(&format!("A\u{e005}{LOREM}"), drop_cap(3, 2));+ assert!(here > 72.0 + 10.0, "the character sits past the drop cap: {here}");+ assert!(starts.len() > 3, "lines below the drop cap");+ for (i, start) in starts.iter().enumerate() {+ assert!((start - here).abs() < 0.01, "line {} starts at {start}, not at {here}", i + 1);+ }+}++#[test]+fn indent_to_here_in_a_list_number_indents_to_the_generated_character() {+ // "^#.^i^t": the paragraph's later lines start where the number's Indent to Here sits,+ // right after "1.", not at the text after the tab.+ let mut para = numbered(designcraft_doc::NumberStyle::Arabic, "^#.^i^t");+ para.list_tab = Some(Some(36.0));+ let (d, sid, _) = doc_with(LOREM, Rect::new(72.0, 36.0, 272.0, 600.0), para);+ let cs = compose_story(&d, sid, &Default::default());+ let lines = all_lines(&cs);+ assert!(lines.len() > 3, "the text wraps");+ let label = |c: char| lines[0].glyphs.iter().find(|g| g.len == 0 && g.rendered_char == c).unwrap();+ let (dot, here) = (label('.'), label('\u{e005}').x);+ assert!((here - (dot.x + dot.adv)).abs() < 0.01, "the character follows the number: {here}");+ let text = lines[0].glyphs.iter().find(|g| g.len > 0).unwrap().x;+ assert!((text - (72.0 + 36.0)).abs() < 0.01 && here < text - 1.0, "the text after the tab is further in: {text}");+ for (i, line) in lines.iter().enumerate().skip(1) {+ let start = line.glyphs.iter().find(|g| g.visible).unwrap().x;+ assert!((start - here).abs() < 0.01, "line {i} starts at {start}, not at {here}");+ }+}+#[test]fn indent_to_here_in_a_right_to_left_paragraph_indents_from_the_right() {// Hebrew words (the bidi classes decide the order; no Hebrew font has to be present): the