Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Text: drop caps align their left edge and count characters by code point

aionggc6b00bc03ddc
diff --git a/ROADMAP.md b/ROADMAP.md
index 63ad7275e..3efaedc6b 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -57,7 +57,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}`, Paragraph panel, Paragraph Style Options › Drop Caps and Nested Styles; IDML DropCapLines/DropCapCharacters/DropCapStyle): the first characters (grapheme clusters, up to 150) are enlarged from the first line's cap height down to the baseline of line N (up to 25), the lines beside them are indented by their advance (on the right in right-to-left paragraphs), baselines don't move; 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 to the baseline of line N (up to 25), 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.
- 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.rs
index 90dc9a35f..bd33ad748 100644
--- a/crates/compose/src/lib.rs
+++ b/crates/compose/src/lib.rs
@@ -587,6 +587,8 @@ pub fn compose(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &Compo
face.cap_height * base_chars.size / face.upem * base_chars.v_scale
};
let drop_grid = cur_frame.and_then(|f| f.grid).filter(|_| pp.grid_align == GridAlign::AllLines).map(|g| g.1);
+ // Align Left Edge (left-to-right paragraphs).
+ let drop_align = pp.drop_cap_align_left && pp.direction == designcraft_doc::TextDirection::LeftToRight;
if !pp.nested_line_styles.is_empty() && cur.fi < frames.len() {
// Nested line styles: find where the first lines end in this column, restyle them, and
// look again (the style changes the widths) until the lines settle.
@@ -597,10 +599,10 @@ pub fn compose(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &Compo
for _ in 0..3 {
// The same drop cap, spacing, hyphenation and breaker as the layout below.
let mut gl = sp.glyphs.clone();
- let dc = split_drop_cap(&mut gl, drop_end, pp.drop_cap_lines, base_leading, base_cap, drop_grid);
+ let dc = split_drop_cap(db, &mut gl, drop_end, pp.drop_cap_lines, base_leading, base_cap, drop_grid, drop_align);
let width = |j: usize| {
let ind = match &dc {
- Some(dc) if j < dc.lines => dc.width,
+ Some(dc) if j < dc.lines => dc.indent(),
_ if j == 0 => pp.first_line_indent,
_ => 0.0,
};
@@ -661,7 +663,7 @@ pub fn compose(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &Compo
let rule_color = |r: &designcraft_doc::Rule, text: &(String, f32)| {
if r.color == designcraft_doc::TEXT_COLOR { text.clone() } else { (r.color.clone(), r.tint) }
};
- let drop_cap = split_drop_cap(&mut sp.glyphs, drop_end, pp.drop_cap_lines, base_leading, base_cap, drop_grid);
+ let drop_cap = split_drop_cap(db, &mut sp.glyphs, drop_end, pp.drop_cap_lines, base_leading, base_cap, drop_grid, drop_align);
match pp.list_type {
designcraft_doc::ListType::Numbers if !pp.list_name.is_empty() => {
// A named list: carries on past other paragraphs (and from earlier stories).
@@ -746,7 +748,7 @@ pub fn compose(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &Compo
let ind = pp.left_indent
+ pp.right_indent
+ match &drop_cap {
- Some(dc) if line_no + j < dc.lines && col_first_line == 0 => dc.width,
+ Some(dc) if line_no + j < dc.lines && col_first_line == 0 => dc.indent(),
_ if line_no + j == 0 => pp.first_line_indent,
_ => 0.0,
};
@@ -843,7 +845,7 @@ pub fn compose(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &Compo
break;
}
// A drop cap sits at the start-side indent; the first-line indent doesn't move it.
- let beside = drop_cap.as_ref().filter(|dc| line_no < dc.lines && col_first_line == 0).map(|dc| dc.width);
+ let beside = drop_cap.as_ref().filter(|dc| line_no < dc.lines && col_first_line == 0).map(DropCap::indent);
let (ind_l, ind_r) = match beside {
Some(w) if rtl => (pp.left_indent, pp.right_indent + w),
Some(w) => (pp.left_indent + w, pp.right_indent),
@@ -858,7 +860,7 @@ pub fn compose(doc: &Document, story: &Story, frames: &[FrameSpec], opts: &Compo
if line_no == 0
&& let Some(dc) = &drop_cap
{
- let at = if rtl { x1 - pp.right_indent - dc.width } else { x0 + pp.left_indent };
+ let at = if rtl { x1 - pp.right_indent - dc.width } else { x0 + pp.left_indent - dc.lsb };
placed.splice(0..0, place_drop_cap(dc, at, rtl));
drop_box = Some(DropCapBox {
end: dc.end,
@@ -2037,8 +2039,10 @@ pub const MAX_DROP_CAP_LINES: u32 = 25;
pub const MAX_DROP_CAP_CHARS: u32 = 150;
/// Byte where paragraph `prange`'s drop cap ends: after its first `drop_cap_chars` characters
-/// (grapheme clusters, spaces included; all of them in a shorter paragraph). `prange.start` when it
-/// has none: no lines or characters, or vertical text (which sets no drop caps).
+/// (code points, as InDesign counts them, spaces included), extended to the end of the grapheme
+/// cluster they end in so a letter keeps its combining marks; all of them in a shorter paragraph.
+/// `prange.start` when it has none: no lines or characters, or vertical text (which sets no drop
+/// caps).
fn drop_cap_end(text: &str, prange: Range<usize>, pp: &ParaProps, vertical: bool) -> usize {
use unicode_segmentation::UnicodeSegmentation as _;
if vertical || pp.drop_cap_lines == 0 || pp.drop_cap_chars == 0 {
@@ -2047,7 +2051,8 @@ fn drop_cap_end(text: &str, prange: Range<usize>, pp: &ParaProps, vertical: bool
let Some(para) = text.get(prange.clone()) else { return prange.start };
let para = para.trim_end_matches('\n');
let n = pp.drop_cap_chars.min(MAX_DROP_CAP_CHARS) as usize;
- prange.start + para.grapheme_indices(true).nth(n).map_or(para.len(), |(i, _)| i)
+ let end = para.char_indices().nth(n).map_or(para.len(), |(i, _)| i);
+ prange.start + para.grapheme_indices(true).map(|(i, _)| i).find(|i| *i >= end).unwrap_or(para.len())
}
/// A paragraph's drop cap: its first glyphs, enlarged to reach down `lines` lines.
@@ -2056,8 +2061,11 @@ struct DropCap {
/// Story byte it ends at.
end: usize,
lines: usize,
- /// Its advance: how far the lines beside it are indented.
+ /// Its advance.
width: f64,
+ /// How far its origin sits left of the indent: its first letter's left side bearing with
+ /// Align Left Edge, else 0.
+ lsb: f64,
/// Its baseline below the first line's, at the paragraph's leading.
drop: f64,
}
@@ -2065,8 +2073,19 @@ struct DropCap {
/// Take the drop cap (the glyphs before byte `end`) off the front of a paragraph's glyphs and scale
/// 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.
-fn split_drop_cap(glyphs: &mut Vec<Glyph>, end: usize, lines: u32, base_leading: f64, base_cap: f64, grid: Option<f64>) -> Option<DropCap> {
+/// 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`]).
+#[allow(clippy::too_many_arguments)]
+fn split_drop_cap(
+ db: &FontDb,
+ glyphs: &mut Vec<Glyph>,
+ end: usize,
+ lines: u32,
+ base_leading: f64,
+ base_cap: f64,
+ grid: Option<f64>,
+ align_left: bool,
+) -> Option<DropCap> {
let n = glyphs.iter().take_while(|g| g.byte < end).count();
if n == 0 {
return None;
@@ -2098,7 +2117,22 @@ fn split_drop_cap(glyphs: &mut Vec<Glyph>, end: usize, lines: u32, base_leading:
g.space *= k;
}
let width = dc.iter().map(|g| g.adv).sum();
- Some(DropCap { glyphs: dc, end, lines, width, drop })
+ let lsb = match dc.first() {
+ Some(g) if align_left => {
+ let ink = designcraft_geom::Shape::bounding_box(&*db.outline(g.face.get(), g.gid));
+ let lsb = g.dx + ink.x0 * g.sx;
+ if ink.width() > 0.0 && lsb.is_finite() { lsb } else { 0.0 }
+ }
+ _ => 0.0,
+ };
+ Some(DropCap { glyphs: dc, end, lines, width, drop, lsb })
+}
+
+impl DropCap {
+ /// How far the lines beside it are indented: to the end of its advance.
+ fn indent(&self) -> f64 {
+ self.width - self.lsb
+ }
}
/// The drop cap's glyphs set from `at` (right to left: mirrored, its first character on the right).
diff --git a/crates/compose/src/tests.rs b/crates/compose/src/tests.rs
index a986d9667..9d6d29e92 100644
--- a/crates/compose/src/tests.rs
+++ b/crates/compose/src/tests.rs
@@ -1576,8 +1576,15 @@ fn short_paragraph_keeps_its_drop_cap_and_the_next_paragraph_is_not_indented() {
}
#[test]
-fn drop_cap_counts_grapheme_clusters_and_clamps_to_the_paragraph() {
- // An accented letter written with a combining mark is one character.
+fn drop_cap_counts_code_points_without_splitting_clusters_and_clamps_to_the_paragraph() {
+ // Four characters: a letter, its combining mark, another letter and a no-break space.
+ let (d, sid, _) = drop_doc("A\u{301}B\u{a0}rest of the words", drop_cap(2, 4));
+ let cs = compose_story(&d, sid, &ComposeOptions::default());
+ let l = &cs.frames[0].lines[0];
+ let big: Vec<usize> = l.glyphs.iter().filter(|g| g.len > 0 && g.y > 1.0).map(|g| g.byte).collect();
+ assert!(big.contains(&0) && big.contains(&3), "{big:?}");
+ assert!(big.iter().all(|b| *b < 6), "the r isn't part of it: {big:?}");
+ // One character that has a combining mark after it takes the mark too.
let (d, sid, _) = drop_doc("e\u{301}tude and more words", drop_cap(2, 1));
let cs = compose_story(&d, sid, &ComposeOptions::default());
let l = &cs.frames[0].lines[0];
@@ -1749,3 +1756,37 @@ fn text_color_rules_follow_the_text() {
d.story_mut(sid).unwrap().paras[0].para.rule_above = Some(swatch);
assert_eq!(decos(&d)[0], ("[Black]".to_string(), 0.3));
}
+
+/// Align Left Edge (InDesign's default): the drop cap's origin moves left by its first letter's
+/// left side bearing so its ink starts at the indent, and the lines beside it start where its
+/// advance ends. Measured case: 14/18 text, two lines, one character.
+#[test]
+fn drop_cap_aligns_its_left_edge() {
+ let text = format!("Once {LOREM}");
+ let compose = |align: Option<bool>| {
+ let para = ParaAttrs { left_indent: Some(10.0), drop_cap_align_left: align, ..drop_cap(2, 1) };
+ let (mut d, sid, _) = doc_with(&text, Rect::new(0.0, 0.0, 300.0, 1000.0), para);
+ d.story_mut(sid).unwrap().paras[0].chars =
+ designcraft_doc::CharAttrs { size: Some(14.0), leading: Some(designcraft_doc::Leading::Points(18.0)), ..Default::default() };
+ compose_story(&d, sid, &ComposeOptions::default())
+ };
+ use designcraft_geom::Shape as _;
+ let ink_left = |g: &PlacedGlyph| g.x + designcraft_fonts::FontDb::global().outline(g.face.get(), g.gid).bounding_box().x0 * g.sx;
+ for align in [None, Some(true), Some(false)] {
+ let cs = compose(align);
+ let lines = all_lines(&cs);
+ let dc = &lines[0].glyphs[0];
+ assert_eq!(dc.byte, 0);
+ let lsb = ink_left(dc) - dc.x;
+ assert!(lsb > 0.5, "the O has a visible side bearing at this size: {lsb}");
+ if align != Some(false) {
+ assert!((ink_left(dc) - 10.0).abs() < 1e-6, "{align:?}: ink at {}", ink_left(dc));
+ } else {
+ assert!((dc.x - 10.0).abs() < 1e-6, "origin at {}", dc.x);
+ }
+ for l in &lines[..2] {
+ assert!((text_x(l, 1) - (dc.x + dc.adv)).abs() < 1e-6, "{align:?}: {} vs {}", text_x(l, 1), dc.x + dc.adv);
+ }
+ assert!((text_x(lines[2], 1) - 10.0).abs() < 1e-6);
+ }
+}
diff --git a/crates/doc/src/attrs.rs b/crates/doc/src/attrs.rs
index 195d6a88c..fb942ff97 100644
--- a/crates/doc/src/attrs.rs
+++ b/crates/doc/src/attrs.rs
@@ -568,12 +568,17 @@ attr_set! {
last_line_indent: f64 = 0.0,
space_before: f64 = 0.0,
space_after: f64 = 0.0,
- /// Drop cap: the paragraph's first `drop_cap_chars` characters (grapheme clusters) set
- /// `drop_cap_lines` lines tall, in the character style `drop_cap_style` ("" or `[None]`: the
- /// text's own formatting).
+ /// Drop cap: the paragraph's first `drop_cap_chars` characters (code points, never
+ /// splitting a base from its combining marks) set `drop_cap_lines` lines tall, in the
+ /// character style `drop_cap_style` ("" or `[None]`: the text's own formatting).
drop_cap_lines: u32 = 0,
drop_cap_chars: u32 = 0,
drop_cap_style: String = String::new(),
+ /// Align Left Edge: the drop cap's ink starts at the indent (its first letter's left side
+ /// bearing is taken off), and the lines beside it start where its advance ends.
+ drop_cap_align_left: bool = true,
+ /// Scale for Descenders (kept and round-tripped; doesn't change the layout).
+ drop_cap_scale_descenders: bool = false,
/// Nested styles, in order from the paragraph start.
nested_styles: Vec<NestedStyle> = Vec::new(),
/// GREP styles: a character style for every match of a pattern (applied after nested).
diff --git a/crates/engine/src/cmd/text.rs b/crates/engine/src/cmd/text.rs
index 3789a1ac9..718bbc4b1 100644
--- a/crates/engine/src/cmd/text.rs
+++ b/crates/engine/src/cmd/text.rs
@@ -115,7 +115,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Paragraph Formatting",
[],
None,
- "{attrs: {align?, leftIndent?, firstLineIndent?, spaceBefore?, spaceAfter?, dropCapLines?, dropCapChars?, dropCapStyle?, hyphenate?, composer?, tabs?, …}}",
+ "{attrs: {align?, leftIndent?, firstLineIndent?, spaceBefore?, spaceAfter?, dropCapLines?, dropCapChars?, dropCapStyle?, dropCapAlignLeft?, dropCapScaleDescenders?, hyphenate?, composer?, tabs?, …}}",
has_text_or_frames,
|s, p| format_paras(s, p.get("attrs").unwrap_or(p))
),
diff --git a/crates/engine/src/tests_idml.rs b/crates/engine/src/tests_idml.rs
index 2ac666291..b3d1ef566 100644
--- a/crates/engine/src/tests_idml.rs
+++ b/crates/engine/src/tests_idml.rs
@@ -346,7 +346,7 @@ fn type_para_sets_a_drop_cap_that_survives_idml() {
let r = s.execute("frame.create", &json!({"rect": [72, 72, 300, 400], "content": "text", "text": text})).unwrap();
let sid = r["story"].as_u64().unwrap();
s.execute("text.select", &json!({"story": sid, "anchor": 3, "focus": 3})).unwrap();
- s.execute("type.para", &json!({"attrs": {"dropCapLines": 3, "dropCapChars": 1, "dropCapStyle": "Initial"}})).unwrap();
+ s.execute("type.para", &json!({"attrs": {"dropCapLines": 3, "dropCapChars": 1, "dropCapStyle": "Initial", "dropCapAlignLeft": false}})).unwrap();
let d = s.doc().unwrap().doc.clone();
let cs = designcraft_compose::compose_story(&d, designcraft_doc::StoryId(sid), &Default::default());
let lines = &cs.frames[0].lines;
@@ -358,5 +358,7 @@ fn type_para_sets_a_drop_cap_that_survives_idml() {
assert_eq!((p.drop_cap_lines, p.drop_cap_chars, p.drop_cap_style.as_deref()), (Some(3), Some(1), Some("Initial")));
let back = designcraft_idml::import_idml(&designcraft_idml::export_idml(&d)).unwrap();
let p = &back.stories.values().find(|st| st.text.starts_with("Once")).unwrap().paras[0].para;
- assert_eq!((p.drop_cap_lines, p.drop_cap_chars, p.drop_cap_style.as_deref()), (Some(3), Some(1), Some("Initial")));
+ assert_eq!((p.drop_cap_lines, p.drop_cap_chars, p.drop_cap_align_left), (Some(3), Some(1), Some(false)));
+ // IDML has no attribute for the drop cap's character style.
+ assert_eq!(p.drop_cap_style, None);
}
diff --git a/crates/format/src/lib.rs b/crates/format/src/lib.rs
index fe53d408d..72efe9e6d 100644
--- a/crates/format/src/lib.rs
+++ b/crates/format/src/lib.rs
@@ -13,7 +13,7 @@
use std::io::{Cursor, Read, Write};
use std::sync::Arc;
-use designcraft_doc::{AssetId, Document, Story};
+use designcraft_doc::{AssetId, Document, ParaAttrs, Story};
use serde_json::{Value, json};
pub const MIME: &str = "application/vnd.designcraft+zip";
@@ -113,32 +113,39 @@ fn load_zip(bytes: &[u8]) -> Result<Document, FormatError> {
/// Bring a document saved in format `from` up to [`VERSION`].
fn upgrade(doc: &mut Document, from: u32) {
if from < 2 {
- pin_keep_all_lines(doc);
+ // Format 1 laid out an unset Keep Lines Together mode as all lines in paragraph, and drop
+ // caps without Align Left Edge.
+ pin_para_default(doc, |a| &mut a.keep_all_lines, true);
+ pin_para_default(doc, |a| &mut a.drop_cap_align_left, false);
}
}
-/// Format 1 laid out an unset Keep Lines Together mode as all lines in paragraph. Pin that where
-/// nothing set it: at the start of each paragraph style chain, and on paragraphs whose style is
-/// missing.
-fn pin_keep_all_lines(doc: &mut Document) {
+/// Pin a paragraph attribute to the value an older format resolved it to where nothing set it:
+/// at the start of each paragraph style chain that leaves it unset, and on paragraphs whose style
+/// is missing.
+fn pin_para_default<T: Clone>(doc: &mut Document, field: fn(&mut ParaAttrs) -> &mut Option<T>, old: T) {
+ let unset = |a: &ParaAttrs| field(&mut a.clone()).is_none();
let roots: std::collections::HashSet<String> = doc
.styles
.paragraph
.iter()
.filter_map(|s| {
let chain = doc.styles.para_chain(&s.name);
- if chain.iter().any(|c| c.para.keep_all_lines.is_some()) { None } else { chain.first().map(|c| c.name.clone()) }
+ if chain.iter().all(|c| unset(&c.para)) { chain.first().map(|c| c.name.clone()) } else { None }
})
.collect();
if !roots.is_empty() {
for s in doc.styles_mut().paragraph.iter_mut().filter(|s| roots.contains(&s.name)) {
- s.para.keep_all_lines = Some(true);
+ *field(&mut s.para) = Some(old.clone());
}
}
let styles = doc.styles.clone();
let mut pin = |st: &mut Story| {
- for p in st.paras.iter_mut().filter(|p| p.para.keep_all_lines.is_none() && styles.para(&p.style).is_none()) {
- p.para.keep_all_lines = Some(true);
+ for p in st.paras.iter_mut().filter(|p| styles.para(&p.style).is_none()) {
+ let v = field(&mut p.para);
+ if v.is_none() {
+ *v = Some(old.clone());
+ }
}
};
for st in doc.stories.values_mut() {
@@ -309,6 +316,35 @@ mod tests {
assert!(!designcraft_doc::NumberedList::default().continue_across_stories);
}
+ /// Format 1 set drop caps without Align Left Edge: those documents still do where nothing set
+ /// it. New documents align the drop cap's left edge.
+ #[test]
+ fn format_1_drop_caps_stay_unaligned() {
+ let mut d = Document::new(&NewDocument::default());
+ let st = d.styles_mut();
+ st.paragraph.push(para_style("Opener", None, None));
+ st.paragraph.push(designcraft_doc::ParagraphStyle {
+ para: designcraft_doc::ParaAttrs { drop_cap_align_left: Some(true), ..Default::default() },
+ ..para_style("Aligned", None, None)
+ });
+ let lid = d.default_layer();
+ let (_, sid) =
+ d.add_text_frame(SpreadRef::Doc(0), Rect::new(10.0, 10.0, 200.0, 200.0), lid, "One\nTwo\nThree", ParaFormat::default()).unwrap();
+ {
+ let s = d.story_mut(sid).unwrap();
+ for (p, name) in s.paras.iter_mut().zip(["Opener", "Aligned", "Missing"]) {
+ p.style = name.into();
+ p.para.drop_cap_lines = Some(2);
+ p.para.drop_cap_chars = Some(1);
+ }
+ }
+ let back = load(&save_v1(&d)).unwrap();
+ let aligned: Vec<bool> = back.story(sid).unwrap().paras.iter().map(|p| back.styles.resolve_para(p).0.drop_cap_align_left).collect();
+ assert_eq!(aligned, [false, true, false]);
+ let now = load(&save(&d).unwrap()).unwrap();
+ assert!(now.styles.resolve_para(&now.story(sid).unwrap().paras[0]).0.drop_cap_align_left);
+ }
+
#[test]
fn rejects_garbage_and_newer_versions() {
assert!(load(b"nope").is_err());
diff --git a/crates/idml/src/export.rs b/crates/idml/src/export.rs
index 6475be0e9..2df46b2c1 100644
--- a/crates/idml/src/export.rs
+++ b/crates/idml/src/export.rs
@@ -1150,9 +1150,13 @@ impl<'a> Ex<'a> {
n!(space_after, "SpaceAfter");
n!(drop_cap_lines, "DropCapLines");
n!(drop_cap_chars, "DropCapCharacters");
- if let Some(s) = &a.drop_cap_style {
- let s = if s.is_empty() { designcraft_doc::NO_CHAR_STYLE } else { s.as_str() };
- el.set("DropCapStyle", names::style_self("CharacterStyle", CHAR_BUILTINS, s));
+ // The drop cap's character style isn't written: IDML has no attribute for it (InDesign
+ // applies one through a Dropcap nested style).
+ if a.drop_cap_align_left.is_some() || a.drop_cap_scale_descenders.is_some() {
+ let d = designcraft_doc::ParaProps::default();
+ let bits = u32::from(a.drop_cap_align_left.unwrap_or(d.drop_cap_align_left))
+ | u32::from(a.drop_cap_scale_descenders.unwrap_or(d.drop_cap_scale_descenders)) << 1;
+ el.set("DropcapDetail", bits);
}
if let Some(g) = a.grid_align {
match g {
diff --git a/crates/idml/src/import.rs b/crates/idml/src/import.rs
index d2624ace9..c96d858f7 100644
--- a/crates/idml/src/import.rs
+++ b/crates/idml/src/import.rs
@@ -1152,6 +1152,12 @@ impl<'r> Importer<'r> {
a.drop_cap_lines = u("DropCapLines");
a.drop_cap_chars = u("DropCapCharacters");
a.drop_cap_style = e.prop("DropCapStyle").map(|r| self.char_style_ref(r.trim()));
+ // DropcapDetail bits: 1 = Align Left Edge, 2 = Scale for Descenders.
+ if let Some(v) = e.num("DropcapDetail").filter(|v| v.is_finite() && *v >= 0.0) {
+ let bits = v as u32;
+ a.drop_cap_align_left = Some(bits & 1 != 0);
+ a.drop_cap_scale_descenders = Some(bits & 2 != 0);
+ }
if let Some(g) = e.prop("GridAlignment") {
a.grid_align = Some(if g == "None" {
GridAlign::None
diff --git a/crates/idml/src/tests.rs b/crates/idml/src/tests.rs
index 6f6b9f0ff..e4289d8d3 100644
--- a/crates/idml/src/tests.rs
+++ b/crates/idml/src/tests.rs
@@ -277,6 +277,7 @@ fn indesign_text_defaults() -> Vec<AttrRow> {
"SpaceAfter": "0" => 0.0, "6" => 6.0, |r| r.0.space_after;
"DropCapLines": "0" => 0, "3" => 3, |r| r.0.drop_cap_lines;
"DropCapCharacters": "0" => 0, "1" => 1, |r| r.0.drop_cap_chars;
+ "DropcapDetail": "1" => (true, false), "2" => (false, true), |r| (r.0.drop_cap_align_left, r.0.drop_cap_scale_descenders);
"GridAlignment": "None" => GridAlign::None, "AlignToBaseline" => GridAlign::AllLines, |r| r.0.grid_align;
"Composer": "HL Composer" => Composer::Paragraph, "HL Single" => Composer::SingleLine, |r| r.0.composer;
"Hyphenation": "true" => true, "false" => false, |r| r.0.hyphenate;
@@ -984,7 +985,21 @@ fn drop_caps_import_and_round_trip() {
};
let d = import_idml_with(&bytes, &|_| None).unwrap();
check(&d);
- check(&import_idml(&export_idml(&d)).unwrap());
+ // The drop cap's character style isn't written to IDML (InDesign sets it through a Dropcap
+ // nested style); Align Left Edge and Scale for Descenders are, as DropcapDetail.
+ let mut d = d;
+ if let Some(s) = d.styles_mut().para_mut("Opener") {
+ s.para.drop_cap_align_left = Some(false);
+ s.para.drop_cap_scale_descenders = Some(true);
+ }
+ let bytes = export_idml(&d);
+ assert!(!zip_text(&bytes, "").contains("DropCapStyle"));
+ assert!(zip_text(&bytes, "Resources/Styles.xml").contains(r#"DropcapDetail="2""#));
+ let back = import_idml(&bytes).unwrap();
+ let st = back.styles.para("Opener").unwrap();
+ assert_eq!((st.para.drop_cap_chars, st.para.drop_cap_lines, st.para.drop_cap_style.as_deref()), (Some(1), Some(3), None));
+ assert_eq!((st.para.drop_cap_align_left, st.para.drop_cap_scale_descenders), (Some(false), Some(true)));
+ assert_eq!(st.para.nested_styles.as_ref().map(|n| n[0].until.clone()), Some(designcraft_doc::NestedUntil::Dropcap));
}
/// Frames take the corners and Text Frame Options they don't write from their object style chain,
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 35deb1081..e5555dbbe 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -1799,6 +1799,12 @@ fn paragraph_style_options(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialo
});
ui.end_row();
});
+ for (label, key) in [("Align Left Edge", "dropCapAlignLeft"), ("Scale for Descenders", "dropCapScaleDescenders")] {
+ let mut on = cur(d, &format!("p.{key}"), &pv[key]).as_bool().unwrap_or(false);
+ if ui.checkbox(&mut on, crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, label))).changed() {
+ d.fields.insert(format!("p.{key}"), json!(on));
+ }
+ }
ui.add_space(8.0);
crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&app.ui.language, "Nested Styles")).font(semibold(12.0)));
let mut list: Vec<Value> = cur(d, "p.nestedStyles", &pv["nestedStyles"]).as_array().cloned().unwrap_or_default();
diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs
index a70bbe22a..912a2e673 100644
--- a/crates/ui-egui/src/i18n.rs
+++ b/crates/ui-egui/src/i18n.rs
@@ -1897,6 +1897,17 @@ const TABLE: &[(&str, [&str; 5])] = &[
("Characters:", ["Zeichen:", "Caractères :", "Caracteres:", "文字数:", "字符数:"]),
("Drop Lines", ["Initialzeilen", "Lignes lettrine", "Líneas capitular", "ドロップ行数", "下沉行数"]),
("Drop Chars", ["Initialzeichen", "Car. lettrine", "Car. capitular", "ドロップ文字数", "下沉字符数"]),
+ ("Align Left Edge", ["Linke Kante ausrichten", "Aligner le bord gauche", "Alinear borde izquierdo", "左端揃え", "左边缘对齐"]),
+ (
+ "Scale for Descenders",
+ [
+ "Für Unterlängen skalieren",
+ "Mise à l'échelle pour les jambages",
+ "Escalar para trazos descendentes",
+ "ディセンダーに合わせて拡大・縮小",
+ "为下伸部分缩放",
+ ],
+ ),
("chars", ["chars", "chars", "chars", "chars", "指定字符"]),
("[Automatic]", ["[Automatic]", "[Automatic]", "[Automatic]", "[Automatic]", "[自动]"]),
("Tracking:", ["Tracking:", "Tracking:", "Tracking:", "Tracking:", "字距:"]),
diff --git a/crates/ui-egui/src/i18n/ar.rs b/crates/ui-egui/src/i18n/ar.rs
index 3180bedea..5c86e686c 100644
--- a/crates/ui-egui/src/i18n/ar.rs
+++ b/crates/ui-egui/src/i18n/ar.rs
@@ -323,6 +323,8 @@ pub(super) const TABLE: &[(&str, &str)] = &[
("Characters:", "الأحرف:"),
("Drop Lines", "أسطر الاستهلال"),
("Drop Chars", "أحرف الاستهلال"),
+ ("Align Left Edge", "محاذاة الحافة اليسرى"),
+ ("Scale for Descenders", "تحجيم للأحرف الهابطة"),
("chars", "محارف محددة"),
("[Automatic]", "[تلقائي]"),
("Size:", "الحجم:"),