Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Gosu::Font and text formatting
- - By salin Date 2010-06-15 06:11
Hi

How can I use the HTML-like markup?  I've tried using a font.draw with "<b>test</b>" and that didn't work.

Thanks.
Parent - By jlnr (dev) Date 2010-06-26 15:19
Sorry, it was really and fully broken on Windows. I wonder why it even worked sometimes, really a mystery. Will be fixed in 0.7.23.
- By jlnr (dev) Date 2010-06-15 06:46
Which system are you on? It should work just like that EXCEPT for Linux with a custom .ttf file loaded. :)

You can use <c=ff0000> to try something that should work everywhere.
- By salin Date 2010-06-15 08:20 Edited 2010-06-16 08:09
os/x 10.5 with a custom .ttf file loaded.  I'm at work now but I'll try <c> when I get home and let you know.

UPDATE:  I've tried <c> with no luck.

UPDATE 2:  I've also tested on Windows XP and <c> works but the other tags don't.  Maybe I'm doing something wrong - tested using this code:

require 'gosu'

class GameWindow < Gosu::Window

  def initialize
    super(300, 200, false)
    #@font = Gosu::Font.new(self, Gosu::default_font_name, 18)
    @font = Gosu::Font.new(self, "Arial", 18)
  end

  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
- By jlnr (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.
- By salin Date 2010-06-16 18:47 Edited 2010-06-16 19:00
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!
- By jlnr (dev) Date 2010-06-16 19:59
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.
Up Topic Gosu / Gosu Exchange / Gosu::Font and text formatting

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill