UI: Remove "Unfitted" Kerning Style Option

This patch removes the "Kerning Style" option for UI widget font
drawing and uses only the current default of "Fitted", since the other
option of "Unfitted" is just the result of truncation errors.

see D12231 for much more information.

Differential Revision: https://developer.blender.org/D12231

Reviewed by Campbell Barton
This commit is contained in:
Harley Acheson 2021-08-18 19:48:30 -07:00
parent ac09411368
commit feaa61a968
11 changed files with 5 additions and 149 deletions

View File

@ -271,7 +271,7 @@ void BLF_state_print(int fontid);
#define BLF_ROTATION (1 << 0)
#define BLF_CLIPPING (1 << 1)
#define BLF_SHADOW (1 << 2)
#define BLF_KERNING_DEFAULT (1 << 3)
// #define BLF_FLAG_UNUSED_3 (1 << 3) /* dirty */
#define BLF_MATRIX (1 << 4)
#define BLF_ASPECT (1 << 5)
#define BLF_WORD_WRAP (1 << 6)

View File

@ -355,9 +355,7 @@ BLI_INLINE GlyphBLF *blf_utf8_next_fast(
#define BLF_KERNING_VARS(_font, _has_kerning, _kern_mode) \
const bool _has_kerning = FT_HAS_KERNING((_font)->face); \
const FT_UInt _kern_mode = (_has_kerning && !((_font)->flags & BLF_KERNING_DEFAULT)) ? \
FT_KERNING_UNFITTED : \
FT_KERNING_DEFAULT;
const FT_UInt _kern_mode = FT_KERNING_DEFAULT;
BLI_INLINE void blf_kerning_step_fast(FontBLF *font,
const FT_UInt kern_mode,

View File

@ -3086,11 +3086,6 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con
UI_fontstyle_set(&fstyle);
if (fstyle.kerning == 1) {
/* for BLF_width */
BLF_enable(fstyle.uifont_id, BLF_KERNING_DEFAULT);
}
ui_but_text_password_hide(password_str, but, false);
if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) {
@ -3141,10 +3136,6 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con
but->pos = glyph_data[1] + but->ofs;
}
if (fstyle.kerning == 1) {
BLF_disable(fstyle.uifont_id, BLF_KERNING_DEFAULT);
}
ui_but_text_password_hide(password_str, but, true);
}

View File

