Sha256: e330d43c94df9331a31bbf85d9c5336ee611a528ffa00a83a4a15740e7d818c0
Contents?: true
Size: 525 Bytes
Versions: 1
Compression:
Stored size: 525 Bytes
Contents
require 'ttfunk' module Grawlix class GlyphSizeCache DEFAULT_FONT_PATH = File.join(File.dirname(__FILE__), '..', '..', 'OpenSans-Regular.ttf') def initialize(font_path = DEFAULT_FONT_PATH) @file = TTFunk::File.open(font_path) @cache = {} end 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 def em_size @em ||= @file.header.units_per_em end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
grawlix-0.1.0 | lib/grawlix/glyph_size_cache.rb |