Font Files

From The DarkMod Wiki
Revision as of 21:57, 9 March 2024 by Geep (talk | contribs) (created article)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Introduction

This article covers the external view of font files, and how they are selected, character-scaled, and used in practice. For the internals of these files, see (COMING SOON).

Generally, TDM does not use fonts provided by the OS, but instead relies on its own, like those for in-game readables described in Fonts Screenshots. Fonts for the Doom3/idTech4 engine are defined by metrics and bitmaps, in up to 3 standard point sizes of 48, 24, and 12. (A "point" is a traditional publishing unit, nominally 1/72 of an inch.) Let's just refer to these resources by "size 12", "size 24", and "size 48". When you request "textscale 1.0" in TDM's gui scripting, the system will (typically) choose size 48 and render its characters from the associated bitmaps with an internal scale factor of 1. But complexities ensue.

Directory Locations

Font files are distributed in tdm_fonts01.pk4, which at the top level has:

  • /fonts/
  • /dds/fonts/

Each of those contain:

  • /english/ Also ideally provides some European coverage
  • /russian/

Each of those in turn has the same set of about a dozen and a half named font directories. Within each are the files discussed next.

Naming and Point Sizes

For a given font, language (either English or Russian), and size, the font information is stored in a binary DAT file and in one or more DDS bitmap files. Generally, for size 12, only one DDS is needed, while the larger characters of size 48 needs more. The expected file naming is:

  • For DAT: fileimage_12.dat, fileimage_24.dat, fileimage_48.dat
  • For DDS: _#_<size>.dds

For example, for Bamberg font, there is:

  • bamberg_0_12.dds
  • bamberg_0_24.dds, bamberg_1_24.dds
  • bamberg_0_48.dds, bamberg_1_48.dds, bamberg_2_48.dds, bamberg_3_48.dds, and bamberg_4_48.dds

It is possible for an FM to add or override font files.

Within the DAT file, the DDS files are referred to as if they had a TGA extension.

Size Selection, Size Usage, and Scaling

As introduced above, the engine expects only files with sizes 12, 24, and 48, and will ignore any others. If one or two of the three sizes is missing, it will use what’s left, preferring the next-larger size substitute.

Within the DAT file, at the end, there's a variable "glyphScale", with values in a factor-of-2 ratio:

  • Size 12: 4.0
  • Size 24: 2.0
  • Size 48: 1.0

This is used to "normalize" the rendered size of character glyphs across all 3 sizes, given that the glyphs in size 48 DDS bitmaps are 4 times larger than those in size 12 bitmaps. This normalization eases size substitution.

Assuming all 3 fontimage sizes are available, the engine (in DeviceContext.cpp), when called upon to do a render, will pick a size based on the invoking GUI’s "textscale" parameter:

  • 0.15 or less: size 12
  • Above 0.15, to 0.30: size 24
  • Above 0.30: size 48

Once a source fontimage is chosen, each character's low-level rendered scale is based on textscale * glyphScale.

It is perhaps surprising that "textscale 0.25", which corresponds to a ¼ * 48 max pt = 12 pt, uses fileimage_24.dat, not fileimage_12.dat. Some likely reasons:

  • The larger bitmap scale-down gave less-jagged results.
  • It sidesteps having to create excellent size 12 files.

On that second point, it takes a substantial effort to create a font size set. By having the textscale cutoff at 0.15 for size 12, it means size 12 will be little used. So there is no big penalty if there are either no size 12 files, or the provided files have incomplete or suboptimal glyphs. Specifically, for English, font creators for sizes 24 and 48 are more likely to strive to implement the full TDM custom character set of European characters, while size 12, if provided at all, usually neglects Europe, accurately covering only ASCII glyphs.

In any event, the broad usage pattern is:

  • size 12: Not used by any standard readable (all of which have textscales of 0.16 or more), menu items, or fixed-sized HUD text. In case of Stone font, could apply to variable-sized HUD text (e.g., weapons, inventory, loot totals), if user-set values of (iconSize * smallTextSize) < 1.0 . Seldom used in FMs. (A rare instance: name tags with Nancy font in "TD2: The Chalice of Kings".)
  • size 24: Used by readables and, in the menu system, settings and certain headlines. Also, more recently, the subtitle system with Stone font. (As of TDM 2.12, this includes horizontal compression at render time.)
  • size 48: Used in the menu system for the big headlines and the main menu. Also used for the larger "Title" text of some readables, like those Stone font.

For More