Class: Dommy::TextMetrics

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/html_canvas_element.rb

Overview

ctx.measureText(...) result. width is an approximation (no font metrics); the extended box metrics are zero. Enough that callers reading .width don't divide by undefined.

Constant Summary collapse

APPROX_CHAR_WIDTH =
6

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ TextMetrics

Returns a new instance of TextMetrics.



173
174
175
# File 'lib/dommy/html_canvas_element.rb', line 173

def initialize(text)
  @width = text.to_s.length * APPROX_CHAR_WIDTH
end

Instance Method Details

#__js_get__(key) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/dommy/html_canvas_element.rb', line 177

def __js_get__(key)
  case key
  when "width" then @width
  when "actualBoundingBoxLeft", "actualBoundingBoxRight",
       "actualBoundingBoxAscent", "actualBoundingBoxDescent",
       "fontBoundingBoxAscent", "fontBoundingBoxDescent",
       "emHeightAscent", "emHeightDescent",
       "hangingBaseline", "alphabeticBaseline", "ideographicBaseline" then 0
  else Bridge::ABSENT
  end
end

#__js_set__(_key, _value) ⇒ Object



189
# File 'lib/dommy/html_canvas_element.rb', line 189

def __js_set__(_key, _value) = Bridge::UNHANDLED