From 1ee7d6c26e208988814e822d000f3551d4eb9c6b Mon Sep 17 00:00:00 2001 From: Mid <> Date: Fri, 19 Sep 2025 23:10:25 +0300 Subject: [PATCH] Fix font boundary --- src/k3font.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/k3font.c b/src/k3font.c index 854e0d3..119a04d 100644 --- a/src/k3font.c +++ b/src/k3font.c @@ -153,13 +153,15 @@ void k3FontDraw(struct k3Font *this, float xStart, float yStart, float sz, const break; } - lineLength++; - struct k3FontGlyph *g = k3FontGetGlyph(this, cp2); if(g) { if(lineWidth + g->width * this->lineScale * sz > wall) { break; } + } + + lineLength++; + if(g) { lineWidth += g->xadvance * this->lineScale * sz; } } @@ -189,7 +191,7 @@ void k3FontDraw(struct k3Font *this, float xStart, float yStart, float sz, const size_t texH = this->texH; k3BatchAdd(tex, - (struct k3RectF) {(float) g->x / texW, (float) g->y / texH, (float) g->width / texW, (float) g->height / texH}, + (struct k3RectF) {(float) (g->x + 0.5) / texW, (float) (g->y + 0.5) / texH, (float) (g->width - 1) / texW, (float) (g->height - 1) / texH}, (struct k3RectF) { x + g->xoffset * this->lineScale * sz, y + ((-g->height - g->yoffset) * this->lineScale + 1) * sz,