[sushi] font-widget: make sure not to pass NULL to check_font_contains_text()



commit 3e08d423fdf92228195151b8a6ee4642307ebdd5
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue May 1 16:33:28 2012 -0400

    font-widget: make sure not to pass NULL to check_font_contains_text()
    
    Since FT_Face->family_name can be NULL, g_strconcat() would return NULL
    immediately, resulting in an empty font_name.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=675239

 src/libsushi/sushi-font-widget.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/src/libsushi/sushi-font-widget.c b/src/libsushi/sushi-font-widget.c
index 11e1811..a9c286b 100644
--- a/src/libsushi/sushi-font-widget.c
+++ b/src/libsushi/sushi-font-widget.c
@@ -54,7 +54,6 @@ struct _SushiFontWidgetPrivate {
   gchar *sample_string;
 
   gchar *font_name;
-  gboolean font_supports_title;
 };
 
 static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
@@ -212,11 +211,18 @@ build_strings_for_face (SushiFontWidget *self)
   else
     self->priv->sample_string = random_string_from_available_chars (self->priv->face, 36);
 
-  self->priv->font_name =
-    g_strconcat (self->priv->face->family_name, " ",
-                 self->priv->face->style_name, NULL);
-  self->priv->font_supports_title =
-    check_font_contain_text (self->priv->face, self->priv->font_name);
+  if (self->priv->face->family_name == NULL) {
+    self->priv->font_name = NULL;
+  } else {
+    gchar *font_name = 
+      g_strconcat (self->priv->face->family_name, " ",
+                   self->priv->face->style_name, NULL);
+
+    if (check_font_contain_text (self->priv->face, font_name))
+      self->priv->font_name = font_name;
+    else
+      g_free (font_name);
+  }
 }
 
 static gint *
@@ -326,7 +332,7 @@ sushi_font_widget_size_request (GtkWidget *drawing_area,
   cairo_set_font_face (cr, font);
   cairo_font_face_destroy (font);
 
-  if (self->priv->font_supports_title) {
+  if (self->priv->font_name != NULL) {
       cairo_set_font_size (cr, title_size);
       cairo_font_extents (cr, &font_extents);
       cairo_text_extents (cr, self->priv->font_name, &extents);
@@ -450,7 +456,7 @@ sushi_font_widget_draw (GtkWidget *drawing_area,
 
   /* draw text */
 
-  if (self->priv->font_supports_title) {
+  if (self->priv->font_name != NULL) {
     cairo_set_font_size (cr, title_size);
     draw_string (cr, padding, self->priv->font_name, &pos_y);
   }



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