From 2d8189cec0dab3d4c9db95c03ebb4eb2de6738c4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 21 Oct 2011 00:48:02 +0000 Subject: - minor edits to font drawing/utf8, was needlessly casting int/unsigned int. - also ifdef'd out more smoke function when the modifiers disabled. --- source/blender/blenfont/intern/blf_font.c | 35 +++++++++++++++------------ source/blender/blenfont/intern/blf_internal.h | 2 +- source/blender/blenfont/intern/blf_util.c | 6 +++-- 3 files changed, 25 insertions(+), 18 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 5161761cf09..9a7fb95dd78 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -129,7 +129,7 @@ static void blf_font_ensure_ascii_table(FontBLF *font) g= (glyph_ascii_table)[c]; \ i++; \ } \ - else if ((c= blf_utf8_next((unsigned char *)(str), &(i)))) { \ + else if ((c= blf_utf8_next((str), &(i))) != BLI_UTF8_ERR) { \ if ((g= blf_glyph_search((font)->glyph_cache, c)) == NULL) { \ g= blf_glyph_add(font, FT_Get_Char_Index((font)->face, c), c); \ } \ @@ -141,15 +141,20 @@ static void blf_font_ensure_ascii_table(FontBLF *font) const FT_UInt kern_mode= (has_kerning == 0) ? 0 : \ (((_font)->flags & BLF_KERNING_DEFAULT) ? \ ft_kerning_default : FT_KERNING_UNFITTED) \ - \ #define BLF_KERNING_STEP(_font, kern_mode, g_prev, g, delta, pen_x) \ { \ if (g_prev) { \ delta.x= delta.y= 0; \ - if (FT_Get_Kerning((_font)->face, g_prev->idx, g->idx, kern_mode, &delta) == 0) \ + if (FT_Get_Kerning((_font)->face, \ + (g_prev)->idx, \ + (g)->idx, \ + kern_mode, \ + &(delta)) == 0) \ + { \ pen_x += delta.x >> 6; \ + } \ } \ } \ @@ -159,7 +164,7 @@ void blf_font_draw(FontBLF *font, const char *str, unsigned int len) GlyphBLF *g, *g_prev= NULL; FT_Vector delta; int pen_x= 0, pen_y= 0; - unsigned int i= 0; + size_t i= 0; GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; BLF_KERNING_VARS(font, has_kerning, kern_mode); @@ -170,9 +175,9 @@ void blf_font_draw(FontBLF *font, const char *str, unsigned int len) BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); - if (c == 0) break; - if (g == NULL) continue; - if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); + if (c == BLI_UTF8_ERR) break; + if (g == NULL) continue; + if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); /* do not return this loop if clipped, we want every character tested */ blf_glyph_render(font, g, (float)pen_x, (float)pen_y); @@ -214,7 +219,7 @@ void blf_font_buffer(FontBLF *font, const char *str) GlyphBLF *g, *g_prev= NULL; FT_Vector delta; int pen_x= (int)font->pos[0], pen_y= 0; - unsigned int i= 0; + size_t i= 0; GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; /* buffer specific vars*/ @@ -235,9 +240,9 @@ void blf_font_buffer(FontBLF *font, const char *str) BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); - if (c == 0) break; - if (g == NULL) continue; - if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); + if (c == BLI_UTF8_ERR) break; + if (g == NULL) continue; + if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); chx= pen_x + ((int)g->pos_x); chy= (int)font->pos[1] + g->height; @@ -340,7 +345,7 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) GlyphBLF *g, *g_prev= NULL; FT_Vector delta; int pen_x= 0, pen_y= 0; - unsigned int i= 0; + size_t i= 0; GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; rctf gbox; @@ -358,9 +363,9 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); - if (c == 0) break; - if (g == NULL) continue; - if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); + if (c == BLI_UTF8_ERR) break; + if (g == NULL) continue; + if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x); gbox.xmin= pen_x; gbox.xmax= pen_x + g->advance; diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index ba0b9985dd4..4c830910e36 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -40,7 +40,7 @@ struct rctf; unsigned int blf_next_p2(unsigned int x); unsigned int blf_hash(unsigned int val); -int blf_utf8_next(unsigned char *buf, unsigned int *iindex); +unsigned int blf_utf8_next(const char *buf, size_t *iindex); char *blf_dir_search(const char *file); char *blf_dir_metrics_search(const char *filename); diff --git a/source/blender/blenfont/intern/blf_util.c b/source/blender/blenfont/intern/blf_util.c index cfe77887674..aef97b6f1cc 100644 --- a/source/blender/blenfont/intern/blf_util.c +++ b/source/blender/blenfont/intern/blf_util.c @@ -37,6 +37,8 @@ #include "blf_internal.h" +#include "BLI_string_utf8.h" + unsigned int blf_next_p2(unsigned int x) { x -= 1; @@ -72,7 +74,7 @@ unsigned int blf_hash(unsigned int val) * The original name: imlib_font_utf8_get_next * more info here: http://docs.enlightenment.org/api/imlib2/html/ */ -int blf_utf8_next(unsigned char *buf, unsigned int *iindex) +unsigned int blf_utf8_next(const char *buf, size_t *iindex) { /* Reads UTF8 bytes from 'buf', starting at 'index' and * returns the code point of the next valid code point. @@ -85,7 +87,7 @@ int blf_utf8_next(unsigned char *buf, unsigned int *iindex) d= buf[index++]; if (!d) - return 0; + return BLI_UTF8_ERR; while (buf[index] && ((buf[index] & 0xc0) == 0x80)) index++; -- cgit v1.2.3