Method: MiniGL::ImageFont#markup_width
- Defined in:
- lib/minigl/text.rb
#markup_width(text) ⇒ Object Also known as: text_width
Returns the width, in pixels, of a given string written by this font. Note: Markup is not supported, this method is named this way to match Gosu::Font‘s signature.
Parameters:
- text
-
The string to be measured
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/minigl/text.rb', line 74 def markup_width(text) w = 0 text.chars.each_with_index do |c, i| if c == ' ' w += @space_width else idx = @chars.index(c) w += idx ? @images[idx].width : 0 w += @char_spacing if i < text.chars.size - 1 end end w end |