summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-12-12 19:00:01 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-12-12 19:01:35 +0200
commitbc0717cdc2802406877557f9547ae3bfc9567c59 (patch)
tree8b62569bae3e72414fce050fd65024fc1a694e5e
parentcef2d288555326e4e268577b63407b4290ca2511 (diff)
Text: Clip glyphs to fit vertically
There may be partial overlaps with full-height glyphs because the fonts are scaled unhinted.
-rw-r--r--src/ui/text.c15
1 files changed, 11 insertions, 4 deletions
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,
108 d->height = height; 108 d->height = height;
109 iZap(d->font); 109 iZap(d->font);
110 stbtt_InitFont(&d->font, constData_Block(data), 0); 110 stbtt_InitFont(&d->font, constData_Block(data), 0);
111 int ascent, descent;
112 stbtt_GetFontVMetrics(&d->font, &ascent, &descent, NULL);
111 d->xScale = d->yScale = stbtt_ScaleForPixelHeight(&d->font, height) * scale; 113 d->xScale = d->yScale = stbtt_ScaleForPixelHeight(&d->font, height) * scale;
112 if (d->isMonospaced) { 114 if (d->isMonospaced) {
113 /* It is important that monospaced fonts align 1:1 with the pixel grid so that 115 /* 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,
120 d->xScale *= floorf(advance) / advance; 122 d->xScale *= floorf(advance) / advance;
121 } 123 }
122 } 124 }
123 d->vertOffset = height * (1.0f - scale) / 2; 125 d->vertOffset = height * (1.0f - scale) / 2;
124 int ascent; 126 d->baseline = ascent * d->yScale;
125 stbtt_GetFontVMetrics(&d->font, &ascent, NULL, NULL);
126 d->baseline = /*ceil*/(ascent * d->yScale);
127 d->symbolsFont = symbolsFont; 127 d->symbolsFont = symbolsFont;
128 d->japaneseFont = regularJapanese_FontId; 128 d->japaneseFont = regularJapanese_FontId;
129 d->koreanFont = regularKorean_FontId; 129 d->koreanFont = regularKorean_FontId;
@@ -797,6 +797,13 @@ static iRect run_Font_(iFont *d, enum iRunMode mode, iRangecc text, size_t maxLe
797 src.h -= over; 797 src.h -= over;
798 dst.h -= over; 798 dst.h -= over;
799 } 799 }
800 if (dst.y < pos.y) {
801 const int over = pos.y - dst.y;
802 dst.y += over;
803 dst.h -= over;
804 src.y += over;
805 src.h -= over;
806 }
800 SDL_RenderCopy(text_.render, text_.cache, &src, &dst); 807 SDL_RenderCopy(text_.render, text_.cache, &src, &dst);
801 } 808 }
802 xpos += advance; 809 xpos += advance;