Font Patcher
Introduction
This utility allows you to "patch" a fontImage.dat file, e.g. change different characters and values without having the other characters being affected (a common problem with q3font, f.i.).
The script reads in a fontImage.dat file, a file with commands, then executes each command and then writes out the modified fontImage.dat file. Here is an example command file:
source font_source/carleton/fontimage_48.dat target ../fonts/english/carleton/fontimage_48.dat // the texture for this font is 256x256 pixel dim 256 256 copy_char 0x43 0xac // copy all fields from C to the new character Č move_by 0xac 74 -52 // new position 174, 19 minus 100, 71 shader 0xac fonts/carleton_6_48.tga // set the right texture file (the .tga is ignored by TDM) extend_top 0xac 8 // extend the character 8 pixel on the top
The order of commands does usually not matter, unless you want for instance to copy a character and then modify it, in this case the copy command must obviously come before any modifications to the character.
Patching multiple fonts
The modified fontImage.dat file will be written out automatically at the end of the parsing stage. If you want to patch more than one fontImage.dat file, you need to use two seperate command files and call the font patcher twice.
Commands
#include
Includes the specified file in place of this line. Example:
#include devel/font_source/copy_letters.txt
#define
Defines a new text macro. Example:
#define H_EXTEND 1
From here on "H_EXTEND" will be replaced with "1" like in this example:
extend_botton 0x65 H_EXTEND
which will look like this to the font patcher:
extend_botton 0x65 1
copy_char
Copy all fields from the source character to the target character:
copy_char 0x43 0xac
Afterwards character 0xac will look exactly the same as 0x43 (C).
dump
This will print all the fields for the character 0x65 (in this case "a") to the console:
dump 0x65
extend_bottom
Extend the character at the bottom by the specified number of pixels (see dim):
extend_bottom 0xac 8
extend_top
Extend the character at the top by the specified number of pixels (see dim):
extend_top 0xac 8
increase_height is an alias for this command.
move_by
Moves the origin of the character bitmap by the specified number of pixels relatively to the original origin, and relative to the size of the texture (which you need to set beforehand with dim):
move_by 0xac 74 -52
This is often used to "relocate" the place where a character is painted on the texture from one texture to the other, by using it in combination with shader.
shader
Each character is painted on a TGA (or better DDS) file, and this command lets you set the name of this file. Note that we specify here ".tga", even tho the actual files are ".dds", and also note that we do not store the language here. In this example, the real file used would be dds/fonts/english/carleton_6_48.dds - TDM will do this automatically for us:
shader 0xac fonts/carleton_6_48.tga
source
Sets the source font image file. Example:
source font_source/carleton/fontimage_48.dat
target
Sets the target font image file. Example:
target ../fonts/english/carleton/fontimage_48.dat
scale
Scale the character by X and Y as factors. Example to make the character 10% bigger:
scale 0xEF 1.1 1.1
Geep 2024: for more, see Font Metrics & DAT File Format#Per-Character Font Scaling
decrease_width
Reduce the width of the character by so many pixels:
decrease_width 0x65 2
increase_width
Increase the width of the character by so many pixels:
increase_width 0x65 2
increase_xskip
Each character has, in addition to it's with, a paramter xSkip, which defines how many pixels are skipped after rendering the character. Unlike real Kerning, this value is independent of the following character.
It does thus define the spacing between characters. With this command, you can increase the space:
increase_xskip 0x65 2
decrease_xskip
Reduces the xSkip parameter. See #increase_xskip for details.
decrease_xskip 0x65 2
Requirements
- Needs Perl.