Class: Dommy::TextMetrics
- Inherits:
-
Object
- Object
- Dommy::TextMetrics
- 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
- #__js_get__(key) ⇒ Object
- #__js_set__(_key, _value) ⇒ Object
-
#initialize(text) ⇒ TextMetrics
constructor
A new instance of TextMetrics.
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 |