@ -1447,10 +1447,6 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
is_alpha = (region->overlap && (theme_col_back[3] != 255));
if (fstyle->kerning == 1) {
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
BLF_enable(fontid, BLF_ROTATION);
BLF_rotation(fontid, M_PI_2);
// UI_fontstyle_set(&style->widget);
@ -1620,10 +1616,6 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
GPU_line_smooth(false);
BLF_disable(fontid, BLF_ROTATION);
if (fstyle->kerning == 1) {
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
}
#undef TABS_PADDING_BETWEEN_FACTOR

View File

@ -1175,9 +1175,6 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
data->wrap_width = min_ii(UI_TIP_MAXWIDTH * U.pixelsize / aspect, winx - (UI_TIP_PADDING * 2));
font_flag |= BLF_WORD_WRAP;
if (data->fstyle.kerning == 1) {
font_flag |= BLF_KERNING_DEFAULT;
}
BLF_enable(data->fstyle.uifont_id, font_flag);
BLF_enable(blf_mono_font, font_flag);
BLF_wordwrap(data->fstyle.uifont_id, data->wrap_width);

View File

@ -83,7 +83,6 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id
style->paneltitle.uifont_id = uifont_id;
style->paneltitle.points = UI_DEFAULT_TITLE_POINTS;
style->paneltitle.kerning = 1;
style->paneltitle.shadow = 3;
style->paneltitle.shadx = 0;
style->paneltitle.shady = -1;
@ -92,7 +91,6 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id
style->grouplabel.uifont_id = uifont_id;
style->grouplabel.points = UI_DEFAULT_TITLE_POINTS;
style->grouplabel.kerning = 1;
style->grouplabel.shadow = 3;
style->grouplabel.shadx = 0;
style->grouplabel.shady = -1;
@ -101,7 +99,6 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id
style->widgetlabel.uifont_id = uifont_id;
style->widgetlabel.points = UI_DEFAULT_TEXT_POINTS;
style->widgetlabel.kerning = 1;
style->widgetlabel.shadow = 3;
style->widgetlabel.shadx = 0;
style->widgetlabel.shady = -1;
@ -110,7 +107,6 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id
style->widget.uifont_id = uifont_id;
style->widget.points = UI_DEFAULT_TEXT_POINTS;
style->widget.kerning = 1;
style->widget.shadow = 1;
style->widget.shady = -1;
style->widget.shadowalpha = 0.5f;
@ -164,9 +160,6 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs,
BLF_shadow(fs->uifont_id, fs->shadow, shadow_color);
BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
}
if (fs->kerning == 1) {
font_flag |= BLF_KERNING_DEFAULT;
}
if (fs_params->word_wrap == 1) {
font_flag |= BLF_WORD_WRAP;
}
@ -278,19 +271,12 @@ void UI_fontstyle_draw_rotated(const uiFontStyle *fs,
BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
}
if (fs->kerning == 1) {
BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
}
BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
BLF_disable(fs->uifont_id, BLF_ROTATION);
BLF_disable(fs->uifont_id, BLF_CLIPPING);
if (fs->shadow) {
BLF_disable(fs->uifont_id, BLF_SHADOW);
}
if (fs->kerning == 1) {
BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
}
}
/**
@ -302,18 +288,10 @@ void UI_fontstyle_draw_rotated(const uiFontStyle *fs,
void UI_fontstyle_draw_simple(
const uiFontStyle *fs, float x, float y, const char *str, const uchar col[4])
{
if (fs->kerning == 1) {
BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
}
UI_fontstyle_set(fs);
BLF_position(fs->uifont_id, x, y, 0.0f);
BLF_color4ubv(fs->uifont_id, col);
BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
if (fs->kerning == 1) {
BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
}
}
/**
@ -326,10 +304,6 @@ void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs,
const float col_fg[4],
const float col_bg[4])
{
if (fs->kerning == 1) {
BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
}
UI_fontstyle_set(fs);
{
@ -357,10 +331,6 @@ void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs,
BLF_position(fs->uifont_id, x, y, 0.0f);
BLF_color4fv(fs->uifont_id, col_fg);
BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
if (fs->kerning == 1) {
BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
}
}
/* ************** helpers ************************ */
@ -405,21 +375,8 @@ const uiStyle *UI_style_get_dpi(void)
int UI_fontstyle_string_width(const uiFontStyle *fs, const char *str)
{
int width;
if (fs->kerning == 1) {
/* for BLF_width */
BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
}
UI_fontstyle_set(fs);
width = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
if (fs->kerning == 1) {
BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
}
return width;
return (int)BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
}
int UI_fontstyle_height_max(const uiFontStyle *fs)

View File

