Class: Browser::Canvas::Text

Inherits:
Object
  • Object
show all
Includes:
Native::Wrapper
Defined in:
opal/browser/canvas/text.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Text

Returns a new instance of Text.


8
9
10
11
12
# File 'opal/browser/canvas/text.rb', line 8

def initialize(context)
  @context = context

  super(@context.to_n)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context


6
7
8
# File 'opal/browser/canvas/text.rb', line 6

def context
  @context
end

Instance Method Details

#fill(text, x = nil, y = nil, max_width = nil) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
# File 'opal/browser/canvas/text.rb', line 18

def fill(text, x = nil, y = nil, max_width = nil)
  x ||= 0
  y ||= 0

  if max_width
    `#@native.fillText(text, x, y, max_width)`
  else
    `#@native.fillText(text, x, y)`
  end

  @context
end

#measure(text) ⇒ Object


14
15
16
# File 'opal/browser/canvas/text.rb', line 14

def measure(text)
  `#@native.measureText(text)`
end

#stroke(text, x = nil, y = nil, max_width = nil) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
# File 'opal/browser/canvas/text.rb', line 31

def stroke(text, x = nil, y = nil, max_width = nil)
  x ||= 0
  y ||= 0

  if max_width
    `#@native.strokeText(text, x, y, max_width)`
  else
    `#@native.strokeText(text, x, y)`
  end

  @context
end