Read paragraph box values through shared IDML model

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 08:10:32 -05:00
1 parent b46323ffda
commit 2a0551b73a
5 files changed
+49 -74

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=60deceb14acd1d03ab874a729f676f8b37ec6198#60deceb14acd1d03ab874a729f676f8b37ec6198"
source = "git+https://github.com/storytold/craft-libs?rev=173700d54a24a98e64d2a81ea129656bcf6d75a8#173700d54a24a98e64d2a81ea129656bcf6d75a8"
dependencies = [
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=60deceb14acd1d03ab874a729f676f8b37ec6198)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=60deceb14acd1d03ab874a729f676f8b37ec6198)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=173700d54a24a98e64d2a81ea129656bcf6d75a8)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=173700d54a24a98e64d2a81ea129656bcf6d75a8)",
"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=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f"
source = "git+https://github.com/storytold/craft-libs?rev=173700d54a24a98e64d2a81ea129656bcf6d75a8#173700d54a24a98e64d2a81ea129656bcf6d75a8"
dependencies = [
"quick-xml 0.41.0",
"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=60deceb14acd1d03ab874a729f676f8b37ec6198#60deceb14acd1d03ab874a729f676f8b37ec6198"
source = "git+https://github.com/storytold/craft-libs?rev=40525913633942f84b06d4837a8d90534a55d63f#40525913633942f84b06d4837a8d90534a55d63f"
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=19692b6190465671e41967c75d0cd4c439d0c84c#19692b6190465671e41967c75d0cd4c439d0c84c"
source = "git+https://github.com/storytold/craft-libs?rev=173700d54a24a98e64d2a81ea129656bcf6d75a8#173700d54a24a98e64d2a81ea129656bcf6d75a8"
dependencies = [
"flate2",
"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=60deceb14acd1d03ab874a729f676f8b37ec6198#60deceb14acd1d03ab874a729f676f8b37ec6198"
source = "git+https://github.com/storytold/craft-libs?rev=19692b6190465671e41967c75d0cd4c439d0c84c#19692b6190465671e41967c75d0cd4c439d0c84c"
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=60deceb14acd1d03ab874a729f676f8b37ec6198)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=173700d54a24a98e64d2a81ea129656bcf6d75a8)",
"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=60deceb14acd1d03ab874a729f676f8b37ec6198)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=173700d54a24a98e64d2a81ea129656bcf6d75a8)",
"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=60deceb14acd1d03ab874a729f676f8b37ec6198)",
"craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=173700d54a24a98e64d2a81ea129656bcf6d75a8)",
"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=60deceb14acd1d03ab874a729f676f8b37ec6198)",
"craft-idml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=173700d54a24a98e64d2a81ea129656bcf6d75a8)",
"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 = "60deceb14acd1d03ab874a729f676f8b37ec6198", version = "=0.1.0" }
craft-idml = { git = "https://github.com/storytold/craft-libs", rev = "173700d54a24a98e64d2a81ea129656bcf6d75a8", 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 = "60deceb14acd1d03ab874a729f676f8b37ec6198", version = "=0.1.0" }
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "173700d54a24a98e64d2a81ea129656bcf6d75a8", 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" }
+3 -1
View File
@@ -1,5 +1,4 @@
use super::frame::{Prefs, frame_grid_relative, text_frame_options, text_wrap};
use super::object_style::INDESIGN_CORNER_SIZE;
use super::package::uri_to_path;
use super::values::{nums, parse_affine, tint};
use super::{
@@ -7,6 +6,9 @@ use super::{
Story, StoryId, Stroke, SubPath, TextFrame, TextFrameOptions, names, sniff_image, swatch, unescape_id,
};
/// InDesign's corner size when a corner shape is set without an explicit radius.
const INDESIGN_CORNER_SIZE: f64 = 12.0;
impl<'r> Importer<'r> {
pub(super) fn item(&mut self, e: &El, parent: Affine) -> Option<Item> {
let model_item = craft_idml::model::PageItem::from_el(&crate::xml::to_craft(e))?;
+1 -21
View File
@@ -1,25 +1,5 @@
use super::values::{finite, tint};
use super::{Corner, DirectionalFeather, DropShadow, Effects, El, GradientFeather, HashMap, Importer, Node, Stroke, names};
/// InDesign's corner size where a file gives a corner shape without one.
pub(super) const INDESIGN_CORNER_SIZE: f64 = 12.0;
/// The four corners of a paragraph border or shading (`prefix` `ParagraphBorder` /
/// `ParagraphShading`): top left, top right, bottom right, bottom left. Unset when none is given.
pub(super) fn corners(e: &El, prefix: &str) -> Option<[Corner; 4]> {
let keys = ["TopLeft", "TopRight", "BottomRight", "BottomLeft"];
let shapes = keys.map(|n| e.prop(&format!("{prefix}{n}CornerOption")));
let sizes = keys.map(|n| e.num(&format!("{prefix}{n}CornerRadius")));
if shapes.iter().all(Option::is_none) && sizes.iter().all(Option::is_none) {
return None;
}
let mut out = [Corner::default(); 4];
for (c, (shape, size)) in out.iter_mut().zip(shapes.iter().zip(sizes)) {
c.shape = shape.as_deref().map_or(designcraft_geom::corners::CornerShape::None, |s| names::corner_in(s.trim()));
c.size = size.filter(|v| v.is_finite()).map_or(12.0, |v| v.max(0.0));
}
Some(out)
}
use super::{DirectionalFeather, DropShadow, Effects, El, GradientFeather, HashMap, Importer, Node, Stroke, names};
impl<'r> Importer<'r> {
/// An item's object style chain: its applied style, the styles that one is based on, then
+32 -39
View File
@@ -1,4 +1,3 @@
use super::object_style::corners;
use super::story::MAX_STORY_NESTING;
use super::values::tint;
use super::{
@@ -284,45 +283,39 @@ impl<'r> Importer<'r> {
.map(|value| value.to_string());
}
a.balance_ragged = list.balance_ragged.map(|value| value.trim() != "NoBalancing" && value.trim() != "false");
a.shading_on = e.boolean("ParagraphShadingOn");
if let Some(c) = e.prop("ParagraphShadingColor") {
a.shading_color = Some(self.swatch_ref(c.trim()));
}
a.shading_tint = tint(e.num("ParagraphShadingTint"));
a.shading_overprint = e.boolean("ParagraphShadingOverprint");
let sides = |f: &dyn Fn(&str) -> String| -> Option<[f64; 4]> {
let v = ["Top", "Left", "Bottom", "Right"].map(|s| e.num(&f(s)));
v.iter().any(Option::is_some).then(|| v.map(|x| x.unwrap_or(0.0)))
let boxes = craft_idml::model::ParagraphBoxValues::from_el(&crate::xml::to_craft(e));
a.shading_on = boxes.shading_on;
a.shading_color = boxes.shading_color.map(|color| self.swatch_ref(color.trim()));
a.shading_tint = tint(boxes.shading_tint);
a.shading_overprint = boxes.shading_overprint;
a.shading_offsets = boxes.shading_offsets;
a.border_on = boxes.border_on;
a.border_color = boxes.border_color.map(|color| self.swatch_ref(color.trim()));
a.border_tint = tint(boxes.border_tint);
a.border_overprint = boxes.border_overprint;
a.border_weights = boxes.border_weights;
a.border_offsets = boxes.border_offsets;
a.border_type = boxes.border_type.as_deref().map(|value| names::stroke_type_in(value.trim()));
a.border_cap = boxes.border_cap.as_deref().map(|value| names::cap_in(value.trim()));
a.border_join = boxes.border_join.as_deref().map(|value| names::join_in(value.trim()));
let map_corners = |values: Option<[(String, f64); 4]>| {
values.map(|values| values.map(|(shape, size)| designcraft_geom::corners::Corner { shape: names::corner_in(shape.trim()), size }))
};
a.shading_offsets = sides(&|s| format!("ParagraphShading{s}Offset"));
a.border_on = e.boolean("ParagraphBorderOn");
if let Some(c) = e.prop("ParagraphBorderColor") {
a.border_color = Some(self.swatch_ref(c.trim()));
}
a.border_tint = tint(e.num("ParagraphBorderTint"));
a.border_overprint = e.boolean("ParagraphBorderOverprint");
a.border_weights = sides(&|s| format!("ParagraphBorder{s}LineWeight"));
a.border_offsets = sides(&|s| format!("ParagraphBorder{s}Offset"));
a.border_type = e.prop("ParagraphBorderType").map(|v| names::stroke_type_in(v.trim()));
a.border_cap = e.prop("ParagraphBorderStrokeEndCap").map(|v| names::cap_in(v.trim()));
a.border_join = e.prop("ParagraphBorderStrokeEndJoin").map(|v| names::join_in(v.trim()));
a.border_corners = corners(e, "ParagraphBorder");
a.border_width = e.prop("ParagraphBorderWidth").map(|v| names::box_width_in(v.trim()));
a.border_top = e.prop("ParagraphBorderTopOrigin").map(|v| names::box_top_in(v.trim()));
a.border_bottom = e.prop("ParagraphBorderBottomOrigin").map(|v| names::box_bottom_in(v.trim()));
a.border_display_if_splits = e.boolean("ParagraphBorderDisplayIfSplits");
a.border_merge = e.boolean("MergeConsecutiveParaBorders");
if let Some(c) = e.prop("ParagraphBorderGapColor") {
a.border_gap_color = Some(self.swatch_ref(c.trim()));
}
a.border_gap_tint = tint(e.num("ParagraphBorderGapTint"));
a.border_gap_overprint = e.boolean("ParagraphBorderGapOverprint");
a.shading_corners = corners(e, "ParagraphShading");
a.shading_width = e.prop("ParagraphShadingWidth").map(|v| names::box_width_in(v.trim()));
a.shading_top = e.prop("ParagraphShadingTopOrigin").map(|v| names::box_top_in(v.trim()));
a.shading_bottom = e.prop("ParagraphShadingBottomOrigin").map(|v| names::box_bottom_in(v.trim()));
a.shading_clip = e.boolean("ParagraphShadingClipToFrame");
a.shading_nonprinting = e.boolean("ParagraphShadingSuppressPrinting");
a.border_corners = map_corners(boxes.border_corners);
a.border_width = boxes.border_width.as_deref().map(|value| names::box_width_in(value.trim()));
a.border_top = boxes.border_top.as_deref().map(|value| names::box_top_in(value.trim()));
a.border_bottom = boxes.border_bottom.as_deref().map(|value| names::box_bottom_in(value.trim()));
a.border_display_if_splits = boxes.border_display_if_splits;
a.border_merge = boxes.border_merge;
a.border_gap_color = boxes.border_gap_color.map(|color| self.swatch_ref(color.trim()));
a.border_gap_tint = tint(boxes.border_gap_tint);
a.border_gap_overprint = boxes.border_gap_overprint;
a.shading_corners = map_corners(boxes.shading_corners);
a.shading_width = boxes.shading_width.as_deref().map(|value| names::box_width_in(value.trim()));
a.shading_top = boxes.shading_top.as_deref().map(|value| names::box_top_in(value.trim()));
a.shading_bottom = boxes.shading_bottom.as_deref().map(|value| names::box_bottom_in(value.trim()));
a.shading_clip = boxes.shading_clip;
a.shading_nonprinting = boxes.shading_nonprinting;
a.span_space_before = e.num("SpanColumnMinSpaceBefore").filter(|v| v.is_finite());
a.span_space_after = e.num("SpanColumnMinSpaceAfter").filter(|v| v.is_finite());
a.list_level = list.level.map(|value| value.round().clamp(1.0, designcraft_doc::LIST_LEVELS as f64) as u32);