From 4658956377aedf196f43c189dbba95fcdc0cfe67 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 08:02:04 -0500 Subject: [PATCH] Read Ruby properties through shared IDML model --- crates/idml/src/model/mod.rs | 6 +-- crates/idml/src/model/resources.rs | 72 ++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/crates/idml/src/model/mod.rs b/crates/idml/src/model/mod.rs index 4f3d323b5..492a09b6b 100644 --- a/crates/idml/src/model/mod.rs +++ b/crates/idml/src/model/mod.rs @@ -30,9 +30,9 @@ pub use resources::{ 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, + ParagraphFlowValues, ParagraphListValues, 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::{ 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 25176e210..eaedfcdcb 100644 --- a/crates/idml/src/model/resources.rs +++ b/crates/idml/src/model/resources.rs @@ -165,6 +165,78 @@ pub struct CharacterAppearanceValues { pub strikethrough_options: TextDecorationValues, } +/// Raw Ruby attributes and properties on an IDML character range or style. +#[derive(Clone, Debug, Default, PartialEq)] +pub struct RubyValues { + pub flag: Option, + pub text: Option, + pub kind: Option, + pub alignment: Option, + pub position: Option, + pub x_offset: Option, + pub y_offset: Option, + pub font: Option, + pub font_style: Option, + pub font_size: Option, + pub x_scale: Option, + pub y_scale: Option, + pub open_type_pro: Option, + pub auto_tcy_digits: Option, + pub auto_tcy_include_roman: Option, + pub auto_tcy_auto_scale: Option, + pub overhang: Option, + pub parent_overhang: Option, + pub parent_spacing: Option, + pub auto_align: Option, + pub auto_scaling: Option, + pub parent_scaling: Option, + pub fill: Option, + pub stroke: Option, + pub fill_tint: Option, + pub stroke_tint: Option, + pub stroke_weight: Option, + pub overprint_fill: Option, + pub overprint_stroke: Option, +} + +impl RubyValues { + /// Reads Ruby text and formatting values from an IDML character range/style. + pub fn from_el(el: &El) -> Self { + let values = Values::of(el); + Self { + flag: values.boolean("RubyFlag").or_else(|| values.num("RubyFlag").map(|value| value != 0.0)), + text: values.prop("RubyString"), + kind: values.prop("RubyType"), + alignment: values.prop("RubyAlignment"), + position: values.prop("RubyPosition"), + x_offset: values.num("RubyXOffset"), + y_offset: values.num("RubyYOffset"), + font: values.prop("RubyFont"), + font_style: values.prop("RubyFontStyle"), + font_size: values.num("RubyFontSize"), + x_scale: values.num("RubyXScale"), + y_scale: values.num("RubyYScale"), + open_type_pro: values.boolean("RubyOpenTypePro"), + auto_tcy_digits: values.num("RubyAutoTcyDigits"), + auto_tcy_include_roman: values.boolean("RubyAutoTcyIncludeRoman"), + auto_tcy_auto_scale: values.boolean("RubyAutoTcyAutoScale"), + overhang: values.boolean("RubyOverhang"), + parent_overhang: values.prop("RubyParentOverhangAmount"), + parent_spacing: values.prop("RubyParentSpacing"), + auto_align: values.boolean("RubyAutoAlign"), + auto_scaling: values.boolean("RubyAutoScaling"), + parent_scaling: values.num("RubyParentScalingPercent"), + fill: values.prop("RubyFill"), + stroke: values.prop("RubyStroke"), + fill_tint: values.num("RubyTint"), + stroke_tint: values.num("RubyStrokeTint"), + stroke_weight: values.num("RubyWeight"), + overprint_fill: values.prop("RubyOverprintFill"), + overprint_stroke: values.prop("RubyOverprintStroke"), + } + } +} + impl CharacterAppearanceValues { /// Reads common character fill, stroke and decoration properties from IDML. pub fn from_el(el: &El) -> Self {