Skip to content

Commit 5458bae

Browse files
committed
rg_gui: Fallback to basic font when a glyph is missing in the chosen font
This is ugly, no doubt, but it's better than having a blank, I think?
1 parent 4aa82b0 commit 5458bae

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

components/retro-go/rg_gui.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,11 @@ static size_t get_glyph(uint32_t *output, const rg_font_t *font, int points, int
265265
if (!font || c == '\r' || c == '\n' || c < 8 || c > 254)
266266
return 0;
267267

268-
size_t glyph_width = font->width;
268+
size_t glyph_width = 0;
269269

270270
if (font->type == 0) // Monospace Bitmap
271271
{
272+
glyph_width = font->width;
272273
if (output)
273274
{
274275
if (c >= font->chars)
@@ -295,7 +296,8 @@ static size_t get_glyph(uint32_t *output, const rg_font_t *font, int points, int
295296
// Based on code by Boris Lovosevic (https://github.com/loboris)
296297
int charCode, adjYOffset, width, height, xOffset, xDelta;
297298
const uint8_t *data = font->data;
298-
while (1) {
299+
while (1)
300+
{
299301
charCode = *data++;
300302
adjYOffset = *data++;
301303
width = *data++;
@@ -311,26 +313,28 @@ static size_t get_glyph(uint32_t *output, const rg_font_t *font, int points, int
311313
data += (((width * height) - 1) / 8) + 1;
312314
}
313315

314-
if (c == charCode)
316+
// If the glyph is not found, we fallback to the basic font which has most glyphs.
317+
// It will be ugly, but at least the letter won't be missing...
318+
if (charCode != c)
319+
return get_glyph(output, &font_basic8x8, RG_MAX(8, points - 2), c);
320+
321+
glyph_width = RG_MAX(width, xDelta);
322+
if (output)
315323
{
316-
glyph_width = RG_MAX(width, xDelta);
317-
if (output)
324+
int ch = 0, mask = 0x80;
325+
for (int y = 0; y < height; y++)
318326
{
319-
int ch = 0, mask = 0x80;
320-
for (int y = 0; y < height; y++)
327+
output[adjYOffset + y] = 0;
328+
for (int x = 0; x < width; x++)
321329
{
322-
output[adjYOffset + y] = 0;
323-
for (int x = 0; x < width; x++)
330+
if (((x + (y * width)) % 8) == 0)
324331
{
325-
if (((x + (y * width)) % 8) == 0)
326-
{
327-
mask = 0x80;
328-
ch = *data++;
329-
}
330-
if ((ch & mask) != 0)
331-
output[adjYOffset + y] |= (1 << (xOffset + x));
332-
mask >>= 1;
332+
mask = 0x80;
333+
ch = *data++;
333334
}
335+
if ((ch & mask) != 0)
336+
output[adjYOffset + y] |= (1 << (xOffset + x));
337+
mask >>= 1;
334338
}
335339
}
336340
}

0 commit comments

Comments
 (0)