Font Patcher: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
Tels (talk | contribs)
m explain dump better
Geep (talk | contribs)
m →‎scale: Add link to Per-Character Font Scaling
 
(7 intermediate revisions by one other user not shown)
Line 1: Line 1:
== Introduction ==
== Introduction ==


This utility allows you to "patch" a '''fontImage.dat''' file, e.g. change different characters and values without having the other characters getting affect (a common proble with [[Font_Conversion_%26_Repair|q3font]], f.i.).
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 [[Font_Conversion_%26_Repair|q3font]], f.i.).


The file 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:
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:


<pre>
<pre>
Line 12: Line 12:


copy_char 0x43 0xac                    // copy all fields from C to the new character Č
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
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 here is ignored by D3)
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
extend_top 0xac 8                      // extend the character 8 pixel on the top
</pre>
</pre>


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|copy]]'' command must come before any modifications to the character.
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|copy]]'' command must obviously come before any modifications to the character.


=== Patching multiple fonts ===
=== Patching multiple fonts ===
Line 34: Line 34:
=== #define ===
=== #define ===


Defines a new text to be replaced. Example:
Defines a new text macro. Example:


<pre>
<pre>
  #define H_EXTEND 1
  #define H_EXTEND 1
</pre>
From here on "H_EXTEND" will be replaced with "1" like in this example:


<pre>
  extend_botton 0x65 H_EXTEND
  extend_botton 0x65 H_EXTEND
</pre>
which will look like this to the font patcher:
<pre>
extend_botton 0x65 1
</pre>
</pre>


Line 76: Line 86:
  move_by 0xac 74 -52
  move_by 0xac 74 -52


This is often used to "reloacte" the place where a character is painted on the texture from one
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]]''.
texture to the other, by using it in combination with ''[[#shader|shader]]''.


Line 83: Line 93:
Each character is painted on a TGA (or better DDS) file, and this command lets you set the
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
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''' - D3 will do this automatically for us:
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
  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 %26 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 [https://en.wikipedia.org/wiki/Kerning 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.


== See also ==
== See also ==


* [[I18N_-_Charset|The Charset TDM uses]]
* [http://www.bloodgate.com/mirrors/tdm/pub/scripts/font_patcher/ Download font_patcher.pl and examples]
* [[I18N_-_Charset|The charsets used by TDM]]
* [[Font Conversion & Repair]]
* [[Font Conversion & Repair]]
* [[I18N]]
* [[I18N]]


[[Category:Fonts]]
[[Category:Fonts]]

Latest revision as of 19:04, 6 July 2024

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.

See also