DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Text: test that a list number's Indent to Here wins over one in the drop cap (#2080)
ljkx70a76b15c51b
diff --git a/crates/compose/src/lib.rs b/crates/compose/src/lib.rsindex c84cb6e27..f110c0ecc 100644--- a/crates/compose/src/lib.rs+++ b/crates/compose/src/lib.rs@@ -4972,8 +4972,9 @@ fn distribute(line: &[Glyph], spaces: &[usize], extra: f64, sp: &Spacing, add: &/// 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.+ // The placed glyphs are in the line's order (bidi only moves them): the drop cap's, then a+ // list label's, which is set beside the drop cap, then the text's. A character in the drop+ // cap or the label counts too, and one in the label comes after one in the drop cap.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() {diff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rsindex 9e9dd354a..4d056dcc2 100644--- a/crates/compose/src/tests.rs+++ b/crates/compose/src/tests.rs@@ -2000,6 +2000,26 @@ fn indent_to_here_in_a_list_number_indents_to_the_generated_character() {}}+#[test]+fn indent_to_here_in_a_list_number_after_one_in_the_drop_cap_wins() {+ // The drop cap "A^i" sits at the indent and the number "1.^i" follows it on the first line,+ // so the number's character is the line's last one: the later lines start there, not at+ // the drop cap's.+ let mut para = ParaAttrs { drop_cap_lines: Some(3), drop_cap_chars: Some(2), ..numbered(designcraft_doc::NumberStyle::Arabic, "^#.^i^t") };+ para.list_tab = Some(Some(36.0));+ let (d, sid, _) = doc_with(&format!("A\u{e005}{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() > 4, "the text wraps below the drop cap");+ let marker = |label: bool| lines[0].glyphs.iter().find(|g| g.rendered_char == '\u{e005}' && (g.len == 0) == label).unwrap().x;+ let (in_cap, in_label) = (marker(false), marker(true));+ assert!(in_label > in_cap + 1.0, "the number follows the drop cap: {in_cap} then {in_label}");+ for (i, line) in lines.iter().enumerate().skip(1) {+ let start = line.glyphs.iter().find(|g| g.visible).unwrap().x;+ assert!((start - in_label).abs() < 0.01, "line {i} starts at {start}, not at {in_label}");+ }+}+#[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