From 1c289636452a80f841d3f8df9ba7155664deba65 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 4 Apr 2021 07:03:09 +0300 Subject: Text: Kerning was broken Kerning has been broken by the changes for adaptive Emoji spacing inside monospace text. Now the current X position is updated correctly also for kerning. --- src/ui/documentwidget.c | 11 +++++++++++ src/ui/text.c | 25 ++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 0c7ebd54..733ed543 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -2496,6 +2496,17 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e fflush(stdout); break; } +#endif +#if 0 + case '0': { + extern int enableKerning_Text; + enableKerning_Text = !enableKerning_Text; + invalidate_DocumentWidget_(d); + refresh_Widget(w); + printf("kerning: %d\n", enableKerning_Text); + fflush(stdout); + break; + } #endif } } diff --git a/src/ui/text.c b/src/ui/text.c index 6af7d6d1..83073d1f 100644 --- a/src/ui/text.c +++ b/src/ui/text.c @@ -72,7 +72,7 @@ struct Impl_Glyph { iHashNode node; int flags; uint32_t glyphIndex; - const iFont *font; /* may come from symbols/emoji */ + iFont *font; /* may come from symbols/emoji */ iRect rect[2]; /* zero and half pixel offset */ iInt2 d[2]; float advance; /* scaled */ @@ -179,6 +179,7 @@ static void deinit_Font(iFont *d) { } static uint32_t glyphIndex_Font_(iFont *d, iChar ch) { + /* TODO: Add a small cache of ~5 most recently found indices. */ const size_t entry = ch - 32; if (entry < iElemCount(d->indexTable)) { if (d->indexTable[entry] == ~0u) { @@ -1098,11 +1099,6 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { if (!isSpace_Char(ch)) { xposExtend += isEmoji ? glyph->advance : advance; } - xposExtend = iMax(xposExtend, xpos); - xposMax = iMax(xposMax, xposExtend); - if (args->continueFrom_out && ((mode & noWrapFlag_RunMode) || isWrapBoundary_(prevCh, ch))) { - lastWordEnd = currentPos; /* mark word wrap position */ - } #if defined (LAGRANGE_ENABLE_KERNING) /* Check the next character. */ if (!isMonospaced && glyph->font == d) { @@ -1110,10 +1106,24 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { const char *peek = chPos; const iChar next = nextChar_(&peek, args->text.end); if (enableKerning_Text && !d->manualKernOnly && next) { - xpos += d->xScale * stbtt_GetGlyphKernAdvance(&d->font, glyph->glyphIndex, next); + const uint32_t nextGlyphIndex = glyphIndex_Font_(glyph->font, next); + const int kern = stbtt_GetGlyphKernAdvance( + &glyph->font->font, glyph->glyphIndex, nextGlyphIndex); + if (kern) { +// printf("%lc(%u) -> %lc(%u): kern %d (%f)\n", ch, glyph->glyphIndex, next, +// nextGlyphIndex, +// kern, d->xScale * kern); + xpos += d->xScale * kern; + xposExtend += d->xScale * kern; + } } } #endif + xposExtend = iMax(xposExtend, xpos); + xposMax = iMax(xposMax, xposExtend); + if (args->continueFrom_out && ((mode & noWrapFlag_RunMode) || isWrapBoundary_(prevCh, ch))) { + lastWordEnd = currentPos; /* mark word wrap position */ + } prevCh = ch; if (--maxLen == 0) { break; @@ -1122,6 +1132,7 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { if (args->runAdvance_out) { *args->runAdvance_out = xposMax - orig.x; } + fflush(stdout); return bounds; } -- cgit v1.2.3