Revision: 19049
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19049
Author:   bdiego
Date:     2009-02-20 06:42:44 +0100 (Fri, 20 Feb 2009)

Log Message:
-----------
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.

Modified Paths:
--------------
    branches/blender2.5/blender/source/Makefile
    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

Modified: branches/blender2.5/blender/source/Makefile
===================================================================
--- branches/blender2.5/blender/source/Makefile 2009-02-20 05:42:09 UTC (rev 
19048)
+++ branches/blender2.5/blender/source/Makefile 2009-02-20 05:42:44 UTC (rev 
19049)
@@ -242,7 +242,7 @@
 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

Modified: branches/blender2.5/blender/source/blender/blenfont/BLF_api.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/BLF_api.h       
2009-02-20 05:42:09 UTC (rev 19048)
+++ branches/blender2.5/blender/source/blender/blenfont/BLF_api.h       
2009-02-20 05:42:44 UTC (rev 19049)
@@ -45,7 +45,11 @@
 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 @@
 /* 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 */

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf.c    
2009-02-20 05:42:09 UTC (rev 19048)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf.c    
2009-02-20 05:42:44 UTC (rev 19049)
@@ -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 @@
 #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 @@
 {
 #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,9 +308,13 @@
 
                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);
 
                glPopMatrix();
@@ -338,3 +369,18 @@
                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
+}

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c       
2009-02-20 05:42:09 UTC (rev 19048)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c       
2009-02-20 05:42:44 UTC (rev 19049)
@@ -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 @@
        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 @@
                        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 @@
 
 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)

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c      
2009-02-20 05:42:09 UTC (rev 19048)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c      
2009-02-20 05:42:44 UTC (rev 19049)
@@ -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 @@
        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 */

Modified: 
branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal.h   
2009-02-20 05:42:09 UTC (rev 19048)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal.h   
2009-02-20 05:42:44 UTC (rev 19049)
@@ -58,7 +58,7 @@
 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 */

Modified: 
branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h
===================================================================
--- 
branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h 
    2009-02-20 05:42:09 UTC (rev 19048)
+++ 
branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h 
    2009-02-20 05:42:44 UTC (rev 19049)
@@ -151,9 +151,6 @@
        /* clipping rectangle. */
        rctf clip_rec;
 
-       /* and clipping mode. */
-       int clip_mode;
-
        /* font dpi (default 72). */
        int dpi;
 
@@ -163,6 +160,9 @@
        /* max texture size. */
        int max_tex_size;
 
+       /* font options. */
+       int flags;
+
        /* freetype2 face. */
        FT_Face face;
 


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to