[baobab/wip/vala] Escape pango markup in charts



commit 2a46c51d1843145647b6e8384bdd2aceb4cea89f
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Jan 7 19:00:25 2012 +0100

    Escape pango markup in charts

 src/baobab-ringschart.c |   32 +++++++++++++++++++-------------
 src/baobab-treemap.c    |   15 ++++++++++-----
 2 files changed, 29 insertions(+), 18 deletions(-)
---
diff --git a/src/baobab-ringschart.c b/src/baobab-ringschart.c
index f801862..8f10abe 100644
--- a/src/baobab-ringschart.c
+++ b/src/baobab-ringschart.c
@@ -429,20 +429,9 @@ baobab_ringschart_draw_subfolder_tips (GtkWidget *chart, cairo_t *cr)
 {
   BaobabRingschartPrivate *priv;
   GList *node;
-  BaobabChartItem *item;
-  BaobabRingschartItem *data;
   gdouble q_angle, q_width, q_height;
-  gdouble tip_x, tip_y;
-  gdouble middle_angle, middle_angle_n, middle_radius;
-  gdouble sector_center_x, sector_center_y;
-  gdouble a;
-  guint i;
   GtkAllocation allocation;
-  PangoLayout *layout;
-  PangoRectangle layout_rect;
-  gchar *markup = NULL;
-  cairo_rectangle_t tooltip_rect;
-  GdkRectangle _rect, last_rect;
+  GdkRectangle last_rect;
 
   priv = BAOBAB_RINGSCHART (chart)->priv;
 
@@ -458,6 +447,20 @@ baobab_ringschart_draw_subfolder_tips (GtkWidget *chart, cairo_t *cr)
   node = priv->subtip_items;
   while (node != NULL)
     {
+      BaobabChartItem *item;
+      BaobabRingschartItem *data;
+      gdouble middle_angle, middle_angle_n, middle_radius;
+      gdouble tip_x, tip_y;
+      gdouble sector_center_x, sector_center_y;
+      gdouble a;
+      guint i;
+      char *escaped;
+      char *markup;
+      PangoLayout *layout;
+      PangoRectangle layout_rect;
+      GdkRectangle _rect;
+      cairo_rectangle_t tooltip_rect;
+
       item = (BaobabChartItem *) node->data;
       data = (BaobabRingschartItem *) item->data;
 
@@ -472,9 +475,12 @@ baobab_ringschart_draw_subfolder_tips (GtkWidget *chart, cairo_t *cr)
 
       /* get the pango layout and its enclosing rectangle */
       layout = gtk_widget_create_pango_layout (chart, NULL);
-      markup = g_strconcat ("<span size=\"small\">", item->name, "</span>", NULL);
+      escaped = g_markup_escape_text (item->name, -1);
+      markup = g_strconcat ("<span size=\"small\">", escaped, "</span>", NULL);
       pango_layout_set_markup (layout, markup, -1);
+      g_free (escaped);
       g_free (markup);
+
       pango_layout_set_indent (layout, 0);
       pango_layout_set_spacing (layout, 0);
       pango_layout_get_pixel_extents (layout, NULL, &layout_rect);
diff --git a/src/baobab-treemap.c b/src/baobab-treemap.c
index 1a84539..b9d0956 100644
--- a/src/baobab-treemap.c
+++ b/src/baobab-treemap.c
@@ -137,15 +137,20 @@ baobab_treemap_draw_rectangle (GtkWidget        *chart,
 
   if ((show_text) && (ITEM_SHOW_LABEL))
     {
+      char *markup;
+
       layout = gtk_widget_create_pango_layout (chart, NULL);
-      pango_layout_set_markup (layout, text, -1);
+      markup = g_markup_escape_text (text, -1);
+      pango_layout_set_markup (layout, markup, -1);
+      g_free (markup);
+
       pango_layout_get_pixel_extents (layout, NULL, &rect);
 
-      if ((rect.width + ITEM_TEXT_PADDING*2 <= width) &&
-          (rect.height + ITEM_TEXT_PADDING*2 <= height))
+      if ((rect.width + ITEM_TEXT_PADDING * 2 <= width) &&
+          (rect.height + ITEM_TEXT_PADDING * 2 <= height))
         {
-          cairo_move_to (cr, x + width/2 - rect.width/2,
-                         y + height/2 - rect.height/2);
+          cairo_move_to (cr, x + width / 2 - rect.width / 2,
+                         y + height / 2 - rect.height / 2);
           pango_cairo_show_layout (cr, layout);
         }
 



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