Add clipping text option to blenfont also add an enable/disable
authorDiego Borghetti <bdiego@gmail.com>
Fri, 20 Feb 2009 05:42:44 +0000 (05:42 +0000)
committerDiego Borghetti <bdiego@gmail.com>
Fri, 20 Feb 2009 05:42:44 +0000 (05:42 +0000)
function for aspect and rotation (and the new clipping).

Update source/Makefile to point to the new libed_sculpt_paint.

source/Makefile
source/blender/blenfont/BLF_api.h
source/blender/blenfont/intern/blf.c
source/blender/blenfont/intern/blf_font.c
source/blender/blenfont/intern/blf_glyph.c
source/blender/blenfont/intern/blf_internal.h
source/blender/blenfont/intern/blf_internal_types.h

index d9dd29143b540979448bde13158e5a591b23b47d..90e93d55f6edd82d935c5e22654607381be3e914 100644 (file)
@@ -242,7 +242,7 @@ PULIB += $(OCGDIR)/blender/ed_object/libed_object.a
 PULIB += $(OCGDIR)/blender/ed_curve/libed_curve.a
 PULIB += $(OCGDIR)/blender/ed_armature/libed_armature.a
 PULIB += $(OCGDIR)/blender/ed_mesh/libed_mesh.a
-PULIB += $(OCGDIR)/blender/ed_sculpt/libed_sculpt.a
+PULIB += $(OCGDIR)/blender/ed_sculpt_paint/libed_sculpt_paint.a
 PULIB += $(OCGDIR)/blender/ed_physics/libed_physics.a
 PULIB += $(OCGDIR)/blender/ed_animation/libed_animation.a
 PULIB += $(OCGDIR)/blender/ed_transform/libed_transform.a
index decdbec8d7ea946fe9fc8ec4607485075649cbcc..1485f0881b2dceadb89f7e3cfbd6e21f156ca731 100644 (file)
@@ -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 */
index 1b29f3ebdd87c4bdf8e28bf394b805002763e78c..5b39c2c8ae52bf00558eed9532bc60f66f8c7d45 100644 (file)
 
 #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
+}
index 825de7a62d2cec1eae92cb4d4f9a1ff4fb4f9218..44847e727278bea5bf9cb81acc7bcc8b4c5ac2d8 100644 (file)
@@ -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)
index 3918be3d469e947083d870eac7f1e63913a781dd..2bbdeb9ad328e19c51d2abc98722c6ad834bdfdd 100644 (file)
@@ -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 */
index 6afb019c5b49b3e8a74ec8bc7493ed22bbe3c03e..25df7e0e95ffb9e79f48a585b2cb434b7811c43c 100644 (file)
@@ -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 */
index a01982838698fa28949680df7bd3e010e896e6ca..ccfd5c64200f5874274415823b569201d385f151 100644 (file)
@@ -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;