DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Drop caps: nested-style lists in table cells and notes clear an inherited drop cap style too
aiongga2ff7d03f862
diff --git a/crates/idml/src/import.rs b/crates/idml/src/import.rsindex 4f2fc5fd6..01f73ad37 100644--- a/crates/idml/src/import.rs+++ b/crates/idml/src/import.rs@@ -2348,11 +2348,7 @@ impl<'r> Importer<'r> {}}for story in self.stories.values_mut() {- for p in &mut story.paras {- if clears(&p.para) && inherits_drop_cap_style(&self.styles, Some(&p.style)) {- p.para.drop_cap_style = Some(st::NO_CHAR_STYLE.into());- }- }+ clear_story_drop_cap_styles(&self.styles, story, 0);}}@@ -2554,6 +2550,30 @@ fn text_frame_options(prefs: &[&El]) -> TextFrameOptions {o}+/// Deepest table-in-cell or note nesting the drop cap pass walks into.+const MAX_STORY_NESTING: usize = 32;++/// [`Importer::clear_inherited_drop_cap_styles`] for one story's paragraphs and those of the table+/// cells, footnotes and endnotes in it.+fn clear_story_drop_cap_styles(styles: &Styles, story: &mut Story, depth: usize) {+ for p in &mut story.paras {+ if p.para.drop_cap_style.is_none() && p.para.nested_styles.is_some() && inherits_drop_cap_style(styles, Some(&p.style)) {+ p.para.drop_cap_style = Some(st::NO_CHAR_STYLE.into());+ }+ }+ if depth >= MAX_STORY_NESTING {+ return;+ }+ for table in story.tables.values_mut() {+ for cell in &mut Arc::make_mut(table).cells {+ clear_story_drop_cap_styles(styles, &mut cell.text, depth + 1);+ }+ }+ for note in story.notes.iter_mut().chain(story.endnotes.iter_mut()) {+ clear_story_drop_cap_styles(styles, &mut Arc::make_mut(note).text, depth + 1);+ }+}+/// Does paragraph style `name` (and its based-on chain) set a drop cap character style? A style/// with a nested style list of its own and no drop cap style has none.fn inherits_drop_cap_style<'a>(styles: &'a Styles, mut name: Option<&'a str>) -> bool {diff --git a/crates/idml/src/tests.rs b/crates/idml/src/tests.rsindex 66488d1fc..630256579 100644--- a/crates/idml/src/tests.rs+++ b/crates/idml/src/tests.rs@@ -1907,6 +1907,30 @@ fn own_nested_styles_clear_an_inherited_drop_cap_style() {assert_eq!(d.styles.resolve_para(&story.paras[1]).0.drop_cap_style, "Strong");}+/// Paragraphs in table cells and footnotes are cleared like story paragraphs.+#[test]+fn own_nested_styles_clear_an_inherited_drop_cap_style_in_cells_and_notes() {+ let opener = |text: &str| {+ format!(+ r#"<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Opener"><Properties>WORDS</Properties><CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]"><Content>{text}</Content></CharacterStyleRange></ParagraphStyleRange>"#+ )+ };+ let paras = format!(+ r#"<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/$ID/NormalParagraphStyle"><CharacterStyleRange AppliedCharacterStyle="CharacterStyle/$ID/[No character style]">+<Content>Body</Content><Footnote>{}</Footnote>+<Table HeaderRowCount="0" FooterRowCount="0"><Row Name="0" MinimumHeight="24"/><Column Name="0" SingleColumnWidth="60"/><Cell Name="0:0">{}</Cell></Table>+</CharacterStyleRange></ParagraphStyleRange>"#,+ opener("Note"),+ opener("Cell")+ );+ let d = import_idml_with(&drop_cap_fixture("", ¶s), &|_| None).unwrap();+ let story = d.stories.values().find(|s| !s.notes.is_empty()).expect("story with a footnote");+ let note = &story.notes[0].text;+ assert_eq!(note.paras[0].para.drop_cap_style.as_deref(), Some(st::NO_CHAR_STYLE), "{:?}", note.text);+ let cell = &story.tables.values().next().expect("a table").cell(0, 0).unwrap().text;+ assert_eq!(cell.paras[0].para.drop_cap_style.as_deref(), Some(st::NO_CHAR_STYLE), "{:?}", cell.text);+}+/// A paragraph that clears its style's drop cap style without nested styles of its own round-trips:/// it is written with the style's list, the Dropcap entry set to [None].#[test]