cssstyle: Implement get_pango_font() directly
authorTimm Bäder <mail@baedert.org>
Thu, 16 Jan 2020 10:27:37 +0000 (11:27 +0100)
committerTimm Bäder <mail@baedert.org>
Sat, 18 Jan 2020 07:49:52 +0000 (08:49 +0100)
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
gtk/gtkwidget.c

index 1456f1290d65e85996b19fda1710d8d90d3e29fa..7f840b0045af857fab32dbb9bcec071679d57c37 100644 (file)
@@ -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;
+
+  description = pango_font_description_new ();
+
+  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));
 
-  prop = _gtk_style_property_lookup ("font");
-  _gtk_style_property_query (prop, &value, query_func, style);
+  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 (PangoFontDescription *)g_value_get_boxed (&value);
+  return description;
 }
index b72b8f66520f94cce9b01367257f0bf3dfd5e042..6b8f724a16b5e3d61232a0987d6dae374a8b99c7 100644 (file)
@@ -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);