diff --git a/crates/idml/src/model/mod.rs b/crates/idml/src/model/mod.rs index 6dc2f8ec6..dcf9794e8 100644 --- a/crates/idml/src/model/mod.rs +++ b/crates/idml/src/model/mod.rs @@ -29,9 +29,9 @@ pub use resources::{ 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, ParagraphListValues, StrokeDefinition, StrokeStyle, - StrokeStyleKind, Style, StyleGroup, StyleGroupWriter, StyleKind, StyleNode, Swatch, SwatchKind, TabStopValues, TintDefinition, color_groups, - inks, named, preference, stroke_styles, style_groups, swatches, + 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, }; 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 b589a6c0d..776ba56db 100644 --- a/crates/idml/src/model/resources.rs +++ b/crates/idml/src/model/resources.rs @@ -91,6 +91,84 @@ pub struct ParagraphAlignmentValues { pub composer: Option, } +/// Paragraph hyphenation, justification spacing and keep options after caller enum mapping. +#[derive(Clone, Debug, Default, PartialEq)] +pub struct ParagraphFlowValues { + pub hyphenate: Option, + pub hyphenate_min_word: Option, + pub hyphenate_after_first: Option, + pub hyphenate_before_last: Option, + pub hyphenate_ladder_limit: Option, + pub hyphenation_zone: Option, + pub hyphenate_capitalized: Option, + pub hyphenate_last_word: Option, + pub hyphenate_across_columns: Option, + pub hyphen_weight: Option, + pub word_spacing: [Option; 3], + pub letter_spacing: [Option; 3], + pub glyph_scaling: [Option; 3], + pub auto_leading: Option, + pub single_word_justification: Option, + pub keep_with_next: Option, + pub keep_lines_together: Option, + pub ignore_edge_alignment: Option, + pub keep_all_lines_together: Option, + pub keep_first_lines: Option, + pub keep_last_lines: Option, + pub start_paragraph: Option, +} + +impl ParagraphFlowValues { + /// Writes IDML attributes for paragraph hyphenation and flow. + pub fn to_attrs(&self) -> Vec<(String, String)> { + let mut attrs = Vec::new(); + for (key, value) in [ + ("Hyphenation", self.hyphenate), + ("HyphenateCapitalizedWords", self.hyphenate_capitalized), + ("HyphenateLastWord", self.hyphenate_last_word), + ("HyphenateAcrossColumns", self.hyphenate_across_columns), + ("KeepLinesTogether", self.keep_lines_together), + ("IgnoreEdgeAlignment", self.ignore_edge_alignment), + ("KeepAllLinesTogether", self.keep_all_lines_together), + ] { + if let Some(value) = value { + attrs.push((key.to_string(), if value { "true" } else { "false" }.to_string())); + } + } + for (key, value) in [ + ("HyphenateWordsLongerThan", self.hyphenate_min_word), + ("HyphenateAfterFirst", self.hyphenate_after_first), + ("HyphenateBeforeLast", self.hyphenate_before_last), + ("HyphenateLadderLimit", self.hyphenate_ladder_limit), + ("HyphenationZone", self.hyphenation_zone), + ("HyphenWeight", self.hyphen_weight), + ("MinimumWordSpacing", self.word_spacing[0]), + ("DesiredWordSpacing", self.word_spacing[1]), + ("MaximumWordSpacing", self.word_spacing[2]), + ("MinimumLetterSpacing", self.letter_spacing[0]), + ("DesiredLetterSpacing", self.letter_spacing[1]), + ("MaximumLetterSpacing", self.letter_spacing[2]), + ("MinimumGlyphScaling", self.glyph_scaling[0]), + ("DesiredGlyphScaling", self.glyph_scaling[1]), + ("MaximumGlyphScaling", self.glyph_scaling[2]), + ("AutoLeading", self.auto_leading), + ("KeepWithNext", self.keep_with_next), + ("KeepFirstLines", self.keep_first_lines), + ("KeepLastLines", self.keep_last_lines), + ] { + if let Some(value) = value { + attrs.push((key.to_string(), crate::value::num(value))); + } + } + for (key, value) in [("SingleWordJustification", &self.single_word_justification), ("StartParagraph", &self.start_paragraph)] { + if let Some(value) = value { + attrs.push((key.to_string(), value.clone())); + } + } + attrs + } +} + impl ParagraphAlignmentValues { /// Writes the IDML attributes for paragraph alignment and spacing. pub fn to_attrs(&self) -> Vec<(String, String)> {