Skip to content

Instantly share code, notes, and snippets.

@bil-bas
Created November 10, 2010 16:16
Show Gist options
  • Save bil-bas/671052 to your computer and use it in GitHub Desktop.
Save bil-bas/671052 to your computer and use it in GitHub Desktop.
The former fails; the latter works
# encoding: ascii-8bit
# To put ö directly into a string, I need to set the encoding to ascii-8bit.
require 'gosu'
include Gosu
class Game < Window
def initialize
super 640, 480, false
end
def update
f = Font.new(self, nil, 16)
p f.text_width("o")
p f.text_width("ö")
self.text_input = TextInput.new
text_input.text += "ö"
p f.text_width(text_input.text)
close
end
end
Game.new.show
# Win7 x64
# 8.5
# 10.0
# 10.0
# If I take the input from the text-input, it works fine.
require 'gosu'
include Gosu
class Game < Window
def initialize
super 640, 480, false
@font = Font.new(self, nil, 16)
self.text_input = TextInput.new
end
def update
@width = @font.text_width(text_input.text)
end
def draw
@font.draw text_input.text, 0, 0, 0
@font.draw @width.to_s, 0, 50, 0
end
end
Game.new.show
# This gives the width of "ö" or "o" as 8.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment