mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-11 13:58:15 +00:00
Corrected issue with ttf font y-offset
This commit is contained in:
14
src/text.c
14
src/text.c
@@ -873,6 +873,18 @@ static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, in
|
||||
// NOTE: We try reading up to 16 MB of elements of 1 byte
|
||||
fread(ttfBuffer, 1, MAX_TTF_SIZE*1024*1024, ttfFile);
|
||||
|
||||
// Find font baseline (vertical origin of the font)
|
||||
// NOTE: This value is required because y-offset depends on it!
|
||||
stbtt_fontinfo fontInfo;
|
||||
int ascent, baseline;
|
||||
float scale;
|
||||
|
||||
stbtt_InitFont(&fontInfo, ttfBuffer, 0);
|
||||
scale = stbtt_ScaleForPixelHeight(&fontInfo, fontSize);
|
||||
stbtt_GetFontVMetrics(&fontInfo, &ascent, 0, 0);
|
||||
baseline = (int)(ascent*scale);
|
||||
|
||||
|
||||
if (fontChars[0] != 32) TraceLog(LOG_WARNING, "TTF spritefont loading: first character is not SPACE(32) character");
|
||||
|
||||
// NOTE: Using stb_truetype crappy packing method, no guarante the font fits the image...
|
||||
@@ -924,7 +936,7 @@ static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, in
|
||||
font.chars[i].rec.height = (int)charData[i].y1 - (int)charData[i].y0;
|
||||
|
||||
font.chars[i].offsetX = charData[i].xoff;
|
||||
font.chars[i].offsetY = charData[i].yoff;
|
||||
font.chars[i].offsetY = baseline + charData[i].yoff;
|
||||
font.chars[i].advanceX = (int)charData[i].xadvance;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user