From 7d897e5e1d90899dbd6e456dc7eb92ae1f07f8ab Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 26 May 2022 22:16:25 -0700
Subject: [PATCH] Make sure we include the last character when measuring text
Partially fixes https://github.com/libsdl-org/SDL_ttf/issues/225
---
SDL_ttf.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/SDL_ttf.c b/SDL_ttf.c
index f770bef..a33f074 100644
--- a/SDL_ttf.c
+++ b/SDL_ttf.c
@@ -3304,11 +3304,13 @@ static int TTF_Size_Internal(TTF_Font *font,
if (measure_width) {
int cw = SDL_max(maxx, FT_FLOOR(x + prev_advance)) - minx;
cw += 2 * font->outline_val;
+ if (cw <= measure_width) {
+ current_width = cw;
+ char_count += 1;
+ }
if (cw >= measure_width) {
break;
}
- current_width = cw;
- char_count += 1;
}
}