Lagrange [work/v1.10]

Text: Clip glyphs to fit vertically

=> d17abb1c6a60e5d8544cd7a7a96ddc126ac13b0d

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;
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.10/cdiff/d17abb1c6a60e5d8544cd7a7a96ddc126ac13b0d
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
65.790545 milliseconds
Gemini-to-HTML Time
0.20214 milliseconds

This content has been proxied by September (3851b).