New Style option: Overlap
authorDiego Borghetti <bdiego@gmail.com>
Tue, 23 Jun 2009 18:26:01 +0000 (18:26 +0000)
committerDiego Borghetti <bdiego@gmail.com>
Tue, 23 Jun 2009 18:26:01 +0000 (18:26 +0000)
If this option is enable, the blenfont check for overlap characters, like
one of my previous commit but now it's optional and disable by default.
(This fix the "Fi" or other case when the characters are too close)

Enable/disable from:
Outliner -> User Preferences -> Styles -> Panel Font -> Overlap

(also for other styles, Group Label, Widget, Widget Label)

source/blender/blenfont/BLF_api.h
source/blender/blenfont/intern/blf_font.c
source/blender/blenfont/intern/blf_glyph.c
source/blender/editors/interface/interface_style.c
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/intern/rna_userdef.c

index cb64615..2ee31a1 100644 (file)
@@ -135,6 +135,7 @@ void BLF_dir_free(char **dirs, int count);
 #define BLF_FONT_KERNING (1<<2)
 #define BLF_USER_KERNING (1<<3)
 #define BLF_SHADOW (1<<4)
+#define BLF_OVERLAP_CHAR (1<<5)
 
 /* font->mode. */
 #define BLF_MODE_TEXTURE 0
index ee4ba0e..a3c5232 100644 (file)
@@ -146,20 +146,22 @@ void blf_font_draw(FontBLF *font, char *str)
 
                        if (FT_Get_Kerning(font->face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta) == 0) {
                                pen_x += delta.x >> 6;
-/*
-                               if (pen_x < old_pen_x)
-                                       pen_x= old_pen_x;
-*/
+
+                               if (font->flags & BLF_OVERLAP_CHAR) {
+                                       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;
-*/
+
+                       if (font->flags & BLF_OVERLAP_CHAR) {
+                               if (pen_x < old_pen_x)
+                                       pen_x= old_pen_x;
+                       }
                }
 
                /* do not return this loop if clipped, we want every character tested */
@@ -228,20 +230,22 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
 
                        if (FT_Get_Kerning(font->face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta) == 0) {
                                pen_x += delta.x >> 6;
-/*
-                               if (pen_x < old_pen_x)
-                                       old_pen_x= pen_x;
-*/
+
+                               if (font->flags & BLF_OVERLAP_CHAR) {
+                                       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)
-                               old_pen_x= pen_x;
-*/
+
+                       if (font->flags & BLF_OVERLAP_CHAR) {
+                               if (pen_x < old_pen_x)
+                                       pen_x= old_pen_x;
+                       }
                }
 
                gbox.xmin= g->box.xmin + pen_x;
index 5e0868e..a637774 100644 (file)
@@ -500,6 +500,8 @@ int blf_glyph_texture_render(FontBLF *font, GlyphBLF *g, float x, float y)
        float color[4];
 
        gt= g->tex_data;
+       xo= 0.0f;
+       yo= 0.0f;
 
        if (font->flags & BLF_SHADOW) {
                xo= x;
index 0d30d8e..e8fba38 100644 (file)
@@ -92,6 +92,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name)
        style->paneltitle.uifont_id= UIFONT_DEFAULT;
        style->paneltitle.points= 13;
        style->paneltitle.kerning= 0.0;
+       style->paneltitle.overlap= 0;
        style->paneltitle.shadow= 5;
        style->paneltitle.shadx= 2;
        style->paneltitle.shady= -2;
@@ -101,6 +102,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name)
        style->grouplabel.uifont_id= UIFONT_DEFAULT;
        style->grouplabel.points= 12;
        style->grouplabel.kerning= 0.0;
+       style->grouplabel.overlap= 0;
        style->grouplabel.shadow= 3;
        style->grouplabel.shadx= 1;
        style->grouplabel.shady= -1;
@@ -109,6 +111,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name)
        style->widgetlabel.uifont_id= UIFONT_DEFAULT;
        style->widgetlabel.points= 11;
        style->widgetlabel.kerning= 0.0;
+       style->widgetlabel.overlap= 0;
        style->widgetlabel.shadow= 3;
        style->widgetlabel.shadx= 1;
        style->widgetlabel.shady= -1;
@@ -171,10 +174,15 @@ void uiStyleFontDraw(uiFontStyle *fs, rcti *rect, char *str)
                BLF_shadow_offset(fs->shadx, fs->shady);
        }
 
+       if (fs->overlap)
+               BLF_enable(BLF_OVERLAP_CHAR);
+
        BLF_draw(str);
        BLF_disable(BLF_CLIPPING);
        if (fs->shadow)
                BLF_disable(BLF_SHADOW);
+       if (fs->overlap)
+               BLF_disable(BLF_OVERLAP_CHAR);
 }
 
 /* ************** helpers ************************ */
index 6be855a..db13acf 100644 (file)
@@ -67,7 +67,8 @@ typedef struct uiFontStyle {
        short uifont_id;                /* saved in file, 0 is default */
        short points;                   /* actual size depends on 'global' dpi */
        float kerning;                  /* kerning space between characters. */
-       float pad;
+       short overlap;                  /* check overlaped characters. */
+       short pad;
        short italic, bold;             /* style hint */
        short shadow;                   /* value is amount of pixels blur */
        short shadx, shady;             /* shadow offset in pixels */
index f381193..97337af 100644 (file)
@@ -139,7 +139,12 @@ static void rna_def_userdef_theme_ui_font_style(BlenderRNA *brna)
 
        prop= RNA_def_property(srna, "kerning", PROP_FLOAT, PROP_NONE);
        RNA_def_property_range(prop, -5.0, 5.0);
-       RNA_def_property_ui_text(prop, "Kerning", "");
+       RNA_def_property_ui_text(prop, "Kerning", "User kerning value in pixels");
+       RNA_def_property_update(prop, NC_WINDOW, NULL);
+
+       prop= RNA_def_property(srna, "overlap", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "overlap", 1);
+       RNA_def_property_ui_text(prop, "Overlap", "Check for overlap characters");
        RNA_def_property_update(prop, NC_WINDOW, NULL);
 
        prop= RNA_def_property(srna, "shadow", PROP_INT, PROP_NONE);