Fix y offset in BakeFontBitmap

Compute Y offset more accurately and the way it is required in
renderer.c.

Instead of returning y offset wrt the baseline position returns it
wrt the top position (the baseline plus the font's ascent).
This commit is contained in:
Francesco Abbate 2020-06-01 14:33:46 +02:00
parent 4c6e15b66c
commit 0389bd000a
2 changed files with 2 additions and 8 deletions

View File

@ -68,7 +68,7 @@ int FontRendererBakeFontBitmap(FontRenderer *fr_, int font_height,
glyph_info.x1 = x_next_i;
glyph_info.y1 = pixels_height - (y_baseline + descender_px - pad_y);
glyph_info.xoff = 0;
glyph_info.yoff = -ascender * font_height;
glyph_info.yoff = -pad_y;
glyph_info.xadvance = x_next - x;
#if 0
fprintf(stderr,

View File

@ -129,14 +129,8 @@ retry:
goto retry;
}
// TODO: consider if this is still needed.
/* adjust glyph yoffsets and xadvance */
int ascent, descent, linegap;
stbtt_GetFontVMetrics(&font->stbfont, &ascent, &descent, &linegap);
float scale = stbtt_ScaleForMappingEmToPixels(&font->stbfont, font->size);
int scaled_ascent = ascent * scale + 0.5;
/* adjust glyph's xadvance */
for (int i = 0; i < 256; i++) {
set->glyphs[i].yoff += scaled_ascent;
set->glyphs[i].xadvance = floor(set->glyphs[i].xadvance);
}