mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-14 22:42:46 +00:00
Parse IDML text wrap preferences
This commit is contained in:
2 files changed
+45
-1
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user