Class: DXOpal::Font

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

Overview

Represents a font Used by Window.draw_font, etc.

Class Method Summary collapse

Instance Method Summary collapse

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

.defaultObject



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_strObject

Return a string like “48px serif”



23
24
25
# File 'lib/dxopal/font.rb', line 23

def _spec_str
  "#{@size}px #{@fontname}"
end

#fontnameObject



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

#sizeObject



14
# File 'lib/dxopal/font.rb', line 14

def size; @size; end