Revision: 20820
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20820
Author:   bdiego
Date:     2009-06-11 23:43:59 +0200 (Thu, 11 Jun 2009)

Log Message:
-----------
Smal tweak to allow the user set a kerning value.

This commit add two option to the blenfont library:

1) BLF_FONT_KERNING

 This enable the kerning information that come with the
font, by default this option is disable and still don't
have a UI for change.

2) BLF USER_KERNING
 This allow the user set a kerning value to by apply for
every character, by default this option is enable but all
the font have a kerning value of zero.

Ton I add this option to the style with a default value of 1.

Access from:
 Outliner -> User Preferences -> Style -> FontStyle -> Kerning

Modified Paths:
--------------
    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_types.h
    
branches/blender2.5/blender/source/blender/editors/interface/interface_style.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_userdef_types.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_userdef.c

Modified: branches/blender2.5/blender/source/blender/blenfont/BLF_api.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/BLF_api.h       
2009-06-11 21:11:33 UTC (rev 20819)
+++ branches/blender2.5/blender/source/blender/blenfont/BLF_api.h       
2009-06-11 21:43:59 UTC (rev 20820)
@@ -85,8 +85,8 @@
 void BLF_rotation(float angle);
 void BLF_clipping(float xmin, float ymin, float xmax, float ymax);
 void BLF_blur(int size);
+void BLF_kerning(int space);
 
-
 void BLF_enable(int option);
 void BLF_disable(int option);
 
@@ -117,6 +117,8 @@
 /* font->flags. */
 #define BLF_ROTATION (1<<0)
 #define BLF_CLIPPING (1<<1)
+#define BLF_FONT_KERNING (1<<2)
+#define BLF_USER_KERNING (1<<3)
 
 /* font->mode. */
 #define BLF_MODE_TEXTURE 0

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf.c    
2009-06-11 21:11:33 UTC (rev 20819)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf.c    
2009-06-11 21:43:59 UTC (rev 20820)
@@ -491,3 +491,12 @@
        if (font)
                font->mode= mode;
 }
+
+void BLF_kerning(int space)
+{
+       FontBLF *font;
+
+       font= global_font[global_font_cur];
+       if (font)
+               font->kerning= space;
+}

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c       
2009-06-11 21:11:33 UTC (rev 20819)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c       
2009-06-11 21:43:59 UTC (rev 20820)
@@ -100,7 +100,7 @@
        GlyphBLF *g, *g_prev;
        FT_Vector delta;
        FT_UInt glyph_index, g_prev_index;
-       int pen_x, pen_y;
+       int pen_x, pen_y, old_pen_x;
        int i, has_kerning;
 
        if (!font->glyph_cache)
@@ -138,14 +138,26 @@
                else if (font->mode == BLF_MODE_TEXTURE && (!g->tex_data))
                        g= blf_glyph_add(font, glyph_index, c);
 
-               if (has_kerning && g_prev) {
+               if ((font->flags & BLF_FONT_KERNING) && has_kerning && g_prev) {
+                       old_pen_x= pen_x;
                        delta.x= 0;
                        delta.y= 0;
 
                        FT_Get_Kerning(font->face, g_prev_index, glyph_index, 
FT_KERNING_UNFITTED, &delta);
                        pen_x += delta.x >> 6;
+
+                       if (pen_x < old_pen_x)
+                               pen_x= old_pen_x;
                }
 
+               if (font->flags & BLF_USER_KERNING) {
+                       old_pen_x= pen_x;
+                       pen_x += font->kerning;
+
+                       if (pen_x < old_pen_x)
+                               pen_x= old_pen_x;
+               }
+
                /* do not return this loop if clipped, we want every character 
tested */
                blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
 
@@ -162,7 +174,7 @@
        FT_Vector delta;
        FT_UInt glyph_index, g_prev_index;
        rctf gbox;
-       int pen_x, pen_y;
+       int pen_x, pen_y, old_pen_x;
        int i, has_kerning;
 
        if (!font->glyph_cache)
@@ -205,14 +217,26 @@
                else if (font->mode == BLF_MODE_TEXTURE && (!g->tex_data))
                        g= blf_glyph_add(font, glyph_index, c);
 
-               if (has_kerning && g_prev) {
+               if ((font->flags & BLF_FONT_KERNING) && has_kerning && g_prev) {
+                       old_pen_x= pen_x;
                        delta.x= 0;
                        delta.y= 0;
 
                        FT_Get_Kerning(font->face, g_prev_index, glyph_index, 
FT_KERNING_UNFITTED, &delta);
                        pen_x += delta.x >> 6;
+
+                       if (pen_x < old_pen_x)
+                               old_pen_x= pen_x;
                }
 
+               if (font->flags & BLF_USER_KERNING) {
+                       old_pen_x= pen_x;
+                       pen_x += font->kerning;
+
+                       if (pen_x < old_pen_x)
+                               old_pen_x= pen_x;
+               }
+
                gbox.xmin= g->box.xmin + pen_x;
                gbox.xmax= g->box.xmax + pen_x;
                gbox.ymin= g->box.ymin + pen_y;
@@ -294,9 +318,10 @@
        font->clip_rec.xmax= 0.0f;
        font->clip_rec.ymin= 0.0f;
        font->clip_rec.ymax= 0.0f;
-       font->flags= 0;
+       font->flags= BLF_USER_KERNING;
        font->dpi= 0;
        font->size= 0;
+       font->kerning= 0;
        font->cache.first= NULL;
        font->cache.last= NULL;
        font->glyph_cache= NULL;

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c      
2009-06-11 21:11:33 UTC (rev 20819)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c      
2009-06-11 21:43:59 UTC (rev 20820)
@@ -213,7 +213,11 @@
        else
                do_new= 1;
 
-       err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | 
FT_LOAD_NO_BITMAP);
+       if (font->flags & BLF_FONT_KERNING)
+               err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_BITMAP);
+       else
+               err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | 
FT_LOAD_NO_BITMAP);
+
        if (err)
                return(NULL);
 
