FontPacker - Pack TrueType fonts into your game

The only way to easily calculate kerning using normal Java APIs is to draw every pair of letters next to each other and see how the advance between them differs from the normal advance. For any difference != 0.0, that’s the kerning for that pair of letters.

Cas :slight_smile:

In Java, another simple solution is to use something like LibGDX’s FreeType extension to get the font metrics, and use [icode]glyph.getKerning(int other)[/icode] to get the kerning information. This is what I’m using for my own font packing tool.

It looks like this:

Since this is a C# project, I guess that doesn’t really apply. :stuck_out_tongue:

The problem is appearing for Oblique/Italic fonts. See The only error in this screenshot of “Microsoft Sans Serif” is in the word “Text”

I’m browsing the MSDN “How to Obtain Font Metrics” and here’s the image they’ve shown.

http://i.msdn.microsoft.com/dynimg/IC35524.png

I’m unable to find a tutorial for kerning. Most of them says to use [icode]GetCharWidth32()[/icode] native function gives how much should we advance after rendering that character but I can’t find one that is purely cross platform.

Here’s another screenshot of the font “Mistral”

I’ve noticed some small gaps between the letters in the bitmap version. However some of these script fonts are rendering nice.

Didn’t I just tell you how to do it?

Cas :slight_smile:

@princec Actually I didn’t understand. Can you provide me with an example?

No, all of the letters in Sample are too widely spaced. They may be consistent, but that doesn’t make them correct.

So did I.

for (char a = minChar; a <= maxChar; a++)
  for (char b = minChar; b <= maxChar; b++)
    kern[a,b] = g.MeasureString(a + "" + b, f) - g.MeasureString(a + "", f) - g.MeasureString("" + b, f);

Now, some difference right?

Now I’m just advancing the width of only one char but not the other on top of it.

@pjt33

Thanks. Now I’ll try this.

@pjt

I didn’t completely understand that formula but using that for every char pair gives value -33. How can I fix it?

I have a class here (part of Hiero) that can read kerning from a TTF file. I use some reflection magic here to try to get the TTF file on Sun VMs if all you have is an AWT Font instance.

I wrote this article about the various tools for generating bitmap fonts. We can add your tool if you like. As I wrote there, the BMFont tool does the best job due to supersampling with FreeType, especially at small sizes. I wish Hiero could do this. :frowning: Hiero4 in gdx-tools is a prototype for a FreeType based tool using MatthiasM’s font renderer he made for TWL. It works but isn’t really finished and doesn’t do supersampling. Also it means no effects, though that can be done in Photoshop if padding is added to the glyphs.

Does gdx-freetype support supersampling? If not, is there any freetype2 docs on it? I’d like to add it to my own tool.

@Sammidysam

Can you test the new beta 2? The binaries are here. I’ve updated to .Net Framework 3 to access the new font related classes.

@davades

I don’t know of libGDX. I’m not using it.

Window ran fine again. Last time I actually didn’t test exporting the font which I really should have done. Sorry. This time I did, and I got a weird error. I also got an exported file, however. The error and the exported file are in the Pastebin links below.

The Error: http://pastebin.com/DDBeWEJ0
The Export: http://paste.fedoraproject.org/27922/78384137

I’ll keep the file until you review the error, as Fedora’s Pastebin does not have a never expire option. :cranky: But calling “cat blah | fpaste” to upload makes it worth it.

Cool, I’ll link your tool and the OP’s tool on the wiki. :slight_smile: Any chance you want to take over Hiero? :smiley: For supersampling, render at a high resolution, then scale down. You can change the high resolution and how you sample when scaling down as a way to get varying levels of antialiasing.

@Sammidysam

That exception is thrown by Mono itself. It failed to display the message box. The font file is fully generated and worked for me when tested. Can you say what version of mono you have? It’s running fine on Mono 2.8 for windows.

Can you try to export in the previous version?

@Nate

Thanks for adding this tool to your wiki. But you’ve written The FontPacker tool uses Java’s font rendering. which is incorrect. It uses the .Net Framework’s classes [icode]TextRenderer[/icode], [icode]FontFamily[/icode] and [icode]Graphics[/icode] classes. The project is written in C#.

@Sammidysam

These lines in the error you’ve posted

[icode]

Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.

[/icode]

Shows that there’s an error in your mono installation probably. Could you reinstall mono and try again?

Oops! Sorry, it slipped my mind that it was .NET. Fixing!

Hurray! It’s finally rendering italic fonts perfectly! Here’s the screenshot

I’ll upload this version after testing with other fonts.