X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=inline;f=djvu%2Fdjvu-document.c;h=3814787545a3a5b5ed283365dcb204e22147c709;hb=205c689a78e992d1ad3cf9223f7c95bf424dda94;hp=aa853a71e68d72c1be4518d733c929ac9bf1195f;hpb=560a7e43fe1f899e72130cb4ab1175d325f8e43c;p=evince.git diff --git a/djvu/djvu-document.c b/djvu/djvu-document.c index aa853a71..38147875 100644 --- a/djvu/djvu-document.c +++ b/djvu/djvu-document.c @@ -25,6 +25,11 @@ #include #include +#include +#include +#include +#include + #define SCALE_FACTOR 0.2 enum { @@ -44,6 +49,8 @@ struct _DjvuDocument ddjvu_context_t *d_context; ddjvu_document_t *d_document; ddjvu_format_t *d_format; + + gchar *uri; }; typedef struct _DjvuDocumentClass DjvuDocumentClass; @@ -85,6 +92,8 @@ djvu_document_load (EvDocument *document, ddjvu_message_wait (djvu_document->d_context); ddjvu_message_pop (djvu_document->d_context); } + g_free (djvu_document->uri); + djvu_document->uri = g_strdup (uri); return TRUE; } @@ -95,8 +104,32 @@ djvu_document_save (EvDocument *document, const char *uri, GError **error) { - g_warning ("djvu_document_save not implemented"); /* FIXME */ - return TRUE; + DjvuDocument *djvu_document = DJVU_DOCUMENT (document); + GnomeVFSResult result; + GnomeVFSURI *source_uri; + GnomeVFSURI *target_uri; + + if (!djvu_document->uri) + return FALSE; + + source_uri = gnome_vfs_uri_new (djvu_document->uri); + target_uri = gnome_vfs_uri_new (uri); + + result = gnome_vfs_xfer_uri (source_uri, target_uri, + GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS, + GNOME_VFS_XFER_ERROR_MODE_ABORT, + GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE, + NULL, + NULL); + gnome_vfs_uri_unref (target_uri); + gnome_vfs_uri_unref (source_uri); + + if (result != GNOME_VFS_OK) + g_set_error (error, + EV_DOCUMENT_ERROR, + 0, + gnome_vfs_result_to_string (result)); + return (result == GNOME_VFS_OK); } static int @@ -116,32 +149,26 @@ djvu_document_get_page_size (EvDocument *document, double *height) { DjvuDocument *djvu_document = DJVU_DOCUMENT (document); - - ddjvu_page_t *d_page; + ddjvu_pageinfo_t info; g_return_if_fail (djvu_document->d_document); - d_page = ddjvu_page_create_by_pageno (djvu_document->d_document, page); - - while (!ddjvu_page_decoding_done (d_page)) { + while (ddjvu_document_get_pageinfo(djvu_document->d_document, page, &info) < DDJVU_JOB_OK) { ddjvu_message_wait (djvu_document->d_context); ddjvu_message_pop (djvu_document->d_context); } - if (width) - *width = ddjvu_page_get_width (d_page) * SCALE_FACTOR; - if (height) - *height = ddjvu_page_get_height (d_page) * SCALE_FACTOR; - - ddjvu_page_release (d_page); + *width = info.width * SCALE_FACTOR; + *height = info.height * SCALE_FACTOR; } static GdkPixbuf * djvu_document_render_pixbuf (EvDocument *document, - int page, gdouble scale) + EvRenderContext *rc) { DjvuDocument *djvu_document = DJVU_DOCUMENT (document); GdkPixbuf *pixbuf; + GdkPixbuf *rotated_pixbuf; ddjvu_rect_t rrect; ddjvu_rect_t prect; @@ -149,15 +176,15 @@ djvu_document_render_pixbuf (EvDocument *document, double page_width, page_height; - d_page = ddjvu_page_create_by_pageno (djvu_document->d_document, page); + d_page = ddjvu_page_create_by_pageno (djvu_document->d_document, rc->page); while (!ddjvu_page_decoding_done (d_page)) { ddjvu_message_wait (djvu_document->d_context); ddjvu_message_pop (djvu_document->d_context); } - page_width = ddjvu_page_get_width (d_page) * scale * SCALE_FACTOR; - page_height = ddjvu_page_get_height (d_page) * scale * SCALE_FACTOR; + page_width = ddjvu_page_get_width (d_page) * rc->scale * SCALE_FACTOR; + page_height = ddjvu_page_get_height (d_page) * rc->scale * SCALE_FACTOR; pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, page_width, page_height); @@ -172,8 +199,10 @@ djvu_document_render_pixbuf (EvDocument *document, gdk_pixbuf_get_rowstride (pixbuf), (gchar *)gdk_pixbuf_get_pixels (pixbuf)); - - return pixbuf; + rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation); + g_object_unref (pixbuf); + + return rotated_pixbuf; } static void @@ -186,6 +215,7 @@ djvu_document_finalize (GObject *object) ddjvu_context_release (djvu_document->d_context); ddjvu_format_release (djvu_document->d_format); + g_free (djvu_document->uri); G_OBJECT_CLASS (djvu_document_parent_class)->finalize (object); } @@ -249,11 +279,12 @@ djvu_document_thumbnails_get_dimensions (EvDocumentThumbnails *document, static GdkPixbuf * djvu_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, gint page, + gint rotation, gint width, gboolean border) { DjvuDocument *djvu_document = DJVU_DOCUMENT (document); - GdkPixbuf *pixbuf; + GdkPixbuf *pixbuf, *rotated_pixbuf; gint thumb_width, thumb_height; guchar *pixels; @@ -262,15 +293,10 @@ djvu_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, djvu_document_thumbnails_get_dimensions (document, page, width, &thumb_width, &thumb_height); - if (border) { - pixbuf = ev_document_misc_get_thumbnail_frame (thumb_width, thumb_height, NULL); - pixels = gdk_pixbuf_get_pixels (pixbuf) + gdk_pixbuf_get_rowstride (pixbuf) + 4; - } else { - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, - thumb_width, thumb_height); - gdk_pixbuf_fill (pixbuf, 0xffffffff); - pixels = gdk_pixbuf_get_pixels (pixbuf); - } + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 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) { ddjvu_message_wait (djvu_document->d_context); @@ -282,8 +308,17 @@ djvu_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, djvu_document->d_format, gdk_pixbuf_get_rowstride (pixbuf), (gchar *)pixels); + + rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - 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); + g_object_unref (tmp_pixbuf); + } - return pixbuf; + return rotated_pixbuf; } static void