Created
November 10, 2010 16:16
-
-
Save bil-bas/671052 to your computer and use it in GitHub Desktop.
The former fails; the latter works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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