X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=backend%2Fdjvu%2Fdjvu-document.c;h=8b45514b6652af06a4dd6cc0db77e6a04f4f6fb9;hb=refs%2Ftags%2FEVINCE_0_8_2;hp=ad18555960a6332d7720dc2e686b4f9ceb495d64;hpb=13a06349251874bd35d2f03c3fc93217cee749a2;p=evince.git diff --git a/backend/djvu/djvu-document.c b/backend/djvu/djvu-document.c index ad185559..8b45514b 100644 --- a/backend/djvu/djvu-document.c +++ b/backend/djvu/djvu-document.c @@ -26,10 +26,8 @@ #include "ev-document-find.h" #include "ev-document-links.h" -#include -#include -#include #include +#include #include #include @@ -67,10 +65,13 @@ djvu_handle_events (DjvuDocument *djvu_document, int wait) { ddjvu_context_t *ctx = djvu_document->d_context; const ddjvu_message_t *msg; + if (!ctx) return; + if (wait) msg = ddjvu_message_wait (ctx); + while ((msg = ddjvu_message_peek (ctx))) { switch (msg->m_any.tag) { case DDJVU_ERROR: @@ -80,6 +81,7 @@ djvu_handle_events (DjvuDocument *djvu_document, int wait) g_warning ("DjvuLibre error: %s:%d", msg->m_error.filename, msg->m_error.lineno); + break; default: break; } @@ -95,6 +97,7 @@ djvu_document_load (EvDocument *document, DjvuDocument *djvu_document = DJVU_DOCUMENT (document); ddjvu_document_t *doc; gchar *filename; + gboolean missing_files = FALSE; /* FIXME: We could actually load uris */ filename = g_filename_from_uri (uri, NULL, error); @@ -103,7 +106,10 @@ djvu_document_load (EvDocument *document, doc = ddjvu_document_create_by_filename (djvu_document->d_context, filename, TRUE); - if (!doc) return FALSE; + if (!doc) { + g_free (filename); + return FALSE; + } if (djvu_document->d_document) ddjvu_document_release (djvu_document->d_document); @@ -111,10 +117,51 @@ djvu_document_load (EvDocument *document, djvu_document->d_document = doc; while (!ddjvu_document_decoding_done (djvu_document->d_document)) - djvu_handle_events(djvu_document, TRUE); + djvu_handle_events (djvu_document, TRUE); g_free (djvu_document->uri); djvu_document->uri = g_strdup (uri); + if (ddjvu_document_get_type (djvu_document->d_document) == DDJVU_DOCTYPE_INDIRECT) { + gint n_files; + gint i; + gchar *base; + + base = g_path_get_dirname (filename); + + n_files = ddjvu_document_get_filenum (djvu_document->d_document); + for (i = 0; i < n_files; i++) { + struct ddjvu_fileinfo_s fileinfo; + gchar *file; + + ddjvu_document_get_fileinfo (djvu_document->d_document, + i, &fileinfo); + + if (fileinfo.type != 'P') + continue; + + file = g_build_filename (base, fileinfo.id, NULL); + if (!g_file_test (file, G_FILE_TEST_EXISTS)) { + missing_files = TRUE; + g_free (file); + + break; + } + g_free (file); + } + g_free (base); + } + g_free (filename); + + if (missing_files) { + g_set_error (error, + G_FILE_ERROR, + G_FILE_ERROR_EXIST, + _("The document is composed by several files. " + "One or more of such files cannot be accessed.")); + + return FALSE; + } + return TRUE; } @@ -150,7 +197,7 @@ djvu_document_get_page_size (EvDocument *document, ddjvu_status_t r; g_return_if_fail (djvu_document->d_document); - + while ((r = ddjvu_document_get_pageinfo(djvu_document->d_document, page, &info)) < DDJVU_JOB_OK) djvu_handle_events(djvu_document, TRUE); @@ -279,61 +326,65 @@ djvu_document_document_iface_init (EvDocumentIface *iface) static void djvu_document_thumbnails_get_dimensions (EvDocumentThumbnails *document, - gint page, - gint suggested_width, - gint *width, - gint *height) + EvRenderContext *rc, + gint *width, + gint *height) { DjvuDocument *djvu_document = DJVU_DOCUMENT (document); - gdouble p_width, p_height; - gdouble page_ratio; + gdouble page_width, page_height; - djvu_document_get_page_size (EV_DOCUMENT(djvu_document), page, &p_width, &p_height); + djvu_document_get_page_size (EV_DOCUMENT(djvu_document), rc->page, + &page_width, &page_height); - page_ratio = p_height / p_width; - *width = suggested_width; - *height = (gint) (suggested_width * page_ratio); - - return; + 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 GdkPixbuf * -djvu_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - gint page, - gint rotation, - gint width, - gboolean border) +djvu_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, + EvRenderContext *rc, + gboolean border) { DjvuDocument *djvu_document = DJVU_DOCUMENT (document); GdkPixbuf *pixbuf, *rotated_pixbuf; + gdouble page_width, page_height; gint thumb_width, thumb_height; - guchar *pixels; g_return_val_if_fail (djvu_document->d_document, NULL); + + djvu_document_get_page_size (EV_DOCUMENT(djvu_document), rc->page, + &page_width, &page_height); - djvu_document_thumbnails_get_dimensions (document, page, width, &thumb_width, &thumb_height); - + thumb_width = (gint) (page_width * rc->scale); + thumb_height = (gint) (page_height * rc->scale); + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, thumb_width, thumb_height); gdk_pixbuf_fill (pixbuf, 0xffffffff); pixels = gdk_pixbuf_get_pixels (pixbuf); - while (ddjvu_thumbnail_status (djvu_document->d_document, page, 1) < DDJVU_JOB_OK) + while (ddjvu_thumbnail_status (djvu_document->d_document, rc->page, 1) < DDJVU_JOB_OK) djvu_handle_events(djvu_document, TRUE); - ddjvu_thumbnail_render (djvu_document->d_document, page, + ddjvu_thumbnail_render (djvu_document->d_document, rc->page, &thumb_width, &thumb_height, djvu_document->d_format, gdk_pixbuf_get_rowstride (pixbuf), (gchar *)pixels); - rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rotation); + rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation); g_object_unref (pixbuf); if (border) { GdkPixbuf *tmp_pixbuf = rotated_pixbuf; - rotated_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, 0, tmp_pixbuf); + + rotated_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf); g_object_unref (tmp_pixbuf); }