mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-14 22:42:46 +00:00
Model IDML page margin preferences
This commit is contained in:
2 files changed
+42
-1
No files matched your search
@@ -22,7 +22,9 @@ pub use resources::{
|
||||
ColorGroup, ColorSpace, GradientStop, GradientStopValue, Ink, StrokeStyle, StrokeStyleKind, Style, StyleGroup, StyleKind, StyleNode, Swatch,
|
||||
SwatchKind, color_groups, inks, named, preference, stroke_styles, style_groups, swatches,
|
||||
};
|
||||
pub use spread::{Graphic, GraphicChild, GraphicKind, Guide, ItemChild, ItemKind, Link, Page, PageChild, PageItem, Spread, SpreadChild, spreads};
|
||||
pub use spread::{
|
||||
Graphic, GraphicChild, GraphicKind, Guide, ItemChild, ItemKind, Link, MarginPreference, Page, PageChild, PageItem, Spread, SpreadChild, spreads,
|
||||
};
|
||||
pub use story::{Ace, CONTAINERS, Cell, Container, ContentPart, Range, Story, Table, TableChild, TextNode, stories};
|
||||
|
||||
use craft_xml::{El, Local, Node};
|
||||
|
||||
@@ -146,6 +146,41 @@ pub struct Page {
|
||||
pub children: Vec<PageChild>,
|
||||
}
|
||||
|
||||
/// Parsed layout values of an IDML `MarginPreference`.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct MarginPreference {
|
||||
pub values: Values,
|
||||
}
|
||||
|
||||
impl MarginPreference {
|
||||
pub fn top(&self) -> Option<f64> {
|
||||
self.values.num("Top")
|
||||
}
|
||||
pub fn left(&self) -> Option<f64> {
|
||||
self.values.num("Left")
|
||||
}
|
||||
pub fn bottom(&self) -> Option<f64> {
|
||||
self.values.num("Bottom")
|
||||
}
|
||||
pub fn right(&self) -> Option<f64> {
|
||||
self.values.num("Right")
|
||||
}
|
||||
pub fn column_count(&self) -> Option<f64> {
|
||||
self.values.num("ColumnCount")
|
||||
}
|
||||
pub fn column_gutter(&self) -> Option<f64> {
|
||||
self.values.num("ColumnGutter")
|
||||
}
|
||||
|
||||
/// Parse at most `limit` whitespace-separated `ColumnsPositions` values; malformed or
|
||||
/// non-finite values invalidate the list.
|
||||
pub fn column_positions(&self, limit: usize) -> Option<Vec<f64>> {
|
||||
let source = self.values.get("ColumnsPositions")?;
|
||||
let values: Option<Vec<f64>> = source.split_whitespace().take(limit).map(|v| v.parse::<f64>().ok().filter(|v| v.is_finite())).collect();
|
||||
values.filter(|values| !values.is_empty())
|
||||
}
|
||||
}
|
||||
|
||||
/// A child of a page, in document order.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum PageChild {
|
||||
@@ -215,6 +250,10 @@ impl Page {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn margin_settings(&self) -> Option<MarginPreference> {
|
||||
self.margin_preference().map(|values| MarginPreference { values })
|
||||
}
|
||||
|
||||
pub fn guides(&self) -> impl DoubleEndedIterator<Item = &Guide> {
|
||||
self.children.iter().filter_map(|c| if let PageChild::Guide(g) = c { Some(g) } else { None })
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user