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 | |
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')
-rw-r--r-- | source/blender/blenfont/intern/blf.c | 32 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_font.c | 16 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_internal.h | 8 |
3 files changed, 28 insertions, 28 deletions
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 130eaaecba5..746ee3c0d93 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -592,44 +592,44 @@ int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth) return columns; } -void BLF_boundbox(int fontid, const char *str, rctf *box) +void BLF_boundbox(int fontid, const char *str, size_t len, rctf *box) { FontBLF *font = blf_get(fontid); if (font) { - blf_font_boundbox(font, str, box); + blf_font_boundbox(font, str, len, box); } } -void BLF_width_and_height(int fontid, const char *str, float *width, float *height) +void BLF_width_and_height(int fontid, const char *str, size_t len, float *r_width, float *r_height) { FontBLF *font = blf_get(fontid); if (font && font->glyph_cache) { - blf_font_width_and_height(font, str, width, height); + blf_font_width_and_height(font, str, len, r_width, r_height); } else { - *width = *height = 0.0f; + *r_width = *r_height = 0.0f; } } -void BLF_width_and_height_default(const char *str, float *width, float *height) +void BLF_width_and_height_default(const char *str, size_t len, float *r_width, float *r_height) { if (!blf_global_font_init()) { - *width = *height = 0.0f; + *r_width = *r_height = 0.0f; return; } BLF_size(global_font_default, global_font_points, global_font_dpi); - BLF_width_and_height(global_font_default, str, width, height); + BLF_width_and_height(global_font_default, str, len, r_width, r_height); } -float BLF_width(int fontid, const char *str) +float BLF_width(int fontid, const char *str, size_t len) { FontBLF *font = blf_get(fontid); if (font && font->glyph_cache) { - return blf_font_width(font, str); + return blf_font_width(font, str, len); } return 0.0f; @@ -646,21 +646,21 @@ float BLF_fixed_width(int fontid) return 0.0f; } -float BLF_width_default(const char *str) +float BLF_width_default(const char *str, size_t len) { if (!blf_global_font_init()) return 0.0f; BLF_size(global_font_default, global_font_points, global_font_dpi); - return BLF_width(global_font_default, str); + return BLF_width(global_font_default, str, len); } -float BLF_height(int fontid, const char *str) +float BLF_height(int fontid, const char *str, size_t len) { FontBLF *font = blf_get(fontid); if (font && font->glyph_cache) { - return blf_font_height(font, str); + return blf_font_height(font, str, len); } return 0.0f; @@ -710,14 +710,14 @@ float BLF_ascender(int fontid) return 0.0f; } -float BLF_height_default(const char *str) +float BLF_height_default(const char *str, size_t len) { if (!blf_global_font_init()) return 0.0f; BLF_size(global_font_default, global_font_points, global_font_dpi); - return BLF_height(global_font_default, str); + return BLF_height(global_font_default, str, len); } void BLF_rotation(int fontid, float angle) 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; } diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index 7d4b39dd337..9f6bad9b00d 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -55,10 +55,10 @@ void blf_font_draw(struct FontBLF *font, const char *str, size_t len); void blf_font_draw_ascii(struct FontBLF *font, const char *str, size_t len); int blf_font_draw_mono(struct FontBLF *font, const char *str, size_t len, int cwidth); void blf_font_buffer(struct FontBLF *font, const char *str); -void blf_font_boundbox(struct FontBLF *font, const char *str, struct rctf *box); -void blf_font_width_and_height(struct FontBLF *font, const char *str, float *width, float *height); -float blf_font_width(struct FontBLF *font, const char *str); -float blf_font_height(struct FontBLF *font, const char *str); +void blf_font_boundbox(struct FontBLF *font, const char *str, size_t len, struct rctf *box); +void blf_font_width_and_height(struct FontBLF *font, const char *str, size_t len, float *width, float *height); +float blf_font_width(struct FontBLF *font, const char *str, size_t len); +float blf_font_height(struct FontBLF *font, const char *str, size_t len); float blf_font_fixed_width(struct FontBLF *font); void blf_font_free(struct FontBLF *font); |