Class: Idml::Render::StyleLookup
- Inherits:
-
Object
- Object
- Idml::Render::StyleLookup
- Defined in:
- lib/idml/render/style_lookup.rb
Overview
Resolves AppliedParagraphStyle and AppliedCharacterStyle
references to their style definitions in Resources/Styles.xml.
Built once per render pass from Parts::Style; StyleResolver
consults it to fill in formatting attributes that the PSR/CSR
element doesn't declare inline.
Merge semantics: PSR/CSR inline attributes override style attributes. When the PSR/CSR declares a value (non-nil), that wins. When it doesn't, the style definition's value is used as a default. When neither declares a value, the attribute remains nil and the renderer applies its own default.
Class Method Summary collapse
Instance Method Summary collapse
-
#character_style(self_ref) ⇒ Object
Returns the CharacterStyle referenced by
self_ref, or nil. -
#initialize(para_styles, char_styles) ⇒ StyleLookup
constructor
A new instance of StyleLookup.
-
#paragraph_style(self_ref) ⇒ Object
Returns the ParagraphStyle referenced by
self_ref, or nil. -
#resolve_char_attr(csr, attr_name) ⇒ Object
Returns the value of
attr_namefrom the CSR, or from the referenced CharacterStyle when the CSR doesn't declare it. -
#resolve_para_attr(psr, attr_name) ⇒ Object
Returns the value of
attr_namefrom the PSR, or from the referenced ParagraphStyle when the PSR doesn't declare it.
Constructor Details
#initialize(para_styles, char_styles) ⇒ StyleLookup
26 27 28 29 |
# File 'lib/idml/render/style_lookup.rb', line 26 def initialize(para_styles, char_styles) @para_styles = para_styles @char_styles = char_styles end |
Class Method Details
.from_package(package) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/idml/render/style_lookup.rb', line 17 def self.from_package(package) styles = package&.style return new({}, {}) unless styles para_styles = index_styles(styles.paragraph_style) char_styles = index_styles(styles.character_style) new(para_styles, char_styles) end |
Instance Method Details
#character_style(self_ref) ⇒ Object
Returns the CharacterStyle referenced by self_ref, or nil.
41 42 43 44 45 |
# File 'lib/idml/render/style_lookup.rb', line 41 def character_style(self_ref) return nil unless self_ref @char_styles[self_ref] end |
#paragraph_style(self_ref) ⇒ Object
Returns the ParagraphStyle referenced by self_ref, or nil.
self_ref is the PSR's AppliedParagraphStyle value (e.g.,
"ParagraphStyle/$ID/NormalParagraphStyle").
34 35 36 37 38 |
# File 'lib/idml/render/style_lookup.rb', line 34 def paragraph_style(self_ref) return nil unless self_ref @para_styles[self_ref] end |
#resolve_char_attr(csr, attr_name) ⇒ Object
Returns the value of attr_name from the CSR, or from the
referenced CharacterStyle when the CSR doesn't declare it.
62 63 64 65 66 67 68 |
# File 'lib/idml/render/style_lookup.rb', line 62 def resolve_char_attr(csr, attr_name) csr_value = csr.public_send(attr_name) return csr_value unless csr_value.nil? style = character_style(csr.applied_character_style) style&.public_send(attr_name) end |
#resolve_para_attr(psr, attr_name) ⇒ Object
Returns the value of attr_name from the PSR, or from the
referenced ParagraphStyle when the PSR doesn't declare it.
Uses public_send (not send) to stay within public API
boundaries — the attribute readers generated by lutaml-model
are public.
52 53 54 55 56 57 58 |
# File 'lib/idml/render/style_lookup.rb', line 52 def resolve_para_attr(psr, attr_name) psr_value = psr.public_send(attr_name) return psr_value unless psr_value.nil? style = paragraph_style(psr.applied_paragraph_style) style&.public_send(attr_name) end |