From 6474733d7cf0952f6ddb6522ccc90b53c91dc9f7 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 07:22:14 -0500 Subject: [PATCH] Map paragraph list values from craft-idml --- Cargo.lock | 58 +++++++++++++-------------- Cargo.toml | 4 +- crates/idml/src/import/text_attrs.rs | 60 +++++++++++++++------------- 3 files changed, 63 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 56707d9c9..9c7bfb32e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1242,20 +1242,20 @@ dependencies = [ [[package]] name = "craft-idml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54#cd9e233af94ae8111a4417a00dc8df0ccb40dc54" +source = "git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558#eed3c28cf016723d004d6f2c79c61424c15d4558" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54)", - "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)", "thiserror 2.0.21", ] [[package]] name = "craft-idml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558#eed3c28cf016723d004d6f2c79c61424c15d4558" +source = "git+https://github.com/storytold/craft-libs?rev=fc4ad0f549a5241a7a78b1c53a2a13d99dc37047#fc4ad0f549a5241a7a78b1c53a2a13d99dc37047" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)", - "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=eed3c28cf016723d004d6f2c79c61424c15d4558)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fc4ad0f549a5241a7a78b1c53a2a13d99dc37047)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fc4ad0f549a5241a7a78b1c53a2a13d99dc37047)", "thiserror 2.0.21", ] @@ -1680,15 +1680,6 @@ dependencies = [ "thiserror 2.0.21", ] -[[package]] -name = "craft-xml" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54#cd9e233af94ae8111a4417a00dc8df0ccb40dc54" -dependencies = [ - "quick-xml 0.41.0", - "thiserror 2.0.21", -] - [[package]] name = "craft-xml" version = "0.1.0" @@ -1717,6 +1708,15 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-xml" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=fc4ad0f549a5241a7a78b1c53a2a13d99dc37047#fc4ad0f549a5241a7a78b1c53a2a13d99dc37047" +dependencies = [ + "quick-xml 0.41.0", + "thiserror 2.0.21", +] + [[package]] name = "craft-zip" version = "0.1.0" @@ -1747,16 +1747,6 @@ dependencies = [ "zip 9.1.1", ] -[[package]] -name = "craft-zip" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54#cd9e233af94ae8111a4417a00dc8df0ccb40dc54" -dependencies = [ - "flate2", - "thiserror 2.0.21", - "zip 9.1.1", -] - [[package]] name = "craft-zip" version = "0.1.0" @@ -1777,6 +1767,16 @@ dependencies = [ "zip 9.1.1", ] +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=fc4ad0f549a5241a7a78b1c53a2a13d99dc37047#fc4ad0f549a5241a7a78b1c53a2a13d99dc37047" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.1", +] + [[package]] name = "crc32fast" version = "1.5.3" @@ -2021,8 +2021,8 @@ dependencies = [ "craft-prepress", "craft-print", "craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f)", - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54)", "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f23b0f33f0d00b157476533a43cbbcfd901aa1f1)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fc4ad0f549a5241a7a78b1c53a2a13d99dc37047)", "designcraft-color", "designcraft-compose", "designcraft-doc", @@ -2103,9 +2103,9 @@ name = "designcraft-idml" version = "0.20.1" dependencies = [ "craft-file-formats", - "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fc4ad0f549a5241a7a78b1c53a2a13d99dc37047)", "craft-svg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cc23ffd4d26f3074808e2187d332564817624f8f)", - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fc4ad0f549a5241a7a78b1c53a2a13d99dc37047)", "designcraft-color", "designcraft-compose", "designcraft-doc", @@ -2222,7 +2222,7 @@ version = "0.20.1" dependencies = [ "craft-docx", "craft-file-formats", - "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cd9e233af94ae8111a4417a00dc8df0ccb40dc54)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fc4ad0f549a5241a7a78b1c53a2a13d99dc37047)", "craft-rtf", "craft-wordmodel", "craft-xlsx", diff --git a/Cargo.toml b/Cargo.toml index d93c7ec4e..41715c983 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,10 +16,10 @@ craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "4052591363 craft-designcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "19692b6190465671e41967c75d0cd4c439d0c84c", version = "=0.1.0" } craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" } craft-epub = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" } -craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "cd9e233af94ae8111a4417a00dc8df0ccb40dc54", version = "=0.1.0" } +craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "fc4ad0f549a5241a7a78b1c53a2a13d99dc37047", version = "=0.1.0" } craft-indd = { git = "https://github.com/storytold/craft-libs", rev = "47bf5650b0d503b97bfb5e841746c4957897d11f", version = "=0.1.0" } craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "cc23ffd4d26f3074808e2187d332564817624f8f", version = "=0.1.0", features = ["tree-render", "tree-text"] } -craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "cd9e233af94ae8111a4417a00dc8df0ccb40dc54", version = "=0.1.0" } +craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "fc4ad0f549a5241a7a78b1c53a2a13d99dc37047", version = "=0.1.0" } craft-xml-dtd = { package = "craft-xml", git = "https://github.com/storytold/craft-libs", rev = "f23b0f33f0d00b157476533a43cbbcfd901aa1f1", version = "=0.1.0" } craft-rtf = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" } craft-xlsx = { git = "https://github.com/storytold/craft-libs", rev = "ba24fe2435adb3c81ad6057faf36365fbba736cf", version = "=0.1.0" } diff --git a/crates/idml/src/import/text_attrs.rs b/crates/idml/src/import/text_attrs.rs index 07f7fe5ac..0fb84bab3 100644 --- a/crates/idml/src/import/text_attrs.rs +++ b/crates/idml/src/import/text_attrs.rs @@ -262,23 +262,27 @@ impl<'r> Importer<'r> { a.rule_above = self.rule(e, "RuleAbove"); a.rule_below = self.rule(e, "RuleBelow"); a.tabs = self.read_tabs(e); - a.list_type = e.prop("BulletsAndNumberingListType").map(|v| match v.trim() { + let list = craft_idml::model::ParagraphListValues::from_el(&crate::xml::to_craft(e)); + a.list_type = list.list_type.map(|value| match value.trim() { "BulletList" => ListType::Bullets, "NumberedList" => ListType::Numbers, _ => ListType::None, }); // A format with no counterpart (CJK, Arabic, Hebrew numbering) is left unset: decimal. - a.number_style = e.prop("NumberingFormat").and_then(|v| names::numbering_format_in(&v)); - a.number_expression = e.prop("NumberingExpression"); - a.list_separator = e.prop("BulletsTextAfter"); - if let Some(b) = e.prop_el("BulletChar") { - // A glyph of a named font (`GlyphWithFont`) has no character to map to. - let unicode = matches!(b.get("BulletCharacterType"), Some("UnicodeOnly" | "UnicodeWithFont")); - if let Some(c) = b.get("BulletCharacterValue").and_then(|v| v.trim().parse::().ok()).and_then(char::from_u32).filter(|_| unicode) { - a.bullet_char = Some(c.to_string()); - } + a.number_style = list.numbering_format.as_deref().and_then(names::numbering_format_in); + a.number_expression = list.expression; + a.list_separator = list.separator; + // A glyph of a named font (`GlyphWithFont`) has no character to map to. + let unicode = matches!(list.bullet_type.as_deref(), Some("UnicodeOnly" | "UnicodeWithFont")); + if unicode { + a.bullet_char = list + .bullet_value + .as_deref() + .and_then(|value| value.trim().parse::().ok()) + .and_then(char::from_u32) + .map(|value| value.to_string()); } - a.balance_ragged = e.prop("BalanceRaggedLines").map(|v| v.trim() != "NoBalancing" && v.trim() != "false"); + a.balance_ragged = list.balance_ragged.map(|value| value.trim() != "NoBalancing" && value.trim() != "false"); a.shading_on = e.boolean("ParagraphShadingOn"); if let Some(c) = e.prop("ParagraphShadingColor") { a.shading_color = Some(self.swatch_ref(c.trim())); @@ -320,28 +324,28 @@ impl<'r> Importer<'r> { a.shading_nonprinting = e.boolean("ParagraphShadingSuppressPrinting"); a.span_space_before = e.num("SpanColumnMinSpaceBefore").filter(|v| v.is_finite()); a.span_space_after = e.num("SpanColumnMinSpaceAfter").filter(|v| v.is_finite()); - a.list_level = e.num("NumberingLevel").filter(|v| v.is_finite()).map(|v| v.round().clamp(1.0, designcraft_doc::LIST_LEVELS as f64) as u32); - if let Some(c) = e.prop("BulletsCharacterStyle") { - a.bullet_char_style = Some(self.char_style_ref(c.trim())); + a.list_level = list.level.map(|value| value.round().clamp(1.0, designcraft_doc::LIST_LEVELS as f64) as u32); + if let Some(style) = list.bullet_character_style { + a.bullet_char_style = Some(self.char_style_ref(style.trim())); } - if let Some(c) = e.prop("NumberingCharacterStyle") { - a.number_char_style = Some(self.char_style_ref(c.trim())); + if let Some(style) = list.numbering_character_style { + a.number_char_style = Some(self.char_style_ref(style.trim())); } - a.bullet_align = e.prop("BulletsAlignment").map(|v| names::list_align_in(v.trim())); - a.number_align = e.prop("NumberingAlignment").map(|v| names::list_align_in(v.trim())); - a.restart_numbers = e.boolean("NumberingApplyRestartPolicy"); - if let Some(r) = e.prop_el("NumberingRestartPolicies") { + a.bullet_align = list.bullet_alignment.as_deref().map(|value| names::list_align_in(value.trim())); + a.number_align = list.numbering_alignment.as_deref().map(|value| names::list_align_in(value.trim())); + a.restart_numbers = list.restart_numbers; + if let Some(level) = list.restart_after_level { // A specific level restarts after that level; any other policy after any higher one. - let level = r.get("LowerLevel").and_then(|v| v.trim().parse::().ok()).unwrap_or(0); - a.restart_after_level = Some(if r.get("RestartPolicy").map(str::trim) == Some("SpecificPreviousLevel") { level } else { 0 }); + a.restart_after_level = Some(if list.restart_after_specific_level { level } else { 0 }); } - if let Some(f) = e.prop("BulletsFont") { - let f = f.trim(); - a.bullet_font = Some(if f == "$ID/" { String::new() } else { f.split('\t').next().unwrap_or(f).to_string() }); + if let Some(font) = list.bullet_font { + let font = font.trim(); + a.bullet_font = Some(if font == "$ID/" { String::new() } else { font.split('\t').next().unwrap_or(font).to_string() }); } - if let Some(f) = e.prop("BulletsFontStyle") { - let f = f.trim(); - a.bullet_font_style = Some(if f == "Nothing" || f == "$ID/" { String::new() } else { f.trim_start_matches("$ID/").to_string() }); + if let Some(style) = list.bullet_font_style { + let style = style.trim(); + a.bullet_font_style = + Some(if style == "Nothing" || style == "$ID/" { String::new() } else { style.trim_start_matches("$ID/").to_string() }); } a }