Game Development Community

Import/exportCachedFont() questions

by Alex Rice · in Torque Game Builder · 06/14/2006 (12:34 pm) · 37 replies

Search for importCachedFont and it's only mentioned here: tdn.garagegames.com/wiki/TorqueUnicode

Nobody is discussing it in the forums, apparently. Maybe not a lot of people know about this feature because it sounds quite useful to me. I did some testing (see 3.) but am unclear about the intended usage of this font system:

1. can importCachedFont() be used to create a bitmap font that at runtime the original font is not required to be installed on the user's computer? i.e. I have a cool quirky font named "XYZ" and I want to exportCachedFont() render it up and make it look cool, then in the game load that image with importCachedFont() then the user does not need font "XYZ" installed because torque has the bitmap image. Please say yes that is the intent!

2. If it's not the intent then I guess it can only be used to decorate and touch up fonts which the user has installed on their system. It's hard to make Arial and Times look cool though, so that would suck.

3. Any torquescript code examples how to round-trip export/touch-up/import a font? I managed to get a font loaded, characters cached, and exported to a .png and it looks great. But the font cache directory, and the importing step is giving me troubles.

thanks
[edit for spelling and formatting]
Page«First 1 2 Next»
#21
09/13/2006 (1:39 pm)
I played around with these functions and got my fonts exported. I then went into Photoshop and added a gradient and outline, I then saved as a RGB mode file as opposed to the original greyscale. Now when I import back in, It seems that the png file loses its transparency and the fonts chars get rendered as with black boxes around them with the transparency missing.

