summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-07-28 17:47:49 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-07-28 17:47:49 +0300
commit60dff6c99dfb680c714ff0949d920b6024ab734a (patch)
tree55df16a95b8b090356745232c10da3f976f8eb30
parent56af1a99da603571df023f72dcb1dccd444f5aaf (diff)
Text: Kerning improvements
Kern double slash manually, disable kerning for the monospace font.
-rw-r--r--src/ui/text.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/ui/text.c b/src/ui/text.c
index 800ebc14..12255fdb 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -58,6 +58,7 @@ struct Impl_Font {
58 int height; 58 int height;
59 int baseline; 59 int baseline;
60 iHash glyphs; 60 iHash glyphs;
61 iBool enableKerning;
61 int baselineOffset; 62 int baselineOffset;
62 enum iFontId symbolsFont; /* font to use for symbols */ 63 enum iFontId symbolsFont; /* font to use for symbols */
63}; 64};
@@ -76,6 +77,7 @@ static void init_Font(iFont *d, const iBlock *data, int height, int bloff, enum
76 stbtt_GetFontVMetrics(&d->font, &ascent, NULL, NULL); 77 stbtt_GetFontVMetrics(&d->font, &ascent, NULL, NULL);
77 d->baseline = (int) ascent * d->scale; 78 d->baseline = (int) ascent * d->scale;
78 d->symbolsFont = symbolsFont; 79 d->symbolsFont = symbolsFont;
80 d->enableKerning = iTrue;
79} 81}
80 82
81static void deinit_Font(iFont *d) { 83static void deinit_Font(iFont *d) {
@@ -152,11 +154,15 @@ void init_Text(SDL_Renderer *render) {
152 { &fontNotoEmojiRegular_Embedded, fontSize_UI * 0.866f, smallSymbols_FontId }, 154 { &fontNotoEmojiRegular_Embedded, fontSize_UI * 0.866f, smallSymbols_FontId },
153 }; 155 };
154 iForIndices(i, fontData) { 156 iForIndices(i, fontData) {
155 init_Font(&d->fonts[i], 157 iFont *font = &d->fonts[i];
158 init_Font(font,
156 fontData[i].ttf, 159 fontData[i].ttf,
157 fontData[i].size, 160 fontData[i].size,
158 i == 0 ? fontSize_UI / 18 : 0, 161 i == 0 ? fontSize_UI / 18 : 0,
159 fontData[i].symbolsFont); 162 fontData[i].symbolsFont);
163 if (fontData[i].ttf == &fontFiraMonoRegular_Embedded) {
164 font->enableKerning = iFalse;
165 }
160 } 166 }
161 } 167 }
162} 168}
@@ -362,11 +368,15 @@ static iInt2 run_Font_(iFont *d, enum iRunMode mode, iRangecc text, size_t maxLe
362 lastWordEnd = chPos; 368 lastWordEnd = chPos;
363 } 369 }
364 /* Check the next character. */ 370 /* Check the next character. */
365 if (glyph->font == d) { 371 if (d->enableKerning && glyph->font == d) {
366 /* TODO: No need to decode the next char twice; check this on the next iteration. */ 372 /* TODO: No need to decode the next char twice; check this on the next iteration. */
367 const char *peek = chPos; 373 const char *peek = chPos;
368 const iChar next = nextChar_(&peek, text.end); 374 const iChar next = nextChar_(&peek, text.end);
369 if (next) { 375 if (ch == '/' && next == '/') {
376 /* Manual kerning for double-slash. */
377 xpos -= glyph->rect[hoff].size.x * 0.5f;
378 }
379 else if (next) {
370 xpos += d->scale * stbtt_GetCodepointKernAdvance(&d->font, ch, next); 380 xpos += d->scale * stbtt_GetCodepointKernAdvance(&d->font, ch, next);
371 } 381 }
372 } 382 }