From 545cc4803e8e9e7418aba98b2c1bec72fa629146 Mon Sep 17 00:00:00 2001 From: Diego Borghetti Date: Thu, 9 Dec 2010 22:27:55 +0000 Subject: Change the BLF_aspect function to handle 3d text. This is need to properly handle 3d text (dalai work on GE), before the BLF_aspect only take one argument, and the result was a call to: glScalef(aspect, aspect, 1.0) Now the three value are store in the font (x, y and z) and also need to be enable using BLF_enable(BLF_ASPECT). By default all the code that don't have BLF_ASPECT enable work with a scale of 1.0 (so nothing change to the current UI). I also remove all the call of BLF_aspect(fontid, 1.0) found in the editors, because is disable by default, so no need any more. Campbell the only thing to check is the python api, right now I modify the api to from: BLF_aspect(fontid, aspect) to: BLF_aspect(fontid, aspect, aspect, 1.0) This is to avoid break the api, but now you need add the BLF_ASPECT option to the function py_blf_enable and in some point change py_blf_aspect to take 3 arguments. --- source/blender/blenfont/BLF_api.h | 3 +- source/blender/blenfont/intern/blf.c | 44 +++++++++++++++++----- source/blender/blenfont/intern/blf_font.c | 34 ++++++++++++++--- .../blender/blenfont/intern/blf_internal_types.h | 2 +- 4 files changed, 67 insertions(+), 16 deletions(-) (limited to 'source/blender/blenfont') diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 84086742b15..b696c64023d 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -45,7 +45,7 @@ int BLF_load_mem_unique(const char *name, unsigned char *mem, int mem_size); /* Attach a file with metrics information from memory. */ void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size); -void BLF_aspect(int fontid, float aspect); +void BLF_aspect(int fontid, float x, float y, float z); void BLF_position(int fontid, float x, float y, float z); void BLF_size(int fontid, int size, int dpi); @@ -195,6 +195,7 @@ void BLF_dir_free(char **dirs, int count); #define BLF_SHADOW (1<<2) #define BLF_KERNING_DEFAULT (1<<3) #define BLF_MATRIX (1<<4) +#define BLF_ASPECT (1<<5) // XXX, bad design extern int blf_mono_font; diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index d9a02b09336..3ac0b8449b0 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -321,13 +321,16 @@ 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) @@ -346,23 +349,43 @@ 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 * font->aspect; + y += 0.1 * ya; + } + + remainder= z - floor(z); + if (remainder > 0.4 && remainder < 0.6) { + if (remainder < 0.5) + z -= 0.1 * za; + else + z += 0.1 * za; } font->pos[0]= x; @@ -406,6 +429,7 @@ void BLF_draw_default(float x, float y, float z, const char *str, size_t len) BLF_position(global_font_default, x, y, z); 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) { @@ -434,7 +458,6 @@ void BLF_rotation_default(float angle) font->angle= angle; } - static void blf_draw__start(FontBLF *font) { /* @@ -452,11 +475,14 @@ static void blf_draw__start(FontBLF *font) glMultMatrixd((GLdouble *)&font->m); 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[0], font->aspect[1], font->aspect[2]); if (font->flags & BLF_ROTATION) glRotatef(font->angle, 0.0f, 0.0f, 1.0f); } + static void blf_draw__end(void) { glPopMatrix(); diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 3adda7bb6f1..d1dcf7aa9b3 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -420,35 +420,57 @@ 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 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, 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, 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) @@ -495,7 +517,9 @@ static void blf_font_fill(FontBLF *font) { int i; - font->aspect= 1.0f; + 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; diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h index 04afaeb2e97..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]; -- cgit v1.2.3