From ec8b2593ecdee9493210df0e6f9c4dbbcb2a1985 Mon Sep 17 00:00:00 2001 From: Diego Borghetti Date: Thu, 11 Jun 2009 21:43:59 +0000 Subject: [PATCH] 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 --- source/blender/blenfont/BLF_api.h | 4 ++- source/blender/blenfont/intern/blf.c | 9 +++++ source/blender/blenfont/intern/blf_font.c | 35 ++++++++++++++++--- source/blender/blenfont/intern/blf_glyph.c | 12 +++++-- .../blenfont/intern/blf_internal_types.h | 3 ++ .../editors/interface/interface_style.c | 5 +++ source/blender/makesdna/DNA_userdef_types.h | 2 ++ source/blender/makesrna/intern/rna_userdef.c | 6 +++- 8 files changed, 67 insertions(+), 9 deletions(-) diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index b5a61f2727f..d1d802622ea 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -85,7 +85,7 @@ float BLF_height_default(char *str); 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 @@ void BLF_dir_free(char **dirs, int count); /* 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 diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 14bc6a33b72..ffb845f7888 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -491,3 +491,12 @@ void BLF_mode(int mode) if (font) font->mode= mode; } + +void BLF_kerning(int space) +{ + FontBLF *font; + + font= global_font[global_font_cur]; + if (font) + font->kerning= space; +} diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 1a96dbc13bc..df77aee70e8 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -100,7 +100,7 @@ void blf_font_draw(FontBLF *font, char *str) 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,12 +138,24 @@ void blf_font_draw(FontBLF *font, char *str) 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 */ @@ -162,7 +174,7 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box) 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,12 +217,24 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box) 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; @@ -294,9 +318,10 @@ 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->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; diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 142d2145ab2..33a435cc5be 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -213,7 +213,11 @@ GlyphBLF *blf_glyph_texture_add(FontBLF *font, FT_UInt index, unsigned int c) 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 @@ GlyphBLF *blf_glyph_bitmap_add(FontBLF *font, FT_UInt index, unsigned int c) 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); diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h index 1c55499b568..d200d910020 100644 --- a/source/blender/blenfont/intern/blf_internal_types.h +++ b/source/blender/blenfont/intern/blf_internal_types.h @@ -167,6 +167,9 @@ typedef struct FontBLF { /* font size. */ int size; + /* kerning space, user setting. */ + int kerning; + /* max texture size. */ int max_tex_size; diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 62a4c01bc6c..a3959327ccd 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -91,6 +91,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) 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 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) 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 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) 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 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) 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 @@ void uiStyleFontSet(uiFontStyle *fs) BLF_set(font->blf_id); BLF_size(fs->points, U.dpi); + BLF_kerning(fs->kerning); } diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 022e1cef840..c99992cb126 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -66,6 +66,8 @@ typedef struct uiFont { 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 */ diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index e0d3201a5e7..1963e48b00f 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -135,7 +135,11 @@ static void rna_def_userdef_theme_ui_font_style(BlenderRNA *brna) 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)");