Object
Implements a simple bitmap font by extracting letters from a PNG.
# File lib/png/font.rb, line 15 def self.default @@default ||= new(File.join(File.dirname(__FILE__), "default_font.png")) end
# File lib/png/font.rb, line 19 def initialize(png_file) @canvas = PNG.load_file png_file @height, @width = canvas.height / 4, canvas.width / 26 @cache = {} end
# File lib/png/font.rb, line 36 def [] c c = c.chr unless String === c x0, y0, x1, y1 = coordinates c @cache[c] ||= @canvas.extract(x0, y0, x1, y1) end
# File lib/png/font.rb, line 25 def coordinates c i = LETTERS.index c raise ArgumentError, "Can't find #{c.inspect}" unless i x = (i % 26) * width y = (3 - (i / 26)) * height # start from the top (3rd row) return x, y, x+width-1, y+height-1 end
[Validate]
Generated with the Darkfish Rdoc Generator 2.