evince r3027 - in trunk: . backend/djvu



Author: carlosgc
Date: Tue Apr 29 19:09:39 2008
New Revision: 3027
URL: http://svn.gnome.org/viewvc/evince?rev=3027&view=rev

Log:
2008-04-29  Carlos Garcia Campos  <carlosgc gnome org>

	* backend/djvu/djvu-document-private.h:
	* backend/djvu/djvu-links.c:
	* backend/djvu/djvu-text.c:
	* backend/djvu/djvu-document.c: (djvu_handle_events),
	(djvu_wait_for_message), (djvu_document_load),
	(document_get_page_size), (djvu_document_render),
	(djvu_document_thumbnails_get_thumbnail),
	(djvu_document_file_exporter_end):

	Make sure load job doesn't finish successfully when the document
	is not successfully decoded by libdjvu. Fixes bug #530202.


Modified:
   trunk/ChangeLog
   trunk/backend/djvu/djvu-document-private.h
   trunk/backend/djvu/djvu-document.c
   trunk/backend/djvu/djvu-links.c
   trunk/backend/djvu/djvu-text.c

Modified: trunk/backend/djvu/djvu-document-private.h
==============================================================================
--- trunk/backend/djvu/djvu-document-private.h	(original)
+++ trunk/backend/djvu/djvu-document-private.h	Tue Apr 29 19:09:39 2008
@@ -45,6 +45,7 @@
 
 int  djvu_document_get_n_pages (EvDocument   *document);
 void djvu_handle_events        (DjvuDocument *djvu_document, 
-			        int           wait);
+			        int           wait,
+				GError      **error);
 
 #endif /* __DJVU_DOCUMENT_INTERNAL_H__ */

Modified: trunk/backend/djvu/djvu-document.c
==============================================================================
--- trunk/backend/djvu/djvu-document.c	(original)
+++ trunk/backend/djvu/djvu-document.c	Tue Apr 29 19:09:39 2008
@@ -68,8 +68,51 @@
      });
 
 
-void 
-djvu_handle_events (DjvuDocument *djvu_document, int wait)
+#define EV_DJVU_ERROR ev_djvu_error_quark ()
+
+static GQuark
+ev_djvu_error_quark (void)
+{
+	static GQuark q = 0;
+	if (q == 0)
+		q = g_quark_from_static_string ("ev-djvu-quark");
+	
+	return q;
+}
+
+static void
+handle_message (const ddjvu_message_t *msg, GError **error)
+{
+	switch (msg->m_any.tag) {
+	        case DDJVU_ERROR: {
+			gchar *error_str;
+			
+			if (msg->m_error.filename) {
+				error_str = g_strdup_printf ("DjvuLibre error: %s:%d",
+							     msg->m_error.filename,
+							     msg->m_error.lineno);
+			} else {
+				error_str = g_strdup_printf ("DjvuLibre error: %s",
+							     msg->m_error.message);
+			}
+			
+			if (error) {
+				g_set_error (error, EV_DJVU_ERROR, 0, error_str);
+			} else {
+				g_warning (error_str);
+			}
+				
+			g_free (error_str);
+			return;
+			}						     
+			break;
+	        default:
+			break;
+	}
+}
+
+void
+djvu_handle_events (DjvuDocument *djvu_document, int wait, GError **error)
 {
 	ddjvu_context_t *ctx = djvu_document->d_context;
 	const ddjvu_message_t *msg;
@@ -78,23 +121,31 @@
 		return;
 
 	if (wait)
-		msg = ddjvu_message_wait (ctx);
+		ddjvu_message_wait (ctx);
 
 	while ((msg = ddjvu_message_peek (ctx))) {
-		switch (msg->m_any.tag) {
-			case DDJVU_ERROR:
-				g_warning ("DjvuLibre error: %s", 
-					   msg->m_error.message);
-				if (msg->m_error.filename)
-					g_warning ("DjvuLibre error: %s:%d", 
-						   msg->m_error.filename,
-						   msg->m_error.lineno);
-				break;
-			default:
-				break;
-		}
+		handle_message (msg, error);
+		ddjvu_message_pop (ctx);
+		if (error && *error)
+			return;
+	}
+}
+
+static void
+djvu_wait_for_message (DjvuDocument *djvu_document, ddjvu_message_tag_t message, GError **error)
+{
+	ddjvu_context_t *ctx = djvu_document->d_context;
+	const ddjvu_message_t *msg;
+
+	ddjvu_message_wait (ctx);
+	while ((msg = ddjvu_message_peek (ctx)) && (msg->m_any.tag != message)) {
+		handle_message (msg, error);
 		ddjvu_message_pop (ctx);
+		if (error && *error)
+			return;
 	}
+	if (msg && msg->m_any.tag == message)
+		ddjvu_message_pop (ctx);
 }
 
 static gboolean
@@ -106,6 +157,7 @@
 	ddjvu_document_t *doc;
 	gchar *filename;
 	gboolean missing_files = FALSE;
+	GError *djvu_error = NULL;
 
 	/* FIXME: We could actually load uris  */
 	filename = g_filename_from_uri (uri, NULL, error);
@@ -124,8 +176,36 @@
 
 	djvu_document->d_document = doc;
 
