mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-14 14:22:39 +00:00
Parse mojikumi rows with shared IDML model
This commit is contained in:
3 files changed
+22
-42
No files matched your search
Generated
+9
-9
@@ -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",
|
||||
|
||||
+2
-2
@@ -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" }
|
||||
|
||||
@@ -20,37 +20,17 @@ fn tab_list_repaired(read: &[TabStop], sanitized: &[TabStop]) -> bool {
|
||||
}
|
||||
|
||||
pub(super) fn mojikumi_row(e: &El) -> Result<designcraft_doc::cjk::MojikumiAki> {
|
||||
let number = |key: &str| -> Result<f64> {
|
||||
let Some(raw) = e.prop(key) else {
|
||||
return Ok(0.0);
|
||||
};
|
||||
raw.trim().parse::<f64>().ok().filter(|v| v.is_finite()).ok_or_else(|| IdmlError::Invalid(format!("Mojikumi row has invalid {key}")))
|
||||
};
|
||||
let integer = |key: &str| -> Result<i16> {
|
||||
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<bool> {
|
||||
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> {
|
||||
|
||||
Reference in new issue
Block a user