My static website generator using poole https://www.xythobuz.de
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2014_06_14_trle_font.md 3.9KB

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 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, used to load the original TR2 menu background image. Suspiciously enough, the PCX file format specification 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 from the web.

Skipping some more investigative work, it turns out there is a little tool called Leikkuri. 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 and OpenRaider/include/FontTRLE.h.

If the original Leikkuri download is no longer available, get it from my archive

To top it all off, here are some screenshots from the development process… :)