Class: SilkLayout::Layout::TextBox
- Defined in:
- lib/silk_layout/layout/inline.rb
Instance Attribute Summary collapse
-
#ascender ⇒ Object
readonly
Returns the value of attribute ascender.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#descender ⇒ Object
readonly
Returns the value of attribute descender.
-
#font_family ⇒ Object
readonly
Returns the value of attribute font_family.
-
#font_name ⇒ Object
readonly
Returns the value of attribute font_name.
-
#font_size ⇒ Object
readonly
Returns the value of attribute font_size.
-
#font_style ⇒ Object
readonly
Returns the value of attribute font_style.
-
#font_weight ⇒ Object
readonly
Returns the value of attribute font_weight.
-
#line_height ⇒ Object
readonly
Returns the value of attribute line_height.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Attributes inherited from Box
#background_color, #border, #border_color, #display, #explicit_height, #explicit_width, #flex, #has_border, #height, #margin, #node, #padding, #width, #x, #y
Instance Method Summary collapse
- #children ⇒ Object
- #clone_with_text(text) ⇒ Object
-
#initialize(text, style) ⇒ TextBox
constructor
A new instance of TextBox.
Methods inherited from Box
#add_child, #border_box_height, #border_box_width, #border_box_x, #border_box_y
Constructor Details
#initialize(text, style) ⇒ TextBox
Returns a new instance of TextBox.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/silk_layout/layout/inline.rb', line 19 def initialize(text, style) super(nil) @text = text style ||= {} @font_size = px(style["font-size"]) || 16 @font_family = style["font-family"] || "Helvetica" @font_weight = style["font-weight"] || "normal" @font_style = style["font-style"] || "normal" @color = style["color"] || "black" metrics = SilkLayout::Render::FontLibrary.metrics( @font_family, font_weight: @font_weight, font_style: @font_style ) @font_name = metrics[:font_name] @ascender = metrics[:ascender] * @font_size / 1000.0 @descender = metrics[:descender] * @font_size / 1000.0 @line_height = parse_line_height(style["line-height"], @font_size) end |
Instance Attribute Details
#ascender ⇒ Object (readonly)
Returns the value of attribute ascender.
8 9 10 |
# File 'lib/silk_layout/layout/inline.rb', line 8 def ascender @ascender end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
8 9 10 |
# File 'lib/silk_layout/layout/inline.rb', line 8 def color @color end |
#descender ⇒ Object (readonly)
Returns the value of attribute descender.
8 9 10 |
# File 'lib/silk_layout/layout/inline.rb', line 8 def descender @descender end |
#font_family ⇒ Object (readonly)
Returns the value of attribute font_family.
8 9 10 |
# File 'lib/silk_layout/layout/inline.rb', line 8 def font_family @font_family end |
#font_name ⇒ Object (readonly)
Returns the value of attribute font_name.
8 9 10 |
# File 'lib/silk_layout/layout/inline.rb', line 8 def font_name @font_name end |
#font_size ⇒ Object (readonly)
Returns the value of attribute font_size.
8 9 10 |
# File 'lib/silk_layout/layout/inline.rb', line 8 def font_size @font_size end |
#font_style ⇒ Object (readonly)
Returns the value of attribute font_style.
8 9 10 |
# File 'lib/silk_layout/layout/inline.rb', line 8 def font_style @font_style end |
#font_weight ⇒ Object (readonly)
Returns the value of attribute font_weight.
8 9 10 |
# File 'lib/silk_layout/layout/inline.rb', line 8 def font_weight @font_weight end |
#line_height ⇒ Object (readonly)
Returns the value of attribute line_height.
8 9 10 |
# File 'lib/silk_layout/layout/inline.rb', line 8 def line_height @line_height end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
8 9 10 |
# File 'lib/silk_layout/layout/inline.rb', line 8 def text @text end |
Instance Method Details
#children ⇒ Object
43 44 45 |
# File 'lib/silk_layout/layout/inline.rb', line 43 def children [] end |
#clone_with_text(text) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/silk_layout/layout/inline.rb', line 47 def clone_with_text(text) self.class.new(text, { "font-size" => "#{@font_size}px", "font-family" => @font_family, "font-weight" => @font_weight, "font-style" => @font_style, "line-height" => "#{@line_height}px", "color" => @color }) end |