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-02-20 08:42:44 +0300
committerDiego Borghetti <bdiego@gmail.com>2009-02-20 08:42:44 +0300
commit8145489a7dc2889bc0fa61f0e23c4dc0f7b300be (patch)
treebcf58e46a5844e2b3852576578a4e8aaa3b716fd /source/blender/blenfont
parent72e99d918215ed549a84e360530fc99d1caf56a1 (diff)
Add clipping text option to blenfont also add an enable/disable
function for aspect and rotation (and the new clipping). Update source/Makefile to point to the new libed_sculpt_paint.
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r--source/blender/blenfont/BLF_api.h9
-rw-r--r--source/blender/blenfont/intern/blf.c62
-rw-r--r--source/blender/blenfont/intern/blf_font.c24
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c33
-rw-r--r--source/blender/blenfont/intern/blf_internal.h2
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h6
6 files changed, 113 insertions, 23 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index decdbec8d7e..1485f0881b2 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -45,6 +45,10 @@ void BLF_boundbox(char *str, rctf *box);
float BLF_width(char *str);
float BLF_height(char *str);
void BLF_rotation(float angle);
+void BLF_clipping(float xmin, float ymin, float xmax, float ymax);
+
+void BLF_enable(int option);
+void BLF_disable(int option);
/* Read the .Blanguages file, return 1 on success or 0 if fails. */
int BLF_lang_init(void);
@@ -78,4 +82,9 @@ char **BLF_dir_get(int *ndir);
/* Free the data return by BLF_dir_get. */
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)
+
#endif /* BLF_API_H */
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 1b29f3ebdd8..5b39c2c8ae5 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -53,11 +53,11 @@
#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "BLF_api.h"
#include "blf_internal_types.h"
#include "blf_internal.h"
-
#ifdef WITH_FREETYPE2
/* Max number of font in memory.
@@ -215,6 +215,28 @@ void BLF_set(int fontid)
#endif
}
+void BLF_enable(int option)
+{
+#ifdef WITH_FREETYPE2
+ FontBLF *font;
+
+ font= global_font[global_font_cur];
+ if (font)
+ font->flags |= option;
+#endif
+}
+
+void BLF_disable(int option)
+{
+#ifdef WITH_FREETYPE2
+ FontBLF *font;
+
+ font= global_font[global_font_cur];
+ if (font)
+ font->flags &= ~option;
+#endif
+}
+
void BLF_aspect(float aspect)
{
#ifdef WITH_FREETYPE2
@@ -230,24 +252,29 @@ void BLF_position(float x, float y, float z)
{
#ifdef WITH_FREETYPE2
FontBLF *font;
- float remainder;
+ float remainder, aspect;
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 * font->aspect;
+ x -= 0.1 * aspect;
else
- x += 0.1 * font->aspect;
+ x += 0.1 * aspect;
}
remainder= y - floor(y);
if (remainder > 0.4 && remainder < 0.6) {
if (remainder < 0.5)
- y -= 0.1 * font->aspect;
+ y -= 0.1 * aspect;
else
- y += 0.1 * font->aspect;
+ y += 0.1 * aspect;
}
font->pos[0]= x;
@@ -281,8 +308,12 @@ void BLF_draw(char *str)
glPushMatrix();
glTranslatef(font->pos[0], font->pos[1], font->pos[2]);
- glScalef(font->aspect, font->aspect, 1.0);
- glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
+
+ 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);
blf_font_draw(font, str);
@@ -338,3 +369,18 @@ void BLF_rotation(float angle)
font->angle= angle;
#endif
}
+
+void BLF_clipping(float xmin, float ymin, float xmax, float ymax)
+{
+#ifdef WITH_FREETYPE2
+ FontBLF *font;
+
+ font= global_font[global_font_cur];
+ if (font) {
+ font->clip_rec.xmin= xmin;
+ font->clip_rec.ymin= ymin;
+ font->clip_rec.xmax= xmax;
+ font->clip_rec.ymax= ymax;
+ }
+#endif
+}
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 825de7a62d2..44847e72727 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -52,6 +52,7 @@
#include "BLI_arithb.h"
#include "BIF_gl.h"
+#include "BLF_api.h"
#include "blf_internal_types.h"
#include "blf_internal.h"
@@ -84,7 +85,7 @@ void blf_font_fill(FontBLF *font)
font->clip_rec.xmax= 0.0f;
font->clip_rec.ymin= 0.0f;
font->clip_rec.ymax= 0.0f;
- font->clip_mode= BLF_CLIP_DISABLE;
+ font->flags= 0;
font->dpi= 0;
font->size= 0;
font->cache.first= NULL;
@@ -209,7 +210,10 @@ void blf_font_draw(FontBLF *font, char *str)
pen_x += delta.x >> 6;
}
- blf_glyph_render(g, (float)pen_x, (float)pen_y);
+ /* This only return zero if the clipping is enable and the glyph is out of the clip rctf. */
+ if (blf_glyph_render(font, g, (float)pen_x, (float)pen_y) == 0)
+ break;
+
pen_x += g->advance;
g_prev= g;
}
@@ -287,18 +291,30 @@ 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) * font->aspect);
+ return((box.xmax - box.xmin) * 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) * font->aspect);
+ return((box.ymax - box.ymin) * aspect);
}
void blf_font_free(FontBLF *font)
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index 3918be3d469..2bbdeb9ad32 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -53,6 +53,7 @@
#include "BLI_string.h"
#include "BIF_gl.h"
+#include "BLF_api.h"
#include "blf_internal_types.h"
#include "blf_internal.h"
@@ -293,29 +294,47 @@ void blf_glyph_free(GlyphBLF *g)
MEM_freeN(g);
}
-void blf_glyph_render(GlyphBLF *g, float x, float y)
+int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
{
GLint cur_tex;
- float dx;
+ float dx, dx1;
+ float y1, y2;
+
+ dx= floor(x + g->pos_x);
+ dx1= dx + g->width;
+ y1= y + g->pos_y;
+ y2= y + g->pos_y - g->height;
+
+ if (font->flags & BLF_CLIPPING) {
+ if (!BLI_in_rctf(&font->clip_rec, dx + font->pos[0], y1 + font->pos[1]))
+ return(0);
+ if (!BLI_in_rctf(&font->clip_rec, dx + font->pos[0], y2 + font->pos[1]))
+ return(0);
+ if (!BLI_in_rctf(&font->clip_rec, dx1 + font->pos[0], y2 + font->pos[1]))
+ return(0);
+ if (!BLI_in_rctf(&font->clip_rec, dx1 + font->pos[0], y1 + font->pos[1]))
+ return(0);
+ }
glGetIntegerv(GL_TEXTURE_2D_BINDING_EXT, &cur_tex);
if (cur_tex != g->tex)
glBindTexture(GL_TEXTURE_2D, g->tex);
- dx= floor(x + g->pos_x);
glBegin(GL_QUADS);
glTexCoord2f(g->uv[0][0], g->uv[0][1]);
- glVertex2f(dx, y + g->pos_y);
+ glVertex2f(dx, y1);
glTexCoord2f(g->uv[0][0], g->uv[1][1]);
- glVertex2f(dx, y + g->pos_y - g->height);
+ glVertex2f(dx, y2);
glTexCoord2f(g->uv[1][0], g->uv[1][1]);
- glVertex2f(dx + g->width, y + g->pos_y - g->height);
+ glVertex2f(dx1, y2);
glTexCoord2f(g->uv[1][0], g->uv[0][1]);
- glVertex2f(dx + g->width, y + g->pos_y);
+ glVertex2f(dx1, y1);
glEnd();
+
+ return(1);
}
#endif /* WITH_FREETYPE2 */
diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h
index 6afb019c5b4..25df7e0e95f 100644
--- a/source/blender/blenfont/intern/blf_internal.h
+++ b/source/blender/blenfont/intern/blf_internal.h
@@ -58,7 +58,7 @@ GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, FT_UInt idx);
GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c);
void blf_glyph_free(GlyphBLF *g);
-void blf_glyph_render(GlyphBLF *g, float x, float y);
+int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y);
#endif /* WITH_FREETYPE2 */
#endif /* BLF_INTERNAL_H */
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index a0198283869..ccfd5c64200 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -151,9 +151,6 @@ typedef struct FontBLF {
/* clipping rectangle. */
rctf clip_rec;
- /* and clipping mode. */
- int clip_mode;
-
/* font dpi (default 72). */
int dpi;
@@ -163,6 +160,9 @@ typedef struct FontBLF {
/* max texture size. */
int max_tex_size;
+ /* font options. */
+ int flags;
+
/* freetype2 face. */
FT_Face face;