Read character appearance through shared IDML model

This commit is contained in:
Dylan M. Taylor
2026-11-13 09:05:20 -05:00
parent 5a4df158db
commit 7fb56d2ffc
2 changed files with 61 additions and 6 deletions
+7 -6
View File
@@ -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,
+54
View File
@@ -140,6 +140,60 @@ pub struct CharacterTypographyValues {
pub skew: Option<f64>,
}
/// One underline or strikethrough style as written in IDML.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct TextDecorationValues {
pub weight: Option<f64>,
pub offset: Option<f64>,
pub color: Option<String>,
pub tint: Option<f64>,
}
/// Character fill/stroke, decoration and toggle values before caller swatch resolution.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct CharacterAppearanceValues {
pub fill_color: Option<String>,
pub fill_tint: Option<f64>,
pub stroke_color: Option<String>,
pub stroke_tint: Option<f64>,
pub stroke_weight: Option<f64>,
pub stroke_alignment: Option<String>,
pub underline: Option<bool>,
pub strikethrough: Option<bool>,
pub ligatures: Option<bool>,
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 {