[goffice] Fix crash when drawing a fallback image without gtk. [#705677]



commit 4c59135ffd3dd5281693c0bc34a5b74914103a32
Author: Jean Brefort <jean brefort normalesup org>
Date:   Fri Aug 9 12:05:05 2013 +0200

    Fix crash when drawing a fallback image without gtk. [#705677]

 ChangeLog                    |    8 ++++++++
 NEWS                         |    1 +
 goffice/canvas/goc-graph.c   |    2 +-
 goffice/graph/gog-renderer.h |   10 ++++++++++
 goffice/utils/go-editor.c    |    2 ++
 goffice/utils/go-image.c     |   35 ++++++++++++++++++++++++-----------
 6 files changed, 46 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 702bcc8..de9db5d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-08-09  Jean Brefort  <jean brefort normalesup org>
+
+       * goffice/canvas/goc-graph.c: fix build without gtk.
+       * goffice/graph/gog-renderer.h: ditto.
+       * goffice/utils/go-editor.c (go_editor_add_page): ditto.
+       * goffice/utils/go-image.c (go_image_draw_fb),
+       (go_image_get_pixbuf_fb), (go_image_new_from_data): ditto and .
+
 2013-08-05  Jean Brefort  <jean brefort normalesup org>
 
        * docs/reference/goffice-0.10-sections.txt: make gtk-doc happy.
diff --git a/NEWS b/NEWS
index 4834355..0ab1996 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ Jean:
        * Fix area vs diameter selection in bubble plots. [#705312]
        * Implement get_data_at_point for area and line plots. [#627277][#689661]
        * Fix rendring of stacked area plots. [#705034]
+       * Fix crash when drawing a fallback image without gtk. [#705677]
 
 Morten:
        * Add prescaling to go_linear_regression_leverage.  [#703381]
diff --git a/goffice/canvas/goc-graph.c b/goffice/canvas/goc-graph.c
index 9afc132..d1397cb 100644
--- a/goffice/canvas/goc-graph.c
+++ b/goffice/canvas/goc-graph.c
@@ -224,6 +224,7 @@ goc_graph_update_bounds (GocItem *item)
                                      (int) (graph->h * item->canvas->pixels_per_unit));
 }
 
+#ifdef GOFFICE_WITH_GTK
 static char *
 format_coordinate (GogAxis *axis, GOFormat *fmt, double x)
 {
@@ -245,7 +246,6 @@ format_coordinate (GogAxis *axis, GOFormat *fmt, double x)
        return g_string_free (res, FALSE);
 }
 
-#ifdef GOFFICE_WITH_GTK
 static void
 goc_graph_do_tooltip (GocGraph *graph)
 {
diff --git a/goffice/graph/gog-renderer.h b/goffice/graph/gog-renderer.h
index 5b53755..ce8d5ec 100644
--- a/goffice/graph/gog-renderer.h
+++ b/goffice/graph/gog-renderer.h
@@ -79,6 +79,16 @@ void  gog_renderer_draw_selection_rectangle  (GogRenderer *renderer, GogViewAlloc
 
 void  gog_renderer_draw_marker   (GogRenderer *rend, double x, double y);
 
+#ifndef GOFFICE_WITH_GTK
+typedef enum
+{
+  GTK_JUSTIFY_LEFT,
+  GTK_JUSTIFY_RIGHT,
+  GTK_JUSTIFY_CENTER,
+  GTK_JUSTIFY_FILL
+} GtkJustification;
+#endif
+
 void  gog_renderer_draw_text     (GogRenderer *rend, char const *text,
                                   GogViewAllocation const *pos,
                                   GOAnchorType anchor,
diff --git a/goffice/utils/go-editor.c b/goffice/utils/go-editor.c
index 76b9584..01492fe 100644
--- a/goffice/utils/go-editor.c
+++ b/goffice/utils/go-editor.c
@@ -131,11 +131,13 @@ go_editor_add_page (GOEditor *editor, gpointer widget, char const *label)
        page = g_new0 (GOEditorPage, 1);
 
        page->widget = widget;
+#ifdef GOFFICE_WITH_GTK
        if (editor->use_scrolled) {
                page->scrolled = g_object_ref (gtk_scrolled_window_new (NULL, NULL));
                gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (page->scrolled),
                                                           widget);
        } else
+#endif
                page->scrolled = g_object_ref (widget);
        page->label = label;
 
diff --git a/goffice/utils/go-image.c b/goffice/utils/go-image.c
index 34e52f2..491fee7 100644
--- a/goffice/utils/go-image.c
+++ b/goffice/utils/go-image.c
@@ -418,6 +418,7 @@ go_image_finalize (GObject *obj)
 static void
 go_image_draw_fb (GOImage *image, cairo_t *cr)
 {
+#ifdef GOFFICE_WITH_GTK
        if (image->pixbuf) {
                cairo_rectangle (cr, 0., 0., image->width, image->height);
                gdk_cairo_set_source_pixbuf (cr, image->pixbuf, 0, 0);
@@ -428,6 +429,8 @@ go_image_draw_fb (GOImage *image, cairo_t *cr)
                                                                                         "unknown_image", 
100, 0, NULL);
                double dx, dy;
                int n;
+               if (placeholder == NULL)
+                       return;
                n = go_fake_floor (image->width / gdk_pixbuf_get_width (placeholder));
                dx = (image->width - n * gdk_pixbuf_get_width (placeholder)) / 2.;
                n = go_fake_floor (image->height / gdk_pixbuf_get_height (placeholder));
@@ -440,12 +443,15 @@ go_image_draw_fb (GOImage *image, cairo_t *cr)
                cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
                cairo_fill (cr);
                cairo_restore (cr);
+               g_object_unref (placeholder);
        }
+#endif
 }
 
 static GdkPixbuf *
 go_image_get_pixbuf_fb (GOImage *image)
 {
+#ifdef GOFFICE_WITH_GTK
        cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                                                    image->width,
                                                                    image->height);
@@ -479,6 +485,9 @@ go_image_get_pixbuf_fb (GOImage *image)
                                                       gdk_pixbuf_get_rowstride (ret));
        cairo_surface_destroy (surface);
        return ret;
+#else
+       return NULL;
+#endif
 }
 
 static GdkPixbuf *
@@ -660,6 +669,7 @@ go_image_new_from_data (char const *type, guint8 const *data, gsize length, char
                }
        }
        if (image == NULL) {
+#ifdef GOFFICE_WITH_GTK
                GdkScreen *screen = gdk_screen_get_default ();
                GtkIconTheme *theme = screen
                        ? gtk_icon_theme_get_default()
@@ -667,19 +677,22 @@ go_image_new_from_data (char const *type, guint8 const *data, gsize length, char
                GdkPixbuf *placeholder;
                const char *icon_name;
 
-               if (gtk_icon_theme_has_icon (theme,"unknown_image"))
-                       icon_name = "unknown_image";
-               else if (gtk_icon_theme_has_icon (theme,"unknown"))
-                       icon_name = "unknown";
-               else
-                       icon_name = gtk_icon_theme_get_example_icon_name (theme);
+               if (theme) {
+                       if (gtk_icon_theme_has_icon (theme, "unknown_image"))
+                               icon_name = "unknown_image";
+                       else if (gtk_icon_theme_has_icon (theme, "unknown"))
+                               icon_name = "unknown";
+                       else
+                               icon_name = gtk_icon_theme_get_example_icon_name (theme);
 
-               placeholder = gtk_icon_theme_load_icon (theme, icon_name, 100, 0, NULL);
-               image = go_pixbuf_new_from_pixbuf (placeholder);
-               g_object_unref (placeholder);
+                       placeholder = gtk_icon_theme_load_icon (theme, icon_name, 100, 0, NULL);
+                       image = go_pixbuf_new_from_pixbuf (placeholder);
+                       g_object_unref (placeholder);
 
-               if (!screen)
-                       g_object_unref (theme);
+                       if (!screen)
+                               g_object_unref (theme);
+               }
+#endif
        }
        if (format)
                *format = g_strdup (type);


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