Class: Ea::Svg::EaEmitter::FontResolver
- Inherits:
-
Object
- Object
- Ea::Svg::EaEmitter::FontResolver
- Defined in:
- lib/ea/svg/ea_emitter/font_resolver.rb
Overview
Resolves the effective font family + size for a DiagramElement, using EA's fallback chain:
1. element.font_family / element.font_size (per-element override)
2. theme.font_family / theme.font_size (when theme is themed)
3. diagram-level default (most common non-nil value across
the diagram's elements)
4. locale fallback (Calibri 10)
Lives outside the Elements emitter so the resolution rule is defined once (MECE) and reusable by Labels and any future text-emitting layer.
Constant Summary collapse
- DEFAULT_FONT_FAMILY =
"Yu Gothic UI"- DEFAULT_ELEMENT_FONT_SIZE =
EA's default element compartment font size (matches reference SVGs which use 9pt for classifier header, attributes, operations, etc. — distinct from theme's diagram-level font size which applies only to frame label and swimlanes).
9
Instance Attribute Summary collapse
-
#diagram ⇒ Object
readonly
Returns the value of attribute diagram.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
Instance Method Summary collapse
- #family_for(element) ⇒ Object
-
#initialize(diagram, theme: nil) ⇒ FontResolver
constructor
A new instance of FontResolver.
- #size_for(element) ⇒ Object
- #size_unit_for(_element) ⇒ Object
- #style_for(element) ⇒ Object
- #weight_for(element) ⇒ Object
Constructor Details
#initialize(diagram, theme: nil) ⇒ FontResolver
Returns a new instance of FontResolver.
29 30 31 32 |
# File 'lib/ea/svg/ea_emitter/font_resolver.rb', line 29 def initialize(diagram, theme: nil) @diagram = diagram @theme = theme || Ea::Theme::Registry.default end |
Instance Attribute Details
#diagram ⇒ Object (readonly)
Returns the value of attribute diagram.
27 28 29 |
# File 'lib/ea/svg/ea_emitter/font_resolver.rb', line 27 def diagram @diagram end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
27 28 29 |
# File 'lib/ea/svg/ea_emitter/font_resolver.rb', line 27 def theme @theme end |
Instance Method Details
#family_for(element) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/ea/svg/ea_emitter/font_resolver.rb', line 34 def family_for(element) explicit = element&.font_family return explicit if explicit && !explicit.empty? return theme.font_family if theme.themed? && theme.font_family diagram_default_family || DEFAULT_FONT_FAMILY end |
#size_for(element) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/ea/svg/ea_emitter/font_resolver.rb', line 42 def size_for(element) explicit = element&.font_size explicit = nil if explicit&.zero? return explicit if explicit return diagram_default_size if diagram_default_size DEFAULT_ELEMENT_FONT_SIZE end |
#size_unit_for(_element) ⇒ Object
51 52 53 |
# File 'lib/ea/svg/ea_emitter/font_resolver.rb', line 51 def size_unit_for(_element) theme.font_size_unit || "pt" end |
#style_for(element) ⇒ Object
60 61 62 |
# File 'lib/ea/svg/ea_emitter/font_resolver.rb', line 60 def style_for(element) element&.font_italic ? "italic" : "normal" end |
#weight_for(element) ⇒ Object
55 56 57 58 |
# File 'lib/ea/svg/ea_emitter/font_resolver.rb', line 55 def weight_for(element) bold = element&.font_bold ? 700 : nil bold || (theme.themed? ? theme.text_weight_normal : 400) end |