[gtk/wip/baedert/css-values: 15/17] cssstyle: Implement get_pango_font() directly
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/css-values: 15/17] cssstyle: Implement get_pango_font() directly
- Date: Thu, 16 Jan 2020 10:41:50 +0000 (UTC)
commit d71bcced9a6fc74a27e650ce02cbf64f998856ff
Author: Timm Bäder <mail baedert org>
Date: Thu Jan 16 11:27:37 2020 +0100
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 21054d1ee2..88367496fb 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"
@@ -415,21 +416,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_font_size_value_get_value (v) *
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;
}
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 11a406276b..8d52ad345c 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]