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 cb64615d64c86e5ed32831480f6b56c0a59bff91..2ee31a17fa658a411da7c873c85ddc910233b42c 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 ee4ba0ee71a6d3b9ce63488bec8d840cf67239fb..a3c5232cc76f8ac05011a5b55b5b255b906732ef 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 5e0868ea68053664e06e358b286f7a7e66357f9b..a637774d7bf8dbd2173f26525ca0322d4f546098 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 0d30d8e69c02b447c395e316da86153ac410cd44..e8fba38f793f5f06a35068f4cac3a15cda337556 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 6be855a27dad1672d8ef5dc8c34324331fdd2d16..db13acf12d5fdb8a9564c537b5d065e1e15d5e32 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 f3811938e28b54f3de9dffe2c1363a2427fb19de..97337af5cb0b434c8eaa03b2d8cfa97c33f23112 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);