Handling other languages and font.

Started by
7 comments, last by LorenzoGatti 11 years ago

my current font system is pretty simple, at the game launch, I build a texture palette of common letters, with ascii this is generally between glyphs 32 to 96 covers the English language pretty decently. Then when i draw a string, I just create a mesh, with the appropriate texture coordinates for the glyph, and do a check that the glyph is inside my range of supported glyphs.

However, i've been thinking of how to extend this to other languages, my palette system can be modified to use unicode glyphs relatively easily, but I don't know what a good range is for covering a good variety of common characters in say Chinese, Japanese, french, German, russian etc. since the input from players is likely going to be in their language, rather than english(particularly if targeting mobile platforms), these would mean that when i'm drawing something with my font code, it wouldn't draw anything as all the input glyphs could be outside my supported range. creating a texture with all possible glyphs seems rather insane as well. I've also considered having "pages" of textures, but that would be rather inefficient as it means having to switch textures every time a glyph in a different "page" is detected.

so what are other people's solutions for dealing with this problem?

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.
Advertisement

creating a texture with all possible glyphs seems rather insane as well. I've also considered having "pages" of textures, but that would be rather inefficient as it means having to switch textures every time a glyph in a different "page" is detected.

That's usually how it's done. You can make it more efficient by drawing all your glyphs from one page before changing the texture (need to prepass the string and batch the location and image uv's of glyphs from each page, then draw a page at a time).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

If you go on the Angel Code site, there's a good program for generating textures for different language fonts. There's also some code and examples for loading the files albeit in Direct X 9. The sample code is a little old, but it could be useful as a good base.

http://www.angelcode.com/products/bmfont/

Learn all about my current projects and watch some of the game development videos that I've made.

Squared Programming Home

New Personal Journal

To get a minimum passable support you need to support at least every code point between 0 and 65535 (thous that have anything valid defined). To get a reasonably good support one should also support combining characters and code points above 65535.

Generating any texture to cover it is impossible. You have to generate and prune them on the fly as needed and possibly combine them yourself in the CPU side as GPU tends to be very inefficient/limiting to hack text together.

For EFIGS (English, French, German, Italian, Spanish) the ANSI range between 0-256 should suffice.

When you add more exotic languages (e.g. Japanese), then there's really two options:

1. Tie an offline font generation tool into your localisation spreadsheet so that you can generate a list of required glyphs, and output just the ones that are required, plus maybe a few extras for user input (e.g. roman alphabet, common punctuation and hiragana/katakana alphabets).

2. Generate the glyphs you need on the fly from a truetype font using a library like FreeType.

The advantage of #1 is that the performance and memory impact is more predictable, it's the approach I've always used on console/handheld games. The advantage of #2 is that it's more flexible, particularly for user input.

I'd say that if your user input is quite a small part of the game (e.g. player enters their name for multiplayer), then use approach #1 as it's probably easier to implement and easier to test. I think Chinese/Japanese games players are quite used to having restricted characters for name entry.

If text entry is central to your app (e.g. a messaging app or something), then go with option 2.

Thanks everybody for the input. I think my best bet is going to be using something like the bmfont tool with pre-parsing text to draw as many of the glpyhs on the same texture as possible in as few passes as possible.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.
Note that not all fonts are equal when it comes to rendering East Asian languages. For instance, there are some characters that are written differently in Japanese and Simplified Chinese that share the same unicode code point. Same with traditional Chinese and simplified Chinese. Getting it right for the different languages involves using the right font for each supported language. What's worse is that a font for one language may not have the information for characters from another language. So if you use a Japanese font for Chinese text occasionally you'll get the outcome where it looks like your text is rendered in two different fonts. What's happening is that font fallback kicks in for the unknown characters and the system tries to find a font that does support that language, so you really are rendering in two different fonts at the same time. Needless to say, this all adds up to quite a bit of a pain in the rear if you want "proper" East Asian language support.
If you are using DirectX, D3DXFont simply works:).

If you want to support all Unicode characters for which you have fonts in arbitrary user input, you could use fonts directly in the input phase (with the game paused, inefficiency should be tolerable) and then build a texture atlas at runtime containing either the actually used characters or rendered strings.

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement