Parse IDML text wrap preferences

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 09:05:19 -05:00
1 parent c2fd26d889
commit 676714b6d2
2 files changed
+45 -1

No files matched your search

+1 -1
View File
@@ -25,7 +25,7 @@ pub use resources::{
};
pub use spread::{
Graphic, GraphicChild, GraphicKind, Guide, ItemChild, ItemKind, Link, MarginPreference, Page, PageChild, PageItem, Spread, SpreadChild, TextPath,
spreads,
TextWrapPreference, spreads,
};
pub use story::{
Ace, CONTAINERS, Cell, CellOptions, Container, ContainerKind, ContentPart, PageReference, Range, Story, StoryAnchor, StoryPreference, Table,
+44
View File
@@ -460,6 +460,10 @@ impl PageItem {
self.other("TextPath").map(|el| TextPath { values: Values::of(el) })
}
pub fn text_wrap(&self) -> Option<TextWrapPreference> {
self.other("TextWrapPreference").map(TextWrapPreference::from_el)
}
/// Replaces the outline.
pub fn set_geometry(&mut self, g: &PathGeometry) {
self.values.set_prop_el("PathGeometry", Some(g.to_el()));
@@ -509,6 +513,46 @@ impl PageItem {
}
}
/// Parsed IDML `TextWrapPreference` values, including the nested offset and contour elements.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct TextWrapPreference {
values: Values,
contour_type: Option<String>,
offsets: Option<[f64; 4]>,
}
impl TextWrapPreference {
pub fn from_el(el: &El) -> Self {
let contour_type = el.child(Local("ContourOption")).and_then(|c| Values::of(c).get("ContourType").map(str::to_string));
let offsets = el.child(Local("Properties")).and_then(|p| p.child(Local("TextWrapOffset"))).map(|o| {
let values = Values::of(o);
[
values.num("Top").unwrap_or(0.0),
values.num("Left").unwrap_or(0.0),
values.num("Bottom").unwrap_or(0.0),
values.num("Right").unwrap_or(0.0),
]
});
Self { values: Values::of(el), contour_type, offsets }
}
pub fn mode(&self) -> Option<&str> {
self.values.get("TextWrapMode")
}
pub fn inverse(&self) -> bool {
self.values.boolean("Inverse") == Some(true)
}
pub fn side(&self) -> Option<&str> {
self.values.get("TextWrapSide")
}
pub fn contour_type(&self) -> Option<&str> {
self.contour_type.as_deref()
}
pub fn offsets(&self) -> Option<[f64; 4]> {
self.offsets
}
}
/// Type-on-a-path settings.
#[derive(Clone, Debug, PartialEq)]
pub struct TextPath {