Read IDML tab stop records in shared model

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 09:05:19 -05:00
1 parent f3e59accad
commit c8142a2f1f
2 files changed
+28 -1

No files matched your search

+1 -1
View File
@@ -29,7 +29,7 @@ pub use resources::{
ColorDefinition, ColorGroup, ColorGroupDefinition, ColorGroupMember, ColorSpace, CompositeFontDefinition, CompositeFontEntryDefinition,
EpubExportTagMap, FontDefinition, FontFamilyDefinition, FontsPart, GradientDefinition, GradientStop, GradientStopDefinition, GradientStopValue,
GraphicPart, Ink, InkDefinition, StrokeDefinition, StrokeStyle, StrokeStyleKind, Style, StyleGroup, StyleGroupWriter, StyleKind, StyleNode,
Swatch, SwatchKind, TintDefinition, color_groups, inks, named, preference, stroke_styles, style_groups, swatches,
Swatch, SwatchKind, TabStopValues, TintDefinition, color_groups, inks, named, preference, stroke_styles, style_groups, swatches,
};
pub use spread::{
Graphic, GraphicChild, GraphicKind, Guide, ItemChild, ItemKind, Link, MarginPreference, Page, PageChild, PageItem, Spread, SpreadChild, TextPath,
+27
View File
@@ -11,6 +11,33 @@ fn others(el: &El) -> impl Iterator<Item = &El> {
el.elements().filter(|e| !e.is(Local("Properties")))
}
/// One IDML tab stop, before the caller maps alignment names into its text model.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct TabStopValues {
pub position: f64,
pub alignment: String,
pub leader: String,
pub alignment_character: String,
}
impl TabStopValues {
/// Reads `ListItem` records in a `TabList` property. Invalid or non-finite positions use 0,
/// matching IDML import fallback behavior; semantic sanitization belongs to the caller.
pub fn from_list(list: &El) -> Vec<Self> {
list.children("ListItem")
.map(|item| {
let text = |name: &str| item.child_text(name).map(|value| value.into_owned());
Self {
position: text("Position").and_then(|value| value.trim().parse::<f64>().ok()).filter(|value| value.is_finite()).unwrap_or(0.0),
alignment: text("Alignment").unwrap_or_default(),
leader: text("Leader").unwrap_or_default(),
alignment_character: text("AlignmentCharacter").unwrap_or_default(),
}
})
.collect()
}
}
/// What a style styles.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum StyleKind {