@ -1576,11 +1576,6 @@ float UI_text_clip_middle_ex(const uiFontStyle *fstyle,
/* need to set this first */
UI_fontstyle_set(fstyle);
if (fstyle->kerning == 1) {
/* for BLF_width */
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
float strwidth = BLF_width(fstyle->uifont_id, str, max_len);
if ((okwidth > 0.0f) && (strwidth > okwidth)) {
@ -1674,10 +1669,6 @@ float UI_text_clip_middle_ex(const uiFontStyle *fstyle,
strwidth = BLF_width(fstyle->uifont_id, str, max_len);
}
if (fstyle->kerning == 1) {
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
BLI_assert(strwidth <= okwidth);
return strwidth;
@ -1736,11 +1727,6 @@ static void ui_text_clip_cursor(const uiFontStyle *fstyle, uiBut *but, const rct
/* need to set this first */
UI_fontstyle_set(fstyle);
if (fstyle->kerning == 1) {
/* for BLF_width */
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
/* define ofs dynamically */
if (but->ofs > but->pos) {
but->ofs = but->pos;
@ -1785,10 +1771,6 @@ static void ui_text_clip_cursor(const uiFontStyle *fstyle, uiBut *but, const rct
}
}
}
if (fstyle->kerning == 1) {
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
}
/**
@ -1806,11 +1788,6 @@ static void ui_text_clip_right_label(const uiFontStyle *fstyle, uiBut *but, cons
/* need to set this first */
UI_fontstyle_set(fstyle);
if (fstyle->kerning == 1) {
/* for BLF_width */
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr, sizeof(but->drawstr));
but->ofs = 0;
@ -1870,10 +1847,6 @@ static void ui_text_clip_right_label(const uiFontStyle *fstyle, uiBut *but, cons
but->strwidth = strwidth;
but->drawstr[drawstr_len] = 0;
}
if (fstyle->kerning == 1) {
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
}
#ifdef WITH_INPUT_IME
@ -1985,11 +1958,6 @@ static void widget_draw_text(const uiFontStyle *fstyle,
align = UI_STYLE_TEXT_CENTER;
}
if (fstyle->kerning == 1) {
/* for BLF_width */
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
/* Special case: when we're entering text for multiple buttons,
* don't draw the text for any of the multi-editing buttons */
if (UNLIKELY(but->flag & UI_BUT_DRAG_MULTI)) {
@ -2151,10 +2119,6 @@ static void widget_draw_text(const uiFontStyle *fstyle,
#endif
}
if (fstyle->kerning == 1) {
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
#if 0
ui_rasterpos_safe(x, y, but->aspect);
transopts = ui_translate_buttons();
@ -2232,10 +2196,6 @@ static void widget_draw_text(const uiFontStyle *fstyle,
}
if (ul_index != -1) {
if (fstyle->kerning == 1) {
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
int ul_width = round_fl_to_int(BLF_width(fstyle->uifont_id, "_", 2));
struct UnderlineData ul_data = {
@ -2256,10 +2216,6 @@ static void widget_draw_text(const uiFontStyle *fstyle,
BLF_position(fstyle->uifont_id, pos_x, pos_y, 0.0f);
BLF_color4ubv(fstyle->uifont_id, wcol->text);
BLF_draw(fstyle->uifont_id, "_", 2);
if (fstyle->kerning == 1) {
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
}
}
}
@ -5369,11 +5325,6 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
/* need to set this first */
UI_fontstyle_set(fstyle);
if (fstyle->kerning == 1) {
/* for BLF_width */
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
if (separator_type == UI_MENU_ITEM_SEPARATOR_SHORTCUT) {
/* Shrink rect to exclude the shortcut string. */
rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1, INT_MAX) + UI_DPI_ICON_SIZE;
@ -5398,10 +5349,6 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
else {
BLI_assert_msg(0, "Unknwon menu item separator type");
}
if (fstyle->kerning == 1) {
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
}
}

View File

@ -863,20 +863,8 @@ FileAttributeColumnType file_attribute_column_type_find_isect(const View2D *v2d,
float file_string_width(const char *str)
{
const uiStyle *style = UI_style_get();
float width;
UI_fontstyle_set(&style->widget);
if (style->widget.kerning == 1) { /* for BLF_width */
BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
}
width = BLF_width(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
if (style->widget.kerning == 1) {
BLF_disable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
}
return width;
return BLF_width(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
}
float file_font_pointsize(void)

View File

@ -71,14 +71,13 @@ typedef struct uiFontStyle {
short uifont_id;
/** Actual size depends on 'global' dpi. */
short points;
/** Unfitted or default kerning value. */
short kerning;
/** Style hint. */
short italic, bold;
/** Value is amount of pixels blur. */
short shadow;
/** Shadow offset in pixels. */
short shadx, shady;
char _pad0[2];
/** Total alpha. */
float shadowalpha;
/** 1 value, typically white or black anyway. */

View File

@ -1118,12 +1118,6 @@ static void rna_def_userdef_theme_ui_font_style(BlenderRNA *brna)
StructRNA *srna;
PropertyRNA *prop;
static const EnumPropertyItem font_kerning_style[] = {
{0, "UNFITTED", 0, "Unfitted", "Use scaled but un-grid-fitted kerning distances"},
{1, "FITTED", 0, "Fitted", "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_clear_flag(srna, STRUCT_UNDO);
@ -1134,12 +1128,6 @@ static void rna_def_userdef_theme_ui_font_style(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Points", "Font size in points");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
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, 0, "rna_userdef_theme_update");
prop = RNA_def_property(srna, "shadow", PROP_INT, PROP_PIXEL);
RNA_def_property_range(prop, 0, 5);
RNA_def_property_ui_text(prop, "Shadow Size", "Shadow size (0, 3 and 5 supported)");

View File

@ -493,7 +493,6 @@ PyObject *BPyInit_blf(void)
PyModule_AddIntConstant(submodule, "ROTATION", BLF_ROTATION);
PyModule_AddIntConstant(submodule, "CLIPPING", BLF_CLIPPING);
PyModule_AddIntConstant(submodule, "SHADOW", BLF_SHADOW);
PyModule_AddIntConstant(submodule, "KERNING_DEFAULT", BLF_KERNING_DEFAULT);
PyModule_AddIntConstant(submodule, "WORD_WRAP", BLF_WORD_WRAP);
PyModule_AddIntConstant(submodule, "MONOCHROME", BLF_MONOCHROME);