Allow the user set which style to use for the kerning value.
This are freetype2 options: Unfitted - Scaled but un-grid-fitted kerning distances Default - Scaled and grid-fitted kerning distances We always use Unfitted, but the "Default" style give better result here, so please test and if nobody complain we can set this style as the default.
This commit is contained in:
parent
395025d67e
commit
b80b581bc0
|
@ -137,6 +137,7 @@ void BLF_dir_free(char **dirs, int count);
|
|||
#define BLF_ROTATION (1<<0)
|
||||
#define BLF_CLIPPING (1<<1)
|
||||
#define BLF_SHADOW (1<<2)
|
||||
#define BLF_KERNING_DEFAULT (1<<3)
|
||||
|
||||
/* font->mode. */
|
||||
#define BLF_MODE_TEXTURE 0
|
||||
|
|
|
@ -102,7 +102,7 @@ void blf_font_draw(FontBLF *font, char *str)
|
|||
FT_Vector delta;
|
||||
FT_UInt glyph_index, g_prev_index;
|
||||
int pen_x, pen_y;
|
||||
int i, has_kerning;
|
||||
int i, has_kerning, st;
|
||||
|
||||
if (!font->glyph_cache)
|
||||
return;
|
||||
|
@ -143,9 +143,13 @@ void blf_font_draw(FontBLF *font, char *str)
|
|||
delta.x= 0;
|
||||
delta.y= 0;
|
||||
|
||||
if (FT_Get_Kerning(font->face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta) == 0) {
|
||||
if (font->flags & BLF_KERNING_DEFAULT)
|
||||
st= FT_Get_Kerning(font->face, g_prev_index, glyph_index, ft_kerning_default, &delta);
|
||||
else
|
||||
st= FT_Get_Kerning(font->face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta);
|
||||
|
||||
if (st == 0)
|
||||
pen_x += delta.x >> 6;
|
||||
}
|
||||
}
|
||||
|
||||
/* do not return this loop if clipped, we want every character tested */
|
||||
|
@ -165,7 +169,7 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
|
|||
FT_UInt glyph_index, g_prev_index;
|
||||
rctf gbox;
|
||||
int pen_x, pen_y;
|
||||
int i, has_kerning;
|
||||
int i, has_kerning, st;
|
||||
|
||||
if (!font->glyph_cache)
|
||||
return;
|
||||
|
@ -211,9 +215,13 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
|
|||
delta.x= 0;
|
||||
delta.y= 0;
|
||||
|
||||
if (FT_Get_Kerning(font->face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta) == 0) {
|
||||
if (font->flags & BLF_KERNING_DEFAULT)
|
||||
st= FT_Get_Kerning(font->face, g_prev_index, glyph_index, ft_kerning_default, &delta);
|
||||
else
|
||||
st= FT_Get_Kerning(font->face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta);
|
||||
|
||||
if (st == 0)
|
||||
pen_x += delta.x >> 6;
|
||||
}
|
||||
}
|
||||
|
||||
gbox.xmin= g->box.xmin + pen_x;
|
||||
|
|
|
@ -93,6 +93,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;
|
||||
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;
|
||||
style->grouplabel.shadow= 3;
|
||||
style->grouplabel.shadx= 1;
|
||||
style->grouplabel.shady= -1;
|
||||
|
@ -108,6 +110,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;
|
||||
style->widgetlabel.shadow= 3;
|
||||
style->widgetlabel.shadx= 1;
|
||||
style->widgetlabel.shady= -1;
|
||||
|
@ -116,6 +119,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name)
|
|||
|
||||
style->widget.uifont_id= UIFONT_DEFAULT;
|
||||
style->widget.points= 11;
|
||||
style->widget.kerning= 0;
|
||||
style->widget.shadowalpha= 0.25f;
|
||||
|
||||
style->columnspace= 5;
|
||||
|
@ -169,10 +173,15 @@ void uiStyleFontDraw(uiFontStyle *fs, rcti *rect, char *str)
|
|||
BLF_shadow_offset(fs->shadx, fs->shady);
|
||||
}
|
||||
|
||||
if (fs->kerning == 1)
|
||||
BLF_enable(BLF_KERNING_DEFAULT);
|
||||
|
||||
BLF_draw(str);
|
||||
BLF_disable(BLF_CLIPPING);
|
||||
if (fs->shadow)
|
||||
BLF_disable(BLF_SHADOW);
|
||||
if (fs->kerning == 1)
|
||||
BLF_disable(BLF_KERNING_DEFAULT);
|
||||
}
|
||||
|
||||
/* ************** helpers ************************ */
|
||||
|
|
|
@ -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; /* unfitted or default kerning value. */
|
||||
char pad[6];
|
||||
short italic, bold; /* style hint */
|
||||
short shadow; /* value is amount of pixels blur */
|
||||
short shadx, shady; /* shadow offset in pixels */
|
||||
|
|
|
@ -128,6 +128,11 @@ static void rna_def_userdef_theme_ui_font_style(BlenderRNA *brna)
|
|||
StructRNA *srna;
|
||||
PropertyRNA *prop;
|
||||
|
||||
static EnumPropertyItem font_kerning_style[] = {
|
||||
{0, "UNFITTED", 0, "Unfitted", "Use scaled but un-grid-fitted kerning distances."},
|
||||
{1, "DEFAULT", 0, "Default", "Use scaled and grid-fitted kerning distances."},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
srna= RNA_def_struct(brna, "ThemeFontStyle", NULL);
|
||||
RNA_def_struct_sdna(srna, "uiFontStyle");
|
||||
RNA_def_struct_ui_text(srna, "Font Style", "Theme settings for Font.");
|
||||
|
@ -137,6 +142,12 @@ static void rna_def_userdef_theme_ui_font_style(BlenderRNA *brna)
|
|||
RNA_def_property_ui_text(prop, "Points", "");
|
||||
RNA_def_property_update(prop, NC_WINDOW, NULL);
|
||||
|
||||
prop= RNA_def_property(srna, "font_kerning_style", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "kerning");
|
||||
RNA_def_property_enum_items(prop, font_kerning_style);
|
||||
RNA_def_property_ui_text(prop, "Kerning Style", "Which style to use for font kerning.");
|
||||
RNA_def_property_update(prop, NC_WINDOW, NULL);
|
||||
|
||||
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)");
|
||||
|
|
Loading…
Reference in New Issue