Module: VER::Font

Defined in:
lib/ver/font.rb

Overview

FIXME:

If a font doesn't support, for example, underline, we will still create a
new font for it.
This means that there can be an infinite number of fonts with identical
options, yet we still try to create new instances because the actual
properties of the font don't equal the properties it was created with.
We might be able to fix this by storing the options used for creation with
the Font and comparing against them instead.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cacheObject (readonly)

Returns the value of attribute cache.



14
15
16
# File 'lib/ver/font.rb', line 14

def cache
  @cache
end

Class Method Details

.[](options) ⇒ Object



19
20
21
22
# File 'lib/ver/font.rb', line 19

def [](options)
  options = normalize_options(options)
  @cache[options] ||= Tk::Font.new(options)
end

.defaultObject



24
25
26
# File 'lib/ver/font.rb', line 24

def default
  VER.options.font
end

.default_optionsObject



28
29
30
# File 'lib/ver/font.rb', line 28

def default_options
  default ? default.actual_hash : {}
end

.normalize_options(options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ver/font.rb', line 32

def normalize_options(options)
  result = {}

  options.each{|key, value|
    case key = key.to_s
    when 'family'
      result[key.to_sym] = value.to_s
    when 'weight', 'slant'
      result[key.to_sym] = value.to_sym
    when 'size'
      result[key.to_sym] = value.to_i
    when 'underline', 'overstrike'
      result[key.to_sym] = !!value
    end
  }

  result
end