Font Combining
When creating a Rockbox theme, you’ll often have a font you’re set on using that doesn’t support many languages. It’s not difficult however to go about adding support for other languages to these fonts by combining them with one that does. This guide goes over how to do that for vector and bitmap fonts, while also showing you how to convert them for use with Rockbox.
Combining Two Fonts using Fontforge
There’s more than a few different apps for combining and modifying fonts, I know glyphs is quite popular especially with professionals, however this guide is around my own setup which is Linux focused. Fontforge is the best tool in this space for Linux, and it’s perfectly equipped for our needs combining fonts. There’s a few minor differences between working with bitmap fonts and vector fonts, so I’ve divided them into their own sections below.
Combining .otf and .ttf Fonts
Firstly, you’re going to need a font to add to your base font. I created a fork of NotoSans called MicroNotoSans designed to provide maximum language coverage with minimum size. It’s modular so you can choose which languages you need if you want to save even more space.
- Open the Base Font, which we want to combine with.
- Go to Element > Merge Fonts choose the MicroNotoSans font, and merge. Often, the merged font won't match the base font in scale. To fix this we can transform the imported glyphs specifically:
- Go to Edit > Select > Changed Glyphs.
- Go to Element > Transform and select Scale.
- Select Origin: Glyph Origin > Scale: 250% 250% > select all boxes. (Note: Scale will differ on the font, so experiment).
- And finally export the font by going to File > Generate Font choosing ‘TrueType’ or ‘OpenType (CFF)’ and clicking Generate.
Combining .bdf Fonts
Again, you’re going to want a font to combine with your base font. I don’t have any Font recommendations, but Rob Hageman’s bitmap font hoard might be of use.
- Open the Base Font, which we want to combine with.
- Go to File > Import… choose your other Font, and import.
- Export the font by going to File > Generate Fonts…. Click the right drop down menu to select ‘BDF’ and then click Generate..
Making Rockbox Fonts
Rockbox uses it’s own, custom font format for it’s interface. Therefore it’s necessary to convert our fonts for use in themes. This process is slightly different for colour and monochrome models, the former allowing anti-aliasing and the latter using exclusively bitmaps fonts. For the moment I’ve focused on the non-bitmap conversion process.
Getting convttf
If you don’t already have the convttf tool, then you’ll need to build it from the source using the following guide.
- Start by cloning the Rockbox repo: git clone git://git.rockbox.org/rockbox.
- Navigate to the tools folder and run the command make convttf. - If you encounter errors with this, make sure "freetype-devel" and "freetype2" (or "ftgl") are installed.
Convert OTF or TTF files with convttf
Convttf is used via the command line, and I find it useful to move the executable into the directory of fonts I’m working with. The executable can be used like the following.
/convttf -p 16 -c 1 fontfile.ttfNotes
- The number beside -p is the size of the font, this unit isn’t pt or px so you will have to experiment.
- -c is for the spacing between letters, 1 is an all round good option for most sizes and fonts.
- If you wish to add padding to the top and bottom of fonts, say for the menu (see Interpod for an example), then two values can be added: -Ta and -Td.
- The values for -Ta and -Td should be negative, used like the following -Ta ‘-3’ -Td ‘-2’. Ta is the top padding, and Td the bottom.
Converting bdf files with convbdf
Convbdf is specifically for working with bitmap fonts. Again, I recommend keeping it in your /bin folder if you’re on Linux and will use it more than once. There’s a lot less control here (though you don’t really need it) Most of the times you can simply use it like this:
/convbdf -f 16-fontfile.bdfNotes
- Unlike convttf, with convbdf the start of the filename denotes the font size. In the above example, the font will be 16px.
- The -f flag makes sure the file outputs as a .fnt file neccesary for use in themes..
- Usin -a and -d flags work similarly to -Ta and -Td with convttf. Allowing you to trim the ascent and descent of the font if neccesary.