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:
authorNick Samarin <nicks1987@bigmir.net>2011-02-16 20:07:18 +0300
committerNick Samarin <nicks1987@bigmir.net>2011-02-16 20:07:18 +0300
commitc5f6a01dd5998976addd2085470bb73a150579e5 (patch)
tree42b3345fb3ea2e7607a6d1eec379b8ce23b5ffbc /source/blender/blenfont/intern
parent4cf62f1e7e2bb28b47f79e4bd7c1482ab742ebbd (diff)
parent9e9e028f059f29d493dc020dda965a9bea8ffd6b (diff)
synched with trunk at revision 34793
Diffstat (limited to 'source/blender/blenfont/intern')
-rw-r--r--source/blender/blenfont/intern/Makefile74
-rw-r--r--source/blender/blenfont/intern/blf.c173
-rw-r--r--source/blender/blenfont/intern/blf_dir.c4
-rw-r--r--source/blender/blenfont/intern/blf_font.c119
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c50
-rw-r--r--source/blender/blenfont/intern/blf_internal.h20
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h11
-rw-r--r--source/blender/blenfont/intern/blf_lang.c6
8 files changed, 309 insertions, 148 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..462ecebc10a 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -66,6 +66,10 @@ int global_font_default= -1;
int global_font_points= 11;
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)
{
if (fontid >= 0 && fontid < BLF_MAX_FONT)
@@ -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..1eb7597fa54 100644
--- a/source/blender/blenfont/intern/blf_dir.c
+++ b/source/blender/blenfont/intern/blf_dir.c
@@ -121,7 +121,7 @@ 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];
@@ -175,7 +175,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 04f40ac825b..ce68df5c8b6 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -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;
@@ -280,7 +338,7 @@ void blf_font_buffer(FontBLF *font, char *str)
}
}
-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;
@@ -359,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)
@@ -434,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;
@@ -460,9 +547,11 @@ static void blf_font_fill(FontBLF *font)
font->b_col[1]= 0;
font->b_col[2]= 0;
font->b_col[3]= 0;
+
+ 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;
@@ -505,7 +594,7 @@ 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;
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index 0d694c28b2b..c36496fb542 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -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"
@@ -49,6 +51,7 @@
#include "blf_internal_types.h"
#include "blf_internal.h"
+FT_Library global_ft_lib;
GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi)
{
@@ -113,6 +116,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;
@@ -190,7 +210,8 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt 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 +219,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, index, FT_LOAD_TARGET_MONO);
+ else
+ err = FT_Load_Glyph(font->face, 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(global_ft_lib, &slot->bitmap, &tempbitmap, 1); /* Does Blender use Pitch 1 always? It works so far */
+ err += FT_Bitmap_Copy(global_ft_lib, &tempbitmap, &slot->bitmap);
+ err += FT_Bitmap_Done(global_ft_lib, &tempbitmap);
+ } else {
+ err = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
+ }
+
if (err || slot->format != FT_GLYPH_FORMAT_BITMAP)
return(NULL);
@@ -228,6 +264,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..afe40973269 100644
--- a/source/blender/blenfont/intern/blf_internal.h
+++ b/source/blender/blenfont/intern/blf_internal.h
@@ -33,28 +33,30 @@ 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);
+FontBLF *blf_font_new(const char *name, const char *filename);
+FontBLF *blf_font_new_from_mem(const char *name, unsigned char *mem, int mem_size);
void blf_font_attach_from_mem(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);
+void blf_font_draw(FontBLF *font, const char *str, unsigned int len);
+void blf_font_draw_ascii(FontBLF *font, const char *str, unsigned int len);
+void blf_font_buffer(FontBLF *font, const char *str);
+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);
+float blf_font_width(FontBLF *font, const char *str);
+float blf_font_height(FontBLF *font, const char *str);
float blf_font_fixed_width(FontBLF *font);
void blf_font_free(FontBLF *font);
GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi);
GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font);
+void blf_glyph_cache_clear(FontBLF *font);
void blf_glyph_cache_free(GlyphCacheBLF *gc);
GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, unsigned int c);
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index 368eb8751de..d7c023fc415 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -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,9 @@ typedef struct FontBLF {
/* current glyph cache, size and dpi. */
GlyphCacheBLF *glyph_cache;
+
+ /* fast ascii lookip */
+ GlyphBLF *glyph_ascii_table[256];
/* 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..8a929e1ebf7 100644
--- a/source/blender/blenfont/intern/blf_lang.c
+++ b/source/blender/blenfont/intern/blf_lang.c
@@ -38,7 +38,7 @@
#include "DNA_listBase.h"
#include "DNA_vec_types.h"
-#include "BKE_utildefines.h"
+
#include "BLI_blenlib.h"
#include "BLI_linklist.h" /* linknode */
@@ -46,7 +46,7 @@
#ifdef __APPLE__
-#include "BKE_utildefines.h"
+
#endif
#define DOMAIN_NAME "blender"
@@ -118,11 +118,13 @@ void BLF_lang_init(void)
void BLF_lang_encoding(char *str)
{
+ (void)str;
return;
}
void BLF_lang_set(char *str)
{
+ (void)str;
return;
}