2014-06-11 17:14:09 -04:00
|
|
|
How to add a new font encoding to wxWidgets
|
|
|
|
===========================================
|
2014-06-11 17:14:02 -04:00
|
|
|
|
2014-06-11 17:14:09 -04:00
|
|
|
Introduction
|
|
|
|
------------
|
2014-06-11 17:14:02 -04:00
|
|
|
|
2014-06-11 17:14:09 -04:00
|
|
|
wxWidgets has built in support for a certain number of font encodings (which
|
2014-06-11 17:14:02 -04:00
|
|
|
is synonymous with code sets and character sets for us here even though it is
|
|
|
|
not exactly the same thing), look at include/wx/fontenc.h for the full list.
|
|
|
|
This list is far from being exhaustive though and if you have enough knowledge
|
|
|
|
about an encoding to add support for it to wxWidgets, this tech note is for
|
|
|
|
you!
|
|
|
|
|
2014-06-11 17:14:09 -04:00
|
|
|
A word of warning though: this is written out of my head and is surely
|
2014-06-11 17:14:02 -04:00
|
|
|
incomplete. Please correct the text here, especially if you detect problems
|
|
|
|
when you try following it.
|
|
|
|
|
2014-06-11 17:14:09 -04:00
|
|
|
Also note that I completely ignore all the difficult issues of support for
|
2014-06-11 17:14:02 -04:00
|
|
|
non European languages in the GUI (i.e. BiDi and text orientation support).
|
|
|
|
|
|
|
|
|
2014-06-11 17:14:09 -04:00
|
|
|
The recipe
|
|
|
|
----------
|
2014-06-11 17:14:02 -04:00
|
|
|
|
|
|
|
Suppose you want to add support for Klingon to wxWidgets. This is what you'd
|
|
|
|
have to do:
|
|
|
|
|
2014-06-11 17:14:09 -04:00
|
|
|
1. include/wx/fontenc.h: add a new `wxFONTENCODING_KLINGON` enum element, if
|
2014-06-11 17:14:02 -04:00
|
|
|
possible without changing the values of the existing elements of the enum
|
|
|
|
and be careful to now make it equal to some other elements -- this means
|
2014-06-11 17:14:09 -04:00
|
|
|
that you have to put it before `wxFONTENCODING_MAX`
|
2014-06-11 17:14:02 -04:00
|
|
|
|
2014-06-11 17:14:09 -04:00
|
|
|
2. `wxFONTENCODING_MAX` must be the same as the number of elements in 3
|
2014-06-11 17:14:02 -04:00
|
|
|
(hopefully) self explanatory arrays in src/common/fmapbase.cpp:
|
|
|
|
|
2014-06-11 17:14:09 -04:00
|
|
|
- gs_encodings
|
|
|
|
- gs_encodingDescs
|
|
|
|
- gs_encodingNames
|
|
|
|
|
|
|
|
You must update all of them, e.g. you'd add `wxFONTENCODING_KLINGON`,
|
2014-06-11 17:14:02 -04:00
|
|
|
"Klingon (Star Trek)" and "klingon" to them in this example. The latter
|
|
|
|
name should ideally be understandable to both Win32 and iconv as it is used
|
|
|
|
to convert to/from this encoding under Windows and Unix respectively.
|
|
|
|
Typically any reasonable name will be supported by iconv, if unsure run
|
|
|
|
"iconv -l" on your favourite Unix system. For the list of charsets
|
|
|
|
supported under Win32, look under HKEY_CLASSES_ROOT\MIME\Database\Charset
|
|
|
|
in regedit. Of course, being consistent with the existing encoding names
|
|
|
|
wouldn't hurt neither.
|
|
|
|
|
|
|
|
3. Normally you don't have to do anything else if you've got support for this
|
|
|
|
encoding under both Win32 and Unix. If you haven't, you should modify
|
|
|
|
wxEncodingConverter to support it (this could be useful anyhow as a
|
|
|
|
fallback for systems where iconv is unavailable). To do it you must:
|
|
|
|
a) add a new table to src/common/unictabl.inc: note that this file is auto
|
|
|
|
generated so you have to modify misc/unictabl script instead (probably)
|
|
|
|
b) possibly update EquivalentEncodings table in src/common/encconv.cpp
|
2014-06-11 17:14:09 -04:00
|
|
|
if `wxFONTENCODING_KLINGON` can be converted into another one
|
2014-06-11 17:14:02 -04:00
|
|
|
(losslessly only or not?)
|
|
|
|
|
2014-06-11 17:14:09 -04:00
|
|
|
4. Add a [unit test](how-to-write-unit-tests.md) for support of your new encoding (with
|
2014-06-11 17:14:02 -04:00
|
|
|
time we should have a wxCSConv unit test so you would just add a case to
|
2014-06-11 17:14:09 -04:00
|
|
|
it for `wxFONTENCODING_KLINGON`) and test everything on as many different
|
2014-06-11 17:14:02 -04:00
|
|
|
platforms as you can.
|