Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2011-09-15 17:02:37 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2011-09-15 17:02:37 +0400
commit30293dc2ca8052ad0c7113c77365feca590f4d05 (patch)
treec5f4a092be7204ef2107792c0a16c0d9f331dbba /source/blender/blenfont
parente715a7185ca176c8a73cd638d4acaa40f75a7d77 (diff)
parent9648c6016b35a72aa23395f5d200e342df16490b (diff)
svn merge -r39834:40222 https://svn.blender.org/svnroot/bf-blender/trunk/blender
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r--source/blender/blenfont/intern/blf_font.c119
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c11
-rw-r--r--source/blender/blenfont/intern/blf_internal.h2
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h6
-rw-r--r--source/blender/blenfont/intern/blf_lang.c4
-rw-r--r--source/blender/blenfont/intern/blf_util.c2
6 files changed, 86 insertions, 58 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index fb6505fe935..3bec7dd2626 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -97,17 +97,59 @@ void blf_font_size(FontBLF *font, int size, int dpi)
}
}
+static void blf_font_ensure_ascii_table(FontBLF *font)
+{
+ GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
+
+ /* build ascii on demand */
+ if(glyph_ascii_table['0']==NULL) {
+ GlyphBLF *g;
+ unsigned int i;
+ for(i=0; i<256; i++) {
+ g= blf_glyph_search(font->glyph_cache, i);
+ if (!g) {
+ FT_UInt glyph_index= FT_Get_Char_Index(font->face, i);
+ g= blf_glyph_add(font, glyph_index, i);
+ }
+ glyph_ascii_table[i]= g;
+ }
+ }
+}
+
+/* Fast path for runs of ASCII characters. Given that common UTF-8
+ * input will consist of an overwhelming majority of ASCII
+ * characters.
+ */
+
+/* Note,
+ * blf_font_ensure_ascii_table(font); must be called before this macro */
+
+#define BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table) \
+ if(((c)= (str)[i]) < 0x80) { \
+ g= (glyph_ascii_table)[c]; \
+ i++; \
+ } \
+ else if ((c= blf_utf8_next((unsigned char *)(str), &(i)))) { \
+ if ((g= blf_glyph_search((font)->glyph_cache, c)) == NULL) { \
+ g= blf_glyph_add(font, FT_Get_Char_Index((font)->face, c), c); \
+ } \
+ } \
+
+
+
void blf_font_draw(FontBLF *font, const char *str, unsigned int len)
{
unsigned int c;
GlyphBLF *g, *g_prev;
FT_Vector delta;
- FT_UInt glyph_index;
int pen_x, pen_y;
- int i, has_kerning, st;
+ int has_kerning, st;
+ unsigned int i;
+ GlyphBLF **glyph_ascii_table;
if (!font->glyph_cache)
return;
+ glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
i= 0;
pen_x= 0;
@@ -115,17 +157,15 @@ void blf_font_draw(FontBLF *font, const char *str, unsigned int len)
has_kerning= FT_HAS_KERNING(font->face);
g_prev= NULL;
+ blf_font_ensure_ascii_table(font);
+
while (str[i] && i < len) {
- c= blf_utf8_next((unsigned char *)str, &i);
+
+ BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
+
if (c == 0)
break;
- g= blf_glyph_search(font->glyph_cache, c);
- if (!g) {
- glyph_index= FT_Get_Char_Index(font->face, c);
- g= blf_glyph_add(font, glyph_index, c);
- }
-
/* if we don't found a glyph, skip it. */
if (!g)
continue;
@@ -157,32 +197,23 @@ void blf_font_draw_ascii(FontBLF *font, const char *str, unsigned int len)
char c;
GlyphBLF *g, *g_prev;
FT_Vector delta;
- FT_UInt glyph_index;
int pen_x, pen_y;
- int i, has_kerning, st;
+ int has_kerning, st;
+ GlyphBLF **glyph_ascii_table;
if (!font->glyph_cache)
return;
+ glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
pen_x= 0;
pen_y= 0;
has_kerning= FT_HAS_KERNING(font->face);
g_prev= NULL;
- /* build ascii on demand */
- if(font->glyph_ascii_table['0']==NULL) {
- for(i=0; i<256; i++) {
- g= blf_glyph_search(font->glyph_cache, i);
- if (!g) {
- glyph_index= FT_Get_Char_Index(font->face, i);
- g= blf_glyph_add(font, glyph_index, i);
- }
- font->glyph_ascii_table[i]= g;
- }
- }
-
+ blf_font_ensure_ascii_table(font);
+
while ((c= *(str++)) && len--) {
- g= font->glyph_ascii_table[c];
+ g= glyph_ascii_table[c];
/* if we don't found a glyph, skip it. */
if (!g)
@@ -216,13 +247,15 @@ void blf_font_buffer(FontBLF *font, const char *str)
unsigned char b_col_char[4];
GlyphBLF *g, *g_prev;
FT_Vector delta;
- FT_UInt glyph_index;
float a, *fbuf;
int pen_x, y, x;
- int i, has_kerning, st, chx, chy;
+ int has_kerning, st, chx, chy;
+ unsigned int i;
+ GlyphBLF **glyph_ascii_table;
if (!font->glyph_cache || (!font->b_fbuf && !font->b_cbuf))
return;
+ glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
i= 0;
pen_x= (int)font->pos[0];
@@ -234,18 +267,16 @@ void blf_font_buffer(FontBLF *font, const char *str)
b_col_char[2]= font->b_col[2] * 255;
b_col_char[3]= font->b_col[3] * 255;
+ blf_font_ensure_ascii_table(font);
+
while (str[i]) {
int pen_y;
- c= blf_utf8_next((unsigned char *)str, &i);
+
+ BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
+
if (c == 0)
break;
- g= blf_glyph_search(font->glyph_cache, c);
- if (!g) {
- glyph_index= FT_Get_Char_Index(font->face, c);
- g= blf_glyph_add(font, glyph_index, c);
- }
-
/* if we don't found a glyph, skip it. */
if (!g)
continue;
@@ -363,10 +394,11 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box)
unsigned int c;
GlyphBLF *g, *g_prev;
FT_Vector delta;
- FT_UInt glyph_index;
rctf gbox;
int pen_x, pen_y;
- int i, has_kerning, st;
+ int has_kerning, st;
+ unsigned int i;
+ GlyphBLF **glyph_ascii_table;
if (!font->glyph_cache)
return;
@@ -382,17 +414,16 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box)
has_kerning= FT_HAS_KERNING(font->face);
g_prev= NULL;
+ blf_font_ensure_ascii_table(font);
+ glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
+
while (str[i]) {
- c= blf_utf8_next((unsigned char *)str, &i);
+
+ BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
+
if (c == 0)
break;
- g= blf_glyph_search(font->glyph_cache, c);
- if (!g) {
- glyph_index= FT_Get_Char_Index(font->face, c);
- g= blf_glyph_add(font, glyph_index, c);
- }
-
/* if we don't found a glyph, skip it. */
if (!g)
continue;
@@ -534,7 +565,7 @@ void blf_font_free(FontBLF *font)
static void blf_font_fill(FontBLF *font)
{
- int i;
+ unsigned int i;
font->aspect[0]= 1.0f;
font->aspect[1]= 1.0f;
@@ -568,8 +599,6 @@ static void blf_font_fill(FontBLF *font)
font->b_col[2]= 0;
font->b_col[3]= 0;
font->ft_lib= ft_lib;
-
- memset(font->glyph_ascii_table, 0, sizeof(font->glyph_ascii_table));
}
FontBLF *blf_font_new(const char *name, const char *filename)
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index e165012f43e..9b39cb65cba 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -74,7 +74,6 @@ GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi)
GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
{
GlyphCacheBLF *gc;
- int i;
gc= (GlyphCacheBLF *)MEM_mallocN(sizeof(GlyphCacheBLF), "blf_glyph_cache_new");
gc->next= NULL;
@@ -82,10 +81,8 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
gc->size= font->size;
gc->dpi= font->dpi;
- for (i= 0; i < 257; i++) {
- gc->bucket[i].first= NULL;
- gc->bucket[i].last= NULL;
- }
+ memset(gc->glyph_ascii_table, 0, sizeof(gc->glyph_ascii_table));
+ memset(gc->bucket, 0, sizeof(gc->bucket));
gc->textures= (GLuint *)malloc(sizeof(GLuint)*256);
gc->ntex= 256;
@@ -136,7 +133,9 @@ void blf_glyph_cache_clear(FontBLF *font)
}
}
- memset(font->glyph_ascii_table, 0, sizeof(font->glyph_ascii_table));
+ if(font->glyph_cache) {
+ memset(font->glyph_cache->glyph_ascii_table, 0, sizeof(font->glyph_cache->glyph_ascii_table));
+ }
}
void blf_glyph_cache_free(GlyphCacheBLF *gc)
diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h
index 9271d8d5a9e..ba0b9985dd4 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, int *iindex);
+int blf_utf8_next(unsigned char *buf, unsigned int *iindex);
char *blf_dir_search(const char *file);
char *blf_dir_metrics_search(const char *filename);
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index c4e192626e8..9840e6446ef 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -46,6 +46,9 @@ typedef struct GlyphCacheBLF {
/* and the glyphs. */
ListBase bucket[257];
+ /* fast ascii lookup */
+ struct GlyphBLF *glyph_ascii_table[256];
+
/* texture array, to draw the glyphs. */
GLuint *textures;
@@ -184,9 +187,6 @@ typedef struct FontBLF {
/* current glyph cache, size and dpi. */
GlyphCacheBLF *glyph_cache;
-
- /* fast ascii lookip */
- GlyphBLF *glyph_ascii_table[256];
/* freetype2 lib handle. */
FT_Library ft_lib;
diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c
index ed03a329ffb..cfa7514f9af 100644
--- a/source/blender/blenfont/intern/blf_lang.c
+++ b/source/blender/blenfont/intern/blf_lang.c
@@ -67,7 +67,7 @@ static char global_language[32];
static char global_encoding_name[32];
/* map from the rna_userdef.c:rna_def_userdef_system(BlenderRNA *brna):language_items */
-static char *locales[] = {
+static const char *locales[] = {
"", "",
"english", "en_US",
"japanese", "ja_JP",
@@ -112,7 +112,7 @@ void BLF_lang_init(void)
void BLF_lang_set(const char *str)
{
char *locreturn;
- char *short_locale;
+ const char *short_locale;
#if defined (_WIN32)
char *long_locale = locales[ 2 * U.language];
#endif
diff --git a/source/blender/blenfont/intern/blf_util.c b/source/blender/blenfont/intern/blf_util.c
index ab6b516787e..edd23ac1ba6 100644
--- a/source/blender/blenfont/intern/blf_util.c
+++ b/source/blender/blenfont/intern/blf_util.c
@@ -72,7 +72,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, int *iindex)
+int blf_utf8_next(unsigned char *buf, unsigned int *iindex)
{
/* Reads UTF8 bytes from 'buf', starting at 'index' and
* returns the code point of the next valid code point.