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:
authorCampbell Barton <ideasman42@gmail.com>2012-10-12 03:42:26 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-10-12 03:42:26 +0400
commit4124e2e0c9d42ec8d84ef06025932abeb333cd65 (patch)
treef0cbd062c81b888a6b0ce9c16f23227edb22050b /source/blender/blenfont
parent0e6e171cddf6740d9c20113303b82695943e0899 (diff)
get the width and height of the font at once when drawing auto-key,
also move BLF'g global font init into its own static function.
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r--source/blender/blenfont/BLF_api.h1
-rw-r--r--source/blender/blenfont/intern/blf.c118
2 files changed, 64 insertions, 55 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index ce10951d6ff..6f348ccc267 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -109,6 +109,7 @@ float BLF_fixed_width(int fontid);
* of the string, using the default font and both value
* are multiplied by the aspect of the font.
*/
+void BLF_width_and_height_default(const char *str, float *width, float *height);
float BLF_width_default(const char *str);
float BLF_height_default(const char *str);
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 92fcb576e7d..f3cc92e7a27 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -69,7 +69,7 @@ static int global_font_dpi = 72;
int blf_mono_font = -1;
int blf_mono_font_render = -1;
-static FontBLF *BLF_get(int fontid)
+static FontBLF *blf_get(int fontid)
{
if (fontid >= 0 && fontid < BLF_MAX_FONT)
return global_font[fontid];
@@ -141,6 +141,21 @@ static int blf_search_available(void)
return -1;
}
+static int blf_global_font_init(void)
+{
+ if (global_font_default == -1) {
+ global_font_default = blf_search("default");
+ }
+
+ if (global_font_default == -1) {
+ printf("Warning: Can't find default font!\n");
+ return 0;
+ }
+ else {
+ return 1;
+ }
+}
+
int BLF_load(const char *name)
{
FontBLF *font;
@@ -219,7 +234,7 @@ int BLF_load_unique(const char *name)
void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
blf_font_attach_from_mem(font, mem, mem_size);
@@ -311,7 +326,7 @@ void BLF_unload(const char *name)
void BLF_enable(int fontid, int option)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
font->flags |= option;
@@ -320,7 +335,7 @@ void BLF_enable(int fontid, int option)
void BLF_disable(int fontid, int option)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
font->flags &= ~option;
@@ -329,7 +344,7 @@ void BLF_disable(int fontid, int option)
void BLF_enable_default(int option)
{
- FontBLF *font = BLF_get(global_font_default);
+ FontBLF *font = blf_get(global_font_default);
if (font) {
font->flags |= option;
@@ -338,7 +353,7 @@ void BLF_enable_default(int option)
void BLF_disable_default(int option)
{
- FontBLF *font = BLF_get(global_font_default);
+ FontBLF *font = blf_get(global_font_default);
if (font) {
font->flags &= ~option;
@@ -347,7 +362,7 @@ void BLF_disable_default(int option)
void BLF_aspect(int fontid, float x, float y, float z)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
font->aspect[0] = x;
@@ -358,7 +373,7 @@ void BLF_aspect(int fontid, float x, float y, float z)
void BLF_matrix(int fontid, const double m[16])
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
memcpy(font->m, m, sizeof(font->m));
@@ -367,7 +382,7 @@ void BLF_matrix(int fontid, const double m[16])
void BLF_position(int fontid, float x, float y, float z)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
float xa, ya, za;
@@ -416,7 +431,7 @@ void BLF_position(int fontid, float x, float y, float z)
void BLF_size(int fontid, int size, int dpi)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
blf_font_size(font, size, dpi);
@@ -425,7 +440,7 @@ void BLF_size(int fontid, int size, int dpi)
void BLF_blur(int fontid, int size)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
font->blur = size;
@@ -437,13 +452,8 @@ void BLF_draw_default(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");
+ if (!blf_global_font_init())
return;
- }
BLF_size(global_font_default, global_font_points, global_font_dpi);
BLF_position(global_font_default, x, y, z);
@@ -456,13 +466,8 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l
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");
+ if (!blf_global_font_init())
return;
- }
BLF_size(global_font_default, global_font_points, global_font_dpi);
BLF_position(global_font_default, x, y, z);
@@ -471,7 +476,7 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l
void BLF_rotation_default(float angle)
{
- FontBLF *font = BLF_get(global_font_default);
+ FontBLF *font = blf_get(global_font_default);
if (font) {
font->angle = angle;
@@ -543,7 +548,7 @@ static void blf_draw__end(GLint mode, GLint param)
void BLF_draw(int fontid, const char *str, size_t len)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
GLint mode, param;
if (font && font->glyph_cache) {
@@ -555,7 +560,7 @@ void BLF_draw(int fontid, const char *str, size_t len)
void BLF_draw_ascii(int fontid, const char *str, size_t len)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
GLint mode, param;
if (font && font->glyph_cache) {
@@ -567,7 +572,7 @@ void BLF_draw_ascii(int fontid, const char *str, size_t len)
void BLF_boundbox(int fontid, const char *str, rctf *box)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
blf_font_boundbox(font, str, box);
@@ -576,16 +581,29 @@ void BLF_boundbox(int fontid, const char *str, rctf *box)
void BLF_width_and_height(int fontid, const char *str, float *width, float *height)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font && font->glyph_cache) {
blf_font_width_and_height(font, str, width, height);
}
+ else {
+ *width = *height = 0.0f;
+ }
+}
+
+void BLF_width_and_height_default(const char *str, float *width, float *height)
+{
+ if (!blf_global_font_init()) {
+ *width = *height = 0.0f;
+ return;
+ }
+
+ BLF_width_and_height(global_font_default, str, width, height);
}
float BLF_width(int fontid, const char *str)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font && font->glyph_cache) {
return blf_font_width(font, str);
@@ -596,7 +614,7 @@ float BLF_width(int fontid, const char *str)
float BLF_fixed_width(int fontid)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font && font->glyph_cache) {
return blf_font_fixed_width(font);
@@ -607,13 +625,8 @@ float BLF_fixed_width(int fontid)
float BLF_width_default(const char *str)
{
- if (global_font_default == -1)
- global_font_default = blf_search("default");
-
- if (global_font_default == -1) {
- printf("Error: Can't found default font!!\n");
+ if (!blf_global_font_init())
return 0.0f;
- }
BLF_size(global_font_default, global_font_points, global_font_dpi);
return BLF_width(global_font_default, str);
@@ -621,7 +634,7 @@ float BLF_width_default(const char *str)
float BLF_height(int fontid, const char *str)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font && font->glyph_cache) {
return blf_font_height(font, str);
@@ -632,7 +645,7 @@ float BLF_height(int fontid, const char *str)
float BLF_height_max(int fontid)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font && font->glyph_cache) {
return font->glyph_cache->max_glyph_height;
@@ -643,7 +656,7 @@ float BLF_height_max(int fontid)
float BLF_width_max(int fontid)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font && font->glyph_cache) {
return font->glyph_cache->max_glyph_width;
@@ -654,7 +667,7 @@ float BLF_width_max(int fontid)
float BLF_descender(int fontid)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font && font->glyph_cache) {
return font->glyph_cache->descender;
@@ -665,7 +678,7 @@ float BLF_descender(int fontid)
float BLF_ascender(int fontid)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font && font->glyph_cache) {
return font->glyph_cache->ascender;
@@ -676,13 +689,8 @@ float BLF_ascender(int fontid)
float BLF_height_default(const char *str)
{
- if (global_font_default == -1)
- global_font_default = blf_search("default");
-
- if (global_font_default == -1) {
- printf("Error: Can't found default font!!\n");
+ if (!blf_global_font_init())
return 0.0f;
- }
BLF_size(global_font_default, global_font_points, global_font_dpi);
@@ -691,7 +699,7 @@ float BLF_height_default(const char *str)
void BLF_rotation(int fontid, float angle)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
font->angle = angle;
@@ -700,7 +708,7 @@ void BLF_rotation(int fontid, float angle)
void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
font->clip_rec.xmin = xmin;
@@ -712,7 +720,7 @@ void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax)
void BLF_clipping_default(float xmin, float ymin, float xmax, float ymax)
{
- FontBLF *font = BLF_get(global_font_default);
+ FontBLF *font = blf_get(global_font_default);
if (font) {
font->clip_rec.xmin = xmin;
@@ -724,7 +732,7 @@ void BLF_clipping_default(float xmin, float ymin, float xmax, float ymax)
void BLF_shadow(int fontid, int level, float r, float g, float b, float a)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
font->shadow = level;
@@ -737,7 +745,7 @@ void BLF_shadow(int fontid, int level, float r, float g, float b, float a)
void BLF_shadow_offset(int fontid, int x, int y)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
font->shadow_x = x;
@@ -747,7 +755,7 @@ void BLF_shadow_offset(int fontid, int x, int y)
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch, struct ColorManagedDisplay *display)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
font->buf_info.fbuf = fbuf;
@@ -761,7 +769,7 @@ void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int
void BLF_buffer_col(int fontid, float r, float g, float b, float a)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font) {
font->buf_info.col[0] = r;
@@ -773,7 +781,7 @@ void BLF_buffer_col(int fontid, float r, float g, float b, float a)
void BLF_draw_buffer(int fontid, const char *str)
{
- FontBLF *font = BLF_get(fontid);
+ FontBLF *font = blf_get(fontid);
if (font && font->glyph_cache && (font->buf_info.fbuf || font->buf_info.cbuf)) {
blf_font_buffer(font, str);