Class: Dare::Font

Inherits:
Object
  • Object
show all
Defined in:
lib/dare/font.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Font

Returns a new instance of Font.



3
4
5
6
7
8
9
10
11
12
# File 'lib/dare/font.rb', line 3

def initialize(opts = {})
  opts[:font] ||= "Arial"
  opts[:canvas] ||= Dare.default_canvas
  opts[:size] ||= 30
  opts[:color] ||= "black"

  @font = opts[:size].to_s + "px" + " " + opts[:font]
  @canvas = opts[:canvas]
  @color = opts[:color]
end

Instance Method Details

#draw(string = "", x = 0, y = 0, opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/dare/font.rb', line 14

def draw(string = "", x = 0, y = 0, opts = {})
  %x{
    #{@canvas.context}.font = #{@font} ;
    #{@canvas.context}.textAlign = 'left';
    #{@canvas.context}.textBaseline = 'top';
    #{@canvas.context}.fillStyle = #{@color};
    #{@canvas.context}.fillText(#{string}, #{x}, #{y});
  }
end