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:
authorDiego Borghetti <bdiego@gmail.com>2009-03-02 08:20:48 +0300
committerDiego Borghetti <bdiego@gmail.com>2009-03-02 08:20:48 +0300
commitacc8d06b777c5c0aa812295014b421c2a5badcf2 (patch)
tree549d6b7a6d17c89edd682ff951db68b80c0af8b9 /source/blender/blenfont
parent06629033b30ae29a4d63372bcfc5e670d439891a (diff)
Cleanup a little before add internal font (bmfont).
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r--source/blender/blenfont/BLF_api.h5
-rw-r--r--source/blender/blenfont/intern/blf.c19
-rw-r--r--source/blender/blenfont/intern/blf_font.c81
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c45
-rw-r--r--source/blender/blenfont/intern/blf_internal.h2
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h34
6 files changed, 88 insertions, 98 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index 2d40cf48814..0e96bf8ceb1 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -85,8 +85,7 @@ char **BLF_dir_get(int *ndir);
void BLF_dir_free(char **dirs, int count);
/* font->flags. */
-#define BLF_ASPECT (1<<0)
-#define BLF_ROTATION (1<<1)
-#define BLF_CLIPPING (1<<2)
+#define BLF_ROTATION (1<<0)
+#define BLF_CLIPPING (1<<1)
#endif /* BLF_API_H */
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 5b39c2c8ae5..fd2047367dd 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -252,29 +252,24 @@ void BLF_position(float x, float y, float z)
{
#ifdef WITH_FREETYPE2
FontBLF *font;
- float remainder, aspect;
+ float remainder;
font= global_font[global_font_cur];
if (font) {
- if (font->flags & BLF_ASPECT)
- aspect= font->aspect;
- else
- aspect= 1.0f;
-
remainder= x - floor(x);
if (remainder > 0.4 && remainder < 0.6) {
if (remainder < 0.5)
- x -= 0.1 * aspect;
+ x -= 0.1 * font->aspect;
else
- x += 0.1 * aspect;
+ x += 0.1 * font->aspect;
}
remainder= y - floor(y);
if (remainder > 0.4 && remainder < 0.6) {
if (remainder < 0.5)
- y -= 0.1 * aspect;
+ y -= 0.1 * font->aspect;
else
- y += 0.1 * aspect;
+ y += 0.1 * font->aspect;
}
font->pos[0]= x;
@@ -308,9 +303,7 @@ void BLF_draw(char *str)
glPushMatrix();
glTranslatef(font->pos[0], font->pos[1], font->pos[2]);
-
- if (font->flags & BLF_ASPECT)
- glScalef(font->aspect, font->aspect, 1.0);
+ glScalef(font->aspect, font->aspect, 1.0);
if (font->flags & BLF_ROTATION)
glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 44847e72727..55aefa73378 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -75,6 +75,7 @@ void blf_font_exit(void)
void blf_font_fill(FontBLF *font)
{
+ font->type= BLF_FONT_FREETYPE2;
font->ref= 1;
font->aspect= 1.0f;
font->pos[0]= 0.0f;
@@ -98,24 +99,23 @@ FontBLF *blf_font_new(char *name, char *filename)
{
FontBLF *font;
FT_Error err;
+ FT_Face face;
- font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new");
- err= FT_New_Face(global_ft_lib, filename, 0, &font->face);
- if (err) {
- MEM_freeN(font);
+ err= FT_New_Face(global_ft_lib, filename, 0, &face);
+ if (err)
return(NULL);
- }
- err= FT_Select_Charmap(font->face, ft_encoding_unicode);
+ err= FT_Select_Charmap(face, ft_encoding_unicode);
if (err) {
printf("Can't set the unicode character map!\n");
- FT_Done_Face(font->face);
- MEM_freeN(font);
+ FT_Done_Face(face);
return(NULL);
}
+ font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new");
font->name= BLI_strdup(name);
font->filename= BLI_strdup(filename);
+ font->engine= (void *)face;
blf_font_fill(font);
return(font);
}
@@ -124,24 +124,23 @@ FontBLF *blf_font_new_from_mem(char *name, unsigned char *mem, int mem_size)
{
FontBLF *font;
FT_Error err;
+ FT_Face face;
- 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);
- if (err) {
- MEM_freeN(font);
+ err= FT_New_Memory_Face(global_ft_lib, mem, mem_size, 0, &face);
+ if (err)
return(NULL);
- }
- err= FT_Select_Charmap(font->face, ft_encoding_unicode);
+ err= FT_Select_Charmap(face, ft_encoding_unicode);
if (err) {
printf("Can't set the unicode character map!\n");
- FT_Done_Face(font->face);
- MEM_freeN(font);
+ FT_Done_Face(face);
return(NULL);
}
+ font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new_from_mem");
font->name= BLI_strdup(name);
font->filename= NULL;
+ font->engine= (void *)face;
blf_font_fill(font);
return(font);
}
@@ -150,8 +149,8 @@ void blf_font_size(FontBLF *font, int size, int dpi)
{
GlyphCacheBLF *gc;
FT_Error err;
-
- err= FT_Set_Char_Size(font->face, 0, (size * 64), dpi, dpi);
+
+ err= FT_Set_Char_Size((FT_Face)font->engine, 0, (size * 64), dpi, dpi);
if (err) {
/* FIXME: here we can go through the fixed size and choice a close one */
printf("The current font don't support the size, %d and dpi, %d\n", size, dpi);
@@ -178,23 +177,26 @@ void blf_font_draw(FontBLF *font, char *str)
unsigned int c;
GlyphBLF *g, *g_prev;
FT_Vector delta;
- FT_UInt glyph_index;
+ FT_Face face;
+ FT_UInt glyph_index, g_prev_index;
int pen_x, pen_y;
int i, has_kerning;
+ face= (FT_Face)font->engine;
i= 0;
pen_x= 0;
pen_y= 0;
- has_kerning= FT_HAS_KERNING(font->face);
+ has_kerning= FT_HAS_KERNING(face);
g_prev= NULL;
+ g_prev_index= 0;
while (str[i]) {
c= blf_utf8_next((unsigned char *)str, &i);
if (c == 0)
break;
- glyph_index= FT_Get_Char_Index(font->face, c);
- g= blf_glyph_search(font->glyph_cache, glyph_index);
+ glyph_index= FT_Get_Char_Index(face, c);
+ g= blf_glyph_search(font->glyph_cache, c);
if (!g)
g= blf_glyph_add(font, glyph_index, c);
@@ -206,7 +208,7 @@ void blf_font_draw(FontBLF *font, char *str)
delta.x= 0;
delta.y= 0;
- FT_Get_Kerning(font->face, g_prev->index, glyph_index, FT_KERNING_UNFITTED, &delta);
+ FT_Get_Kerning(face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta);
pen_x += delta.x >> 6;
}
@@ -216,6 +218,7 @@ void blf_font_draw(FontBLF *font, char *str)
pen_x += g->advance;
g_prev= g;
+ g_prev_index= glyph_index;
}
}
@@ -224,11 +227,13 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
unsigned int c;
GlyphBLF *g, *g_prev;
FT_Vector delta;
- FT_UInt glyph_index;
+ FT_UInt glyph_index, g_prev_index;
+ FT_Face face;
rctf gbox;
int pen_x, pen_y;
int i, has_kerning;
+ face= (FT_Face)font->engine;
box->xmin= 32000.0f;
box->xmax= -32000.0f;
box->ymin= 32000.0f;
@@ -237,16 +242,17 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
i= 0;
pen_x= 0;
pen_y= 0;
- has_kerning= FT_HAS_KERNING(font->face);
+ has_kerning= FT_HAS_KERNING(face);
g_prev= NULL;
+ g_prev_index= 0;
while (str[i]) {
c= blf_utf8_next((unsigned char *)str, &i);
if (c == 0)
break;
- glyph_index= FT_Get_Char_Index(font->face, c);
- g= blf_glyph_search(font->glyph_cache, glyph_index);
+ glyph_index= FT_Get_Char_Index(face, c);
+ g= blf_glyph_search(font->glyph_cache, c);
if (!g)
g= blf_glyph_add(font, glyph_index, c);
@@ -258,7 +264,7 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
delta.x= 0;
delta.y= 0;
- FT_Get_Kerning(font->face, g_prev->index, glyph_index, FT_KERNING_UNFITTED, &delta);
+ FT_Get_Kerning(face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta);
pen_x += delta.x >> 6;
}
@@ -279,6 +285,7 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
pen_x += g->advance;
g_prev= g;
+ g_prev_index= glyph_index;
}
if (box->xmin > box->xmax) {
@@ -291,30 +298,18 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
float blf_font_width(FontBLF *font, char *str)
{
- float aspect;
rctf box;
- if (font->flags & BLF_ASPECT)
- aspect= font->aspect;
- else
- aspect= 1.0f;
-
blf_font_boundbox(font, str, &box);
- return((box.xmax - box.xmin) * aspect);
+ return((box.xmax - box.xmin) * font->aspect);
}
float blf_font_height(FontBLF *font, char *str)
{
- float aspect;
rctf box;
- if (font->flags & BLF_ASPECT)
- aspect= font->aspect;
- else
- aspect= 1.0f;
-
blf_font_boundbox(font, str, &box);
- return((box.ymax - box.ymin) * aspect);
+ return((box.ymax - box.ymin) * font->aspect);
}
void blf_font_free(FontBLF *font)
@@ -328,7 +323,7 @@ void blf_font_free(FontBLF *font)
blf_glyph_cache_free(gc);
}
- FT_Done_Face(font->face);
+ FT_Done_Face((FT_Face)font->engine);
if (font->filename)
MEM_freeN(font->filename);
if (font->name)
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index 2bbdeb9ad32..7212deff8c8 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -78,8 +78,10 @@ GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi)
GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
{
GlyphCacheBLF *gc;
+ FT_Face face;
int i;
+ face= (FT_Face)font->engine;
gc= (GlyphCacheBLF *)MEM_mallocN(sizeof(GlyphCacheBLF), "blf_glyph_cache_new");
gc->next= NULL;
gc->prev= NULL;
@@ -98,23 +100,23 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
gc->y_offs= 0;
gc->pad= 3;
- gc->num_glyphs= font->face->num_glyphs;
- gc->rem_glyphs= font->face->num_glyphs;
- gc->ascender= ((float)font->face->size->metrics.ascender) / 64.0f;
- gc->descender= ((float)font->face->size->metrics.descender) / 64.0f;
+ gc->num_glyphs= face->num_glyphs;
+ gc->rem_glyphs= face->num_glyphs;
+ gc->ascender= ((float)face->size->metrics.ascender) / 64.0f;
+ gc->descender= ((float)face->size->metrics.descender) / 64.0f;
- if (FT_IS_SCALABLE(font->face)) {
- gc->max_glyph_width= (float)((font->face->bbox.xMax - font->face->bbox.xMin) *
- (((float)font->face->size->metrics.x_ppem) /
- ((float)font->face->units_per_EM)));
+ if (FT_IS_SCALABLE(face)) {
+ gc->max_glyph_width= (float)((face->bbox.xMax - face->bbox.xMin) *
+ (((float)face->size->metrics.x_ppem) /
+ ((float)face->units_per_EM)));
- gc->max_glyph_height= (float)((font->face->bbox.yMax - font->face->bbox.yMin) *
- (((float)font->face->size->metrics.y_ppem) /
- ((float)font->face->units_per_EM)));
+ gc->max_glyph_height= (float)((face->bbox.yMax - face->bbox.yMin) *
+ (((float)face->size->metrics.y_ppem) /
+ ((float)face->units_per_EM)));
}
else {
- gc->max_glyph_width= ((float)font->face->size->metrics.max_advance) / 64.0f;
- gc->max_glyph_height= ((float)font->face->size->metrics.height) / 64.0f;
+ gc->max_glyph_width= ((float)face->size->metrics.max_advance) / 64.0f;
+ gc->max_glyph_height= ((float)face->size->metrics.height) / 64.0f;
}
gc->p2_width= 0;
@@ -180,15 +182,15 @@ void blf_glyph_cache_texture(FontBLF *font, GlyphCacheBLF *gc)
free((void *)buf);
}
-GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, FT_UInt idx)
+GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, unsigned int c)
{
GlyphBLF *p;
unsigned int key;
- key= blf_hash(idx);
+ key= blf_hash(c);
p= gc->bucket[key].first;
while (p) {
- if (p->index == idx)
+ if (p->c == c)
return(p);
p= p->next;
}
@@ -200,21 +202,23 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c)
FT_GlyphSlot slot;
GlyphCacheBLF *gc;
GlyphBLF *g;
+ FT_Face face;
FT_Error err;
FT_Bitmap bitmap;
FT_BBox bbox;
unsigned int key;
- g= blf_glyph_search(font->glyph_cache, index);
+ g= blf_glyph_search(font->glyph_cache, c);
if (g)
return(g);
- err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP);
+ face= (FT_Face)font->engine;
+ err= FT_Load_Glyph(face, index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP);
if (err)
return(NULL);
/* get the glyph. */
- slot= font->face->glyph;
+ slot= face->glyph;
err= FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
if (err || slot->format != FT_GLYPH_FORMAT_BITMAP)
@@ -224,7 +228,6 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c)
g->next= NULL;
g->prev= NULL;
g->c= c;
- g->index= index;
gc= font->glyph_cache;
if (gc->cur_tex == -1) {
@@ -280,7 +283,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c)
/* update the x offset for the next glyph. */
gc->x_offs += (int)(g->box.xmax - g->box.xmin + gc->pad);
- key= blf_hash(g->index);
+ key= blf_hash(g->c);
BLI_addhead(&(gc->bucket[key]), g);
gc->rem_glyphs--;
return(g);
diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h
index 25df7e0e95f..1c29c736776 100644
--- a/source/blender/blenfont/intern/blf_internal.h
+++ b/source/blender/blenfont/intern/blf_internal.h
@@ -54,7 +54,7 @@ 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);
-GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, FT_UInt idx);
+GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, unsigned int c);
GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c);
void blf_glyph_free(GlyphBLF *g);
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index ccfd5c64200..99c6dac13e2 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -28,16 +28,6 @@
#ifndef BLF_INTERNAL_TYPES_H
#define BLF_INTERNAL_TYPES_H
-typedef struct DirBLF {
- struct DirBLF *next;
- struct DirBLF *prev;
-
- /* full path where search fonts. */
- char *path;
-} DirBLF;
-
-#ifdef WITH_FREETYPE2
-
typedef struct GlyphCacheBLF {
struct GlyphCacheBLF *next;
struct GlyphCacheBLF *prev;
@@ -95,9 +85,6 @@ typedef struct GlyphBLF {
/* and the character, as UTF8 */
unsigned int c;
- /* Freetype2 index. */
- FT_UInt index;
-
/* texture id where this glyph is store. */
GLuint tex;
@@ -133,6 +120,9 @@ typedef struct FontBLF {
/* filename or NULL. */
char *filename;
+ /* font type, can be freetype2 or internal. */
+ int type;
+
/* reference count. */
int ref;
@@ -163,17 +153,23 @@ typedef struct FontBLF {
/* font options. */
int flags;
- /* freetype2 face. */
- FT_Face face;
-
/* list of glyph cache for this font. */
ListBase cache;
/* current glyph cache, size and dpi. */
GlyphCacheBLF *glyph_cache;
+
+ /* engine data. */
+ void *engine;
} FontBLF;
-#endif /* WITH_FREETYPE2 */
+typedef struct DirBLF {
+ struct DirBLF *next;
+ struct DirBLF *prev;
+
+ /* full path where search fonts. */
+ char *path;
+} DirBLF;
typedef struct LangBLF {
struct LangBLF *next;
@@ -193,4 +189,8 @@ typedef struct LangBLF {
#define BLF_CLIP_DISABLE 0
#define BLF_CLIP_OUT 1
+/* font->type */
+#define BLF_FONT_FREETYPE2 0
+#define BLF_FONT_INTERNAL 1
+
#endif /* BLF_INTERNAL_TYPES_H */