Class: SvgDrawer::TextBox

Inherits:
Base
  • Object
show all
Defined in:
lib/svg_drawer/text_box.rb

Instance Attribute Summary

Attributes inherited from Base

#child_params, #inherited_params, #params

Instance Method Summary collapse

Methods inherited from Base

defaults, #draw, #ensure_complete!, #param, #param!, requires, special, #update_params!

Constructor Details

#initialize(text, params = {}) ⇒ TextBox

Returns a new instance of TextBox.



19
20
21
22
23
24
# File 'lib/svg_drawer/text_box.rb', line 19

def initialize(text, params = {})
  super(params)
  @text = text.to_s.strip.gsub(/\s+/, ' ')
  fonts_config = SvgDrawer.configuration
  @config = fonts_config['default'].merge(fonts_config[param(:font)] || {})
end

Instance Method Details

#heightObject

If overflow is true, but we don’t have any explicit height set, report the calculated height.



34
35
36
37
38
39
40
# File 'lib/svg_drawer/text_box.rb', line 34

def height
  return @height if @height
  ensure_complete!
  @height = param(:overflow) || !param(:wrap) ?
    param(:height, calculate_height).to_d :
    [param(:height, 0), calculate_height].max.to_d
end

#incompleteObject



42
43
44
# File 'lib/svg_drawer/text_box.rb', line 42

def incomplete
  false
end

#widthObject



26
27
28
29
30
# File 'lib/svg_drawer/text_box.rb', line 26

def width
  return @width if @width
  ensure_complete!
  @width = param(:width, calculate_width).to_d
end