From bc0717cdc2802406877557f9547ae3bfc9567c59 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 12 Dec 2020 19:00:01 +0200 Subject: Text: Clip glyphs to fit vertically There may be partial overlaps with full-height glyphs because the fonts are scaled unhinted. --- src/ui/text.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/ui/text.c') diff --git a/src/ui/text.c b/src/ui/text.c index cdcff6ab..c36fceb5 100644 --- a/src/ui/text.c +++ b/src/ui/text.c @@ -108,6 +108,8 @@ static void init_Font(iFont *d, const iBlock *data, int height, float scale, d->height = height; iZap(d->font); stbtt_InitFont(&d->font, constData_Block(data), 0); + int ascent, descent; + stbtt_GetFontVMetrics(&d->font, &ascent, &descent, NULL); d->xScale = d->yScale = stbtt_ScaleForPixelHeight(&d->font, height) * scale; if (d->isMonospaced) { /* It is important that monospaced fonts align 1:1 with the pixel grid so that @@ -120,10 +122,8 @@ static void init_Font(iFont *d, const iBlock *data, int height, float scale, d->xScale *= floorf(advance) / advance; } } - d->vertOffset = height * (1.0f - scale) / 2; - int ascent; - stbtt_GetFontVMetrics(&d->font, &ascent, NULL, NULL); - d->baseline = /*ceil*/(ascent * d->yScale); + d->vertOffset = height * (1.0f - scale) / 2; + d->baseline = ascent * d->yScale; d->symbolsFont = symbolsFont; d->japaneseFont = regularJapanese_FontId; d->koreanFont = regularKorean_FontId; @@ -797,6 +797,13 @@ static iRect run_Font_(iFont *d, enum iRunMode mode, iRangecc text, size_t maxLe src.h -= over; dst.h -= over; } + if (dst.y < pos.y) { + const int over = pos.y - dst.y; + dst.y += over; + dst.h -= over; + src.y += over; + src.h -= over; + } SDL_RenderCopy(text_.render, text_.cache, &src, &dst); } xpos += advance; -- cgit v1.2.3