[gtk/hint-metrics-setting] Add a gtk-hint-metrics setting
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/hint-metrics-setting] Add a gtk-hint-metrics setting
- Date: Wed, 1 Sep 2021 19:35:28 +0000 (UTC)
commit ae7079199cdba87c74135a72dafd63194ffabeaa
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Sep 1 15:17:53 2021 -0400
Add a gtk-hint-metrics setting
This lets people switch back to font rendering that is closer
to what GTK 3 does. It is not perfect - subpixel antialiasing
is not going to work. But it give us an Escape hatch while
we shake out the bugs in our linear layout.
Related: #3787
gtk/gtksettings.c | 28 +++++++++++++++++++++++++++-
gtk/gtkwidget.c | 13 ++++++++++---
2 files changed, 37 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c
index af4538e94f..a0d55bc11a 100644
--- a/gtk/gtksettings.c
+++ b/gtk/gtksettings.c
@@ -166,6 +166,7 @@ enum {
PROP_XFT_HINTSTYLE,
PROP_XFT_RGBA,
PROP_XFT_DPI,
+ PROP_HINT_METRICS,
PROP_CURSOR_THEME_NAME,
PROP_CURSOR_THEME_SIZE,
PROP_ALTERNATIVE_BUTTON_ORDER,
@@ -556,6 +557,7 @@ gtk_settings_class_init (GtkSettingsClass *class)
g_assert (result == PROP_XFT_RGBA);
+
/**
* GtkSettings:gtk-xft-dpi:
*
@@ -572,6 +574,25 @@ gtk_settings_class_init (GtkSettingsClass *class)
g_assert (result == PROP_XFT_DPI);
+ /**
+ * GtkSettings:gtk-hint-metrics:
+ *
+ * Whether hinting should be applied to font metrics.
+ *
+ * Note that this also turns off subpixel positioning of glyphs,
+ * since it conflicts with metrics hinting.
+ *
+ * Since: 4.6
+ */
+ result = settings_install_property_parser (class,
+ g_param_spec_boolean ("gtk-hint-metrics",
+ P_("Hint Metrics"),
+ P_("Whether hinting should be applied to
font metrics"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
+ g_assert (result == PROP_HINT_METRICS);
+
/**
* GtkSettings:gtk-cursor-theme-name:
*
@@ -1439,6 +1460,7 @@ gtk_settings_notify (GObject *object,
case PROP_XFT_HINTING:
case PROP_XFT_HINTSTYLE:
case PROP_XFT_RGBA:
+ case PROP_HINT_METRICS:
settings_update_font_options (settings);
gtk_system_setting_changed (settings->display, GTK_SYSTEM_SETTING_FONT_CONFIG);
break;
@@ -1678,6 +1700,7 @@ settings_update_font_options (GtkSettings *settings)
cairo_antialias_t antialias_mode;
char *rgba_str;
cairo_subpixel_order_t subpixel_order;
+ gboolean hint_metrics;
if (settings->font_options)
cairo_font_options_destroy (settings->font_options);
@@ -1687,11 +1710,14 @@ settings_update_font_options (GtkSettings *settings)
"gtk-xft-hinting", &hinting,
"gtk-xft-hintstyle", &hint_style_str,
"gtk-xft-rgba", &rgba_str,
+ "gtk-hint-metrics", &hint_metrics,
NULL);
settings->font_options = cairo_font_options_create ();
- cairo_font_options_set_hint_metrics (settings->font_options, CAIRO_HINT_METRICS_OFF);
+ cairo_font_options_set_hint_metrics (settings->font_options,
+ hint_metrics ? CAIRO_HINT_METRICS_ON
+ : CAIRO_HINT_METRICS_OFF);
hint_style = CAIRO_HINT_STYLE_DEFAULT;
if (hinting == 0)
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 2a8e288232..db5ec6dc69 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -6441,8 +6441,16 @@ update_pango_context (GtkWidget *widget,
pango_context_set_font_description (context, font_desc);
pango_font_description_free (font_desc);
- if (cairo_version () >= CAIRO_VERSION_ENCODE (1, 17, 4))
- pango_context_set_round_glyph_positions (context, FALSE);
+ settings = gtk_widget_get_settings (widget);
+
+ if (settings &&
+ cairo_version () >= CAIRO_VERSION_ENCODE (1, 17, 4))
+ {
+ gboolean hint_metrics;
+
+ g_object_get (settings, "gtk-hint-metrics", &hint_metrics, NULL);
+ pango_context_set_round_glyph_positions (context, hint_metrics);
+ }
pango_context_set_base_dir (context,
_gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
@@ -6450,7 +6458,6 @@ update_pango_context (GtkWidget *widget,
pango_cairo_context_set_resolution (context, _gtk_css_number_value_get (style->core->dpi, 100));
- settings = gtk_widget_get_settings (widget);
font_options = (cairo_font_options_t*)g_object_get_qdata (G_OBJECT (widget), quark_font_options);
if (settings && font_options)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]