diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-12-02 13:33:45 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-12-02 14:10:07 +0400 |
commit | 1815225faa75eb64e83fdc9f066fcd6339502d52 (patch) | |
tree | 6558780d85792c9c41fcf280069870fae70eed7a /source/blender/blenfont/intern/blf_font.c | |
parent | f64ae4cbe5a724496624de9e479c04f325613be5 (diff) |
Blender Font (BLF): add length argument to string width/height functions
This also fixes a crash editing buttons longer then UI_MAX_DRAW_STR
Diffstat (limited to 'source/blender/blenfont/intern/blf_font.c')
-rw-r--r-- | source/blender/blenfont/intern/blf_font.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 998b415a6af..40943225223 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -415,7 +415,7 @@ void blf_font_buffer(FontBLF *font, const char *str) } } -void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) +void blf_font_boundbox(FontBLF *font, const char *str, size_t len, rctf *box) { unsigned int c; GlyphBLF *g, *g_prev = NULL; @@ -435,7 +435,7 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) blf_font_ensure_ascii_table(font); - while (str[i]) { + while ((i < len) && str[i]) { BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); if (c == BLI_UTF8_ERR) @@ -468,7 +468,7 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) } } -void blf_font_width_and_height(FontBLF *font, const char *str, float *width, float *height) +void blf_font_width_and_height(FontBLF *font, const char *str, size_t len, float *width, float *height) { float xa, ya; rctf box; @@ -482,12 +482,12 @@ void blf_font_width_and_height(FontBLF *font, const char *str, float *width, flo ya = 1.0f; } - blf_font_boundbox(font, str, &box); + blf_font_boundbox(font, str, len, &box); *width = (BLI_rctf_size_x(&box) * xa); *height = (BLI_rctf_size_y(&box) * ya); } -float blf_font_width(FontBLF *font, const char *str) +float blf_font_width(FontBLF *font, const char *str, size_t len) { float xa; rctf box; @@ -497,11 +497,11 @@ float blf_font_width(FontBLF *font, const char *str) else xa = 1.0f; - blf_font_boundbox(font, str, &box); + blf_font_boundbox(font, str, len, &box); return BLI_rctf_size_x(&box) * xa; } -float blf_font_height(FontBLF *font, const char *str) +float blf_font_height(FontBLF *font, const char *str, size_t len) { float ya; rctf box; @@ -511,7 +511,7 @@ float blf_font_height(FontBLF *font, const char *str) else ya = 1.0f; - blf_font_boundbox(font, str, &box); + blf_font_boundbox(font, str, len, &box); return BLI_rctf_size_y(&box) * ya; } |