Class: MtgCardMaker::TextRenderingService
- Inherits:
-
Object
- Object
- MtgCardMaker::TextRenderingService
- Defined in:
- lib/mtg_card_maker/text_rendering_service.rb
Overview
Minimal text rendering service with basic word wrapping for SVG. This service handles text layout, wrapping, and attribute generation for SVG text elements with configurable font sizes, colors, and spacing.
Instance Attribute Summary collapse
-
#available_width ⇒ Integer
The available width for text wrapping.
-
#color ⇒ String
The text color.
-
#css_class ⇒ String?
The CSS class for styling.
-
#font_size ⇒ Integer
The font size.
-
#layer_config ⇒ LayerConfig
The layer configuration.
-
#line_height ⇒ Integer
The line height.
-
#text ⇒ String
The text to render.
-
#x ⇒ Integer
The x-coordinate for text positioning.
-
#y ⇒ Integer
The y-coordinate for text positioning.
Class Method Summary collapse
-
.wrapped_text_lines ⇒ Object
Convenience method for backward compatibility.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ TextRenderingService
constructor
Initialize a new text rendering service.
-
#wrapped_text_lines(text = nil) ⇒ Array<Array>
Returns an array of [line, attrs] for SVG text elements.
Constructor Details
#initialize(**kwargs) ⇒ TextRenderingService
Initialize a new text rendering service
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mtg_card_maker/text_rendering_service.rb', line 56 def initialize(**kwargs) # Set defaults defaults = { text: '', layer_config: LayerConfig.default, x: 0, y: 0, font_size: nil, color: nil, available_width: nil, line_height: nil, css_class: nil } # Merge defaults with provided kwargs final_params = defaults.merge(kwargs) # Set instance variables final_params.each do |key, value| send("#{key}=", value) if respond_to?("#{key}=") end # Post-process dependent values @font_size ||= @layer_config.default_font_size @color ||= @layer_config.default_text_color @available_width ||= CARD_WIDTH @line_height ||= calculate_default_line_height end |
Instance Attribute Details
#available_width ⇒ Integer
Returns the available width for text wrapping.
36 37 38 |
# File 'lib/mtg_card_maker/text_rendering_service.rb', line 36 def available_width @available_width end |
#color ⇒ String
Returns the text color.
33 34 35 |
# File 'lib/mtg_card_maker/text_rendering_service.rb', line 33 def color @color end |
#css_class ⇒ String?
Returns the CSS class for styling.
42 43 44 |
# File 'lib/mtg_card_maker/text_rendering_service.rb', line 42 def css_class @css_class end |
#font_size ⇒ Integer
Returns the font size.
30 31 32 |
# File 'lib/mtg_card_maker/text_rendering_service.rb', line 30 def font_size @font_size end |
#layer_config ⇒ LayerConfig
Returns the layer configuration.
21 22 23 |
# File 'lib/mtg_card_maker/text_rendering_service.rb', line 21 def layer_config @layer_config end |
#line_height ⇒ Integer
Returns the line height.
39 40 41 |
# File 'lib/mtg_card_maker/text_rendering_service.rb', line 39 def line_height @line_height end |
#text ⇒ String
Returns the text to render.
18 19 20 |
# File 'lib/mtg_card_maker/text_rendering_service.rb', line 18 def text @text end |
#x ⇒ Integer
Returns the x-coordinate for text positioning.
24 25 26 |
# File 'lib/mtg_card_maker/text_rendering_service.rb', line 24 def x @x end |
#y ⇒ Integer
Returns the y-coordinate for text positioning.
27 28 29 |
# File 'lib/mtg_card_maker/text_rendering_service.rb', line 27 def y @y end |
Class Method Details
.wrapped_text_lines ⇒ Object
Convenience method for backward compatibility
155 156 157 |
# File 'lib/mtg_card_maker/text_rendering_service.rb', line 155 def wrapped_text_lines(*, **) new(*, **).wrapped_text_lines end |
Instance Method Details
#wrapped_text_lines(text = nil) ⇒ Array<Array>
Returns an array of [line, attrs] for SVG text elements
89 90 91 92 |
# File 'lib/mtg_card_maker/text_rendering_service.rb', line 89 def wrapped_text_lines(text = nil) @text = text if text render_text_lines end |