Class: BitmapFont
- Inherits:
-
Object
- Object
- BitmapFont
- Defined in:
- src/ruby/include/cypher.rb
Class Method Summary collapse
Class Method Details
.draw_text(png, s, font, x, y) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'src/ruby/include/cypher.rb', line 124 def self.draw_text(png, s, font, x, y) self.load_font(font) s.each_char do |c| if @@fonts[font][c] png.compose!(@@fonts[font][c], x, y) x += @@fonts[font][c].width + 3 elsif c == ' ' x += @@fonts[font]['A'].width + 3 end end end |
.load_font(path) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'src/ruby/include/cypher.rb', line 113 def self.load_font(path) @@fonts ||= {} return if @@fonts[path] @@fonts[path] = {} Dir[File.join(File.join('/app/cypher', path), '*.png')].each do |p| c = File.basename(p).sub('.png', '') b = ChunkyPNG::Image.from_file(p) @@fonts[path][c] = b end end |
.text_width(s, font) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'src/ruby/include/cypher.rb', line 136 def self.text_width(s, font) self.load_font(font) width = 0 s.each_char do |c| if @@fonts[font][c] width += @@fonts[font][c].width + 3 elsif c == ' ' width += @@fonts[font]['A'].width + 3 end end width - 3 end |