Delegate Fonts.xml writing to craft-idml

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 06:43:31 -05:00
1 parent acf2538612
commit 3b81561a73
3 files changed
+45 -50

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=99113d82a#99113d82a16bd25b791d682b2b70807ac12fe9e9"
source = "git+https://github.com/storytold/craft-libs?rev=4f22dfad3#4f22dfad31c0abb496b5f8db9444cb2d0d49ec80"
dependencies = [
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=99113d82a)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=99113d82a)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4f22dfad3)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4f22dfad3)",
"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=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551"
source = "git+https://github.com/storytold/craft-libs?rev=4f22dfad3#4f22dfad31c0abb496b5f8db9444cb2d0d49ec80"
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=99113d82a#99113d82a16bd25b791d682b2b70807ac12fe9e9"
source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551"
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=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551"
source = "git+https://github.com/storytold/craft-libs?rev=4f22dfad3#4f22dfad31c0abb496b5f8db9444cb2d0d49ec80"
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=99113d82a#99113d82a16bd25b791d682b2b70807ac12fe9e9"
source = "git+https://github.com/storytold/craft-libs?rev=8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551#8abfa9d0f14bafbfc3449fc552ffeafb9ca6a551"
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=99113d82a)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4f22dfad3)",
"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=99113d82a)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4f22dfad3)",
"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=99113d82a)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4f22dfad3)",
"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=99113d82a)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=4f22dfad3)",
"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 = "99113d82a", version = "=0.1.0" }
craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "4f22dfad3", 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 = "99113d82a", version = "=0.1.0" }
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "4f22dfad3", 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" }
+32 -37
View File
@@ -1,6 +1,7 @@
use super::common::{bool_s, p, pct, pkg_root};
use super::common::{bool_s, pct, pkg_root};
use super::spread::margin_el;
use super::{El, Ex, PARA_BUILTINS, document, escape_id, names, num, pt, st};
use craft_idml::model::{CompositeFontDefinition, CompositeFontEntryDefinition, FontDefinition, FontFamilyDefinition, FontsPart};
impl<'a> Ex<'a> {
// ---------- Fonts.xml ----------
@@ -10,26 +11,29 @@ impl<'a> Ex<'a> {
}
pub(super) fn fonts_part(&mut self) -> Vec<u8> {
let mut root = pkg_root("Fonts");
let mut fonts_part = FontsPart::default();
for f in &self.d.styles.composite_fonts {
let mut el = El::new("CompositeFont").attr("Self", format!("CompositeFont/{}", escape_id(&f.name))).attr("Name", &f.name);
let mut entries = Vec::new();
for (i, e) in f.entries.iter().enumerate() {
self.note_font(&e.family, &e.style);
el.push(
El::new("CompositeFontEntry")
.attr("Self", format!("dcComposite{}_{i}", escape_id(&f.name)))
.attr("Name", &e.name)
.attr("CustomCharacters", &e.characters)
.attr("FontStyle", &e.style)
.attr("RelativeSize", num(e.relative_size * 100.0))
.attr("HorizontalScale", num(e.horizontal_scale * 100.0))
.attr("VerticalScale", num(e.vertical_scale * 100.0))
.attr("BaselineShift", num(e.baseline_shift * 100.0))
.attr("ScaleOption", bool_s(e.scale_option))
.child(El::new("Properties").child(p("AppliedFont", "string", &e.family))),
);
entries.push(CompositeFontEntryDefinition {
self_id: format!("dcComposite{}_{i}", escape_id(&f.name)),
name: e.name.clone(),
characters: e.characters.clone(),
font_style: e.style.clone(),
relative_size: num(e.relative_size * 100.0),
horizontal_scale: num(e.horizontal_scale * 100.0),
vertical_scale: num(e.vertical_scale * 100.0),
baseline_shift: num(e.baseline_shift * 100.0),
scale_option: e.scale_option,
applied_font: e.family.clone(),
});
}
root.push(el);
fonts_part.composites.push(CompositeFontDefinition {
self_id: format!("CompositeFont/{}", escape_id(&f.name)),
name: f.name.clone(),
entries,
});
}
let fonts = std::mem::take(&mut self.fonts);
for (fam, styles) in &fonts {
@@ -37,30 +41,21 @@ impl<'a> Ex<'a> {
self.next += 1;
self.next
});
let mut fe = El::new("FontFamily").attr("Self", &fid).attr("Name", fam);
let mut faces = Vec::new();
for s in styles {
fe.push(
El::new("Font")
.attr("Self", format!("{fid}Fontn{fam} {s}"))
.attr("FontFamily", fam)
.attr("Name", format!("{fam} {s}"))
.attr("PostScriptName", format!("$ID/{}-{}", fam.replace(' ', ""), s.replace(' ', "")))
.attr("Status", "NotAvailable")
.attr("FontStyleName", s)
.attr("FontType", "OpenTypeTT")
.attr("WritingScript", "0")
.attr("FullName", format!("{fam} {s}"))
.attr("FullNameNative", format!("{fam} {s}"))
.attr("FontStyleNameNative", s)
.attr("PlatformName", "$ID/")
.attr("Version", "$ID/")
.attr("TypekitID", "$ID/"),
);
let name = format!("{fam} {s}");
faces.push(FontDefinition {
self_id: format!("{fid}Fontn{fam} {s}"),
family: fam.clone(),
name,
postscript_name: format!("$ID/{}-{}", fam.replace(' ', ""), s.replace(' ', "")),
style: s.clone(),
});
}
root.push(fe);
fonts_part.families.push(FontFamilyDefinition { self_id: fid, name: fam.clone(), fonts: faces });
}
self.fonts = fonts;
document(&root)
craft_idml::part_xml(&fonts_part.to_el())
}
// ---------- Preferences.xml ----------