From 6bc26299fa3b78b2159d8b3bbae27c7c269f8bb4 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 09:30:04 -0500 Subject: [PATCH] Use shared IDML anchored setting writer --- Cargo.lock | 18 ++++++------- Cargo.toml | 4 +-- crates/idml/src/export/story.rs | 47 +++++++++++++++------------------ 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc25469ce..c07fb8fa4 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=5326cfb88#5326cfb882788d071bb12456a4331fd7d4ae02ba" +source = "git+https://github.com/storytold/craft-libs?rev=7408ef8cc#7408ef8cc6e8ee6a9d4d87cbe3521cb0fd3b13a2" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5326cfb88)", - "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5326cfb88)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7408ef8cc)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7408ef8cc)", "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=5326cfb88#5326cfb882788d071bb12456a4331fd7d4ae02ba" +source = "git+https://github.com/storytold/craft-libs?rev=7408ef8cc#7408ef8cc6e8ee6a9d4d87cbe3521cb0fd3b13a2" dependencies = [ "quick-xml 0.41.0", "thiserror 2.0.21", @@ -1720,7 +1720,7 @@ dependencies = [ [[package]] name = "craft-zip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=5326cfb88#5326cfb882788d071bb12456a4331fd7d4ae02ba" +source = "git+https://github.com/storytold/craft-libs?rev=7408ef8cc#7408ef8cc6e8ee6a9d4d87cbe3521cb0fd3b13a2" 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=5326cfb88)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7408ef8cc)", "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=5326cfb88)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7408ef8cc)", "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=5326cfb88)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7408ef8cc)", "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=5326cfb88)", + "craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=7408ef8cc)", "craft-rtf", "craft-wordmodel", "craft-xlsx", diff --git a/Cargo.toml b/Cargo.toml index fd6cd5f1a..1d15ed551 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 = "93d0998383aa150fa50a2ffbf49ef37786e37eca", 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 = "5326cfb88", version = "=0.1.0" } +craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "7408ef8cc", 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 = "5326cfb88", version = "=0.1.0" } +craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "7408ef8cc", 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/export/story.rs b/crates/idml/src/export/story.rs index 7d8090dc1..d3232e21e 100644 --- a/crates/idml/src/export/story.rs +++ b/crates/idml/src/export/story.rs @@ -1,7 +1,5 @@ -use super::common::{anchor_self, bool_s, change_type, uid, with_props, xref_format_self}; -use super::{ - CHAR_BUILTINS, CharFormat, El, Ex, ListType, NO_CHAR_ID, Node, PARA_BUILTINS, ParaAttrs, ParaFormat, Story, TOC_STYLE_ID, names, num, st, -}; +use super::common::{anchor_self, change_type, uid, with_props, xref_format_self}; +use super::{CHAR_BUILTINS, CharFormat, El, Ex, ListType, NO_CHAR_ID, Node, PARA_BUILTINS, ParaAttrs, ParaFormat, Story, TOC_STYLE_ID, names, st}; impl<'a> Ex<'a> { /// `` of a placed graphic: its layer attributes and nested layer tree. @@ -164,21 +162,19 @@ impl<'a> Ex<'a> { let mut e = self.item_el(&o.item, o.item.xf); use designcraft_doc::anchored::AnchorAlign as A; let setting = match &o.position { - designcraft_doc::AnchorPosition::Inline { y_offset } => { - El::new("AnchoredObjectSetting").attr("AnchoredPosition", "InlinePosition").attr("AnchorYoffset", num(*y_offset)) - } - designcraft_doc::AnchorPosition::AboveLine { align, space_before, space_after } => El::new("AnchoredObjectSetting") - .attr("AnchoredPosition", "AboveLine") - .attr( - "HorizontalAlignment", + designcraft_doc::AnchorPosition::Inline { y_offset } => craft_idml::model::AnchoredObjectSetting::inline_position(*y_offset).to_el(), + designcraft_doc::AnchorPosition::AboveLine { align, space_before, space_after } => { + craft_idml::model::AnchoredObjectSetting::above_line( match align { A::Left => "LeftAlign", A::Center => "CenterAlign", A::Right => "RightAlign", }, + *space_before, + *space_after, ) - .attr("AnchorSpaceAbove", num(*space_before)) - .attr("AnchorYoffset", num(*space_after)), + .to_el() + } designcraft_doc::AnchorPosition::Custom { x_relative, y_relative, @@ -188,20 +184,21 @@ impl<'a> Ex<'a> { ref_point, keep_within_column, spine_relative, - } => El::new("AnchoredObjectSetting") - .attr("AnchoredPosition", "Anchored") - .attr("AnchorPoint", names::anchor_out(*object_point)) - .attr("HorizontalReferencePoint", names::anchor_rel_out(*x_relative, false)) - .attr("VerticalReferencePoint", names::anchor_rel_out(*y_relative, true)) - .attr("HorizontalAlignment", ["LeftAlign", "CenterAlign", "RightAlign"][(*ref_point % 3) as usize]) - .attr("VerticalAlignment", ["TopAlign", "CenterAlign", "BottomAlign"][(*ref_point / 3).min(2) as usize]) + } => craft_idml::model::AnchoredObjectSetting::anchored( + names::anchor_out(*object_point), + names::anchor_rel_out(*x_relative, false), + names::anchor_rel_out(*y_relative, true), + ["LeftAlign", "CenterAlign", "RightAlign"][(*ref_point % 3) as usize], + ["TopAlign", "CenterAlign", "BottomAlign"][(*ref_point / 3).min(2) as usize], // IDML measures a left-aligned object's X offset leftwards. - .attr("AnchorXoffset", num(if *ref_point % 3 == 0 { 0.0 - *x_offset } else { *x_offset })) - .attr("AnchorYoffset", num(*y_offset)) - .attr("PinPosition", bool_s(*keep_within_column)) - .attr("SpineRelative", bool_s(*spine_relative)), + if *ref_point % 3 == 0 { 0.0 - *x_offset } else { *x_offset }, + *y_offset, + *keep_within_column, + *spine_relative, + ) + .to_el(), }; - e.push(setting); + e.push(crate::xml::from_craft(setting)); return Some(e); } None