-	while (!ddjvu_document_decoding_done (djvu_document->d_document)) 
-		djvu_handle_events (djvu_document, TRUE);
+	djvu_wait_for_message (djvu_document, DDJVU_DOCINFO, &djvu_error);
+	if (djvu_error) {
+		g_set_error (error,
+			     EV_DOCUMENT_ERROR,
+			     EV_DOCUMENT_ERROR_INVALID,
+			     djvu_error->message);
+		g_error_free (djvu_error);
+		g_free (filename);
+		ddjvu_document_release (djvu_document->d_document);
+		djvu_document->d_document = NULL;
+
+		return FALSE;
+	}
+
+	if (ddjvu_document_decoding_error (djvu_document->d_document))
+		djvu_handle_events (djvu_document, TRUE, &djvu_error);
+
+	if (djvu_error) {
+		g_set_error (error,
+			     EV_DOCUMENT_ERROR,
+			     EV_DOCUMENT_ERROR_INVALID,
+			     djvu_error->message);
+		g_error_free (djvu_error);
+		g_free (filename);
+		ddjvu_document_release (djvu_document->d_document);
+		djvu_document->d_document = NULL;
+		
+		return FALSE;
+	}
+	
 	g_free (djvu_document->uri);
 	djvu_document->uri = g_strdup (uri);
 
@@ -204,10 +284,10 @@
 	ddjvu_status_t r;
 	
 	while ((r = ddjvu_document_get_pageinfo(djvu_document->d_document, page, &info)) < DDJVU_JOB_OK)
-		djvu_handle_events(djvu_document, TRUE);
+		djvu_handle_events(djvu_document, TRUE, NULL);
 	
 	if (r >= DDJVU_JOB_FAILED)
-		djvu_handle_events(djvu_document, TRUE);
+		djvu_handle_events(djvu_document, TRUE, NULL);
 
         *width = info.width * SCALE_FACTOR; 
         *height = info.height * SCALE_FACTOR;
@@ -245,7 +325,7 @@
 	d_page = ddjvu_page_create_by_pageno (djvu_document->d_document, rc->page->index);
 	
 	while (!ddjvu_page_decoding_done (d_page))
-		djvu_handle_events(djvu_document, TRUE);
+		djvu_handle_events(djvu_document, TRUE, NULL);
 
 	page_width = ddjvu_page_get_width (d_page) * rc->scale * SCALE_FACTOR + 0.5;
 	page_height = ddjvu_page_get_height (d_page) * rc->scale * SCALE_FACTOR + 0.5;
@@ -435,7 +515,7 @@
 	pixels = gdk_pixbuf_get_pixels (pixbuf);
 	
 	while (ddjvu_thumbnail_status (djvu_document->d_document, rc->page->index, 1) < DDJVU_JOB_OK)
-		djvu_handle_events(djvu_document, TRUE);
+		djvu_handle_events(djvu_document, TRUE, NULL);
 		    
 	ddjvu_thumbnail_render (djvu_document->d_document, rc->page->index, 
 				&thumb_width, &thumb_height,
@@ -504,7 +584,7 @@
 
 	ddjvu_job_t * job = ddjvu_document_print(djvu_document->d_document, fn, d_optc, d_optv);
 	while (!ddjvu_job_done(job)) {	
-		djvu_handle_events (djvu_document, TRUE);
+		djvu_handle_events (djvu_document, TRUE, NULL);
 	}
 
 	fclose(fn); 

Modified: trunk/backend/djvu/djvu-links.c
==============================================================================
--- trunk/backend/djvu/djvu-links.c	(original)
+++ trunk/backend/djvu/djvu-links.c	Tue Apr 29 19:09:39 2008
@@ -344,7 +344,7 @@
 	miniexp_t outline;
 
 	while ((outline = ddjvu_document_get_outline (djvu_document->d_document)) == miniexp_dummy)
-		djvu_handle_events (djvu_document, TRUE);
+		djvu_handle_events (djvu_document, TRUE, NULL);
 
 	if (outline) {
 		ddjvu_miniexp_release (djvu_document->d_document, outline);
@@ -367,10 +367,10 @@
         ddjvu_pageinfo_t page_info;
 
 	while ((page_annotations = ddjvu_document_get_pageanno (djvu_document->d_document, page)) == miniexp_dummy)
-		djvu_handle_events (djvu_document, TRUE);
+		djvu_handle_events (djvu_document, TRUE, NULL);
 
 	while (ddjvu_document_get_pageinfo (djvu_document->d_document, page, &page_info) < DDJVU_JOB_OK)
-		djvu_handle_events(djvu_document, TRUE);
+		djvu_handle_events(djvu_document, TRUE, NULL);
 
 	if (page_annotations) {
 		hyperlinks = ddjvu_anno_get_hyperlinks (page_annotations);
@@ -417,7 +417,7 @@
 	miniexp_t outline = miniexp_nil;
 
 	while ((outline = ddjvu_document_get_outline (djvu_document->d_document)) == miniexp_dummy)
-		djvu_handle_events (djvu_document, TRUE);
+		djvu_handle_events (djvu_document, TRUE, NULL);
 
 	if (outline) {
 		model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,

Modified: trunk/backend/djvu/djvu-text.c
==============================================================================
--- trunk/backend/djvu/djvu-text.c	(original)
+++ trunk/backend/djvu/djvu-text.c	Tue Apr 29 19:09:39 2008
@@ -62,7 +62,7 @@
 		ddjvu_document_get_pagetext (djvu_document->d_document,
 					     djvu_text->search_page,
 					     "char")) == miniexp_dummy)
-		djvu_handle_events (djvu_document, TRUE);
+		djvu_handle_events (djvu_document, TRUE, NULL);
 
 	if (page_text != miniexp_nil) {
 		DjvuTextPage *page = djvu_text_page_new (page_text);
@@ -168,7 +168,7 @@
 	while ((page_text =
 		ddjvu_document_get_pagetext (djvu_document->d_document,
 					     page, "char")) == miniexp_dummy)
-		djvu_handle_events (djvu_document, TRUE);
+		djvu_handle_events (djvu_document, TRUE, NULL);
 
 	if (page_text != miniexp_nil) {
 		DjvuTextPage *page = djvu_text_page_new (page_text);



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