diff --git a/crates/idml/src/model/mod.rs b/crates/idml/src/model/mod.rs index e96a0341d..4f3d323b5 100644 --- a/crates/idml/src/model/mod.rs +++ b/crates/idml/src/model/mod.rs @@ -26,12 +26,13 @@ pub use effects::{DirectionalFeatherValues, DropShadowValues, FeatherValues, Gra pub use geometry::{MAX_PATH_POINTS, PathGeometry, PathGeometryError, PathPoint, SubPath}; pub use preferences::TextFramePreferences; pub use resources::{ - CharacterTypographyValues, CjkCharacterValues, 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, StrokeDefinition, StrokeStyle, StrokeStyleKind, Style, StyleGroup, StyleGroupWriter, StyleKind, StyleNode, Swatch, - SwatchKind, TabStopValues, TintDefinition, color_groups, inks, named, preference, stroke_styles, style_groups, swatches, + CharacterAppearanceValues, CharacterTypographyValues, CjkCharacterValues, 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, 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::{ ClippingPathValues, Graphic, GraphicChild, GraphicKind, GraphicLayerOptions, Guide, ItemChild, ItemKind, Link, MarginPreference, Page, PageChild, diff --git a/crates/idml/src/model/resources.rs b/crates/idml/src/model/resources.rs index 1b2e57c92..acbad4d29 100644 --- a/crates/idml/src/model/resources.rs +++ b/crates/idml/src/model/resources.rs @@ -140,6 +140,60 @@ pub struct CharacterTypographyValues { pub skew: Option, } +/// One underline or strikethrough style as written in IDML. +#[derive(Clone, Debug, Default, PartialEq)] +pub struct TextDecorationValues { + pub weight: Option, + pub offset: Option, + pub color: Option, + pub tint: Option, +} + +/// Character fill/stroke, decoration and toggle values before caller swatch resolution. +#[derive(Clone, Debug, Default, PartialEq)] +pub struct CharacterAppearanceValues { + pub fill_color: Option, + pub fill_tint: Option, + pub stroke_color: Option, + pub stroke_tint: Option, + pub stroke_weight: Option, + pub stroke_alignment: Option, + pub underline: Option, + pub strikethrough: Option, + pub ligatures: Option, + pub underline_options: TextDecorationValues, + pub strikethrough_options: TextDecorationValues, +} + +impl CharacterAppearanceValues { + /// Reads common character fill, stroke and decoration properties from IDML. + pub fn from_el(el: &El) -> Self { + let values = Values::of(el); + let decoration = |prefix: &str| { + let number = |suffix: &str| values.num(&format!("{prefix}{suffix}")).filter(|value| *value > -9000.0); + TextDecorationValues { + weight: number("Weight"), + offset: number("Offset"), + color: values.prop(&format!("{prefix}Color")), + tint: values.num(&format!("{prefix}Tint")), + } + }; + Self { + fill_color: values.prop("FillColor"), + fill_tint: values.num("FillTint"), + stroke_color: values.prop("StrokeColor"), + stroke_tint: values.num("StrokeTint"), + stroke_weight: values.num("StrokeWeight"), + stroke_alignment: values.prop("StrokeAlignment"), + underline: values.boolean("Underline"), + strikethrough: values.boolean("StrikeThru"), + ligatures: values.boolean("Ligatures"), + underline_options: decoration("Underline"), + strikethrough_options: decoration("StrikeThru"), + } + } +} + impl CharacterTypographyValues { /// Reads the common typography attributes and properties from an IDML character range/style. pub fn from_el(el: &El) -> Self {