From d0856d1d546a07acf29e3a2ac873fe7dc1d7c61b Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Sun, 24 Jun 2018 17:47:40 +0200 Subject: Fix most of 'disappearing' first letter in right-aligned labels. BLF' blf_font_width_to_strlen() could easily generate strings with up to nearly two pixels length over requested limit! Note that the fiddling between floats and ints values make things really confusing here... :/ There is still a few limit cases where, even though computed str length is now always below reauested limit, we still get first letter disappearing, no idea why currently. --- source/blender/blenfont/intern/blf_font.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender/blenfont') diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 13c857b0d4b..b3ab36f7bcc 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -652,7 +652,7 @@ size_t blf_font_width_to_strlen(FontBLF *font, const char *str, size_t len, floa int pen_x = 0; size_t i = 0, i_prev; GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table; - const int width_i = (int)width + 1; + const int width_i = (int)width; int width_new; BLF_KERNING_VARS(font, has_kerning, kern_mode); @@ -674,7 +674,7 @@ size_t blf_font_width_to_strlen(FontBLF *font, const char *str, size_t len, floa pen_x += g->advance_i; - if (width_i < pen_x) { + if (width_i <= pen_x) { break; } -- cgit v1.2.3