Issue #2902: Preference option to set "Interface/Theme" font size.

Though GTK+3 is supposed to take care of scaling fonts with high density
displays, it turns out it is not enough for many, for various reasons (taste,
eyesight, distance to the display…). So we add this additional settings to tweak
further the font size.

With Aryeom, we experimented/discussed both a percentage UI vs. an absolute font
size field (e.g. as they provide in GNOME Tweaks). In the end, we went for a
percentage UI because we realize that we don't necessarily know what is the
current size at all. Mostly you just want bigger or smaller, and don't
necessarily care so much at which value is the font size.

This settings only has a single limitation (that we could find), which is when
used on a theme with widget rules using absolute font-size rules (px, or
keywords such as small/medium/large). As long as the CSS rules are relative
though (either to the parent widget, or to the root size), then it works fine.
Basically a theme hard-coding font sizes won't fare well with this settings, but
since we can consider this bad practice, it's an acceptable limitation.
This commit is contained in:
Jehan 2023-09-25 22:09:42 +02:00
parent f6310c3db7
commit f38449115f
5 changed files with 89 additions and 0 deletions

View File

@ -76,6 +76,7 @@ enum
PROP_ICON_THEME_PATH,
PROP_ICON_THEME,
PROP_PREFER_SYMBOLIC_ICONS,
PROP_FONT_RELATIVE_SIZE,
PROP_USE_HELP,
PROP_SHOW_HELP_BUTTON,
PROP_HELP_LOCALES,
@ -358,6 +359,13 @@ gimp_gui_config_class_init (GimpGuiConfigClass *klass)
TRUE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_FONT_RELATIVE_SIZE,
"font-relative-size",
"Tweak font-size from the theme",
FONT_SIZE_BLURB,
0.5, 2.0, 1.0,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_USE_HELP,
"use-help",
"Use help",
@ -695,6 +703,9 @@ gimp_gui_config_set_property (GObject *object,
case PROP_PREFER_SYMBOLIC_ICONS:
gui_config->prefer_symbolic_icons = g_value_get_boolean (value);
break;
case PROP_FONT_RELATIVE_SIZE:
gui_config->font_relative_size = g_value_get_double (value);
break;
case PROP_USE_HELP:
gui_config->use_help = g_value_get_boolean (value);
break;
@ -872,6 +883,9 @@ gimp_gui_config_get_property (GObject *object,
case PROP_PREFER_SYMBOLIC_ICONS:
g_value_set_boolean (value, gui_config->prefer_symbolic_icons);
break;
case PROP_FONT_RELATIVE_SIZE:
g_value_set_double (value, gui_config->font_relative_size);
break;
case PROP_USE_HELP:
g_value_set_boolean (value, gui_config->use_help);
break;

View File

@ -68,6 +68,7 @@ struct _GimpGuiConfig
gchar *icon_theme_path;
gchar *icon_theme;
gboolean prefer_symbolic_icons;
gdouble font_relative_size;
gboolean override_icon_size;
GimpIconSize custom_icon_size;
gboolean use_help;

View File

@ -561,6 +561,9 @@ _("When enabled, symbolic icons will be preferred if available.")
#define ICON_THEME_PATH_BLURB \
"Sets the icon theme search path."
#define FONT_SIZE_BLURB \
_("Tweak font size of the graphical interface.")
#define IMAGE_CONVERT_PROFILE_INTENT_BLURB \
_("Sets the default rendering intent for the 'Convert to Color Profile' dialog.")

View File

@ -155,6 +155,11 @@ static void prefs_gui_config_notify_icon_size (GObject *config,
GtkRange *range);
static void prefs_icon_size_value_changed (GtkRange *range,
GimpGuiConfig *config);
static void prefs_gui_config_notify_font_size (GObject *config,
GParamSpec *pspec,
GtkRange *range);
static void prefs_font_size_value_changed (GtkRange *range,
GimpGuiConfig *config);
/* private variables */
@ -971,6 +976,38 @@ prefs_gui_config_notify_icon_size (GObject *config,
config);
}
static void
prefs_font_size_value_changed (GtkRange *range,
GimpGuiConfig *config)
{
gdouble value = gtk_range_get_value (range);
g_signal_handlers_block_by_func (config,
G_CALLBACK (prefs_gui_config_notify_font_size),
range);
g_object_set (G_OBJECT (config),
"font-relative-size", value / 100.0,
NULL);
g_signal_handlers_unblock_by_func (config,
G_CALLBACK (prefs_gui_config_notify_font_size),
range);
}
static void
prefs_gui_config_notify_font_size (GObject *config,
GParamSpec *pspec,
GtkRange *range)
{
g_signal_handlers_block_by_func (range,
G_CALLBACK (prefs_font_size_value_changed),
config);
gtk_range_set_value (range,
GIMP_GUI_CONFIG (config)->font_relative_size * 100.0);
g_signal_handlers_unblock_by_func (range,
G_CALLBACK (prefs_font_size_value_changed),
config);
}
static void
prefs_format_string_select_callback (GtkListBox *listbox,
GtkListBoxRow *row,
@ -2112,6 +2149,31 @@ prefs_dialog_new (Gimp *gimp,
gtk_box_pack_start (GTK_BOX (vbox3), scale, FALSE, FALSE, 0);
gtk_widget_show (scale);
/* Font sizes. */
vbox3 = prefs_frame_new (_("Font Scaling"), GTK_CONTAINER (vbox2), FALSE);
gimp_help_set_help_data (vbox3,
_("Font scaling will not work with themes using absolute sizes."),
NULL);
scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
50, 200, 10);
gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_BOTTOM);
gtk_scale_add_mark (GTK_SCALE (scale), 50.0, GTK_POS_BOTTOM,
_("50%"));
gtk_scale_add_mark (GTK_SCALE (scale), 100.0, GTK_POS_BOTTOM,
_("100%"));
gtk_scale_add_mark (GTK_SCALE (scale), 200.0, GTK_POS_BOTTOM,
_("200%"));
gtk_range_set_value (GTK_RANGE (scale),
(gdouble) GIMP_GUI_CONFIG (object)->font_relative_size * 100.0);
g_signal_connect (G_OBJECT (scale), "value-changed",
G_CALLBACK (prefs_font_size_value_changed),
GIMP_GUI_CONFIG (object));
g_signal_connect (G_OBJECT (object), "notify::font-relative-size",
G_CALLBACK (prefs_gui_config_notify_font_size),
scale);
gtk_box_pack_start (GTK_BOX (vbox3), scale, FALSE, FALSE, 0);
gtk_widget_show (scale);
/* Reload Current Theme button */
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);

View File

@ -100,6 +100,9 @@ themes_init (Gimp *gimp)
g_signal_connect (config, "notify::custom-icon-size",
G_CALLBACK (themes_theme_change_notify),
gimp);
g_signal_connect (config, "notify::font-relative-size",
G_CALLBACK (themes_theme_change_notify),
gimp);
themes_theme_change_notify (config, NULL, gimp);
}
@ -373,6 +376,12 @@ themes_apply_theme (Gimp *gimp,
button_icon_size);
}
if (! error && config->font_relative_size != 1.0)
g_output_stream_printf (output, NULL, NULL, &error,
"\n"
"* { font-size: %frem; }",
config->font_relative_size);
if (! error)
{
g_output_stream_printf (