diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-12-16 14:47:10 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-12-16 15:00:30 +0400 |
commit | ce3f42e16a9e501b7c0221a6ed152d0926cc59e7 (patch) | |
tree | aca1331a4d0d5db6856ec79e9bd33f2d999a493e /source/blender/blenfont/intern/blf.c | |
parent | c193dbe30b40beb435d6edde7117469f4706f98e (diff) |
BLF API: Add BLF_width_to_strlen,rstrlen gives a byte offset from a string width
Diffstat (limited to 'source/blender/blenfont/intern/blf.c')
-rw-r--r-- | source/blender/blenfont/intern/blf.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 746ee3c0d93..a5aa19704ec 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -592,6 +592,46 @@ int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth) return columns; } +size_t BLF_width_to_strlen(int fontid, const char *str, size_t len, float width, float *r_width) +{ + FontBLF *font = blf_get(fontid); + + if (font) { + const float xa = (font->flags & BLF_ASPECT) ? font->aspect[0] : 1.0f; + size_t ret; + ret = blf_font_width_to_strlen(font, str, len, width / xa, r_width); + if (r_width) { + *r_width *= xa; + } + return ret; + } + + if (r_width) { + *r_width = 0.0f; + } + return 0; +} + +size_t BLF_width_to_rstrlen(int fontid, const char *str, size_t len, float width, float *r_width) +{ + FontBLF *font = blf_get(fontid); + + if (font) { + const float xa = (font->flags & BLF_ASPECT) ? font->aspect[0] : 1.0f; + size_t ret; + ret = blf_font_width_to_rstrlen(font, str, len, width / xa, r_width); + if (r_width) { + *r_width *= xa; + } + return ret; + } + + if (r_width) { + *r_width = 0.0f; + } + return 0; +} + void BLF_boundbox(int fontid, const char *str, size_t len, rctf *box) { FontBLF *font = blf_get(fontid); |