[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19168] branches/blender2.5/blender/source /blender: Cleanup a little before add internal font (bmfont).
Diego Borghetti
bdiego at gmail.com
Mon Mar 2 06:21:11 CET 2009
Revision: 19168
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19168
Author: bdiego
Date: 2009-03-02 06:20:48 +0100 (Mon, 02 Mar 2009)
Log Message:
-----------
Cleanup a little before add internal font (bmfont).
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/blenfont/BLF_api.h
branches/blender2.5/blender/source/blender/blenfont/intern/blf.c
branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c
branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c
branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal.h
branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h
branches/blender2.5/blender/source/blender/editors/space_info/space_info.c
Modified: branches/blender2.5/blender/source/blender/blenfont/BLF_api.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/BLF_api.h 2009-03-02 04:08:24 UTC (rev 19167)
+++ branches/blender2.5/blender/source/blender/blenfont/BLF_api.h 2009-03-02 05:20:48 UTC (rev 19168)
@@ -85,8 +85,7 @@
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 */
Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf.c 2009-03-02 04:08:24 UTC (rev 19167)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf.c 2009-03-02 05:20:48 UTC (rev 19168)
@@ -252,29 +252,24 @@
{
#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,10 +303,8 @@
glPushMatrix();
glTranslatef(font->pos[0], font->pos[1], font->pos[2]);
+ glScalef(font->aspect, font->aspect, 1.0);
- if (font->flags & BLF_ASPECT)
- glScalef(font->aspect, font->aspect, 1.0);
-
if (font->flags & BLF_ROTATION)
glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c 2009-03-02 04:08:24 UTC (rev 19167)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c 2009-03-02 05:20:48 UTC (rev 19168)
@@ -75,6 +75,7 @@
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 *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 *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 @@
{
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 @@
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 @@
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 @@
pen_x += g->advance;
g_prev= g;
+ g_prev_index= glyph_index;
}
}
@@ -224,11 +227,13 @@
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 @@
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 @@
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 @@
pen_x += g->advance;
g_prev= g;
+ g_prev_index= glyph_index;
}
if (box->xmin > box->xmax) {
@@ -291,30 +298,18 @@
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 @@
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)
Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c 2009-03-02 04:08:24 UTC (rev 19167)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c 2009-03-02 05:20:48 UTC (rev 19168)
@@ -78,8 +78,10 @@
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 @@
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 @@
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 @@
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);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list