From 821efcb725987c23afd12ea856e23ad954d0c590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 16 Jan 2020 11:27:37 +0100 Subject: [PATCH] cssstyle: Implement get_pango_font() directly Instead of going through the slow GValue code path. This function was unused, so use it in GtkWidget's update_pango_context() now. --- gtk/gtkcssstyle.c | 51 ++++++++++++++++++++++++++++++++++++----------- gtk/gtkwidget.c | 5 ++--- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/gtk/gtkcssstyle.c b/gtk/gtkcssstyle.c index 1456f1290d..7f840b0045 100644 --- a/gtk/gtkcssstyle.c +++ b/gtk/gtkcssstyle.c @@ -31,6 +31,7 @@ #include "gtkcsscolorvalueprivate.h" #include "gtkcssshorthandpropertyprivate.h" #include "gtkcssstringvalueprivate.h" +#include "gtkcssfontsizevalueprivate.h" #include "gtkcssfontfeaturesvalueprivate.h" #include "gtkcssstylepropertyprivate.h" #include "gtkcsstransitionprivate.h" @@ -423,21 +424,47 @@ gtk_css_style_get_pango_attributes (GtkCssStyle *style) return attrs; } -static GtkCssValue * -query_func (guint id, - gpointer values) -{ - return gtk_css_style_get_value (values, id); -} - PangoFontDescription * gtk_css_style_get_pango_font (GtkCssStyle *style) { - GtkStyleProperty *prop; - GValue value = { 0, }; + PangoFontDescription *description; + GtkCssValue *v; - prop = _gtk_style_property_lookup ("font"); - _gtk_style_property_query (prop, &value, query_func, style); + description = pango_font_description_new (); - return (PangoFontDescription *)g_value_get_boxed (&value); + v = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_FONT_FAMILY); + if (_gtk_css_array_value_get_n_values (v) > 1) + { + int i; + GString *s = g_string_new (""); + + for (i = 0; i < _gtk_css_array_value_get_n_values (v); i++) + { + if (i > 0) + g_string_append (s, ","); + g_string_append (s, _gtk_css_string_value_get (_gtk_css_array_value_get_nth (v, i))); + } + + pango_font_description_set_family (description, s->str); + g_string_free (s, TRUE); + } + else + { + pango_font_description_set_family (description, + _gtk_css_string_value_get (_gtk_css_array_value_get_nth (v, 0))); + } + + v = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_FONT_SIZE); + pango_font_description_set_absolute_size (description, round (_gtk_css_number_value_get (v, 100) * PANGO_SCALE)); + + v = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_FONT_STYLE); + pango_font_description_set_style (description, _gtk_css_font_style_value_get (v)); + + v = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_FONT_WEIGHT); + pango_font_description_set_weight (description, _gtk_css_number_value_get (v, 100)); + + v = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_FONT_STRETCH); + pango_font_description_set_stretch (description, _gtk_css_font_stretch_value_get (v)); + + return description; } diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index b72b8f6652..6b8f724a16 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -6582,6 +6582,7 @@ static void update_pango_context (GtkWidget *widget, PangoContext *context) { + GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget); PangoFontDescription *font_desc; GtkStyleContext *style_context; GtkSettings *settings; @@ -6590,9 +6591,7 @@ update_pango_context (GtkWidget *widget, char *variations; style_context = _gtk_widget_get_style_context (widget); - gtk_style_context_get (style_context, - "font", &font_desc, - NULL); + font_desc = gtk_css_style_get_pango_font (gtk_css_node_get_style (priv->cssnode)); value = _gtk_style_context_peek_property (_gtk_widget_get_style_context (widget), GTK_CSS_PROPERTY_FONT_VARIATION_SETTINGS); variations = gtk_css_font_variations_value_get_variations (value);