From b26a370ce4b5865582b634a70794816d740ac2c8 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 1 Sep 2021 15:17:53 -0400 Subject: Add a gtk-hint-font-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..fb303bb2e4 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_FONT_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-font-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-font-metrics", + P_("Hint Font Metrics"), + P_("Whether hinting should be applied to font metrics"), + FALSE, + GTK_PARAM_READWRITE)); + + g_assert (result == PROP_HINT_FONT_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_FONT_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_font_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-font-metrics", &hint_font_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_font_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..6ef2add082 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_font_metrics; + + g_object_get (settings, "gtk-hint-font-metrics", &hint_font_metrics, NULL); + pango_context_set_round_glyph_positions (context, hint_font_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) { -- cgit v1.2.1