Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Available fonts / default font / fixed width font question
- By HybridMind Date 2009-01-02 05:48
Julian and others,

Any recommendations on how to deal with unknown availability of fonts on systems?  I had been just sticking with Gosu::default_font since I saw a doc comment that it would most likely work on all systems.  Recently though, I became frustrated with the default font because it is not a fixed width font so high score tables where getting really ugly looking.  So, I load up "courier" now and that works on my windows box but I'm not sure what fonts / font names are used over win/ mac / linux etc.  Is there anything thing I can do with regard to getting a reliable fixed-width font?  Can you distribute with a font?  Is there by chance a call to Gosu::default_fixed_width_font..?  (joke) ..  Anyway, just looking for any tips anyone would want to provide on how you normally deal with fonts in Gosu / Ruby.

Thanks all!

- By hima Date 2009-01-02 17:40
You can distribute a game with a font. You just need to create a font folder inside the game folder. And when you load a font do something like this

@font = Gosu::Font.new(self, "dat/font/SP-Normal.ttf", 20)

Here I save the font in dat/font/ folder.  And the font file name is SP-Normal.ttf. It has to be the filename, not the font name :)
- By HybridMind Date 2009-01-02 21:10
Thanks for the tip Hima-- I guess I hadn't really thought about just including fonts I want to use right in my /media directory.  Seems to work great though!
- By jlnr (dev) Date 2009-01-04 13:24 Edited 2009-01-04 14:32
But you have to keep in mind that this does not work on Linux due to limitations of the API used there :( Also, you have to have to redistribution rights for the font etc. etc., which limits you to a small number of fonts again.

I wonder if you should just use one of the "web safe fonts": http://en.wikipedia.org/wiki/Web-safe_fonts

If your user has a browser to download your game, they should also have all these fonts. I'll put it on my ToDo list to see if they really, really work on Linux, but if any of you wants to try it before I get to boot my VM, any feedback is welcome. :)
- By HybridMind Date 2009-01-04 16:11
Thanks for that link Julian.  On this topic- it seems mysterious to me that the following works:

I had courier working under Gosu by just originally doing:

@font = Gosu::Font.new(window, "Courier", 20)

The mystery to me is that I don't actually have a font file name named "Courier".  In /windows/fonts the filename is called "cour.ttf".  How did Gosu know to pick the right font?  Is there some kind of abstraction layer?  Is this an OS level thing that correctly found it?  Is it reading from the "name" of the font and not the "filename" ?

Anyway, good points on the whole legality of distributing fonts!  I think you are right that I should just use web safe fonts.  I just want to understand how Gosu will lookup the font names so I know how to call the fonts in a Gosu::Font.new call so that they grab the right web safe ones.  Any tips?

Thanks!
- By jlnr (dev) Date 2009-01-04 23:11
Yes, TTF fonts contain a name string that is different from the filename. Gosu just tells every operating system to fetch the Courier font and they know what file is the right one for that (that's why you sometimes have to manually rebuild font tables on Linux). In fact, if Gosu wants to load a TTF file on Windows, it has to load the actual file, then specify the name that's inside the TTF file for drawing, which is why there is a small TTF file parser contained within Gosu (duh).
- By HybridMind Date 2009-01-05 03:57
Thanks for providing further information Julian!  Hope that 'duh' wasn't because I asked something too stupid..!  ;)
- By jlnr (dev) Date 2009-01-05 08:59
Nah, more about having to parse binary TTF files just for one string ;)