class Grawlix::GlyphSizeCache

Constants

DEFAULT_FONT_PATH

Public Class Methods

new(font_path = DEFAULT_FONT_PATH) click to toggle source
# File lib/grawlix/glyph_size_cache.rb, line 7
def initialize(font_path = DEFAULT_FONT_PATH)
  @file = TTFunk::File.open(font_path)
  @cache = {}
end

Public Instance Methods

em_size() click to toggle source
# File lib/grawlix/glyph_size_cache.rb, line 16
def em_size
  @em ||= @file.header.units_per_em
end
width_for(character) click to toggle source
# File lib/grawlix/glyph_size_cache.rb, line 12
def width_for(character)
  @cache[character] ||= @file.horizontal_metrics.for(@file.cmap.unicode.first[character.unpack("U*").first]).advance_width.to_f / em_size
end