Sha256: c7e7893a8871aa356bf2439ac31f0eaab7dc47ccaf63708ef39dca9efc3164c8
Contents?: true
Size: 1.05 KB
Versions: 8
Compression:
Stored size: 1.05 KB
Contents
class SugarPNG class Font DEFAULT_DIR = File.expand_path("../../data/font", File.dirname(__FILE__)) HEIGHT = 16 def initialize dir = DEFAULT_DIR @dir = dir @pages = {} end def height HEIGHT end # get glyph by index def [] idx idx = idx.ord if !idx.is_a?(Integer) && idx.respond_to?(:ord) raise ArgumentError.new("invalid idx type: #{idx.class}") unless idx.is_a?(Integer) raise ArgumentError.new("invalid idx: #{idx.inspect}") if idx<0 || idx>0xffff pageno = idx >> 8 @pages[pageno] ||= Page.new(File.join(@dir, "%02x" % pageno)) @pages[pageno][idx] end class Page def initialize fname @data = Marshal.load(File.binread(fname)) @glyphs = {} end # get glyph by index def [] ord idx = ord&0xff @glyphs[idx] ||= Glyph.new( :height => HEIGHT, :width => @data[idx].size/2, :data => @data[idx], :ord => ord ) end end # class Page end # class Font end
Version data entries
8 entries across 8 versions & 1 rubygems