#include "ev-document-find.h"
#include "ev-document-links.h"
-#include <libdjvu/ddjvuapi.h>
-#include <libdjvu/miniexp.h>
-#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf-core.h>
+#include <glib/gi18n.h>
#include <glib/gunicode.h>
#include <string.h>
{
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:
g_warning ("DjvuLibre error: %s:%d",
msg->m_error.filename,
msg->m_error.lineno);
+ break;
default:
break;
}
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);
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);
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;
}
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);
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);
}