From 1999b1f99dc5f5432896bdf6806635a3de0bfb43 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 09:09:51 -0500 Subject: [PATCH] Parse IDML object style assignments in shared model --- crates/idml/src/model/mod.rs | 8 +++---- crates/idml/src/model/resources.rs | 38 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/crates/idml/src/model/mod.rs b/crates/idml/src/model/mod.rs index d9a15d85b..ddcb3a565 100644 --- a/crates/idml/src/model/mod.rs +++ b/crates/idml/src/model/mod.rs @@ -34,10 +34,10 @@ pub use resources::{ CharacterAppearanceValues, CharacterSpecialValues, CharacterTypographyValues, CjkCharacterValues, CjkParagraphValues, ColorDefinition, ColorGroup, ColorGroupDefinition, ColorGroupMember, ColorSpace, CompositeFontDefinition, CompositeFontEntryDefinition, EpubExportTagMap, FontDefinition, FontFamilyDefinition, FontsPart, GradientDefinition, GradientStop, GradientStopDefinition, GradientStopValue, GraphicPart, - GrepStyleValue, Ink, InkDefinition, MojikumiRow, NestedLineStyleValue, NestedStyleValue, NestedStyleValues, OpenTypeFeatureValues, - ParagraphAlignmentValues, ParagraphBoxValues, ParagraphFlowValues, ParagraphListValues, ParagraphSpanValues, RubyValues, StrokeDefinition, - StrokeStyle, StrokeStyleKind, Style, StyleGroup, StyleGroupWriter, StyleKind, StyleNode, Swatch, SwatchKind, TabStopValues, TextDecorationValues, - TintDefinition, color_groups, inks, named, preference, stroke_styles, style_groups, swatches, + GrepStyleValue, Ink, InkDefinition, MojikumiRow, NestedLineStyleValue, NestedStyleValue, NestedStyleValues, ObjectStyleValues, + OpenTypeFeatureValues, ParagraphAlignmentValues, ParagraphBoxValues, ParagraphFlowValues, ParagraphListValues, ParagraphSpanValues, RubyValues, + StrokeDefinition, StrokeStyle, StrokeStyleKind, Style, StyleGroup, StyleGroupWriter, StyleKind, StyleNode, Swatch, SwatchKind, TabStopValues, + TextDecorationValues, TintDefinition, color_groups, inks, named, preference, stroke_styles, style_groups, swatches, }; pub use spread::{ BaselineFrameGridOption, BaselineFrameGridRelative, ClippingPathValues, FrameFittingOption, Graphic, GraphicChild, GraphicKind, diff --git a/crates/idml/src/model/resources.rs b/crates/idml/src/model/resources.rs index f88ebff83..11a76b186 100644 --- a/crates/idml/src/model/resources.rs +++ b/crates/idml/src/model/resources.rs @@ -1368,6 +1368,44 @@ pub struct Style { pub rest: Vec, } +/// Parsed assignments on an IDML object style before application style-reference resolution. +#[derive(Clone, Debug, Default, PartialEq)] +pub struct ObjectStyleValues { + pub name: Option, + pub based_on: Option, + pub fill_enabled: bool, + pub fill_color: Option, + pub fill_tint: Option, + pub stroke_enabled: bool, + pub paragraph_style_enabled: bool, + pub paragraph_style: Option, + pub text_frame_general_options: bool, + pub text_frame_preference: Option, +} + +impl ObjectStyleValues { + /// Reads object-style enable flags and the values controlled by those flags. + pub fn from_el(el: &El) -> Self { + let values = Values::of(el); + let enabled = |flag: &str, attribute: &str| match values.get(flag) { + Some(value) => value == "true", + None => values.get(attribute).is_some(), + }; + Self { + name: values.name().map(str::to_owned), + based_on: values.prop("BasedOn"), + fill_enabled: enabled("EnableFill", "FillColor"), + fill_color: values.get("FillColor").map(str::to_owned), + fill_tint: values.num("FillTint"), + stroke_enabled: enabled("EnableStroke", "StrokeColor"), + paragraph_style_enabled: enabled("EnableParagraphStyle", "AppliedParagraphStyle"), + paragraph_style: values.get("AppliedParagraphStyle").map(str::to_owned), + text_frame_general_options: values.get("EnableTextFrameGeneralOptions") == Some("true"), + text_frame_preference: el.child(Local("TextFramePreference")).cloned(), + } + } +} + impl StyleGroup { /// The root group `el`; `None` when `el` is no root style group. pub fn from_el(el: &El) -> Option {