[evince] [document] Fixes handling of broken documents



commit 3fe3051453cad77a2964c96b53caf4e5a432b2fe
Author: Nickolay V. Shmyrev <nshmyrev yandex ru>
Date:   Sun May 3 15:35:39 2009 +0400

    [document] Fixes handling of broken documents
    
    Instead of aborting on assertion, we gracefully report that document is broken.
    Fixes GNOME bug #580886.
---
 backend/pdf/ev-poppler.cc     |    2 +-
 libview/ev-page-cache.c       |   24 ++++++++++++++++++++++--
 libview/ev-page-cache.h       |    1 +
 shell/ev-sidebar-thumbnails.c |    9 +++++++--
 shell/ev-window.c             |   23 +++++++++++++++--------
 5 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc
index 3c39e59..70af88e 100644
--- a/backend/pdf/ev-poppler.cc
+++ b/backend/pdf/ev-poppler.cc
@@ -1341,7 +1341,7 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails
 		pixbuf = make_thumbnail_for_page (poppler_page, rc, width, height);
 	}
 
-        if (border) {		
+        if (border && pixbuf) {
 		border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf);
 		g_object_unref (pixbuf);
 		pixbuf = border_pixbuf;
diff --git a/libview/ev-page-cache.c b/libview/ev-page-cache.c
index a8639ef..c3bb60c 100644
--- a/libview/ev-page-cache.c
+++ b/libview/ev-page-cache.c
@@ -416,8 +416,6 @@ ev_page_cache_new (EvDocument *document)
 	/* make some sanity check assertions */
 	if (! page_cache->uniform)
 		g_assert (page_cache->size_cache != NULL);
-	if (page_cache->uniform && page_cache->n_pages > 0)
-		g_assert (page_cache->uniform_width > 0 && page_cache->uniform_height > 0);
 
 	ev_document_doc_mutex_unlock ();
 
@@ -427,6 +425,28 @@ ev_page_cache_new (EvDocument *document)
 	return page_cache;
 }
 
+gboolean
+ev_page_cache_check_dimensions (EvPageCache *page_cache)
+{
+	gint document_width, document_height;
+
+	if (page_cache->uniform && page_cache->n_pages > 0)
+		if (page_cache->uniform_width <= 0 || page_cache->uniform_height <= 0)
+			return TRUE;
+
+	ev_page_cache_get_max_width (page_cache,
+    		    	    	     0, 1.0,
+				     &document_width);
+	ev_page_cache_get_max_height (page_cache,
+				      0, 1.0,
+				      &document_height);
+
+	if (document_width <= 0 || document_height <= 0)
+		return TRUE;
+
+	return FALSE;
+}
+
 gint
 ev_page_cache_get_n_pages (EvPageCache *page_cache)
 {
diff --git a/libview/ev-page-cache.h b/libview/ev-page-cache.h
index 814ede7..03e43d7 100644
--- a/libview/ev-page-cache.h
+++ b/libview/ev-page-cache.h
@@ -83,6 +83,7 @@ gboolean       ev_page_cache_set_page_label      (EvPageCache *page_cache,
 
 EvPageCache   *ev_page_cache_get		 (EvDocument *document);
 
+gboolean       ev_page_cache_check_dimensions	 (EvPageCache *page_cache);
 
 G_END_DECLS
 
diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c
index 08be12b..d86e6a5 100644
--- a/shell/ev-sidebar-thumbnails.c
+++ b/shell/ev-sidebar-thumbnails.c
@@ -662,9 +662,14 @@ ev_sidebar_thumbnails_set_document (EvSidebarPage	*sidebar_page,
 
 	EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
 
-	g_return_if_fail (EV_IS_DOCUMENT_THUMBNAILS (document));
-
 	priv->page_cache = ev_page_cache_get (document);
+
+	if (!EV_IS_DOCUMENT_THUMBNAILS (document) ||
+	    ev_page_cache_get_n_pages (priv->page_cache) <= 0 ||
+	    ev_page_cache_check_dimensions (priv->page_cache)) {
+		return;
+	}
+
 	priv->document = document;
 	priv->n_pages = ev_page_cache_get_n_pages (priv->page_cache);
 	priv->loading_icons = g_hash_table_new_full (g_str_hash,
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 5d99f66..bc7d151 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -992,10 +992,12 @@ setup_document_from_metadata (EvWindow *window)
 			request_width = MIN (request_width, gdk_screen_get_width (screen));
 			request_height = MIN (request_width, gdk_screen_get_height (screen));
 		}
-			        
-		gtk_window_resize (GTK_WINDOW (window),
-				   request_width,
-				   request_height);
+		
+		if (request_width > 0 && request_height > 0) {
+			gtk_window_resize (GTK_WINDOW (window),
+					   request_width,
+					   request_height);
+		}
 	    	g_value_unset (&width_ratio);
 		g_value_unset (&height_ratio);
 	}
@@ -1157,7 +1159,8 @@ ev_window_refresh_window_thumbnail (EvWindow *ev_window, int rotation)
 	EvDocument *document = ev_window->priv->document;
 	
 	if (!EV_IS_DOCUMENT_THUMBNAILS (document) ||
-	    ev_page_cache_get_n_pages (ev_window->priv->page_cache) <= 0) {
+	    ev_page_cache_get_n_pages (ev_window->priv->page_cache) <= 0 ||
+	    ev_page_cache_check_dimensions (ev_window->priv->page_cache)) {
 		return;
 	}
 	
@@ -1244,15 +1247,19 @@ ev_window_set_document (EvWindow *ev_window, EvDocument *document)
 		ev_window->priv->dest = NULL;
 	}
 
-	if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) > 0) {
-		ev_view_set_document (view, document);
-	} else {
+	if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) <= 0) {
 		ev_window_warning_message (ev_window, "%s",
 					   _("The document contains no pages"));
+	} else if (ev_page_cache_check_dimensions (ev_window->priv->page_cache)) {
+		ev_window_warning_message (ev_window, "%s",
+					   _("The document contains only empty pages"));
+	} else {
+		ev_view_set_document (view, document);
 	}
 
 	if (ev_window->priv->setup_document_idle > 0)
 		g_source_remove (ev_window->priv->setup_document_idle);
+
 	ev_window->priv->setup_document_idle = g_idle_add ((GSourceFunc)ev_window_setup_document, ev_window);
 }
 



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