ExportCachedFont() and importCachedFont()
by Clint Herron · in Torque Game Builder · 09/19/2006 (4:24 am) · 1 replies
I recently finished my first real game in Torque Game Builder. It was a bit of a nerve-wracking experience as it was for a short-term game-writing competition, but all-told I think it turned out alright.
However, it was on the last day of the competition when I was trying to get a new font loaded into TGB that I think I stumbled across at least one bug in the way fonts are dealt with in TGB.
To elaborate, let me first show you my font cache:
All groovy, yes? So we export a font and re-import it, then re-export it again.
Behold, arial_bold_20_a.png, and arial_bold_20_b.png:


And repeating the process again for arial_bold_20_c.png gives us:

Regarding importCachedFont(), the docs say:
So evidently, there's some trouble there, because you obviously *don't* want to call with the same parameters because it keeps increasing your border if you have one specified.
Not exactly a huge bug -- sure, the font size is a little off, but it's still usable. But then comes the next problem. Duplicate the font, and export it (so that you can edit it in your favorite .png editor, and re-import it and load it into your profiles to use as a custom font).
All works fine. Edit that font in your favorite editor (in this case, I've tested it both with Windows Paint and Gimp), and I saved it as testfont_20_c.png.
You can see the two fonts here:


Import and re-export as version d:
And behold the result:

I don't know how well it shows up here in the forums, but it basically bounding-boxes each individual font and displays a white background.
And when you load it up in your game, it displays each letter as a black bounding box, rather than having your painstakingly drawn font (I made the mistake of aligning my whole new font before I tested importing any of it -- boy was that a dissapointment).
Evidentally there is something special in the way that Torque expects the PNG to be formatted that Gimp and Paint don't do.
Thanks for reading! I hope this bug report has been useful. If it is a user error rather than a TGB error, please correct me.
Respectfully,
clint
However, it was on the last day of the competition when I was trying to get a new font loaded into TGB that I think I stumbled across at least one bug in the way fonts are dealt with in TGB.
To elaborate, let me first show you my font cache:
==>dumpFontCacheStatus();
--------------------------------------------------------------------------
Font Cache Usage Report (16 fonts found)
'Lucida Console' 12pt
- 1 texture sheets, 95 mapped characters.
- Codepoints range from 0xd to 0x7e.
- Platform font is present.
'Arial Bold' 20pt
- 1 texture sheets, 83 mapped characters.
- Codepoints range from 0x20 to 0x7a.
- Platform font is present.
*snip because of exceeding character limit*
'Arial' 12pt
- 1 texture sheets, 42 mapped characters.
- Codepoints range from 0x20 to 0x79.
- Platform font is present.All groovy, yes? So we export a font and re-import it, then re-export it again.
==>exportCachedFont("Arial Bold", 20, "./arial_bold_20_a.png", 5, 0);
==>importCachedFont("Arial Bold", 20, "./arial_bold_20_a.png", 5, 0);
==>exportCachedFont("Arial Bold", 20, "./arial_bold_20_b.png", 5, 0);Behold, arial_bold_20_a.png, and arial_bold_20_b.png:


And repeating the process again for arial_bold_20_c.png gives us:

Regarding importCachedFont(), the docs say:
Quote:Import an image strip from exportCachedFont. Call with the same parameters you called
exportCachedFont.
So evidently, there's some trouble there, because you obviously *don't* want to call with the same parameters because it keeps increasing your border if you have one specified.
Not exactly a huge bug -- sure, the font size is a little off, but it's still usable. But then comes the next problem. Duplicate the font, and export it (so that you can edit it in your favorite .png editor, and re-import it and load it into your profiles to use as a custom font).
==>duplicateCachedFont("Arial Bold", 20, "TestFont");
o Writing duplicate font 'common/data/fonts/TestFont 20 (ansi).uft' to disk...
==>exportCachedFont("TestFont", 20, "./testfont_20_a.png", 5, 0);All works fine. Edit that font in your favorite editor (in this case, I've tested it both with Windows Paint and Gimp), and I saved it as testfont_20_c.png.
You can see the two fonts here:


Import and re-export as version d:
==>importCachedFont("TestFont", 20, "./testfont_20_c.png", 5, 0);
==>exportCachedFont("TestFont", 20, "./testfont_20_d.png", 5, 0);And behold the result:

I don't know how well it shows up here in the forums, but it basically bounding-boxes each individual font and displays a white background.
And when you load it up in your game, it displays each letter as a black bounding box, rather than having your painstakingly drawn font (I made the mistake of aligning my whole new font before I tested importing any of it -- boy was that a dissapointment).
Evidentally there is something special in the way that Torque expects the PNG to be formatted that Gimp and Paint don't do.
Thanks for reading! I hope this bug report has been useful. If it is a user error rather than a TGB error, please correct me.
Respectfully,
clint
About the author
Torque 3D Owner Matthew Langley
Torque