Search code examples
fontskerning

Should each font character have it's own kern table?


I am designing a file format for storing fonts, it will be used in my game where i need to draw ASCII text on the screen. At first i thought that i needed to keep a separate kern table for every character in the font, but after researching i found out that many font file formats used in games don't have any kern tables at all (e.g., Arma's FXY font https://community.bistudio.com/wiki/FXY_File_Format), they just use one offset for each character to determine where to draw the next character. Is this enough for simple ASCII text?Are there any drawbacks/limitations?


Solution

  • "Simple ASCII text" has nothing to do with kerning. Some of the (potentially) most ugly kerning candidates are in the Simple ASCII range; even with all-caps text only you can expect "AV" and "TA" combos.

    Whether or not to include kerning in your text engine depends on some factors not mentioned in your post:

    1. The type of font. A square-ish font doesn't need accurate kerning as much as a fully antialiased high quality font. A font that mimicks an 8x8 monospaced system font does not need kerning; a font with an eccentric design (say, a very wide "T") may.
    2. The size of the font in pixels. For an 8x8 pixel font I would simply not bother.
    3. The overhead in calculating string widths and drawing text onto the screen. For a typical game, such as a shoot-em-up, drawing text is secondary only and should happen as fast as possible. For lots of text in an adventure-style game, you'd want nicer output.

    Even the act of only having to check every combination for possible kerning is time consuming, whether or not it results in an adjustment. For fastest performance, you can have a list of adjustment values for every character per character -- essentially, for 96 characters you need 96 * 96 lookups. Any other algorithm is possible (e.g., a linked list per character) but will be slower -- and can use less memory.

    Also, not every possible character combo needs kerning information. You should design your font with built-in white space left and right, the so-called "side bearing". This 'natural' spacing would only need adjustment for as little as possible combinations.

    All in all, It Depends. Best is to try both: without and with kerning. Estimate the negative impact on the performance against the positive of the "looks", and decide which one you prefer.