font encoding overviewwxwidgets has support for multiple font encodings starting from release 2.2. by encoding we mean here the mapping between the character codes and the letters. probably the most well-known encoding is (7 bit) ascii one which is used almost universally now to represent the letters of the english alphabet and some other common characters. however, it is not enough to represent the letters of foreign alphabets and here other encodings come into play. please note that we will only discuss 8-bit fonts here and not unicode. font encoding support is ensured by several classes: wxfont itself, but also wxfontenumerator and wxfontmapper. wxfont encoding support is reflected by a (new) constructor parameter encoding which takes one of the following values (elements of enumeration type wxfontencoding):
as you may see, microsoft's encoding partly mirror the standard iso8859 ones, but there are (minor) differences even between iso8859-1 (latin1, iso encoding for western europe) and cp1251 (winlatin1, standard code page for english versions of windows) and there are more of them for other encodings. the situation is particularly complicated with cyrillic encodings for which (more than) three incompatible encodings exist: koi8 (the old standard, widely used on the internet), iso8859-5 (iso standard for cyrillic) and cp1251 (wincyrillic). this abundance of (incompatible) encodings should make it clear that using encodings is less easy than it might seem. the problems arise both from the fact that the standard encodings for the given language (say russian, which is written in cyrillic) are different on different platforms and because the fonts in the given encoding might just not be installed (this is especially a problem with unix, or, in general, non-win32 systems). to clarify, the wxfontenumerator class may be used to enumerate both all available encodings and to find the facename(s) in which the given encoding exists. if you can find the font in the correct encoding with wxfontenumerator then your troubles are over, but, unfortunately, sometimes this is not enough. for example, there is no standard way (that i know of, please tell me if you do!) to find a font on a windows system for koi8 encoding (only for wincyrillic one which is quite different), so wxfontenumerator will never return one, even if the user has installed a koi8 font on his system. to solve this problem, a wxfontmapper class is provided. this class stores the mapping between the encodings and the font face names which support them in wxconfig object. of course, it would be fairly useless if it tried to determine these mappings by itself, so, instead, it (optionally) asks the user and remembers his answers so that the next time the program will automatically choose the correct font. all these topics are illustrated by the font sample; please refer to it and the documentation of the classes mentioned here for further explanations.
|