2 Commits

Author SHA1 Message Date
987a0e54c7 [examples][core_delta_time] Convert GetFrameTime() to milliseconds before printing (#6201) 2026-10-02 00:14:13 +02:00
ab23bd388e [rtext] Fix BDF glyph offsets (#6200)
LoadFontDataBDF() computed offsetX as charBBxoff0 + fontBByoff0, adding the
font bounding box's Y offset to a horizontal position, and offsetY as
fontBBh - (charBBh + charBByoff0 + fontBByoff0 + fontAscent). Every glyph
was drawn shifted, by an amount that depends on the font (4 px left and
up for Spleen 8x16, 5 px left and 3 px down for Helvetica 12), so text was
clipped at the top or left.

A glyph's BBX offsets are relative to the pen position on the baseline,
and the baseline is FONT_ASCENT below the top of the line, so
offsetX = charBBxoff0 and offsetY = fontAscent - (charBBh + charBByoff0).
FONT_ASCENT defaults to the top of the font bounding box when the font
doesn't define it.
2026-10-02 00:13:27 +02:00
2 changed files with 6 additions and 3 deletions

View File

@ -92,7 +92,7 @@ int main(void)
if (currentFps <= 0) fpsText = TextFormat("FPS: unlimited (%i)", GetFPS());
else fpsText = TextFormat("FPS: %i (target: %i)", GetFPS(), currentFps);
DrawText(fpsText, 10, 10, 20, DARKGRAY);
DrawText(TextFormat("Frame time: %02.02f ms", GetFrameTime()), 10, 30, 20, DARKGRAY);
DrawText(TextFormat("Frame time: %02.02f ms", GetFrameTime()*1000.0f), 10, 30, 20, DARKGRAY);
DrawText("Use the scroll wheel to change the fps limit, r to reset", 10, 50, 20, DARKGRAY);
// Draw the text above the circles

View File

@ -2943,8 +2943,10 @@ static GlyphInfo *LoadFontDataBDF(const unsigned char *fileData, int dataSize, c
if (outGlyphPtr != NULL)
{
outGlyphPtr->value = charEncoding;
outGlyphPtr->offsetX = charBBxoff0 + fontBByoff0;
outGlyphPtr->offsetY = fontBBh - (charBBh + charBByoff0 + fontBByoff0 + fontAscent);
// BBX offsets place the glyph bitmap relative to the pen position on the baseline,
// raylib offsets are measured from the top of the line, fontAscent above the baseline
outGlyphPtr->offsetX = charBBxoff0;
outGlyphPtr->offsetY = fontAscent - (charBBh + charBByoff0);
outGlyphPtr->advanceX = charDWidthX;
outGlyphPtr->image.data = RL_CALLOC(charBBw*charBBh, 1);
@ -2987,6 +2989,7 @@ static GlyphInfo *LoadFontDataBDF(const unsigned char *fileData, int dataSize, c
if (strstr(buffer, "FONTBOUNDINGBOX") != NULL)
{
readVars = sscanf(buffer, "FONTBOUNDINGBOX %i %i %i %i", &fontBBw, &fontBBh, &fontBBxoff0, &fontBByoff0);
fontAscent = fontBBh + fontBByoff0; // Default if FONT_ASCENT property is not provided
continue;
}