Class: DXOpal::Font
- Inherits:
-
Object
- Object
- DXOpal::Font
- Defined in:
- lib/dxopal/font.rb
Overview
Represents a font Used by Window.draw_font, etc.
Class Method Summary collapse
Instance Method Summary collapse
-
#_spec_str ⇒ Object
Return a string like “48px serif”.
- #fontname ⇒ Object
- #get_width(string) ⇒ Object
-
#initialize(size, fontname = nil, option = {}) ⇒ Font
constructor
A new instance of Font.
- #size ⇒ Object
Constructor Details
#initialize(size, fontname = nil, option = {}) ⇒ Font
Returns a new instance of Font.
8 9 10 11 12 |
# File 'lib/dxopal/font.rb', line 8 def initialize(size, fontname=nil, option={}) @size = size @orig_fontname = fontname @fontname = fontname || "sans-serif" end |
Class Method Details
.default ⇒ Object
5 |
# File 'lib/dxopal/font.rb', line 5 def self.default; @@default ||= Font.new(24); end |
.default=(f) ⇒ Object
6 |
# File 'lib/dxopal/font.rb', line 6 def self.default=(f); @@default = f; end |
Instance Method Details
#_spec_str ⇒ Object
Return a string like “48px serif”
23 24 25 |
# File 'lib/dxopal/font.rb', line 23 def _spec_str "#{@size}px #{@fontname}" end |
#fontname ⇒ Object
15 |
# File 'lib/dxopal/font.rb', line 15 def fontname; @orig_fontname; end |
#get_width(string) ⇒ Object
17 18 19 20 |
# File 'lib/dxopal/font.rb', line 17 def get_width(string) canvas = Native(`document.getElementById('dxopal-canvas')`) canvas.getContext('2d').measureText(string).width end |
#size ⇒ Object
14 |
# File 'lib/dxopal/font.rb', line 14 def size; @size; end |