mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-14 14:22:39 +00:00
Use shared IDML anchored object values
This commit is contained in:
3 files changed
+28
-39
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=24922d9b9#24922d9b9081918996e37a0693a2f29e68d8f886"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=0e30b40c8#0e30b40c800f9de11ce4e4a2f14493398ba8bc1a"
|
||||
dependencies = [
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=24922d9b9)",
|
||||
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=24922d9b9)",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=0e30b40c8)",
|
||||
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=0e30b40c8)",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
@@ -1647,7 +1647,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=24922d9b9#24922d9b9081918996e37a0693a2f29e68d8f886"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=0e30b40c8#0e30b40c800f9de11ce4e4a2f14493398ba8bc1a"
|
||||
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=24922d9b9#24922d9b9081918996e37a0693a2f29e68d8f886"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=0e30b40c8#0e30b40c800f9de11ce4e4a2f14493398ba8bc1a"
|
||||
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=24922d9b9)",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=0e30b40c8)",
|
||||
"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=24922d9b9)",
|
||||
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=0e30b40c8)",
|
||||
"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=24922d9b9)",
|
||||
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=0e30b40c8)",
|
||||
"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=24922d9b9)",
|
||||
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=0e30b40c8)",
|
||||
"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 = "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 = "24922d9b9", version = "=0.1.0" }
|
||||
craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "0e30b40c8", 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 = "24922d9b9", version = "=0.1.0" }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "0e30b40c8", 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" }
|
||||
|
||||
@@ -309,54 +309,43 @@ impl<'r> Importer<'r> {
|
||||
// then from the IDML defaults.
|
||||
let style_chain = self.object_style_chain(&c);
|
||||
let levels: Vec<&El> = std::iter::once(&c).chain(style_chain.iter()).collect();
|
||||
let s = |k: &str| {
|
||||
let set = levels.iter().filter_map(|l| l.find("AnchoredObjectSetting")).find_map(|x| x.get(k));
|
||||
set.unwrap_or(match k {
|
||||
"AnchoredPosition" => "InlinePosition",
|
||||
"AnchorPoint" => "BottomRightAnchor",
|
||||
"HorizontalAlignment" => "LeftAlign",
|
||||
"HorizontalReferencePoint" => "TextFrame",
|
||||
"VerticalAlignment" => "BottomAlign",
|
||||
"VerticalReferencePoint" => "LineBaseline",
|
||||
"PinPosition" => "true",
|
||||
_ => "",
|
||||
})
|
||||
};
|
||||
let get = |k: &str| s(k).trim().parse::<f64>().ok().filter(|v| v.is_finite()).unwrap_or(0.0);
|
||||
let position = match s("AnchoredPosition") {
|
||||
let model_levels: Vec<_> = levels.iter().map(|level| crate::xml::to_craft(level)).collect();
|
||||
let model_refs: Vec<_> = model_levels.iter().collect();
|
||||
let anchored = craft_idml::model::AnchoredObjectValues::from_elements(&model_refs);
|
||||
let position = match anchored.position.as_str() {
|
||||
"AboveLine" => designcraft_doc::AnchorPosition::AboveLine {
|
||||
align: match s("HorizontalAlignment") {
|
||||
align: match anchored.horizontal_alignment.as_str() {
|
||||
"CenterAlign" => A::Center,
|
||||
"RightAlign" => A::Right,
|
||||
_ => A::Left,
|
||||
},
|
||||
space_before: get("AnchorSpaceAbove"),
|
||||
space_after: get("AnchorYoffset"),
|
||||
space_before: anchored.space_above,
|
||||
space_after: anchored.y_offset,
|
||||
},
|
||||
"Anchored" => {
|
||||
let col = match s("HorizontalAlignment") {
|
||||
let col = match anchored.horizontal_alignment.as_str() {
|
||||
"CenterAlign" => 1,
|
||||
"RightAlign" => 2,
|
||||
_ => 0,
|
||||
};
|
||||
let row = match s("VerticalAlignment") {
|
||||
let row = match anchored.vertical_alignment.as_str() {
|
||||
"CenterAlign" => 1,
|
||||
"BottomAlign" => 2,
|
||||
_ => 0,
|
||||
};
|
||||
designcraft_doc::AnchorPosition::Custom {
|
||||
x_relative: names::anchor_rel_in(s("HorizontalReferencePoint")),
|
||||
y_relative: names::anchor_rel_in(s("VerticalReferencePoint")),
|
||||
x_relative: names::anchor_rel_in(&anchored.horizontal_reference),
|
||||
y_relative: names::anchor_rel_in(&anchored.vertical_reference),
|
||||
// IDML measures a left-aligned object's X offset leftwards.
|
||||
x_offset: if col == 0 { 0.0 - get("AnchorXoffset") } else { get("AnchorXoffset") },
|
||||
y_offset: get("AnchorYoffset"),
|
||||
object_point: names::anchor_in(s("AnchorPoint")),
|
||||
x_offset: if col == 0 { 0.0 - anchored.x_offset } else { anchored.x_offset },
|
||||
y_offset: anchored.y_offset,
|
||||
object_point: names::anchor_in(&anchored.anchor_point),
|
||||
ref_point: row * 3 + col,
|
||||
keep_within_column: s("PinPosition") == "true",
|
||||
spine_relative: s("SpineRelative") == "true",
|
||||
keep_within_column: anchored.pin_position,
|
||||
spine_relative: anchored.spine_relative,
|
||||
}
|
||||
}
|
||||
_ => designcraft_doc::AnchorPosition::Inline { y_offset: get("AnchorYoffset") },
|
||||
_ => designcraft_doc::AnchorPosition::Inline { y_offset: anchored.y_offset },
|
||||
};
|
||||
b.objects.push(designcraft_doc::AnchoredObject::new(item, position));
|
||||
b.push(&designcraft_doc::OBJECT_MARK.to_string(), cf);
|
||||
|
||||
Reference in new issue
Block a user