cairo: Avoid GLib-GObject-CRITICAL from g_object_unref() on error path.
[pspp-builds.git] / src / output / cairo.c
index 612878035eb98baf98e20020c1c33919fad19355..3584f30f575c4ef680d1d232ed3350f3e9e51ad3 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -235,7 +235,7 @@ static struct output_driver *
 xr_create (const char *name, enum output_device_type device_type,
            struct string_map *o)
 {
-  enum { MIN_LENGTH = 3 };
+  enum { MIN_WIDTH = 3, MIN_LENGTH = 3 };
   struct output_driver *d;
   struct xr_driver *xr;
   cairo_surface_t *surface;
@@ -300,6 +300,16 @@ xr_create (const char *name, enum output_device_type device_type,
   if (!xr_set_cairo (xr, xr->cairo))
     goto error;
 
+  if (xr->width / (xr->font_height / 2) < MIN_WIDTH)
+    {
+      error (0, 0, _("The defined page is not wide enough to hold at least %d "
+                     "characters in the default font.  In fact, there's only "
+                     "room for %d characters."),
+             MIN_WIDTH,
+             xr->width / (xr->font_height / 2));
+      goto error;
+    }
+
   if (xr->length / xr->font_height < MIN_LENGTH)
     {
       error (0, 0, _("The defined page is not long "
@@ -487,7 +497,8 @@ xr_submit (struct output_driver *driver, const struct output_item *output_item)
           {
             struct table_item *item;
 
-            item = table_item_create (table_from_string (0, text), NULL);
+            item = table_item_create (table_from_string (TAB_LEFT, text),
+                                      NULL);
             xr_submit (&xr->driver, &item->output_item);
             table_item_unref (item);
           }
@@ -884,7 +895,8 @@ free_font (struct xr_font *font)
   if (font->desc != NULL)
     pango_font_description_free (font->desc);
   pango_font_metrics_unref (font->metrics);
-  g_object_unref (font->layout);
+  if (font->layout != NULL)
+    g_object_unref (font->layout);
 }
 
 /* Cairo driver class. */
@@ -945,7 +957,8 @@ xr_rendering_create (struct xr_driver *xr, const struct output_item *item,
       const char *text = text_item_get_text (text_item);
       struct table_item *table_item;
 
-      table_item = table_item_create (table_from_string (0, text), NULL);
+      table_item = table_item_create (table_from_string (TAB_LEFT, text),
+                                      NULL);
       r = xr_rendering_create (xr, &table_item->output_item, cr);
       table_item_unref (table_item);
     }