From 192d89231813c8043db5130b59992cbb8e7de423 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 07:12:50 -0500 Subject: [PATCH] Parse mojikumi rows with shared IDML model --- Cargo.lock | 18 ++++++------ Cargo.toml | 4 +-- crates/idml/src/import/text_attrs.rs | 42 ++++++++-------------------- 3 files changed, 22 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dddf58900..4d3d5b3b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1242,10 +1242,10 @@ dependencies = [ [[package]] name = "craft-idml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4abdd336b8b14c30366d28c1bb296284d2056772#4abdd336b8b14c30366d28c1bb296284d2056772" +source = "git+https://github.com/storytold/craft-libs?rev=4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930#4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4abdd336b8b14c30366d28c1bb296284d2056772)", - "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4abdd336b8b14c30366d28c1bb296284d2056772)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930)", "thiserror 2.0.21", ] @@ -1656,7 +1656,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4abdd336b8b14c30366d28c1bb296284d2056772#4abdd336b8b14c30366d28c1bb296284d2056772" +source = "git+https://github.com/storytold/craft-libs?rev=4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930#4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930" dependencies = [ "quick-xml 0.41.0", "thiserror 2.0.21", @@ -1730,7 +1730,7 @@ dependencies = [ [[package]] name = "craft-zip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4abdd336b8b14c30366d28c1bb296284d2056772#4abdd336b8b14c30366d28c1bb296284d2056772" +source = "git+https://github.com/storytold/craft-libs?rev=4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930#4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930" dependencies = [ "flate2", "thiserror 2.0.21", @@ -2021,7 +2021,7 @@ 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=4abdd336b8b14c30366d28c1bb296284d2056772)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930)", "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f23b0f33f0d00b157476533a43cbbcfd901aa1f1)", "designcraft-color", "designcraft-compose", @@ -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=4abdd336b8b14c30366d28c1bb296284d2056772)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930)", "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=4abdd336b8b14c30366d28c1bb296284d2056772)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930)", "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=4abdd336b8b14c30366d28c1bb296284d2056772)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930)", "craft-rtf", "craft-wordmodel", "craft-xlsx", diff --git a/Cargo.toml b/Cargo.toml index 55a29ad5f..7985df9db 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 = "4abdd336b8b14c30366d28c1bb296284d2056772", version = "=0.1.0" } +craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930", 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 = "4abdd336b8b14c30366d28c1bb296284d2056772", version = "=0.1.0" } +craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "4bb95f34d6e0e6345b7eefd9dbfb9eb7bb619930", 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 6656b3de7..44ccfc5cd 100644 --- a/crates/idml/src/import/text_attrs.rs +++ b/crates/idml/src/import/text_attrs.rs @@ -20,37 +20,17 @@ fn tab_list_repaired(read: &[TabStop], sanitized: &[TabStop]) -> bool { } pub(super) fn mojikumi_row(e: &El) -> Result { - let number = |key: &str| -> Result { - let Some(raw) = e.prop(key) else { - return Ok(0.0); - }; - raw.trim().parse::().ok().filter(|v| v.is_finite()).ok_or_else(|| IdmlError::Invalid(format!("Mojikumi row has invalid {key}"))) - }; - let integer = |key: &str| -> Result { - let v = number(key)?; - if v.fract() != 0.0 || v < f64::from(i16::MIN) || v > f64::from(i16::MAX) { - return Err(IdmlError::Invalid(format!("Mojikumi {key} must be an in-range integer"))); - } - Ok(v as i16) - }; - let boolean = |key: &str| -> Result { - match e.prop(key).as_deref().map(str::trim) { - None | Some("false") => Ok(false), - Some("true") => Ok(true), - _ => Err(IdmlError::Invalid(format!("Mojikumi row has invalid {key}"))), - } - }; - let row = designcraft_doc::cjk::MojikumiAki { - target_class: integer("TargetMojikumiClass")?, - side_class: integer("SideMojikumiClass")?, - after: boolean("SideIsAfterTarget")?, - minimum: number("Minimum")?, - desired: number("Desired")?, - maximum: number("Maximum")?, - priority: integer("CompressionPriority")?, - does_not_float: boolean("AkiDoesNotFloat")?, - }; - Ok(row) + let model = craft_idml::model::MojikumiRow::from_el(&crate::xml::to_craft(e)).map_err(IdmlError::Invalid)?; + Ok(designcraft_doc::cjk::MojikumiAki { + target_class: model.target_class, + side_class: model.side_class, + after: model.after, + minimum: model.minimum, + desired: model.desired, + maximum: model.maximum, + priority: model.priority, + does_not_float: model.does_not_float, + }) } impl<'r> Importer<'r> {