DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Drop caps: a space after the cap doesn't widen the indent
aiongg21863563f307
diff --git a/ROADMAP.md b/ROADMAP.mdindex b0a3c2f29..d391ea828 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -68,7 +68,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope- Appearance of Black complete: Printing/Exporting rich black for RGB output (PNG), Overprint [Black] Swatch at 100% (document, IDML OverprintBlack).- Hyperlinks and Bookmarks panels (Window ▸ Interactive): new from the selection, edit (`hyperlink.edit`), go to source (`hyperlink.goToSource`), rename bookmarks (`bookmark.rename`), go to page, delete.- Nested line styles (`nestedLineStyles` paragraph attribute, Paragraph Style Options › Drop Caps and Nested Styles, IDML AllNestedLineStyles): the first lines restyle until the line breaks settle.-- Drop caps (`type.para {dropCapLines, dropCapChars, dropCapStyle, dropCapAlignLeft, dropCapScaleDescenders}`, Paragraph panel, Paragraph Style Options › Drop Caps and Nested Styles; IDML DropCapLines/DropCapCharacters/DropcapDetail, DropCapStyle on import): the first characters (code points, as InDesign counts them, never splitting a letter from its combining marks; up to 150) are enlarged from the first line's cap height down N − 1 leadings of the text after them (up to 25 lines; grid steps on a baseline grid), the lines beside them are indented by their advance (on the right in right-to-left paragraphs), baselines don't move; Align Left Edge (on by default) moves the drop cap left by its first letter's side bearing so its ink starts at the indent; Scale for Descenders is kept but doesn't change the layout yet; a drop cap character style, and nested styles through the drop cap (Dropcap delimiter). Drawn on screen and in PDF (text in order), with caret, hit testing and selection over the enlarged letters. Vertical text sets no drop caps.+- Drop caps (`type.para {dropCapLines, dropCapChars, dropCapStyle, dropCapAlignLeft, dropCapScaleDescenders}`, Paragraph panel, Paragraph Style Options › Drop Caps and Nested Styles; IDML DropCapLines/DropCapCharacters/DropcapDetail, DropCapStyle on import): the first characters (code points, as InDesign counts them, never splitting a letter from its combining marks; up to 150) are enlarged from the first line's cap height down N − 1 leadings of the text after them (up to 25 lines; grid steps on a baseline grid), the lines beside them are indented by their advance (on the right in right-to-left paragraphs), spaces right after them are set at their size without widening the indent, baselines don't move; Align Left Edge (on by default) moves the drop cap left by its first letter's side bearing so its ink starts at the indent; Scale for Descenders is kept but doesn't change the layout yet; a drop cap character style, and nested styles through the drop cap (Dropcap delimiter). Drawn on screen and in PDF (text in order), with caret, hit testing and selection over the enlarged letters. Vertical text sets no drop caps.- User dictionary hyphenation exceptions (`hyphenation.addException/removeException/list`, Edit ▸ Spelling ▸ User Dictionary): `ex~am~ple` breaks only at `~`, a plain word never hyphenates.- Frame Fitting Options (`object.fittingOptions`, Object ▸ Fitting ▸ Frame Fitting Options…): Auto-Fit refits on resize, fitting, Align From reference point, crop amounts; IDML FrameFittingOption.- Paragraph borders (per-side weights, colour, tint, offsets) and shading offsets, drawn per column part of split paragraphs (also when overset); Paragraph panel controls; IDML ParagraphBorder*/ParagraphShading*Offset.diff --git a/crates/compose/src/lib.rs b/crates/compose/src/lib.rsindex d29528529..ab1066f77 100644--- a/crates/compose/src/lib.rs+++ b/crates/compose/src/lib.rs@@ -2868,7 +2868,8 @@ struct DropCap {/// it so its cap height reaches from the first line's cap height down to line `lines`' baseline,/// measured in the leading and cap height of the text after it./// On a baseline grid of increment `grid`, lines are that many grid steps apart. With-/// `align_left` its ink starts at the indent (see [`DropCap::lsb`]).+/// `align_left` its ink starts at the indent (see [`DropCap::lsb`]). Spaces right after it join it+/// at its size without widening it.#[allow(clippy::too_many_arguments)]fn split_drop_cap(db: &ScopedFonts<'_>,@@ -2886,6 +2887,9 @@ fn split_drop_cap(}let lines = lines.clamp(1, MAX_DROP_CAP_LINES) as usize;let mut dc: Vec<Glyph> = glyphs.drain(..n).collect();+ let spaces = glyphs.iter().take_while(|g| g.is_space()).count();+ let mut after: Vec<Glyph> = glyphs.drain(..spaces).collect();+ let end = after.last().map_or(end, |g| g.byte.saturating_add(g.len).max(end));let body = glyphs.iter().find(|g| g.len > 0 && g.cap > 0.0);let (lead, cap) = body.map_or((base_leading, base_cap), |g| (g.leading, g.cap));let lead = match grid.map(|inc| (lead / inc - 1e-6).ceil().max(1.0) * inc) {@@ -2896,7 +2900,7 @@ fn split_drop_cap(let own = dc.iter().map(|g| g.cap).fold(0.0, f64::max);let k = if own > 0.0 { (drop + cap) / own } else { 1.0 };let k = if k.is_finite() && k > 0.0 { k.min(1000.0) } else { 1.0 };- for g in &mut dc {+ for g in dc.iter_mut().chain(after.iter_mut()) {g.adv *= k;g.dx *= k;g.dy *= k;@@ -2910,7 +2914,6 @@ fn split_drop_cap(g.size *= k;g.space *= k;}- let width = dc.iter().map(|g| g.adv).sum();let lsb = match dc.first() {Some(g) if align_left => {let ink = designcraft_geom::Shape::bounding_box(&*db.outline(g.face.get(), g.gid));@@ -2919,6 +2922,8 @@ fn split_drop_cap(}_ => 0.0,};+ let width = dc.iter().map(|g| g.adv).sum();+ dc.append(&mut after);Some(DropCap { glyphs: dc, end, lines, width, drop, lsb })}diff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rsindex 57c5516dd..5b06adfcc 100644--- a/crates/compose/src/tests.rs+++ b/crates/compose/src/tests.rs@@ -2164,6 +2164,24 @@ fn drop_cap_reaches_down_by_the_text_leading_past_a_line_with_larger_leading() {assert!((b.baseline - (lines[0].baseline + 2.0 * 14.4)).abs() < 1e-6, "{}", b.baseline);}+/// A space after the drop cap is set at its size on its baseline and doesn't widen the indent: the+/// lines beside it start where its characters end.+#[test]+fn space_after_a_drop_cap_does_not_widen_the_indent() {+ let (d, sid, _) = drop_doc(&format!("In 2003 {LOREM}"), drop_cap(2, 2));+ let cs = compose_story(&d, sid, &ComposeOptions::default());+ let lines = all_lines(&cs);+ let (i, n) = (&lines[0].glyphs[0], &lines[0].glyphs[1]);+ assert_eq!((i.byte, n.byte), (0, 1));+ let end = n.x + n.adv;+ for l in &lines[..2] {+ assert!((text_x(l, 3) - end).abs() < 1e-6, "{} vs {end}", text_x(l, 3));+ }+ let space = lines[0].glyphs.iter().find(|g| g.byte == 2).unwrap();+ assert!((space.sy - n.sy).abs() < 1e-9 && (space.y - n.y).abs() < 1e-9, "the space is set like the drop cap");+ assert_eq!(lines[0].drop_cap.unwrap().end, 3);+}+/// A rule in Text Color takes the colour of the paragraph's text: the first character's for the/// rule above, the last character's for the rule below. A swatch colour is used as is.#[test]