Sha256: 34278c786eeafcec8e7134d4a32e669881ef78c61c78788b044b1a0f8a6dfa51

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

module VER
  # 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.
  module Font
    module_function

    class << self
      attr_reader :cache
    end

    @cache = {}

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

    def default
      VER.options.font
    end

    def default_options
      default ? default.actual_hash : {}
    end

    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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ver-2010.08 lib/ver/font.rb
ver-2010.02 lib/ver/font.rb
ver-2009.12.14 lib/ver/font.rb
ver-2009.11.29 lib/ver/font.rb
ver-2009.11.28 lib/ver/font.rb