[gnome-shell] [St] Implement text-decoration: [underline|strikethrough]



commit 55fbb9d0af6d8f533876d6e8cf07c0fbf665f996
Author: Colin Walters <walters verbum org>
Date:   Wed Dec 2 14:42:26 2009 -0500

    [St] Implement text-decoration: [underline|strikethrough]
    
    Move CSS handling of StLabel and StButton for their underlying
    ClutterText objects into st_private, and implement support for
    the underline and strikethrough St text-decoration properties.
    
    Overline isn't implemented for lack of a corresponding Pango
    attribute, and blink, well...
    
    https://bugzilla.gnome.org/show_bug.cgi?id=599661

 src/st/st-button.c  |   14 +-------------
 src/st/st-label.c   |   20 ++++----------------
 src/st/st-private.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/st/st-private.h |    3 +++
 4 files changed, 57 insertions(+), 29 deletions(-)
---
diff --git a/src/st/st-button.c b/src/st/st-button.c
index e1602e0..52032f0 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 db9b0c1..1a304a4 100644
--- a/src/st/st-label.c
+++ b/src/st/st-label.c
@@ -43,7 +43,7 @@
 #include <clutter/clutter.h>
 
 #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;
-
-  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);
+  StLabelPrivate *priv = ST_LABEL(self)->priv;
+
+  _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 7332e12..182e36d 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 34ef85e..42ac824 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__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]