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:
Diffstat (limited to 'source/blender/blenfont/intern')
-rw-r--r--source/blender/blenfont/intern/Makefile74
-rw-r--r--source/blender/blenfont/intern/blf.c185
-rw-r--r--source/blender/blenfont/intern/blf_dir.c23
-rw-r--r--source/blender/blenfont/intern/blf_font.c173
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c55
-rw-r--r--source/blender/blenfont/intern/blf_internal.h49
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h16
-rw-r--r--source/blender/blenfont/intern/blf_lang.c68
-rw-r--r--source/blender/blenfont/intern/blf_util.c3
9 files changed, 397 insertions, 249 deletions
diff --git a/source/blender/blenfont/intern/Makefile b/source/blender/blenfont/intern/Makefile
deleted file mode 100644
index d3a6e656028..00000000000
--- a/source/blender/blenfont/intern/Makefile
+++ /dev/null
@@ -1,74 +0,0 @@
-#
-# $Id$
-#
-# ***** BEGIN GPL LICENSE BLOCK *****
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2008 Blender Foundation.
-# All rights reserved.
-#
-# Contributor(s): none yet.
-#
-# ***** END GPL LICENSE BLOCK *****
-#
-#
-
-LIBNAME = blenfont
-DIR = $(OCGDIR)/blender/blenfont
-
-include nan_compile.mk
-
-CFLAGS += $(LEVEL_1_C_WARNINGS)
-#CFLAGS += -O2 -Wall -Wno-char-subscripts
-
-# OpenGL and Freetype2
-CPPFLAGS += -I$(NAN_GLEW)/include
-CPPFLAGS += $(OGL_CPPFLAGS)
-CPPFLAGS += -I$(NAN_FREETYPE)/include
-
-ifeq ($(OS), windows)
- CPPFLAGS += -I$(NAN_ICONV)/include
- ifeq ($(FREE_WINDOWS), true)
- CPPFLAGS += -I$(NAN_FREETYPE)/include/freetype2
- CPPFLAGS += -DUSE_GETTEXT_DLL
- endif
-else
- CPPFLAGS += -I$(NAN_FREETYPE)/include/freetype2
-endif
-
-ifeq ($(OS),linux)
- ifeq ($(CPU),alpha)
- CPPFLAGS += -I$(NAN_MESA)/include
- endif
- ifeq ($(CPU),i386)
- CPPFLAGS += -I$(NAN_MESA)/include
- endif
- ifeq ($(CPU),powerpc)
- CPPFLAGS += -I/usr/src/MesaCVS/include
- endif
-endif
-
-# Modules
-CPPFLAGS += -I../../editors/include
-CPPFLAGS += -I../../makesdna
-CPPFLAGS += -I../../blenlib
-CPPFLAGS += -I../../blenkernel
-
-# Memory allocator
-CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
-
-# Our own headers
-CPPFLAGS += -I..
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index f6b7c5f71e6..2a135b1fb84 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -56,15 +56,19 @@
#define BLF_MAX_FONT 16
/* Font array. */
-FontBLF *global_font[BLF_MAX_FONT];
+static FontBLF *global_font[BLF_MAX_FONT];
/* Number of font. */
-int global_font_num= 0;
+static int global_font_num= 0;
/* Default size and dpi, for BLF_draw_default. */
-int global_font_default= -1;
-int global_font_points= 11;
-int global_font_dpi= 72;
+static int global_font_default= -1;
+static int global_font_points= 11;
+static int global_font_dpi= 72;
+
+// XXX, should these be made into global_font_'s too?
+int blf_mono_font= -1;
+int blf_mono_font_render= -1;
static FontBLF *BLF_get(int fontid)
{
@@ -99,7 +103,19 @@ void BLF_exit(void)
blf_font_exit();
}
-static int blf_search(char *name)
+void BLF_cache_clear(void)
+{
+ FontBLF *font;
+ int i;
+
+ for (i= 0; i < global_font_num; i++) {
+ font= global_font[i];
+ if (font)
+ blf_glyph_cache_clear(font);
+ }
+}
+
+static int blf_search(const char *name)
{
FontBLF *font;
int i;
@@ -112,7 +128,7 @@ static int blf_search(char *name)
return(-1);
}
-int BLF_load(char *name)
+int BLF_load(const char *name)
{
FontBLF *font;
char *filename;
@@ -124,7 +140,7 @@ int BLF_load(char *name)
/* check if we already load this font. */
i= blf_search(name);
if (i >= 0) {
- font= global_font[i];
+ /*font= global_font[i];*/ /*UNUSED*/
return(i);
}
@@ -153,7 +169,7 @@ int BLF_load(char *name)
return(i);
}
-int BLF_load_unique(char *name)
+int BLF_load_unique(const char *name)
{
FontBLF *font;
char *filename;
@@ -199,7 +215,7 @@ void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size)
blf_font_attach_from_mem(font, mem, mem_size);
}
-int BLF_load_mem(char *name, unsigned char *mem, int mem_size)
+int BLF_load_mem(const char *name, unsigned char *mem, int mem_size)
{
FontBLF *font;
int i;
@@ -209,7 +225,7 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size)
i= blf_search(name);
if (i >= 0) {
- font= global_font[i];
+ /*font= global_font[i];*/ /*UNUSED*/
return(i);
}
@@ -235,7 +251,7 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size)
return(i);
}
-int BLF_load_mem_unique(char *name, unsigned char *mem, int mem_size)
+int BLF_load_mem_unique(const char *name, unsigned char *mem, int mem_size)
{
FontBLF *font;
int i;
@@ -305,36 +321,71 @@ void BLF_disable_default(int option)
font->flags &= ~option;
}
-void BLF_aspect(int fontid, float aspect)
+void BLF_aspect(int fontid, float x, float y, float z)
{
FontBLF *font;
font= BLF_get(fontid);
- if (font)
- font->aspect= aspect;
+ if (font) {
+ font->aspect[0]= x;
+ font->aspect[1]= y;
+ font->aspect[2]= z;
+ }
+}
+
+void BLF_matrix(int fontid, double *m)
+{
+ FontBLF *font;
+ int i;
+
+ font= BLF_get(fontid);
+ if (font) {
+ for (i= 0; i < 16; i++)
+ font->m[i]= m[i];
+ }
}
void BLF_position(int fontid, float x, float y, float z)
{
FontBLF *font;
float remainder;
+ float xa, ya, za;
font= BLF_get(fontid);
if (font) {
+ if (font->flags & BLF_ASPECT) {
+ xa= font->aspect[0];
+ ya= font->aspect[1];
+ za= font->aspect[2];
+ }
+ else {
+ xa= 1.0f;
+ ya= 1.0f;
+ za= 1.0f;
+ }
+
remainder= x - floor(x);
if (remainder > 0.4 && remainder < 0.6) {
if (remainder < 0.5)
- x -= 0.1 * font->aspect;
+ x -= 0.1 * xa;
else
- x += 0.1 * font->aspect;
+ x += 0.1 * xa;
}
remainder= y - floor(y);
if (remainder > 0.4 && remainder < 0.6) {
if (remainder < 0.5)
- y -= 0.1 * font->aspect;
+ y -= 0.1 * ya;
+ else
+ y += 0.1 * ya;
+ }
+
+ remainder= z - floor(z);
+ if (remainder > 0.4 && remainder < 0.6) {
+ if (remainder < 0.5)
+ z -= 0.1 * za;
else
- y += 0.1 * font->aspect;
+ z += 0.1 * za;
}
font->pos[0]= x;
@@ -361,7 +412,7 @@ void BLF_blur(int fontid, int size)
font->blur= size;
}
-void BLF_draw_default(float x, float y, float z, char *str)
+void BLF_draw_default(float x, float y, float z, const char *str, size_t len)
{
if (!str)
return;
@@ -376,7 +427,26 @@ void BLF_draw_default(float x, float y, float z, char *str)
BLF_size(global_font_default, global_font_points, global_font_dpi);
BLF_position(global_font_default, x, y, z);
- BLF_draw(global_font_default, str);
+ BLF_draw(global_font_default, str, len);
+}
+
+/* same as above but call 'BLF_draw_ascii' */
+void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t len)
+{
+ if (!str)
+ return;
+
+ if (global_font_default == -1)
+ global_font_default= blf_search("default");
+
+ if (global_font_default == -1) {
+ printf("Warning: Can't found default font!!\n");
+ return;
+ }
+
+ BLF_size(global_font_default, global_font_points, global_font_dpi);
+ BLF_position(global_font_default, x, y, z);
+ BLF_draw_ascii(global_font_default, str, len); /* XXX, use real length */
}
void BLF_rotation_default(float angle)
@@ -388,36 +458,59 @@ void BLF_rotation_default(float angle)
font->angle= angle;
}
-void BLF_draw(int fontid, char *str)
+static void blf_draw__start(FontBLF *font)
{
- FontBLF *font;
-
/*
* The pixmap alignment hack is handle
* in BLF_position (old ui_rasterpos_safe).
*/
- font= BLF_get(fontid);
- if (font) {
- glEnable(GL_BLEND);
- glEnable(GL_TEXTURE_2D);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glPushMatrix();
- glTranslatef(font->pos[0], font->pos[1], font->pos[2]);
- glScalef(font->aspect, font->aspect, 1.0);
+ glEnable(GL_BLEND);
+ glEnable(GL_TEXTURE_2D);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glPushMatrix();
+
+ if (font->flags & BLF_MATRIX)
+ glMultMatrixd((GLdouble *)&font->m);
+
+ glTranslatef(font->pos[0], font->pos[1], font->pos[2]);
+
+ if (font->flags & BLF_ASPECT)
+ glScalef(font->aspect[0], font->aspect[1], font->aspect[2]);
+
+ if (font->flags & BLF_ROTATION)
+ glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
+}
- if (font->flags & BLF_ROTATION)
- glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
+static void blf_draw__end(void)
+{
+ glPopMatrix();
+ glDisable(GL_BLEND);
+ glDisable(GL_TEXTURE_2D);
+}
- blf_font_draw(font, str);
+void BLF_draw(int fontid, const char *str, size_t len)
+{
+ FontBLF *font= BLF_get(fontid);
+ if (font) {
+ blf_draw__start(font);
+ blf_font_draw(font, str, len);
+ blf_draw__end();
+ }
+}
- glPopMatrix();
- glDisable(GL_BLEND);
- glDisable(GL_TEXTURE_2D);
+void BLF_draw_ascii(int fontid, const char *str, size_t len)
+{
+ FontBLF *font= BLF_get(fontid);
+ if (font) {
+ blf_draw__start(font);
+ blf_font_draw_ascii(font, str, len);
+ blf_draw__end();
}
}
-void BLF_boundbox(int fontid, char *str, rctf *box)
+void BLF_boundbox(int fontid, const char *str, rctf *box)
{
FontBLF *font;
@@ -426,7 +519,7 @@ void BLF_boundbox(int fontid, char *str, rctf *box)
blf_font_boundbox(font, str, box);
}
-void BLF_width_and_height(int fontid, char *str, float *width, float *height)
+void BLF_width_and_height(int fontid, const char *str, float *width, float *height)
{
FontBLF *font;
@@ -435,7 +528,7 @@ void BLF_width_and_height(int fontid, char *str, float *width, float *height)
blf_font_width_and_height(font, str, width, height);
}
-float BLF_width(int fontid, char *str)
+float BLF_width(int fontid, const char *str)
{
FontBLF *font;
@@ -455,7 +548,7 @@ float BLF_fixed_width(int fontid)
return(0.0f);
}
-float BLF_width_default(char *str)
+float BLF_width_default(const char *str)
{
float width;
@@ -472,7 +565,7 @@ float BLF_width_default(char *str)
return(width);
}
-float BLF_height(int fontid, char *str)
+float BLF_height(int fontid, const char *str)
{
FontBLF *font;
@@ -482,7 +575,7 @@ float BLF_height(int fontid, char *str)
return(0.0f);
}
-float BLF_height_default(char *str)
+float BLF_height_default(const char *str)
{
float height;
@@ -586,7 +679,7 @@ void BLF_buffer_col(int fontid, float r, float g, float b, float a)
}
}
-void BLF_draw_buffer(int fontid, char *str)
+void BLF_draw_buffer(int fontid, const char *str)
{
FontBLF *font;
diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c
index e650586aa9c..8f816fac3ee 100644
--- a/source/blender/blenfont/intern/blf_dir.c
+++ b/source/blender/blenfont/intern/blf_dir.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -44,6 +44,7 @@
#include "BIF_gl.h"
+#include "BLF_api.h"
#include "blf_internal_types.h"
static ListBase global_font_dir= { NULL, NULL };
@@ -121,24 +122,20 @@ void BLF_dir_free(char **dirs, int count)
MEM_freeN(dirs);
}
-char *blf_dir_search(char *file)
+char *blf_dir_search(const char *file)
{
DirBLF *dir;
char full_path[FILE_MAXDIR+FILE_MAXFILE];
- char *s;
-
- dir= global_font_dir.first;
- s= NULL;
- while (dir) {
- BLI_join_dirfile(full_path, dir->path, file);
+ char *s= NULL;
+
+ for(dir=global_font_dir.first; dir; dir= dir->next) {
+ BLI_join_dirfile(full_path, sizeof(full_path), dir->path, file);
if (BLI_exist(full_path)) {
- s= (char *)MEM_mallocN(strlen(full_path)+1,"blf_dir_search");
- strcpy(s, full_path);
+ s= BLI_strdup(full_path);
break;
}
- dir= dir->next;
}
-
+
if (!s) {
/* check the current directory, why not ? */
if (BLI_exist(file))
@@ -175,7 +172,7 @@ int blf_dir_split(const char *str, char *file, int *size)
/* Some font have additional file with metrics information,
* in general, the extension of the file is: .afm or .pfm
*/
-char *blf_dir_metrics_search(char *filename)
+char *blf_dir_metrics_search(const char *filename)
{
char *mfile;
char *s;
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index a932682b027..733352286b9 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -52,17 +52,17 @@
#include "blf_internal.h"
-/* freetype2 handle. */
-FT_Library global_ft_lib;
+/* freetype2 handle ONLY for this file!. */
+static FT_Library ft_lib;
int blf_font_init(void)
{
- return(FT_Init_FreeType(&global_ft_lib));
+ return(FT_Init_FreeType(&ft_lib));
}
void blf_font_exit(void)
{
- FT_Done_FreeType(global_ft_lib);
+ FT_Done_FreeType(ft_lib);
}
void blf_font_size(FontBLF *font, int size, int dpi)
@@ -92,7 +92,7 @@ void blf_font_size(FontBLF *font, int size, int dpi)
}
}
-void blf_font_draw(FontBLF *font, char *str)
+void blf_font_draw(FontBLF *font, const char *str, unsigned int len)
{
unsigned int c;
GlyphBLF *g, *g_prev;
@@ -110,7 +110,7 @@ void blf_font_draw(FontBLF *font, char *str)
has_kerning= FT_HAS_KERNING(font->face);
g_prev= NULL;
- while (str[i]) {
+ while (str[i] && i < len) {
c= blf_utf8_next((unsigned char *)str, &i);
if (c == 0)
break;
@@ -146,7 +146,65 @@ void blf_font_draw(FontBLF *font, char *str)
}
}
-void blf_font_buffer(FontBLF *font, char *str)
+/* faster version of blf_font_draw, ascii only for view dimensions */
+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;
+
+ if (!font->glyph_cache)
+ return;
+
+ 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;
+ }
+ }
+
+ while ((c= *(str++)) && len--) {
+ g= font->glyph_ascii_table[c];
+
+ /* if we don't found a glyph, skip it. */
+ if (!g)
+ continue;
+
+ if (has_kerning && g_prev) {
+ delta.x= 0;
+ delta.y= 0;
+
+ if (font->flags & BLF_KERNING_DEFAULT)
+ st= FT_Get_Kerning(font->face, g_prev->idx, g->idx, ft_kerning_default, &delta);
+ else
+ st= FT_Get_Kerning(font->face, g_prev->idx, g->idx, FT_KERNING_UNFITTED, &delta);
+
+ if (st == 0)
+ pen_x += delta.x >> 6;
+ }
+
+ /* do not return this loop if clipped, we want every character tested */
+ blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
+
+ pen_x += g->advance;
+ g_prev= g;
+ }
+}
+
+void blf_font_buffer(FontBLF *font, const char *str)
{
unsigned char *cbuf;
unsigned int c;
@@ -155,7 +213,7 @@ void blf_font_buffer(FontBLF *font, char *str)
FT_Vector delta;
FT_UInt glyph_index;
float a, *fbuf;
- int pen_x, pen_y, y, x, yb, diff;
+ int pen_x, y, x, yb;
int i, has_kerning, st, chx, chy;
if (!font->glyph_cache || (!font->b_fbuf && !font->b_cbuf))
@@ -163,7 +221,6 @@ void blf_font_buffer(FontBLF *font, char *str)
i= 0;
pen_x= (int)font->pos[0];
- pen_y= (int)font->pos[1];
has_kerning= FT_HAS_KERNING(font->face);
g_prev= NULL;
@@ -172,6 +229,7 @@ void blf_font_buffer(FontBLF *font, char *str)
b_col_char[2]= font->b_col[2] * 255;
while (str[i]) {
+ int pen_y;
c= blf_utf8_next((unsigned char *)str, &i);
if (c == 0)
break;
@@ -200,25 +258,15 @@ void blf_font_buffer(FontBLF *font, char *str)
}
chx= pen_x + ((int)g->pos_x);
- diff= g->height - ((int)g->pos_y);
- if (diff > 0) {
- if (g->pitch < 0)
- pen_y += diff;
- else
- pen_y -= diff;
+ chy= (int)font->pos[1] + g->height;
+
+ if (g->pitch < 0) {
+ pen_y = (int)font->pos[1] + (g->height - (int)g->pos_y);
}
- else if (diff < 0) {
- if (g->pitch < 0)
- pen_y -= diff;
- else
- pen_y += diff;
+ else {
+ pen_y = (int)font->pos[1] - (g->height - (int)g->pos_y);
}
- if (g->pitch < 0)
- chy= pen_y - ((int)g->pos_y);
- else
- chy= pen_y + ((int)g->pos_y);
-
if ((chx + g->width) >= 0 && chx < font->bw && (pen_y + g->height) >= 0 && pen_y < font->bh) {
/* dont draw beyond the buffer bounds */
int width_clip= g->width;
@@ -285,25 +333,12 @@ void blf_font_buffer(FontBLF *font, char *str)
}
}
- if (diff > 0) {
- if (g->pitch < 0)
- pen_x -= diff;
- else
- pen_y += diff;
- }
- else if (diff < 0) {
- if (g->pitch < 0)
- pen_x += diff;
- else
- pen_y -= diff;
- }
-
pen_x += g->advance;
g_prev= g;
}
}
-void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
+void blf_font_boundbox(FontBLF *font, const char *str, rctf *box)
{
unsigned int c;
GlyphBLF *g, *g_prev;
@@ -382,37 +417,59 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
}
}
-void blf_font_width_and_height(FontBLF *font, char *str, float *width, float *height)
+void blf_font_width_and_height(FontBLF *font, const char *str, float *width, float *height)
{
+ float xa, ya;
rctf box;
if (font->glyph_cache) {
+ if (font->flags & BLF_ASPECT) {
+ xa= font->aspect[0];
+ ya= font->aspect[1];
+ }
+ else {
+ xa= 1.0f;
+ ya= 1.0f;
+ }
+
blf_font_boundbox(font, str, &box);
- *width= ((box.xmax - box.xmin) * font->aspect);
- *height= ((box.ymax - box.ymin) * font->aspect);
+ *width= ((box.xmax - box.xmin) * xa);
+ *height= ((box.ymax - box.ymin) * ya);
}
}
-float blf_font_width(FontBLF *font, char *str)
+float blf_font_width(FontBLF *font, const char *str)
{
+ float xa;
rctf box;
if (!font->glyph_cache)
return(0.0f);
+ if (font->flags & BLF_ASPECT)
+ xa= font->aspect[0];
+ else
+ xa= 1.0f;
+
blf_font_boundbox(font, str, &box);
- return((box.xmax - box.xmin) * font->aspect);
+ return((box.xmax - box.xmin) * xa);
}
-float blf_font_height(FontBLF *font, char *str)
+float blf_font_height(FontBLF *font, const char *str)
{
+ float ya;
rctf box;
if (!font->glyph_cache)
return(0.0f);
+ if (font->flags & BLF_ASPECT)
+ ya= font->aspect[1];
+ else
+ ya= 1.0f;
+
blf_font_boundbox(font, str, &box);
- return((box.ymax - box.ymin) * font->aspect);
+ return((box.ymax - box.ymin) * ya);
}
float blf_font_fixed_width(FontBLF *font)
@@ -457,11 +514,18 @@ void blf_font_free(FontBLF *font)
static void blf_font_fill(FontBLF *font)
{
- font->aspect= 1.0f;
+ int i;
+
+ font->aspect[0]= 1.0f;
+ font->aspect[1]= 1.0f;
+ font->aspect[2]= 1.0f;
font->pos[0]= 0.0f;
font->pos[1]= 0.0f;
font->angle= 0.0f;
- unit_m4(font->mat);
+
+ for (i= 0; i < 16; i++)
+ font->m[i]= 0;
+
font->clip_rec.xmin= 0.0f;
font->clip_rec.xmax= 0.0f;
font->clip_rec.ymin= 0.0f;
@@ -483,16 +547,19 @@ static void blf_font_fill(FontBLF *font)
font->b_col[1]= 0;
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(char *name, char *filename)
+FontBLF *blf_font_new(const char *name, const char *filename)
{
FontBLF *font;
FT_Error err;
char *mfile;
font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new");
- err= FT_New_Face(global_ft_lib, filename, 0, &font->face);
+ err= FT_New_Face(ft_lib, filename, 0, &font->face);
if (err) {
MEM_freeN(font);
return(NULL);
@@ -528,13 +595,13 @@ void blf_font_attach_from_mem(FontBLF *font, const unsigned char *mem, int mem_s
FT_Attach_Stream(font->face, &open);
}
-FontBLF *blf_font_new_from_mem(char *name, unsigned char *mem, int mem_size)
+FontBLF *blf_font_new_from_mem(const char *name, unsigned char *mem, int mem_size)
{
FontBLF *font;
FT_Error err;
font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new_from_mem");
- err= FT_New_Memory_Face(global_ft_lib, mem, mem_size, 0, &font->face);
+ err= FT_New_Memory_Face(ft_lib, mem, mem_size, 0, &font->face);
if (err) {
MEM_freeN(font);
return(NULL);
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index 0d694c28b2b..b1cc4ba3084 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -36,10 +36,12 @@
#include FT_FREETYPE_H
#include FT_GLYPH_H
#include FT_OUTLINE_H
+#include FT_BITMAP_H
#include "MEM_guardedalloc.h"
#include "DNA_vec_types.h"
+#include "DNA_userdef_types.h"
#include "BLI_blenlib.h"
@@ -113,6 +115,23 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
return(gc);
}
+void blf_glyph_cache_clear(FontBLF *font)
+{
+ GlyphCacheBLF *gc;
+ GlyphBLF *g;
+ int i;
+
+ for(gc=font->cache.first; gc; gc=gc->next) {
+ for (i= 0; i < 257; i++) {
+ while (gc->bucket[i].first) {
+ g= gc->bucket[i].first;
+ BLI_remlink(&(gc->bucket[i]), g);
+ blf_glyph_free(g);
+ }
+ }
+ }
+}
+
void blf_glyph_cache_free(GlyphCacheBLF *gc)
{
GlyphBLF *g;
@@ -185,12 +204,13 @@ GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, unsigned int c)
return(NULL);
}
-GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c)
+GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
{
FT_GlyphSlot slot;
GlyphBLF *g;
FT_Error err;
- FT_Bitmap bitmap;
+ FT_Bitmap bitmap, tempbitmap;
+ int sharp = (U.text_render & USER_TEXT_DISABLE_AA);
FT_BBox bbox;
unsigned int key;
@@ -198,14 +218,29 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c)
if (g)
return(g);
- err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP);
+ if (sharp)
+ err = FT_Load_Glyph(font->face, (FT_UInt)index, FT_LOAD_TARGET_MONO);
+ else
+ err = FT_Load_Glyph(font->face, (FT_UInt)index, FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP); /* Sure about NO_* flags? */
if (err)
return(NULL);
/* get the glyph. */
slot= font->face->glyph;
- err= FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
+ if (sharp) {
+ err = FT_Render_Glyph(slot, FT_RENDER_MODE_MONO);
+
+ /* Convert result from 1 bit per pixel to 8 bit per pixel */
+ /* Accum errors for later, fine if not interested beyond "ok vs any error" */
+ FT_Bitmap_New(&tempbitmap);
+ err += FT_Bitmap_Convert(font->ft_lib, &slot->bitmap, &tempbitmap, 1); /* Does Blender use Pitch 1 always? It works so far */
+ err += FT_Bitmap_Copy(font->ft_lib, &tempbitmap, &slot->bitmap);
+ err += FT_Bitmap_Done(font->ft_lib, &tempbitmap);
+ } else {
+ err = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
+ }
+
if (err || slot->format != FT_GLYPH_FORMAT_BITMAP)
return(NULL);
@@ -213,7 +248,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c)
g->next= NULL;
g->prev= NULL;
g->c= c;
- g->idx= index;
+ g->idx= (FT_UInt)index;
g->tex= 0;
g->build_tex= 0;
g->bitmap= NULL;
@@ -228,6 +263,14 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c)
g->height= bitmap.rows;
if (g->width && g->height) {
+ if (sharp) {
+ /* Font buffer uses only 0 or 1 values, Blender expects full 0..255 range */
+ int i;
+ for (i=0; i < (g->width * g->height); i++) {
+ bitmap.buffer[i] = 255 * bitmap.buffer[i];
+ }
+ }
+
g->bitmap= (unsigned char *)MEM_mallocN(g->width * g->height, "glyph bitmap");
memcpy((void *)g->bitmap, (void *)bitmap.buffer, g->width * g->height);
}
diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h
index 844a7a3c3de..d07b2605575 100644
--- a/source/blender/blenfont/intern/blf_internal.h
+++ b/source/blender/blenfont/intern/blf_internal.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -28,39 +28,46 @@
#ifndef BLF_INTERNAL_H
#define BLF_INTERNAL_H
+struct FontBLF;
+struct GlyphBLF;
+struct GlyphCacheBLF;
+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);
char *blf_dir_search(const char *file);
-char *blf_dir_metrics_search(char *filename);
+char *blf_dir_metrics_search(const char *filename);
int blf_dir_split(const char *str, char *file, int *size);
int blf_font_init(void);
void blf_font_exit(void);
-FontBLF *blf_font_new(char *name, char *filename);
-FontBLF *blf_font_new_from_mem(char *name, unsigned char *mem, int mem_size);
-void blf_font_attach_from_mem(FontBLF *font, const unsigned char *mem, int mem_size);
+struct FontBLF *blf_font_new(const char *name, const char *filename);
+struct FontBLF *blf_font_new_from_mem(const char *name, unsigned char *mem, int mem_size);
+void blf_font_attach_from_mem(struct FontBLF *font, const unsigned char *mem, int mem_size);
-void blf_font_size(FontBLF *font, int size, int dpi);
-void blf_font_draw(FontBLF *font, char *str);
-void blf_font_buffer(FontBLF *font, char *str);
-void blf_font_boundbox(FontBLF *font, char *str, rctf *box);
-void blf_font_width_and_height(FontBLF *font, char *str, float *width, float *height);
-float blf_font_width(FontBLF *font, char *str);
-float blf_font_height(FontBLF *font, char *str);
-float blf_font_fixed_width(FontBLF *font);
-void blf_font_free(FontBLF *font);
+void blf_font_size(struct FontBLF *font, int size, int dpi);
+void blf_font_draw(struct FontBLF *font, const char *str, unsigned int len);
+void blf_font_draw_ascii(struct FontBLF *font, const char *str, unsigned int len);
+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);
+float blf_font_fixed_width(struct FontBLF *font);
+void blf_font_free(struct FontBLF *font);
-GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi);
-GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font);
-void blf_glyph_cache_free(GlyphCacheBLF *gc);
+struct GlyphCacheBLF *blf_glyph_cache_find(struct FontBLF *font, int size, int dpi);
+struct GlyphCacheBLF *blf_glyph_cache_new(struct FontBLF *font);
+void blf_glyph_cache_clear(struct FontBLF *font);
+void blf_glyph_cache_free(struct GlyphCacheBLF *gc);
-GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, unsigned int c);
-GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c);
+struct GlyphBLF *blf_glyph_search(struct GlyphCacheBLF *gc, unsigned int c);
+struct GlyphBLF *blf_glyph_add(struct FontBLF *font, unsigned int index, unsigned int c);
-void blf_glyph_free(GlyphBLF *g);
-int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y);
+void blf_glyph_free(struct GlyphBLF *g);
+int blf_glyph_render(struct FontBLF *font, struct GlyphBLF *g, float x, float y);
#endif /* BLF_INTERNAL_H */
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index 368eb8751de..d12487b5c8b 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -133,7 +133,7 @@ typedef struct FontBLF {
char *filename;
/* aspect ratio or scale. */
- float aspect;
+ float aspect[3];
/* initial position for draw the text. */
float pos[3];
@@ -154,8 +154,10 @@ typedef struct FontBLF {
/* shadow color. */
float shadow_col[4];
- /* this is the matrix that we load before rotate/scale/translate. */
- float mat[4][4];
+ /* Multiplied this matrix with the current one before
+ * draw the text! see blf_draw__start.
+ */
+ double m[16];
/* clipping rectangle. */
rctf clip_rec;
@@ -177,6 +179,12 @@ 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;
/* freetype2 face. */
FT_Face face;
diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c
index 7054d955faf..da0b767f64d 100644
--- a/source/blender/blenfont/intern/blf_lang.c
+++ b/source/blender/blenfont/intern/blf_lang.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -29,6 +29,8 @@
#include <stdlib.h>
#include <string.h>
+#include "BLF_api.h"
+
#ifdef INTERNATIONAL
#include <locale.h>
@@ -38,15 +40,15 @@
#include "DNA_listBase.h"
#include "DNA_vec_types.h"
-#include "BKE_utildefines.h"
+#include "MEM_guardedalloc.h"
-#include "BLI_blenlib.h"
#include "BLI_linklist.h" /* linknode */
#include "BLI_string.h"
+#include "BLI_path_util.h"
#ifdef __APPLE__
-#include "BKE_utildefines.h"
+
#endif
#define DOMAIN_NAME "blender"
@@ -54,9 +56,9 @@
#define FONT_SIZE_DEFAULT 12
/* locale options. */
-char global_messagepath[1024];
-char global_language[32];
-char global_encoding_name[32];
+static char global_messagepath[1024];
+static char global_language[32];
+static char global_encoding_name[32];
void BLF_lang_init(void)
@@ -69,43 +71,45 @@ void BLF_lang_init(void)
BLI_strncpy(global_messagepath, messagepath, sizeof(global_messagepath));
else
global_messagepath[0]= '\0';
+
}
-
+/* XXX WARNING!!! IN osx somehow the previous function call jumps in this one??? (ton, ppc) */
void BLF_lang_set(const char *str)
{
+ if(str==NULL) {
+ return;
+ }
+ else {
+
#if defined (_WIN32) || defined(__APPLE__)
- BLI_setenv("LANG", str);
+ BLI_setenv("LANG", str);
#else
- char *locreturn= setlocale(LC_ALL, str);
- if (locreturn == NULL) {
- char *lang;
-
- lang= (char*)malloc(sizeof(char)*(strlen(str)+7));
+ char *locreturn= setlocale(LC_ALL, str);
+ if (locreturn == NULL) {
+ char *lang= BLI_sprintfN("%s.UTF-8", str);
- lang[0]= '\0';
- strcat(lang, str);
- strcat(lang, ".UTF-8");
+ locreturn= setlocale(LC_ALL, lang);
+ if (locreturn == NULL) {
+ printf("could not change language to %s nor %s\n", str, lang);
+ }
- locreturn= setlocale(LC_ALL, lang);
- if (locreturn == NULL) {
- printf("could not change language to %s nor %s\n", str, lang);
+ MEM_freeN(lang);
}
- free(lang);
- }
-
- setlocale(LC_NUMERIC, "C");
+ setlocale(LC_NUMERIC, "C");
#endif
- textdomain(DOMAIN_NAME);
- bindtextdomain(DOMAIN_NAME, global_messagepath);
- /* bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name); */
- strcpy(global_language, str);
+ textdomain(DOMAIN_NAME);
+ bindtextdomain(DOMAIN_NAME, global_messagepath);
+ /* bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name); */
+ BLI_strncpy(global_language, str, sizeof(global_language));
+
+ }
}
void BLF_lang_encoding(const char *str)
{
- strcpy(global_encoding_name, str);
+ BLI_strncpy(global_encoding_name, str, sizeof(global_encoding_name));
/* bind_textdomain_codeset(DOMAIN_NAME, encoding_name); */
}
@@ -116,13 +120,15 @@ void BLF_lang_init(void)
return;
}
-void BLF_lang_encoding(char *str)
+void BLF_lang_encoding(const char *str)
{
+ (void)str;
return;
}
-void BLF_lang_set(char *str)
+void BLF_lang_set(const char *str)
{
+ (void)str;
return;
}
diff --git a/source/blender/blenfont/intern/blf_util.c b/source/blender/blenfont/intern/blf_util.c
index 30e6e3fd3f5..640876954ab 100644
--- a/source/blender/blenfont/intern/blf_util.c
+++ b/source/blender/blenfont/intern/blf_util.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -30,6 +30,7 @@
#include <stdlib.h>
#include <string.h>
+#include "blf_internal.h"
unsigned int blf_next_p2(unsigned int x)
{