def draw @font.draw("This should be <c=ffff00>yellow</c>", 10, 10, 1.0, 1.0, 1.0) @font.draw("This should be <b>bold</b>", 10, 30, 1.0, 1.0, 1.0) @font.draw("This should be <i>italic</i>", 10, 50, 1.0, 1.0, 1.0) @font.draw("This should be <u>underlined</u>", 10, 70, 1.0, 1.0, 1.0) end
end
window = GameWindow.new window.show
Byjlnr (dev)
Date 2010-06-16 14:59
Edited 2010-06-16 15:24
That is weird. All tags work for me for standard OS X font with both Font and Image#from_text. However, if I load a custom font, it stops working. You would think that either OS X or Windows would bother to do fake italics/fake bold if necessary. Does the font you use include variants for bold and italics?
Oh—underline looks ugly with Gosu right now anyway. I think I will do my own custom underlining soon, and then that will work at least. (Right now, Gosu underlines word for word, leaving ugly gaps.)
But I found another problem: <b> does not work as expected with Gosu::Font, BECAUSE: since <b> looks better for most stuff, Gosu::Font just had bold as the default, and in Ruby, you cannot even change it. If you want non-bold text with Gosu::Font, prepend </b> to the string. Image#from_text does not have this default. I don't want to mess around with existing games, so I can only change this when I introduce the new Gosu::Font constructor which does not need the Window argument, which will create a non-bold Font. Until then, please use </b> to initiate non-bold text.
Backwards compatibility is stupid, so glad that I have new-style constructors planned soon. They really help with cleaning this mess up.
Actually I've been a bit of an idiot, I forgot I had already implemented a colour tag system for drawing fonts and was foolishly using that to test, the upshot is it is working on OS X for me now.
Btw if you specify a colour for a font then all <c> are ignored - is this correct? e.g.,
@font.draw("This should be <c=ffff00>yellow</c>", 10, 10, 1.0, 1.0, 1.0, Gosu::Color::BLACK)
...this draws the entire line in black.
Thanks for the info regarding prepending </b> for non-bold text.
Looking forward to the new Font constructor:P Keep up the great work!
I think the numbers are multiplied. So basically, you can use the color argument in Font#draw to darken the text, or to make it more transparent. Which is consistent with what the color argument to Image#draw does.