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
This commit is contained in:
Diego Borghetti
2009-06-11 21:43:59 +00:00
parent a054f3ccce
commit ec8b2593ec
8 changed files with 67 additions and 9 deletions

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -167,6 +167,9 @@ typedef struct FontBLF {
/* font size. */
int size;
/* kerning space, user setting. */
int kerning;
/* max texture size. */
int max_tex_size;

View File

@@ -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);
}

View File

@@ -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 */

View File

@@ -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)");