diff --git a/src/st/st-button.c b/src/st/st-button.c index e1602e086..52032f0f3 100644 --- a/src/st/st-button.c +++ b/src/st/st-button.c @@ -98,10 +98,6 @@ static void st_button_update_label_style (StButton *button) { ClutterActor *label; - StThemeNode *theme_node; - ClutterColor color; - const PangoFontDescription *font; - gchar *font_string = NULL; label = st_bin_get_child ((StBin*) button); @@ -109,15 +105,7 @@ st_button_update_label_style (StButton *button) if (!CLUTTER_IS_TEXT (label)) return; - theme_node = st_widget_get_theme_node (ST_WIDGET (button)); - - st_theme_node_get_foreground_color (theme_node, &color); - clutter_text_set_color (CLUTTER_TEXT (label), &color); - - font = st_theme_node_get_font (theme_node); - font_string = pango_font_description_to_string (font); - clutter_text_set_font_name (CLUTTER_TEXT (label), font_string); - g_free (font_string); + _st_set_text_from_style ((ClutterText*) label, st_widget_get_theme_node (ST_WIDGET (button))); } static void diff --git a/src/st/st-label.c b/src/st/st-label.c index db9b0c154..1a304a4bf 100644 --- a/src/st/st-label.c +++ b/src/st/st-label.c @@ -43,7 +43,7 @@ #include #include "st-label.h" - +#include "st-private.h" #include "st-widget.h" enum @@ -110,21 +110,9 @@ st_label_get_property (GObject *gobject, static void st_label_style_changed (StWidget *self) { - StLabelPrivate *priv; - StThemeNode *theme_node; - ClutterColor color; - const PangoFontDescription *font; - gchar *font_string; + StLabelPrivate *priv = ST_LABEL(self)->priv; - priv = ST_LABEL (self)->priv; - theme_node = st_widget_get_theme_node (self); - st_theme_node_get_foreground_color (theme_node, &color); - clutter_text_set_color (CLUTTER_TEXT (priv->label), &color); - - font = st_theme_node_get_font (theme_node); - font_string = pango_font_description_to_string (font); - clutter_text_set_font_name (CLUTTER_TEXT (priv->label), font_string); - g_free (font_string); + _st_set_text_from_style ((ClutterText *)priv->label, st_widget_get_theme_node (self)); ST_WIDGET_CLASS (st_label_parent_class)->style_changed (self); } diff --git a/src/st/st-private.c b/src/st/st-private.c index 7332e122a..182e36de7 100644 --- a/src/st/st-private.c +++ b/src/st/st-private.c @@ -110,3 +110,52 @@ _st_allocate_fill (ClutterActor *child, *childbox = allocation; } + +/** + * _st_set_text_from_style: + * @text: Target #ClutterText + * @theme_node: Source #StThemeNode + * + * Set various GObject properties of the @text object using + * CSS information from @theme_node. + */ +void +_st_set_text_from_style (ClutterText *text, + StThemeNode *theme_node) +{ + + ClutterColor color; + StTextDecoration decoration; + PangoAttrList *attribs; + const PangoFontDescription *font; + gchar *font_string; + + st_theme_node_get_foreground_color (theme_node, &color); + clutter_text_set_color (text, &color); + + font = st_theme_node_get_font (theme_node); + font_string = pango_font_description_to_string (font); + clutter_text_set_font_name (text, font_string); + g_free (font_string); + + attribs = pango_attr_list_new (); + + decoration = st_theme_node_get_text_decoration (theme_node); + if (decoration & ST_TEXT_DECORATION_UNDERLINE) + { + PangoAttribute *underline = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE); + pango_attr_list_insert (attribs, underline); + } + if (decoration & ST_TEXT_DECORATION_LINE_THROUGH) + { + PangoAttribute *strikethrough = pango_attr_strikethrough_new (TRUE); + pango_attr_list_insert (attribs, strikethrough); + } + /* Pango doesn't have an equivalent attribute for _OVERLINE, and we deliberately + * skip BLINK (for now...) + */ + + clutter_text_set_attributes (text, attribs); + + pango_attr_list_unref (attribs); +} diff --git a/src/st/st-private.h b/src/st/st-private.h index 34ef85e74..42ac82423 100644 --- a/src/st/st-private.h +++ b/src/st/st-private.h @@ -55,4 +55,7 @@ void _st_allocate_fill (ClutterActor *child, gboolean x_fill, gboolean y_fill); +void _st_set_text_from_style (ClutterText *text, + StThemeNode *theme_node); + #endif /* __ST_PRIVATE_H__ */