Do I have to leave the font png file in greyscale mode for this to work and be able to import back in.
#22
09/13/2006 (1:51 pm)
You've probably checked, but is the transparency info being saved correctly from Photoshop? Some versions had a problem and needed the SuperPNG plugin
#23
09/21/2006 (1:45 pm)
I still can't get this working perfectly. I've got everything writing to the cache fine, and exporting the pngs fine, and can get it correctly displaying effects from an rgba png. The only problem is that when I import the first time, the letters slightly shift down and to the right by the padding amount. If I set weight to 0 when I export and import, everything's fine (but there isn't enough space between the letters to add effects correctly of course). If I set weight to 3 when I export and weight to 3 when I import, the text shifts. Greater weight values cause it to shift even more. If I export with weight=3 and import with weight=0, the letters are garbage (as expected, but since it's shifting the way it should work, of course I tried it).

This is on the initial import. After that point I can reimport with weight=0 any time I make changes to the pngs and it stays in the same place and looks fine. I thought it was just vertical at first (and there's already enough room vertically for me) so I removed all the vertical padding in gNewFont.cc (importStrip/exportStrip) and it aligned correctly vertically, but I just noticed it's doing the same thing horizontally where I do require the padding. I'll play with the source more to see where it's going wrong, but if it sounds like I'm doing something obviously wrong, it would be great to know.

Thanks!
#24
09/21/2006 (6:35 pm)
Fixed my problem by changing gNewFont.cc's GFont::exportStrip() method to not add its padding at the beginning. This is a waste of vertical space at the moment, but it does the job as advertised instead of shifting imported text over. After this change, exporting and importing with any padding value work correctly, and then using weight=0 on every subsequent import will update the font.

Line 1022:
U32 curWidth = kerning + padding;

changes to:
U32 curWidth = 0;

Line 1035:

Point2I outRi(curWidth, padding + getBaseline() - mCharInfoList[i].yOrigin);

changes to:
Point2I outRi(curWidth, getBaseline() - mCharInfoList[i].yOrigin);
#25
08/05/2007 (8:54 am)
Anybody knows how it can be done in TGB 1.5.1 ?
I have an errors in writeFontCache():
--------------------------------------------------------------------------
   Writing font cache to disk (7 fonts found)
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Cooper Black 32 (ansi).uft' for write!
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Cooper Black 24 (ansi).uft' for write!
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Arial 24 (ansi).uft' for write!
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Arial 36 (ansi).uft' for write!
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Lucida Console 12 (ansi).uft' for write!
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Arial Bold 14 (ansi).uft' for write!
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Arial 14 (ansi).uft' for write!
GFont::exportStrip - failed to open './common/ui/cache/pngs/Cooper Black 24.png' for writing.
GFont::exportStrip - failed to open './common/ui/cache/pngs/Cooper Black 32.png' for writing.
--------------------------------------------------------------------------
   Writing font cache to disk (7 fonts found)
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Cooper Black 32 (ansi).uft' for write!
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Cooper Black 24 (ansi).uft' for write!
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Arial 24 (ansi).uft' for write!
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Arial 36 (ansi).uft' for write!
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Lucida Console 12 (ansi).uft' for write!
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Arial Bold 14 (ansi).uft' for write!
      o Could not open 'C:/Documents and Settings/XXXX/Application Data/Independent/UntitledGame/fonts/Arial 14 (ansi).uft' for write!

how I can set path to save fonts ?
Thanks.
#26
08/05/2007 (7:51 pm)
Have you tried my font resource? It does the exact same thing, just slightly more automated. I just took the functions Kevin Ryan posted here and gave it a GUI. Check it out here:www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=13348
#27
02/04/2008 (1:59 pm)
Has anyone been able to make this work? I use the tool Joe Rossi made and able to create the png edit it and then load it back in to TGB 1.7. The part that I get lost at is how you use it on a t2dTextObject. I have tried various different things but to no avail. Any suggestion or example code would greatly help.
#28
02/04/2008 (6:29 pm)
@Robert

OK good, once you have the png you should be able to load your fonts with a function like this:
function load_custom_font( %name, %size, %weight){ 
    %pngdir = "pngs/";
    %fontdir = "common/ui/cache/";  
    %fileName =  %fontdir @ %pngdir @ %name SPC %size @ ".png";
    importCachedFont( %name,  %size, %fileName, %weight,  0);
}

//example call
 load_custom_font( "Ariel", 80, 0 );


Then just set the font of your textObjects to the same font and size.

Make sure when loading your font that you use the same size you saved it as. Otherwise it will end up looking normal, without your texture.
#29
03/20/2008 (1:26 am)
Hi, Joe

I can't make it work. I create the png edit with your tool, modify with photoshop and then load it back in to TGB 1.7

Then I set the font of the textObject to the same font and size and it doesn' work. I am using your code of the previous post but still it does not work. I really don't know what i am doing wrong.

Please, can you post a little example with a level (just with a textObject in it) and a script that works? I think it would be pretty useful.

Thanks in advance and sorry for my english
#30
08/28/2008 (10:33 pm)
Hi Rossi,

Can we use this font into guiTextCtrl or other gui control also. I was confused because in this thread only t2dTextObjext is mentioned.

If We can use this changed font through guiTextCtrl or other, then how we can use? Do we need to define custom profile to use in gui controls something like "GuiMyFontProfile". if so then, in definition of custom profile how we can write all profile definition(body).



thnaks
#31
08/29/2008 (12:50 am)
I'm not sure, I haven't tried that. I only used the fonts on textObjects. I don't think it will work, but I could be wrong. Try it and let me know. I think you will need to edit your GUI profile code to make it use the font. I don't use the TGE GUI system so I'm not sure how you would do that.
#32
09/10/2008 (12:54 am)
Hi Rossi,

Can you try your custom font can be used by guiTextCtrl or guiTextEditCtrl ? Because this custom font is working yoyr side so you can check very easily.

Here still I can't make it work. something problem.
#33
08/04/2009 (7:06 pm)
Hey Kevin...
I tried using the script functions you provided to export and import the font. I was successful in exporting the fonts to a png file, however I am unable to import it back. I get an error stating "misunderstood format specifier". While exporting the fonts the bitmap format is assigned as GFXFormat_FIRST in exportStrip(). While importing however it is unable to retrieve the format correctly. Moreover the read(), checkForTransparency() and allocateBitmap() does not allow GFXFormat_FIRST and thus the error. Am I missing something while exporting ?
#34
08/05/2009 (12:13 am)
When I initially used these functions it was around the time that T2D was switching over to TGB so the code base may be slightly different from when I posted here. But just last week I was able to use the import/export stuff for a iTGB game so I'm not sure what your problem could be.

I did look a little at the underlying code three years ago when I first used, but the format/errors you mention don't sound familiar to me. Have you tried exporting and then immediately imported without editing the PNG at all to see if that works. I now that depending upon the version of photoshop that you have there can be problems with the outputted PNG file. There was a plug-in (I think called superPNG) that I had to get to make my version of photoshop do the alpha channel correctly.
#35
08/05/2009 (1:28 pm)
Tx kevin... I managed to fix that error with a small change in the engine with some help from GG. However I am still unable to import the cached font back. I first create the font (Comic Sans), then call fontbitmapIO(false) which correctly generates the png files. Next I try and import the fonts back using fontbitmapIO(true). However it does not update the Comic Sans UFT files in the font folder (but there is no error). I was wondering if I got the steps right.
#36
08/05/2009 (2:36 pm)
More recent versions of TGB can save files in a different location than where you are running the game.

So for example on machine files will sometimes be saved at:

c:\Documents and Settings\Kevin\Application Data\Independent\HunterSub

The actual save folder is based upon the Company and GameName fields of commonConfig.xml that you can find in the common folder.

Not sure if this is your problem, but it could be.
#37
08/05/2009 (6:34 pm)
I checked the folder structure ... and looked for all .UFT files on my system... I don't think there is an issue there. But the problem still persists. I am running out of ideas. Any input will be helpful.
Page«First 1 2 Next»