Read character typography through shared IDML model

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 07:55:42 -05:00
1 parent fc66be4021
commit 36db87ba20
3 files changed
+31 -30

No files matched your search

Generated
+11 -11
View File
@@ -1242,10 +1242,10 @@ dependencies = [
[[package]]
name = "craft-idml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=7b2e903fa223ebda6274825954ec470be757ae02#7b2e903fa223ebda6274825954ec470be757ae02"
source = "git+https://github.com/storytold/craft-libs?rev=914123d662728b49864ff2917147e5fbb4df8d80#914123d662728b49864ff2917147e5fbb4df8d80"
dependencies = [
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7b2e903fa223ebda6274825954ec470be757ae02)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7b2e903fa223ebda6274825954ec470be757ae02)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=914123d662728b49864ff2917147e5fbb4df8d80)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=914123d662728b49864ff2917147e5fbb4df8d80)",
"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=7b2e903fa223ebda6274825954ec470be757ae02#7b2e903fa223ebda6274825954ec470be757ae02"
source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551"
dependencies = [
"quick-xml 0.41.0",
"thiserror 2.0.21",
@@ -1665,7 +1665,7 @@ dependencies = [
[[package]]
name = "craft-xml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551"
source = "git+https://github.com/storytold/craft-libs?rev=914123d662728b49864ff2917147e5fbb4df8d80#914123d662728b49864ff2917147e5fbb4df8d80"
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=7b2e903fa223ebda6274825954ec470be757ae02#7b2e903fa223ebda6274825954ec470be757ae02"
source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551"
dependencies = [
"flate2",
"thiserror 2.0.21",
@@ -1740,7 +1740,7 @@ dependencies = [
[[package]]
name = "craft-zip"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551"
source = "git+https://github.com/storytold/craft-libs?rev=914123d662728b49864ff2917147e5fbb4df8d80#914123d662728b49864ff2917147e5fbb4df8d80"
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=7b2e903fa223ebda6274825954ec470be757ae02)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=914123d662728b49864ff2917147e5fbb4df8d80)",
"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=7b2e903fa223ebda6274825954ec470be757ae02)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=914123d662728b49864ff2917147e5fbb4df8d80)",
"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=7b2e903fa223ebda6274825954ec470be757ae02)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=914123d662728b49864ff2917147e5fbb4df8d80)",
"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=7b2e903fa223ebda6274825954ec470be757ae02)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=914123d662728b49864ff2917147e5fbb4df8d80)",
"craft-rtf",
"craft-wordmodel",
"craft-xlsx",
+2 -2
View File
@@ -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 = "7b2e903fa223ebda6274825954ec470be757ae02", version = "=0.1.0" }
craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "914123d662728b49864ff2917147e5fbb4df8d80", 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 = "7b2e903fa223ebda6274825954ec470be757ae02", version = "=0.1.0" }
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "914123d662728b49864ff2917147e5fbb4df8d80", 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" }
+18 -17
View File
@@ -36,38 +36,39 @@ pub(super) fn mojikumi_row(e: &El) -> Result<designcraft_doc::cjk::MojikumiAki>
impl<'r> Importer<'r> {
pub(super) fn char_attrs(&mut self, e: &El) -> CharAttrs {
let mut a = CharAttrs::default();
if let Some(f) = e.prop("AppliedFont") {
let values = craft_idml::model::CharacterTypographyValues::from_el(&crate::xml::to_craft(e));
if let Some(f) = values.applied_font {
// Some writers append the style after a tab. Spaces are part of a family's name
// ("Minion Pro " is another font than "Minion Pro"); line breaks around it aren't.
let fam = f.split('\t').next().unwrap_or(&f).trim_matches(['\n', '\r']);
a.font_family = self.composite_names.get(fam.trim()).cloned().or_else(|| names::font_family_in(fam));
}
// "Nothing" leaves the style unset: it comes from the paragraph style.
a.font_style = e.prop("FontStyle").filter(|s| !matches!(s.trim(), "Nothing" | "$ID/Nothing"));
a.size = e.num("PointSize");
a.leading = e.prop("Leading").and_then(|l| names::leading_in(l.trim()));
a.font_style = values.font_style.filter(|s| !matches!(s.trim(), "Nothing" | "$ID/Nothing"));
a.size = values.point_size;
a.leading = values.leading.as_deref().and_then(|leading| names::leading_in(leading.trim()));
// Automatic kerning may carry an inactive numeric value (including the
// 1e11 IDML sentinel). It must not become a multi-million-em advance.
a.kerning = e.prop("KerningMethod").and_then(|k| match k.trim().trim_start_matches("$ID/") {
a.kerning = values.kerning_method.as_deref().and_then(|k| match k.trim().trim_start_matches("$ID/") {
"Optical" => Some(Kerning::Optical),
"Metrics" | "Metrics - Roman Only" => Some(Kerning::Metrics),
"None" => Some(Kerning::None),
_ => None,
});
if a.kerning.is_none() {
a.kerning = e.num("KerningValue").filter(|v| v.is_finite() && v.abs() < 1e10).map(Kerning::Manual);
a.kerning = values.kerning_value.filter(|v| v.is_finite() && v.abs() < 1e10).map(Kerning::Manual);
}
a.tracking = e.num("Tracking");
a.leading_aki = e.num("LeadingAki").map(|v| (v >= 0.0).then_some(v));
a.trailing_aki = e.num("TrailingAki").map(|v| (v >= 0.0).then_some(v));
a.tsume = e.num("Tsume").map(|v| (v / 100.0).clamp(0.0, 1.0));
a.jidori = e.num("Jidori").map(|v| v.clamp(0.0, 10000.0) as u32);
a.leading_model = e.prop("LeadingModel").and_then(|v| crate::cjk::leading_in(&v));
a.character_alignment = e.prop("CharacterAlignment").and_then(|v| crate::cjk::alignment_in(&v));
a.h_scale = e.num("HorizontalScale").map(|v| v / 100.0);
a.v_scale = e.num("VerticalScale").map(|v| v / 100.0);
a.baseline_shift = e.num("BaselineShift");
a.skew = e.num("Skew");
a.tracking = values.tracking;
a.leading_aki = values.leading_aki.map(|v| (v >= 0.0).then_some(v));
a.trailing_aki = values.trailing_aki.map(|v| (v >= 0.0).then_some(v));
a.tsume = values.tsume.map(|v| (v / 100.0).clamp(0.0, 1.0));
a.jidori = values.jidori.map(|v| v.clamp(0.0, 10000.0) as u32);
a.leading_model = values.leading_model.as_deref().and_then(crate::cjk::leading_in);
a.character_alignment = values.character_alignment.as_deref().and_then(crate::cjk::alignment_in);
a.h_scale = values.horizontal_scale.map(|v| v / 100.0);
a.v_scale = values.vertical_scale.map(|v| v / 100.0);
a.baseline_shift = values.baseline_shift;
a.skew = values.skew;
if let Some(r) = e.prop("FillColor") {
a.fill = Some(self.swatch_ref(r.trim()));
}