summaryrefslogtreecommitdiff
path: root/gtk/gtkcssstyle.c
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2020-01-16 11:27:37 +0100
committerTimm Bäder <mail@baedert.org>2020-01-18 08:49:52 +0100
commit821efcb725987c23afd12ea856e23ad954d0c590 (patch)
tree4f50ed4a37fa3da9e9d72903e85f7c59c489fd0e /gtk/gtkcssstyle.c
parent85793fe6b663061acbd814d93e0e2324db59f8dd (diff)
downloadgtk+-821efcb725987c23afd12ea856e23ad954d0c590.tar.gz
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.
Diffstat (limited to 'gtk/gtkcssstyle.c')
-rw-r--r--gtk/gtkcssstyle.c51
1 files changed, 39 insertions, 12 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;
+
+ 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;
}