Writing · Ep. 8 · 0x0B18–0x0BF8 · Reverse engineering
Devlog #3: English broke the font renderer, so I rebuilt it
The original font atlas only has fixed-width glyphs. Here's how I added a proportional Latin font for the OreGairu English Patch.
The problem
Japanese text looks fine in a monospaced grid: every kana and kanji is the same width. English does not. With the stock font, i takes as much room as W, and a single line of dialogue overflows the text box.
The fix is to give every glyph its own advance width and teach the renderer to use it.
Reading the glyph table
Each entry in the font table is eight bytes. I only needed three fields:
struct Glyph {
uint16_t codepoint;
uint16_t atlas_index;
uint8_t width; // always 24 in the stock font
uint8_t height;
int8_t bearing_x;
uint8_t advance; // the field we actually care about
};Field | Stock value | After the rebuild |
|---|---|---|
| 24 | 6–24 |
| 24 | glyph width + 1 |
| 0 | −1 to 2 |
Measuring a line
A line now fits when the sum of its advances stays under the box width:
With the stock font that sum was simply , which is why short English lines still overflowed.
Next
Text-box reflow: wrapping on word boundaries instead of character counts. The atlas rebuild itself now lives in Font Atlas Studio.
