title: Blog post: TRLE Font reader date: 2014-06-14 comments: true flattr: true github: https://github.com/xythobuz/OpenRaider --- Ever since starting my OpenRaider fork, I’ve wanted to use more of the original Tomb Raider game assets, not depending on many external files. On of these dependencies was the SDL2-TTF Font reading support, that requires me to include a TTF font file in the source tree. I tried to find a font file used by the original game engines, but to no avail. It seems as if the font is hard-coded into the game binaries. But the [TRLE](http://www.tombraiderchronicles.com/tr5/editor/trle.html) that came with TR5 includes a Font.pc file, and there are 3rd-party tools out there to change it. However, I was stuck for a long time, searching for a file format specification. Some weeks ago, I already implemented a [PCX image reader](https://github.com/xythobuz/OpenRaider/blob/master/src/utils/pcx.cpp), used to load the original TR2 menu background image. Suspiciously enough, the [PCX file format specification](http://bespin.org/~qz/pc-gpe/pcx.txt) includes a section about a simple font file format, similar to PCX. However, the Font.pc file clearly don’t match this specification. Still, all the Font.pc files have exactly the same size, 262144 bytes. I was still certain the file had to include every glyph after another, probably in ASCII order, with fixed sizes. That’s why I tried to find some numbers that can divide 262144 evenly. It could be something like 256 characters, 16 x 16 pixel, RGBA, which would match (4 * 16 * 16 * 256 = 262144). However, that’s still nowhere matching with the contents of the file. In reality, the .pc file is even simpler than I thought. It’s just a 256x256 Pixel, RGBA RAW image, no header, no compression, etc. Rename it to Font.raw, open it with Photoshop, there’s the font. So I downloaded some [samples](http://www.trsearch.org/Media.php?action=getlist&typeid=75) from the web. Skipping some more investigative work, it turns out there is a little tool called [Leikkuri](http://trep.trlevel.de/en/downloads.html). I’ve never ran it, but it’s Readme and the included lps file for TR4 fonts was enough to solve the mystery. The font glyphs are stored in the .pc file. TR4 and many community fonts use the same default positions for each glyph. In this case, you just need the .pc file, the Font loader can figure out the defaults. However, these default positions are very close together and inefficient. So many custom-made fonts use other positions. The Leikkuri tool can then be used to patch these new positions into the original Tomb Raider game engine binaries. That’s why I wrote some code that can read the glyph positions from a Leikkuri preset file (.lps) to use non-official Font.pc files. The relevant code is in [OpenRaider/src/FontTRLE.cpp](https://github.com/xythobuz/OpenRaider/blob/master/src/FontTRLE.cpp) and [OpenRaider/include/FontTRLE.h](https://github.com/xythobuz/OpenRaider/blob/master/include/FontTRLE.h). If the original Leikkuri download is no longer available, get it from my [archive](archive.html)... To top it all off, here are some screenshots from the development process... :)