Bitmap font and text drawing (System/dbfont.ddx + executable)
Read from the 2017 PC build
(PDUWP.exe 1.3.25854.2) and checked
against our dbfont.ddx (decoded
with Pillow: every single-byte glyph’s ink lies
inside its table width, and the digit strip sits
where the HUD reads it). All battle HUD, skill
card and menu text goes through this module
(0x14028c830–0x14028d9a0) and the rich-text
layer on top of it (0x140247550, 0x1402477e0).
Strings are UTF-8 (1-, 2- and
3-byte sequences; 4-byte ones end the
string).
Atlas recap. 1024 × 2048 DXT1, 16 × 16 px cells, 64 per row, cell index = row · 64 + column (“Font atlas” above). Only 15 of a cell’s 16 rows are drawn.
Code point → cell (0x14028cf00, 0x14028d330). Code points below 0x100 are their own cell. Above, a two-level table: 256 page pointers at 0x1402dd3c0 (index = code point >> 8; 143 pages are set: Latin extensions, Greek, Cyrillic, punctuation, symbols, kana, the CJK and Hangul ranges, full-width forms), each page 256 × u16 (index = low byte): bits 0–14 the cell, bit 15 set on every cell of the wide (two-byte) part. Cell 0 or a missing page gives cell 0x81 (the fallback box). Cells 0x80–0x9F are filled through pages 0x01, 0x02, 0x20, 0x21 and match the Windows-1252 layout, so the first four atlas rows are code page 1252. Code points of 0x20 and below draw nothing.
Advance width, in atlas pixels, before scaling:
- cell < 0x100: the byte table at 0x1402dd2c0 (256 entries, index = cell):
| cells | widths |
|---|---|
| 0x20–0x2F | 6 6 7 11 9 12 11 6 8 8 9 9 6 9 6 9 |
| 0x30–0x3F | 8 8 8 8 8 8 8 8 8 8 7 7 8 8 8 9 |
| 0x40–0x4F | 12 12 11 11 12 9 9 12 11 6 9 11 9 12 12 12 |
| 0x50–0x5F | 11 12 11 10 10 11 12 12 11 11 11 8 9 8 8 9 |
| 0x60–0x6F | 6 9 9 9 9 9 7 9 9 5 6 8 5 12 9 9 |
| 0x70–0x7F | 9 9 8 9 8 9 9 12 8 9 8 8 6 8 8 16 |
| 0x80–0x8F | 10 8 8 10 9 10 8 8 9 9 10 8 12 8 10 8 |
| 0x90–0x9F | 8 8 8 10 9 8 9 10 10 12 9 9 9 8 9 10 |
| 0xA0–0xAF | 8 6 11 10 12 10 9 9 10 11 8 9 9 9 11 9 |
| 0xB0–0xBF | 8 10 8 8 10 9 10 8 8 8 8 9 12 12 12 9 |
| 0xC0–0xCF | 11 11 11 11 11 11 10 9 8 8 8 8 8 8 8 8 |
| 0xD0–0xDF | 12 12 11 11 11 11 11 11 12 10 10 10 10 10 10 8 |
| 0xE0–0xEF | 8 8 8 8 8 8 12 9 9 9 9 9 8 8 8 8 |
| 0xF0–0xFF | 9 8 9 9 9 9 9 9 12 8 8 8 8 8 9 8 |
(cells below 0x20 are 0);
- cells 0x334–0x384 (the 81 Cyrillic cells):
the table at 0x1403ff250 of
{i32 left, i32 width}per cell: the glyph startsleftpx into its cell and iswidthwide (widths 8–16, left 0–5); - every other cell: 16.
One glyph (0x14028cd80,
called with x, y, cell, width and the two scale
settings): a quad from (x, y),
width · sx / 8 wide and
sy − sy / 16 high (integer
division, truncating), sampling the cell’s left
width px (from left
for the Cyrillic cells) and top 15 px. The pen
then moves by
width · sx / 8 + spacing. So
sx = 8, sy = 16 is the atlas at
1:1; the HUD’s other setting, sx = 7,
sy = 14, is 7/8 scale. Texture coordinates are
int16 with 32768 = the full atlas (512 per cell
across, 256 per cell down).
Text state (globals; callers set them before drawing and usually restore 7 / 14):
| Global | Meaning |
|---|---|
| 0x14054c9ac | sx, the horizontal scale in eighths (8 = 1:1) |
| 0x14054c9a8 | sy, the line height in px (16 = 1:1) |
| 0x14054c994 | extra spacing added after every glyph |
| 0x14054c9a4 | line step: a line feed moves down sy + this in the plain draw, and by this value alone in the rich draw (menus set it to the full line pitch, e.g. 24) |
| 0x14054c9b0..bc | four ARGB corner colours (top-left, top-right, bottom-right, bottom-left); one colour in all four = flat text |
| 0x14054c9c0 | line start x (set by a string draw; line feeds return here) |
| 0x14054c9c4 | wrap width in px from the line start (0 = no wrap) |
| 0x14054c964 / 0x14054c978 | glyphs queued / the limit of 1000 per batch |
Glyph quads are queued (four 0x1C-byte
vertices: f32 x, y at +0, int16 u, v at +0x10,
ARGB at +0x18) and drawn by the flush
0x14028caa0 with the font2 shaders:
output colour = vertex colour, output alpha =
the atlas texel’s blue channel × vertex alpha
(the atlas is white on black, so the texel is
the coverage), pixels with zero coverage
discarded.
Plain string draw 0x14028d420(x, y, string): UTF-8 decode, 0x0A = line feed, other codes below 0x20 skipped, every glyph through the routine above. No wrap, no escapes.
Rich string draw
0x1402477e0(x, y, string, mode, rect) and its
width twin 0x140247550(string, mode,
stop-at-tab). A string that starts with
$ is first looked up in the port’s
string table ($$key 0x140023290,
$key 0x1400230a0). Control
codes:
- 0x0A line feed (x back to the line start, y += the line step global);
- 0x0C jump to the tab mark (x = mark x + mark offset);
- 0x07, up to five decimal digits n, one letter (case-insensitive):
| Letter | Effect |
|---|---|
w |
set the tab mark: mark x = current x, offset n (the following text is a column n px wide, ended by 0x0C) |
c |
the same mark, and centre the text up to the next 0x0C in n px (x += (n − width) / 2) |
r |
right-align: x = rect x + n − width of the text up to the next 0x0C |
p |
x = rect x + n |
s |
x += n |
f |
switch the glyph mode to n |
# |
draw inline icon n (button glyphs; record table at 0x1403fa230, 4 bytes each, byte 3 = the icon’s advance, 18–28 px) through 0x140247410, only when the icon set at 0x140533c08 is loaded |
- Glyph modes: 0 proportional
text with word wrap (before each glyph
0x14028d630 measures the run up to the next
character ≤ 0x20; when the run would pass the
wrap width and fits on a line by itself, a line
feed comes first); 4 the same
with a drop shadow (the glyph first at (+1, +1)
with colour 0, then in the text colour);
1 the wide capitals
set: code points 0x20–0xFF drawn from
atlas rows 116–119 (cell = code
+ 116 · 64, so the digits are row 116 and the
capitals row 117; the source starts 1 px left of
the cell and is 14 px wide), a fixed 14
px advance, drawn 14 × 15 at 1:1
whatever sx / sy say; 2 mode 1
with the (+1, +1) colour-0 shadow;
3 the counter digits:
characters
0–9map to cells 0–9 of row 116 andA… to cell 10 onward (the small digits, the up / down arrows and the infinity sign that follow the big digits in that row), 14 px advance.
Atlas rows 116–122 (the part the code-point table never reaches): row 116 = ten big digits (ink 10 px wide, full cell height), ten small thin digits, up arrow, down arrow, infinity; rows 117–119 = the wide capital set laid out like cells 0x40–0x5F, 0x80–0x9F, 0xC0–0xDF; row 120 = ten narrow digits (7 px) and small marks; rows 121–122 = symbol glyphs.
HUD numbers. The digit
sprites the HUD draws with 0x140198ad0 from
source (digit · 16, 0x740) are row 116 of this
atlas (0x740 = 116 · 16): the big digits, at the
HUD’s 12 px spacing (health, aura, deck count)
or 14 px (card stat line). 0x140198ad0(x, y, …,
argb, rect) draws a source rectangle of the
texture bound to the 2-D context at
[0x140527c78] + 0x500; the rect
argument overrides the default source (x, y
added, width, height replaced).
Confidence. Width table, cell mapping, scale rule, escapes: H (code, and the table checked against the atlas ink; row 116 seen in the decoded atlas). Mode 1–3 glyph sources: H for the arithmetic, M for which screens use them. Inline icon table layout: M.
Implementation notes for the rebuild
- Converter: write the atlas as a PNG (through
Esper-RE’s texture path or a BC library, not a
new decoder) and a
font.jsonholding the 256-entry width table, the 81{left, width}pairs and the code-point → cell map (read from the user’s executable through structs: 256 × u64 page pointers, 256 × u16 pages). - Godot: one
PdFont.draw(x, y, text, sx, sy, colours)that follows the glyph rule above (integer maths), plus the rich layer: the 0x07 escapes, tab mark, wrap rule, modes 0–4. No Godot font resource: the quads come straight from the atlas. pd_hud.gd: replace_text()/_digits()with it. Settings per element: names 8 / 16, descriptions 7 / 14 over the shadow pass, digits from row 116 at 12 or 14 px spacing.- Text colour is per corner: keep four colours in the API (menus use vertical gradients).