Call of Duty: Font System

From COD Modding & Mapping Wiki
Revision as of 16:16, 6 July 2009 by Zeroy (talk | contribs) (New page: {{Note|Call of Duty 2, 4 and 5 seem to use the same font system with identical file structure specifications. Call of Duty 1 is way different, it uses a combination of .dds images and .dat...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Call of Duty 2, 4 and 5 seem to use the same font system with identical file structure specifications. Call of Duty 1 is way different, it uses a combination of .dds images and .dat files and has not been investigated yet. Therefore, this article focuses on the font system from CoD2 on.

A font is made up of 4 files:

  1. image (*.iwi)
  2. material
  3. material_properties
  4. font mapping

The material and material_properties files belong to the image, like for every other iwi. The font mapping file references itself, the material file and maps the letters in the image to the ascii (respectively unicode) characters, used in the string files (raw\[LANGUAGE]\localizedstrings\*.str). The material_properties file is implicitly associated with the material by the engine and doesn't require an explcit reference.


The main font of CoD4 is gamefonts_pc. It is located in main\localized_english_iw00.iwd --> images\gamefonts_pc.iwi. The image contains 7 different fonts (background is actually transparent):

Font name size (hex) size (dec)
smallFont 0x0A 10
normalFont 0x10 16
consoleFont 0x10 16
boldFont 0x10 16
bigFont 0x18 24
objectiveFont 0x23 35
extraBigFont 0x30 48


These are the settings of the font material in Asset Manager:


The structure of a font mapping file is like this:

Header (16 bytes)
----------------------------
int font_name_offset;		// string at the end of the file (self reference?)
int font_size;			// in pixels
int number_of_records; 	// 1 record = 1 character
int font_material_offset; 	// material name string (matrial references font image)

Entry (24 byte each)
----------------------------
byte char_code[2];		// ascii/unicode mapping of the character
byte char_spacing[3];		// margin left, top, right
byte char_dimension[2];	// pixel width & height
byte empty;			// always 0x00 in stock game fonts
float char_rectangle[4];	// image dimension * float = coord, one rectangle per char

Footer
----------------------------
string font_name;		// e.g. "fonts/normalFont"
string font_material;		// e.g. "fonts/gamefonts_pc"


A character record in detail (margin and dimension = pixels):

BYTE[0,1] == character code (unicode supported?)
BYTE[2] == margin left
BYTE[3] == margin top
BYTE[4] == margin right (actually more like padding, necessary because the game uses non-monospaced fonts)
BYTE[5] == width
BYTE[6] == height
BYTE[7] == unknown (no visible change, always 0x00 in stock font files)
BYTE[8-11] == (float) UV of left side of the bounding rectangle of the char (from top left of image)
BYTE[12-15] == (float) UV of top of the bounding rectangle
BYTE[16-19] == (float) UV of right side of the bounding rectangle
BYTE[20-23] == (float) UV of bottom of the bounding rectangle


Download Regolith's CoD Font Explorer

A font editor/creator is currently being developed.

Forum discussion: RGN - Game Fonts


--CoDEmanX 00:23, 6 July 2009 (UTC)