Use shared IDML anchored setting writer

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 09:30:04 -05:00
1 parent 1cb0c04143
commit 6bc26299fa
3 files changed
+33 -36

No files matched your search

Generated
+9 -9
View File
@@ -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",
+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 = "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" }
+22 -25
View File
@@ -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> {
/// `<GraphicLayerOption>` 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