|
@@ -0,0 +1,78 @@
|
|
1
|
+title: Blog
|
|
2
|
+post: TRLE Font reader
|
|
3
|
+date: 2014-06-14
|
|
4
|
+comments: true
|
|
5
|
+flattr: true
|
|
6
|
+twitter: xythobuz
|
|
7
|
+github: https://github.com/xythobuz/OpenRaider
|
|
8
|
+---
|
|
9
|
+
|
|
10
|
+## {{ page["post"] }}
|
|
11
|
+<!--%
|
|
12
|
+from datetime import datetime
|
|
13
|
+date = datetime.strptime(page["date"], "%Y-%m-%d").strftime("%B %d, %Y")
|
|
14
|
+print "*Posted at %s.*" % date
|
|
15
|
+%-->
|
|
16
|
+
|
|
17
|
+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.
|
|
18
|
+
|
|
19
|
+On of these dependencies was the SDL2-TTF Font reading support, that requires me to include a TTF font file in the source tree.
|
|
20
|
+
|
|
21
|
+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.
|
|
22
|
+
|
|
23
|
+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.
|
|
24
|
+
|
|
25
|
+However, I was stuck for a long time, searching for a file format specification.
|
|
26
|
+
|
|
27
|
+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.
|
|
28
|
+
|
|
29
|
+However, the Font.pc file clearly don’t match this specification.
|
|
30
|
+
|
|
31
|
+Still, all the Font.pc files have exactly the same size, 262144 bytes.
|
|
32
|
+
|
|
33
|
+I was still certain the file had to include every glyph after another, probably in ASCII order, with fixed sizes.
|
|
34
|
+
|
|
35
|
+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.
|
|
36
|
+
|
|
37
|
+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.
|
|
38
|
+
|
|
39
|
+So I downloaded some [samples](http://www.trsearch.org/Media.php?action=getlist&typeid=75) from the web.
|
|
40
|
+
|
|
41
|
+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.
|
|
42
|
+
|
|
43
|
+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.
|
|
44
|
+
|
|
45
|
+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.
|
|
46
|
+
|
|
47
|
+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.
|
|
48
|
+
|
|
49
|
+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).
|
|
50
|
+
|
|
51
|
+If the original Leikkuri download is no longer available, get it from my [archive](archive.html)...
|
|
52
|
+
|
|
53
|
+To top it all off, here are some screenshots from the development process... :)
|
|
54
|
+
|
|
55
|
+<div class="yoxview">
|
|
56
|
+ <a href="img/trle_1.png" class="thumbnail">
|
|
57
|
+ <img src="img/trle_1_small.png" alt="Photo" title="Uuhh... Yeah...">
|
|
58
|
+ </a>
|
|
59
|
+ <a href="img/trle_2.png" class="thumbnail">
|
|
60
|
+ <img src="img/trle_2_small.png" alt="Photo" title="Not too bad...?">
|
|
61
|
+ </a>
|
|
62
|
+ <a href="img/trle_3.png" class="thumbnail">
|
|
63
|
+ <img src="img/trle_3_small.png" alt="Photo" title="Woah, progress!">
|
|
64
|
+ </a>
|
|
65
|
+ <a href="img/trle_4.png" class="thumbnail">
|
|
66
|
+ <img src="img/trle_4_small.png" alt="Photo" title="Now with proper alignment">
|
|
67
|
+ </a>
|
|
68
|
+ <a href="img/trle_5.png" class="thumbnail">
|
|
69
|
+ <img src="img/trle_5_small.png" alt="Photo" title="Trying another font file">
|
|
70
|
+ </a>
|
|
71
|
+ <a href="img/trle_6.png" class="thumbnail">
|
|
72
|
+ <img src="img/trle_6_small.png" alt="Photo" title="Fixed the lowercase p!">
|
|
73
|
+ </a>
|
|
74
|
+ <a href="img/trle_7.png" class="thumbnail">
|
|
75
|
+ <img src="img/trle_7_small.png" alt="Photo" title="And with custom lps file">
|
|
76
|
+ </a>
|
|
77
|
+</div>
|
|
78
|
+
|