@@ -328,7 +332,11 @@
        else
                do_new= 1;
 
-       err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | 
FT_LOAD_NO_BITMAP);
+       if (font->flags & BLF_FONT_KERNING)
+               err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_BITMAP);
+       else
+               err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | 
FT_LOAD_NO_BITMAP);
+
        if (err)
                return(NULL);
 

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-06-11 21:11:33 UTC (rev 20819)
+++ 
branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h 
    2009-06-11 21:43:59 UTC (rev 20820)
@@ -167,6 +167,9 @@
        /* font size. */
        int size;
 
+       /* kerning space, user setting. */
+       int kerning;
+
        /* max texture size. */
        int max_tex_size;
 

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface_style.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_style.c  
    2009-06-11 21:11:33 UTC (rev 20819)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_style.c  
    2009-06-11 21:43:59 UTC (rev 20820)
@@ -91,6 +91,7 @@
        
        style->paneltitle.uifont_id= UIFONT_DEFAULT;
        style->paneltitle.points= 13;
+       style->paneltitle.kerning= 1;
        style->paneltitle.shadow= 5;
        style->paneltitle.shadx= 2;
        style->paneltitle.shady= -2;
@@ -99,6 +100,7 @@
        
        style->grouplabel.uifont_id= UIFONT_DEFAULT;
        style->grouplabel.points= 12;
+       style->grouplabel.kerning= 1;
        style->grouplabel.shadow= 3;
        style->grouplabel.shadx= 1;
        style->grouplabel.shady= -1;
@@ -106,6 +108,7 @@
        
        style->widgetlabel.uifont_id= UIFONT_DEFAULT;
        style->widgetlabel.points= 11;
+       style->widgetlabel.kerning= 1;
        style->widgetlabel.shadow= 3;
        style->widgetlabel.shadx= 1;
        style->widgetlabel.shady= -1;
@@ -114,6 +117,7 @@
        
        style->widget.uifont_id= UIFONT_DEFAULT;
        style->widget.points= 11;
+       style->widget.kerning= 1;
        style->widget.shadowalpha= 0.25f;
 
        style->columnspace= 5;
@@ -263,5 +267,6 @@
        
        BLF_set(font->blf_id);
        BLF_size(fs->points, U.dpi);
+       BLF_kerning(fs->kerning);
 }
 

Modified: 
branches/blender2.5/blender/source/blender/makesdna/DNA_userdef_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesdna/DNA_userdef_types.h     
2009-06-11 21:11:33 UTC (rev 20819)
+++ branches/blender2.5/blender/source/blender/makesdna/DNA_userdef_types.h     
2009-06-11 21:43:59 UTC (rev 20820)
@@ -66,6 +66,8 @@
 typedef struct uiFontStyle {
        short uifont_id;                /* saved in file, 0 is default */
        short points;                   /* actual size depends on 'global' dpi 
*/
+       short kerning;                  /* kerning space between characters. */
+       char pad[6];
        short italic, bold;             /* style hint */
        short shadow;                   /* value is amount of pixels blur */
        short shadx, shady;             /* shadow offset in pixels */

Modified: 
branches/blender2.5/blender/source/blender/makesrna/intern/rna_userdef.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_userdef.c    
2009-06-11 21:11:33 UTC (rev 20819)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_userdef.c    
2009-06-11 21:43:59 UTC (rev 20820)
@@ -135,7 +135,11 @@
        prop= RNA_def_property(srna, "points", PROP_INT, PROP_NONE);
        RNA_def_property_range(prop, 6, 48);
        RNA_def_property_ui_text(prop, "Points", "");
-       
+
+       prop= RNA_def_property(srna, "kerning", PROP_INT, PROP_NONE);
+       RNA_def_property_range(prop, -5, 5);
+       RNA_def_property_ui_text(prop, "Kerning", "");
+
        prop= RNA_def_property(srna, "shadow", PROP_INT, PROP_NONE);
        RNA_def_property_range(prop, 0, 5);
        RNA_def_property_ui_text(prop, "Shadow Size", "Shadow size in pixels 
(0, 3 and 5 supported)");


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

Reply via email to