]> www.fi.muni.cz Git - evince.git/blobdiff - backend/impress/impress-document.c
Check pointer != NULL before using it. Fixes bug #416841.
[evince.git] / backend / impress / impress-document.c
index 3ea993d1c8e83a7dc511ae6de1ad8f92a494b8b8..5f5982ed7fcc08b928e8012e6ec5b883cc0e5910 100644 (file)
@@ -19,7 +19,9 @@
  */
 
 #include <gtk/gtk.h>
+#include <glib/gi18n.h>
 #include <string.h>
+
 #include "imposter.h"
 #include "impress-document.h"
 #include "ev-document-thumbnails.h"
@@ -286,8 +288,10 @@ impress_document_load (EvDocument  *document,
   filename = g_filename_from_uri (uri, NULL, error);
   if (!filename)
     {
-      //FIXME
-      //g_error_set ();
+      g_set_error (error,
+                  EV_DOCUMENT_ERROR,
+                  EV_DOCUMENT_ERROR_INVALID,
+                  _("Remote files aren't supported"));
       return FALSE;
     }
 
@@ -295,7 +299,10 @@ impress_document_load (EvDocument  *document,
 
   if (!imp)
     {
-      //FIXME translate the err, set error
+      g_set_error (error,
+                  EV_DOCUMENT_ERROR,
+                  EV_DOCUMENT_ERROR_INVALID,
+                  _("Invalid document"));
       g_free (filename);
       return FALSE;
     }
@@ -357,6 +364,7 @@ imp_render_get_from_drawable (ImpressDocument *impress_document)
                                         0, 0,
                                         0, 0,
                                         PAGE_WIDTH, PAGE_HEIGHT);
+
   g_cond_broadcast (impress_document->cond);
   return FALSE;
 }
@@ -376,10 +384,12 @@ impress_document_render_pixbuf (EvDocument  *document,
   g_mutex_lock (impress_document->mutex);
   impress_document->cond = g_cond_new ();
 
+  ev_document_fc_mutex_unlock ();
   g_idle_add ((GSourceFunc) imp_render_get_from_drawable, impress_document);
-
   g_cond_wait (impress_document->cond, impress_document->mutex);
   g_cond_free (impress_document->cond);
+  ev_document_fc_mutex_lock ();
+
   g_mutex_unlock (impress_document->mutex);
 
   scaled_pixbuf = gdk_pixbuf_scale_simple (impress_document->pixbuf,
@@ -397,13 +407,23 @@ impress_document_finalize (GObject *object)
 {
   ImpressDocument *impress_document = IMPRESS_DOCUMENT (object);
 
-  g_mutex_free (impress_document->mutex);
+  if (impress_document->mutex)
+    g_mutex_free (impress_document->mutex);
+
+  if (impress_document->imp)
+    imp_close (impress_document->imp);
+
+  if (impress_document->ctx)
+    imp_delete_context (impress_document->ctx);
+
+  if (impress_document->pango_ctx)
+    g_object_unref (impress_document->pango_ctx);
+
+  if (impress_document->pixmap)
+    g_object_unref (G_OBJECT (impress_document->pixmap));
 
-  imp_close (impress_document->imp);
-  imp_delete_context (impress_document->ctx);
-  g_free (impress_document->pango_ctx);
-  g_object_unref (G_OBJECT (impress_document->pixmap));
-  g_object_unref (impress_document->gc);
+  if (impress_document->gc)
+    g_object_unref (impress_document->gc);
 
   G_OBJECT_CLASS (impress_document_parent_class)->finalize (object);
 }
@@ -447,27 +467,19 @@ impress_document_document_iface_init (EvDocumentIface *iface)
 
 static GdkPixbuf *
 impress_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
-                                       gint                  page,
-                                       gint                  rotation,
-                                       gint                  size,
-                                       gboolean              border)
+                                          EvRenderContext      *rc, 
+                                          gboolean              border)
 {
   GdkPixbuf *pixbuf = NULL;
   gdouble w, h;
-  EvRenderContext *rc;
 
-  impress_document_get_page_size (EV_DOCUMENT (document),
-                              page,
-                              &w, &h);
-
-  rc = ev_render_context_new (rotation, page, size/w);
   pixbuf = impress_document_render_pixbuf (EV_DOCUMENT (document), rc);
-  g_object_unref (G_OBJECT (rc));
 
   if (border)
     {
       GdkPixbuf *tmp_pixbuf = pixbuf;
-      pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, 0, tmp_pixbuf);
+      
+      pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf);
       g_object_unref (tmp_pixbuf);
     }
 
@@ -476,21 +488,26 @@ impress_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
 
 static void
 impress_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
-                                        gint                  page,
-                                        gint                  suggested_width,
-                                        gint                 *width,
-                                        gint                 *height)
+                                           EvRenderContext      *rc,
+                                           gint                 *width,
+                                           gint                 *height)
 {
-  gdouble page_ratio;
-  gdouble w, h;
+  gdouble page_width, page_height;
 
   impress_document_get_page_size (EV_DOCUMENT (document),
-                              page,
-                              &w, &h);
-  g_return_if_fail (w > 0);
-  page_ratio = h/w;
-  *width = suggested_width;
-  *height = (gint) (suggested_width * page_ratio);
+                                 rc->page,
+                                 &page_width, &page_height);
+  
+  if (rc->rotation == 90 || rc->rotation == 270)
+    {
+      *width = (gint) (page_height * rc->scale);
+      *height = (gint) (page_width * rc->scale);
+    }
+  else
+    {
+      *width = (gint) (page_width * rc->scale);
+      *height = (gint) (page_height * rc->scale);
+    }
 }
 
 static void
@@ -513,7 +530,7 @@ impress_document_init (ImpressDocument *impress_document)
   impress_document->pixmap = gdk_pixmap_new (window,
                                             PAGE_WIDTH, PAGE_HEIGHT, -1);
   impress_document->gc = gdk_gc_new (impress_document->pixmap);
-  impress_document->pango_ctx = gdk_pango_context_get ();
+  impress_document->pango_ctx = gdk_pango_context_get_for_screen (gdk_screen_get_default ());
 }
 
 /*