Include font ascent in glyph y-offset when loading BDF font

This commit is contained in:
Stanley Fuller 2024-01-19 22:06:22 +11:00
parent f73773edf4
commit 46dae78ffc

View File

@ -2297,6 +2297,7 @@ static GlyphInfo *LoadBDFFontData(const unsigned char *fileData, int dataSize, i
int fontBBh = 0; // Font base character bounding box height int fontBBh = 0; // Font base character bounding box height
int fontBBxoff0 = 0; // Font base character bounding box X0 offset int fontBBxoff0 = 0; // Font base character bounding box X0 offset
int fontBByoff0 = 0; // Font base character bounding box Y0 offset int fontBByoff0 = 0; // Font base character bounding box Y0 offset
int fontAscent = 0; // Font ascent
bool charStarted = false; // Has character started (STARTCHAR) bool charStarted = false; // Has character started (STARTCHAR)
bool charBitmapStarted = false; // Has bitmap data started (BITMAP) bool charBitmapStarted = false; // Has bitmap data started (BITMAP)
@ -2413,7 +2414,7 @@ static GlyphInfo *LoadBDFFontData(const unsigned char *fileData, int dataSize, i
{ {
charGlyphInfo->value = charEncoding; charGlyphInfo->value = charEncoding;
charGlyphInfo->offsetX = charBBxoff0 + fontBByoff0; charGlyphInfo->offsetX = charBBxoff0 + fontBByoff0;
charGlyphInfo->offsetY = fontBBh - (charBBh + charBByoff0 + fontBByoff0); charGlyphInfo->offsetY = fontBBh - (charBBh + charBByoff0 + fontBByoff0 + fontAscent);
charGlyphInfo->advanceX = charDWidthX; charGlyphInfo->advanceX = charDWidthX;
charGlyphInfo->image.data = RL_CALLOC(charBBw * charBBh, 1); charGlyphInfo->image.data = RL_CALLOC(charBBw * charBBh, 1);
@ -2465,6 +2466,13 @@ static GlyphInfo *LoadBDFFontData(const unsigned char *fileData, int dataSize, i
continue; continue;
} }
// FONT_ASCENT
if (strstr(buffer, "FONT_ASCENT") != NULL)
{
readVars = sscanf(buffer, "FONT_ASCENT %i", &fontAscent);
continue;
}
// STARTCHAR // STARTCHAR
if (strstr(buffer, "STARTCHAR") != NULL) if (strstr(buffer, "STARTCHAR") != NULL)
{ {