fonts


Description

The bitmap fonts in /fonts (altek20.fnt and altek22.fnt) are used at least for DivX/Xvid subtitles. They may also be used for the Setup screen and for different on screen messages, although John noticed that there is an altek16 font embedded in dvdplayer.bin which may be used instead. dvdplayer also contains a reference to altek18.fnt, but as of today we don't know if this one it's really used or not.

 

dvdplayer.bin sourcecode is unavailable but Leon figured out that the fonts themselves are in fact Unicode fonts. They are stored in RB11 (RockBox 11) format and are included in Nano-X microwindows project that dvdplayer.bin uses. Despite having Unicode fonts, it was found found that MG35 does not support UTF-8 encoding for subtitles, and simply uses the Windows-1252 mapping to display the characters on screen. 

 

The problem

 

The majority of the available subtitle files are encoded in 8-bit using one of the Windows codepages (e.g. Windows-1250 for East European languages, or Windows-1251 for Cyrillic, etc.). But MG35 interprets them using the Windows-1252 codepage. As a result, instead of the expected characters, on screen you get some other odd-looking "garbage" characters.

 

The solution

 

The immediate solution is to convert the subtitle file to the Windows-1252 codepage, by replacing the language-specific characters with standard English characters. But this requires an extra manual step, and has the disadvantage of changing the subtitle file itself for the worst. Also, it will be of no use for Cyrillic subtitles.

 

So the idea occured that we can repack the built-in fonts to support other languages, by just swapping character bitmaps from their default position to the desired codepage index, e.g. Windows CP1250. This means that no characters are lost in process and that font file size is preserved.

 

The tool for the job is the convrb11 program. When doing a recode, one can follow the result of the font creation within C files (altek20.c and altek22.c) created along with .fnt files.

 

Following a similar idea, John has even created some beta firmware with Hebrew, Greek and Cyrillic fonts.

 

Changing the built-in fonts

 

In order to allow changing the fonts without rebuilding the cramfs and reflashing, you can mount /usr/fonts onto /fonts.

 

mount -o loop /usr/fonts /fonts

 

This allows one to replace the built-in fonts (from flash) with different subtitle fonts provided on the harddrive. This can finally solve the problem of having to build various firmwares with different subtitle fonts built into cramfs (Western, Central European, Hebrew, etc). 

 

The only problem is that this has to be done in /usr/initrc after dvddplayer is loaded (because dvdplayer loads the IDE  modules, so hdd is not available before that). But in their infinite wisdom, the dvdplayer programmers decided to load the font at startup. That's right, 500k of RAM  are wasted for the font, even if you're not using subtitles at all (we are not sure if the fonts are used anywhere else) ! This brings another issue: by the time you replaced the built-in font, it is already loaded in memory, so it will still be used by dvdplayer. The only known way to force a font reload is to change the size of the used font: press Subtitle on the remote, select "Subtitle move and size", then press right arrow on the remote.

 

The final solution will be to stop dvdplayer from doing the module loading, and load them before dvdplayer, either by including them in the kernel of by calling insmod in /etc/sashrc. This way, at the moment dvdplayer loads the fonts, /fots already points to the /usr/fonts.

 

If you want/need another fonts, you can try to use one from the RB11 font collection. There is also a map of the character sets included in each font. All the fonts support Latin, Basic and Latin-1 Supplement, and most of them have partial support for Latin Extended Additional, Latin Extended-A and Latin Extended-B, Hebrew, Cyrillic and Greek/Coptic. Don't forget to rename the seleted font as altek20.fnt or altek22.fnt.

 

Howto

mount -o loop /usr/fonts /fonts

 

 

More improvements

 

Stripping the built-in altek16 font

 

[John] What about converting the built-in font (altek16) to a specific codepage and dispensing with the larger fonts altogether? This could also shrink dvdplayer by about 400kB, and reduce idle ram usage by nearly 1.5 MB (50%!) [VB: so I  understand dvdplayer embeds a 16 point font? Maybe used for the setup screen? There is a reference for Helvetica...]

 

Shrinking the fonts

[Leon] The fonts can be shrinked to range [32..255]. However, John thought that this may be unnecesarry since the font files are stored in the cramfs, which compresses them very well. But shrinking them may still reduce the memory footprint at runtime.  Here are the results of decimating the fonts:

-92.40% (-514705 bytes) altek20.fnt

-92.15% (-592085 bytes) altek22.fnt

For those interested to try them, we provide the shrinked font files  and their C files. Please let us know if they work for you or if you find any negative side-effect.

 

[John: Have you tried changing the UI language with these characters missing?] 

 

Getting rid of the fonts altogether?

 

[John] Furthermore, do we know when/where the altek20 vs altek22 fonts are used? Do we even need both? What about a symlink from 22->20 or viceversa? Combined, these cuts could get 1.2MB of fonts down to 0.1MB or so. Or, as above, just get rid of them entirely. 

 

Adding altek18.fnt

 

dvdplayer contains a reference to another font, altek18.fnt. It may be possible that if this file exists, it will be loaded and used as a new option for subtitle font size. [VB: unfortunately, if I provide the altek18.fnt font, dvdplayer doesn't try to use it, as I  expected]