From: Carlos Garcia Campos Date: Fri, 16 Feb 2007 17:27:12 +0000 (+0000) Subject: Use an EvRenderContext for rendering thumbnails instead of a suggested X-Git-Tag: EVINCE_0_8_0~44 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=1d6150237848b4c1fede94ce23baa4fd8870fd93;p=evince.git Use an EvRenderContext for rendering thumbnails instead of a suggested 2007-02-16 Carlos Garcia Campos * backend/dvi/dvi-document.c: (dvi_document_thumbnails_get_dimensions), (dvi_document_thumbnails_get_thumbnail): * backend/impress/impress-document.c: (impress_document_thumbnails_get_thumbnail), (impress_document_thumbnails_get_dimensions): * backend/ps/ps-document.c: (ps_document_thumbnails_get_thumbnail), (ps_document_thumbnails_get_dimensions): * backend/djvu/djvu-document.c: (djvu_document_thumbnails_get_dimensions), (djvu_document_thumbnails_get_thumbnail): * backend/tiff/tiff-document.c: (tiff_document_thumbnails_get_thumbnail), (tiff_document_thumbnails_get_dimensions): * backend/pdf/ev-poppler.cc: (make_thumbnail_for_page), (pdf_document_thumbnails_get_thumbnail), (pdf_document_thumbnails_get_dimensions): * backend/comics/comics-document.c: (comics_document_thumbnails_get_thumbnail), (comics_document_thumbnails_get_dimensions): * backend/pixbuf/pixbuf-document.c: (pixbuf_document_thumbnails_get_thumbnail), (pixbuf_document_thumbnails_get_dimensions): * libdocument/ev-document-thumbnails.[ch]: (ev_document_thumbnails_get_thumbnail), (ev_document_thumbnails_get_dimensions): * libdocument/ev-document-misc.[ch]: (ev_document_misc_get_thumbnail_frame): * shell/ev-jobs.[ch]: (ev_job_thumbnail_dispose), (ev_job_thumbnail_new), (ev_job_thumbnail_run): * shell/ev-sidebar-thumbnails.c: (get_scale_for_page), (add_range), (ev_sidebar_thumbnails_set_loading_icon), (refresh), (ev_sidebar_thumbnails_refresh): * shell/ev-window.c: (ev_window_setup_document): * thumbnailer/evince-thumbnailer.c: (evince_thumbnail_pngenc_get): Use an EvRenderContext for rendering thumbnails instead of a suggested width, so that different sized pages get sized proportionally. svn path=/trunk/; revision=2332 --- diff --git a/ChangeLog b/ChangeLog index e83ae34a..08b37b5b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,44 @@ +2007-02-16 Carlos Garcia Campos + + * backend/dvi/dvi-document.c: + (dvi_document_thumbnails_get_dimensions), + (dvi_document_thumbnails_get_thumbnail): + * backend/impress/impress-document.c: + (impress_document_thumbnails_get_thumbnail), + (impress_document_thumbnails_get_dimensions): + * backend/ps/ps-document.c: (ps_document_thumbnails_get_thumbnail), + (ps_document_thumbnails_get_dimensions): + * backend/djvu/djvu-document.c: + (djvu_document_thumbnails_get_dimensions), + (djvu_document_thumbnails_get_thumbnail): + * backend/tiff/tiff-document.c: + (tiff_document_thumbnails_get_thumbnail), + (tiff_document_thumbnails_get_dimensions): + * backend/pdf/ev-poppler.cc: (make_thumbnail_for_page), + (pdf_document_thumbnails_get_thumbnail), + (pdf_document_thumbnails_get_dimensions): + * backend/comics/comics-document.c: + (comics_document_thumbnails_get_thumbnail), + (comics_document_thumbnails_get_dimensions): + * backend/pixbuf/pixbuf-document.c: + (pixbuf_document_thumbnails_get_thumbnail), + (pixbuf_document_thumbnails_get_dimensions): + * libdocument/ev-document-thumbnails.[ch]: + (ev_document_thumbnails_get_thumbnail), + (ev_document_thumbnails_get_dimensions): + * libdocument/ev-document-misc.[ch]: + (ev_document_misc_get_thumbnail_frame): + * shell/ev-jobs.[ch]: (ev_job_thumbnail_dispose), + (ev_job_thumbnail_new), (ev_job_thumbnail_run): + * shell/ev-sidebar-thumbnails.c: (get_scale_for_page), (add_range), + (ev_sidebar_thumbnails_set_loading_icon), (refresh), + (ev_sidebar_thumbnails_refresh): + * shell/ev-window.c: (ev_window_setup_document): + * thumbnailer/evince-thumbnailer.c: (evince_thumbnail_pngenc_get): + + Use an EvRenderContext for rendering thumbnails instead of a suggested + width, so that different sized pages get sized proportionally. + 2007-02-15 Carlos Garcia Campos * shell/ev-view.c: (ev_view_button_press_event), diff --git a/backend/comics/comics-document.c b/backend/comics/comics-document.c index 7f53f85a..e0fdd31e 100644 --- a/backend/comics/comics-document.c +++ b/backend/comics/comics-document.c @@ -409,52 +409,19 @@ get_supported_image_extensions() return extensions; } -static void -comics_document_thumbnails_get_geometry (EvDocumentThumbnails *document, - gint page, - gint suggested_width, - gint *width, - gint *height, - gdouble *scale_factor) -{ - gdouble orig_width, orig_height, scale; - - comics_document_get_page_size (EV_DOCUMENT (document), page, - &orig_width, &orig_height); - scale = suggested_width / orig_width; - - if (width) - *width = suggested_width; - if (height) - *height = orig_height * scale; - if (scale_factor) - *scale_factor = scale; -} - static GdkPixbuf * comics_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - gint page, - gint rotation, - gint size, - gboolean border) + EvRenderContext *rc, + gboolean border) { - GdkPixbuf *thumbnail, *framed; - gint thumb_width, thumb_height; - gdouble scale; - EvRenderContext *rc; + GdkPixbuf *thumbnail; - comics_document_thumbnails_get_geometry (document, page, size, - &thumb_width, &thumb_height, - &scale); - - rc = ev_render_context_new (rotation, page, scale); - thumbnail = comics_document_render_pixbuf (EV_DOCUMENT (document), - rc); - g_object_unref (G_OBJECT (rc)); + thumbnail = comics_document_render_pixbuf (EV_DOCUMENT (document), rc); if (border) { GdkPixbuf *tmp_pixbuf = thumbnail; - thumbnail = ev_document_misc_get_thumbnail_frame (-1, -1, 0, tmp_pixbuf); + + thumbnail = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf); g_object_unref (tmp_pixbuf); } @@ -463,14 +430,22 @@ comics_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, static void comics_document_thumbnails_get_dimensions (EvDocumentThumbnails *document, - gint page, - gint suggested_width, - gint *width, - gint *height) + EvRenderContext *rc, + gint *width, + gint *height) { - comics_document_thumbnails_get_geometry (document, page, - suggested_width, - width, height, NULL); + gdouble page_width, page_height; + + comics_document_get_page_size (EV_DOCUMENT (document), rc->page, + &page_width, &page_height); + + 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 void diff --git a/backend/djvu/djvu-document.c b/backend/djvu/djvu-document.c index bf74c9a2..8b45514b 100644 --- a/backend/djvu/djvu-document.c +++ b/backend/djvu/djvu-document.c @@ -326,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); } diff --git a/backend/dvi/dvi-document.c b/backend/dvi/dvi-document.c index 4de5e64e..bd699709 100644 --- a/backend/dvi/dvi-document.c +++ b/backend/dvi/dvi-document.c @@ -17,8 +17,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include - #include "dvi-document.h" #include "ev-document-thumbnails.h" #include "ev-document-misc.h" @@ -267,27 +265,27 @@ dvi_document_document_iface_init (EvDocumentIface *iface) static void dvi_document_thumbnails_get_dimensions (EvDocumentThumbnails *document, - gint page, - gint suggested_width, + EvRenderContext *rc, gint *width, gint *height) { - DviDocument *dvi_document = DVI_DOCUMENT (document); - gdouble page_ratio; - - page_ratio = dvi_document->base_height / dvi_document->base_width; - *width = suggested_width; - *height = (gint) (suggested_width * page_ratio); + DviDocument *dvi_document = DVI_DOCUMENT (document); + gdouble page_width = dvi_document->base_width; + gdouble page_height = dvi_document->base_height; - 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 * -dvi_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - gint page, - gint rotation, - gint width, - gboolean border) +dvi_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, + EvRenderContext *rc, + gboolean border) { DviDocument *dvi_document = DVI_DOCUMENT (document); GdkPixbuf *pixbuf; @@ -296,11 +294,12 @@ dvi_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, gint thumb_width, thumb_height; gint proposed_width, proposed_height; - dvi_document_thumbnails_get_dimensions (document, page, width, &thumb_width, &thumb_height); - + thumb_width = (gint) (dvi_document->base_width * rc->scale); + thumb_height = (gint) (dvi_document->base_height * rc->scale); + g_mutex_lock (dvi_context_mutex); - mdvi_setpage(dvi_document->context, page); + mdvi_setpage (dvi_document->context, rc->page); mdvi_set_shrink (dvi_document->context, (int)dvi_document->base_width * dvi_document->params->hshrink / thumb_width, @@ -325,12 +324,13 @@ dvi_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, g_mutex_unlock (dvi_context_mutex); - 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); } diff --git a/backend/impress/impress-document.c b/backend/impress/impress-document.c index 9756a84d..5f5982ed 100644 --- a/backend/impress/impress-document.c +++ b/backend/impress/impress-document.c @@ -467,27 +467,19 @@ impress_document_document_iface_init (EvDocumentIface *iface) static GdkPixbuf * impress_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - gint page, - gint rotation, - gint size, - gboolean border) + EvRenderContext *rc, + gboolean border) { GdkPixbuf *pixbuf = NULL; gdouble w, h; - EvRenderContext *rc; - impress_document_get_page_size (EV_DOCUMENT (document), - page, - &w, &h); - - rc = ev_render_context_new (rotation, page, size/w); pixbuf = impress_document_render_pixbuf (EV_DOCUMENT (document), rc); - g_object_unref (G_OBJECT (rc)); if (border) { GdkPixbuf *tmp_pixbuf = pixbuf; - pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, 0, tmp_pixbuf); + + pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf); g_object_unref (tmp_pixbuf); } @@ -496,21 +488,26 @@ impress_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, static void impress_document_thumbnails_get_dimensions (EvDocumentThumbnails *document, - gint page, - gint suggested_width, - gint *width, - gint *height) + EvRenderContext *rc, + gint *width, + gint *height) { - gdouble page_ratio; - gdouble w, h; + gdouble page_width, page_height; impress_document_get_page_size (EV_DOCUMENT (document), - page, - &w, &h); - g_return_if_fail (w > 0); - page_ratio = h/w; - *width = suggested_width; - *height = (gint) (suggested_width * page_ratio); + rc->page, + &page_width, &page_height); + + 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 void diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc index 7c2c5281..715226ad 100644 --- a/backend/pdf/ev-poppler.cc +++ b/backend/pdf/ev-poppler.cc @@ -92,8 +92,7 @@ static void pdf_document_file_exporter_iface_init (EvFileExporterIface static void pdf_selection_iface_init (EvSelectionIface *iface); static void pdf_document_page_transition_iface_init (EvDocumentTransitionIface *iface); static void pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails, - gint page, - gint size, + EvRenderContext *rc, gint *width, gint *height); static int pdf_document_get_n_pages (EvDocument *document); @@ -1174,32 +1173,15 @@ pdf_document_document_images_iface_init (EvDocumentImagesIface *iface) } static GdkPixbuf * -make_thumbnail_for_size (PdfDocument *pdf_document, - gint page, - int rotation, - gint size) +make_thumbnail_for_page (PdfDocument *pdf_document, + PopplerPage *poppler_page, + EvRenderContext *rc) { - PopplerPage *poppler_page; GdkPixbuf *pixbuf; int width, height; - double scale; - gdouble unscaled_width, unscaled_height; - poppler_page = poppler_document_get_page (pdf_document->document, page); - g_return_val_if_fail (poppler_page != NULL, NULL); - - pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document), page, - size, &width, &height); - poppler_page_get_size (poppler_page, &unscaled_width, &unscaled_height); - scale = width / unscaled_width; - - /* rotate */ - if (rotation == 90 || rotation == 270) { - int temp; - temp = width; - width = height; - height = temp; - } + pdf_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (pdf_document), + rc, &width, &height); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); @@ -1208,20 +1190,15 @@ make_thumbnail_for_size (PdfDocument *pdf_document, ev_document_fc_mutex_lock (); poppler_page_render_to_pixbuf (poppler_page, 0, 0, width, height, - scale, rotation, pixbuf); + rc->scale, rc->rotation, pixbuf); ev_document_fc_mutex_unlock (); - - - g_object_unref (poppler_page); return pixbuf; } static GdkPixbuf * pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails, - gint page, - gint rotation, - gint size, + EvRenderContext *rc, gboolean border) { PdfDocument *pdf_document; @@ -1231,18 +1208,17 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails pdf_document = PDF_DOCUMENT (document_thumbnails); - poppler_page = poppler_document_get_page (pdf_document->document, page); + poppler_page = poppler_document_get_page (pdf_document->document, rc->page); g_return_val_if_fail (poppler_page != NULL, NULL); pixbuf = poppler_page_get_thumbnail (poppler_page); - - if (pixbuf == NULL) { + if (!pixbuf) { /* There is no provided thumbnail. We need to make one. */ - pixbuf = make_thumbnail_for_size (pdf_document, page, rotation, size); + pixbuf = make_thumbnail_for_page (pdf_document, poppler_page, rc); } if (border) { - border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, rotation, pixbuf); + border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf); g_object_unref (pixbuf); pixbuf = border_pixbuf; } @@ -1254,8 +1230,7 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails static void pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails, - gint page, - gint size, + EvRenderContext *rc, gint *width, gint *height) { @@ -1264,10 +1239,8 @@ pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnail gint has_thumb; pdf_document = PDF_DOCUMENT (document_thumbnails); - poppler_page = poppler_document_get_page (pdf_document->document, page); + poppler_page = poppler_document_get_page (pdf_document->document, rc->page); - g_return_if_fail (width != NULL); - g_return_if_fail (height != NULL); g_return_if_fail (poppler_page != NULL); has_thumb = poppler_page_get_thumbnail_size (poppler_page, width, height); @@ -1276,9 +1249,19 @@ pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnail double page_width, page_height; poppler_page_get_size (poppler_page, &page_width, &page_height); - *width = size; - *height = (int) (size * page_height / page_width); + + *width = (gint) (page_width * rc->scale); + *height = (gint) (page_height * rc->scale); } + + if (rc->rotation == 90 || rc->rotation == 270) { + gint temp; + + temp = *width; + *width = *height; + *height = temp; + } + g_object_unref (poppler_page); } diff --git a/backend/pixbuf/pixbuf-document.c b/backend/pixbuf/pixbuf-document.c index e3d064da..c1cace00 100644 --- a/backend/pixbuf/pixbuf-document.c +++ b/backend/pixbuf/pixbuf-document.c @@ -168,25 +168,22 @@ pixbuf_document_document_iface_init (EvDocumentIface *iface) } static GdkPixbuf * -pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - gint page, - gint rotation, - gint size, - gboolean border) +pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, + EvRenderContext *rc, + gboolean border) { PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document); GdkPixbuf *pixbuf, *rotated_pixbuf; - gdouble scale_factor; - gint height; + gint width, height; - scale_factor = (gdouble)size / gdk_pixbuf_get_width (pixbuf_document->pixbuf); - - height = gdk_pixbuf_get_height (pixbuf_document->pixbuf) * scale_factor; + width = (gint) (gdk_pixbuf_get_width (pixbuf_document->pixbuf) * rc->scale); + height = (gint) (gdk_pixbuf_get_height (pixbuf_document->pixbuf) * rc->scale); - pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, size, height, + pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, + width, height, GDK_INTERP_BILINEAR); - rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rotation); + rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation); g_object_unref (pixbuf); return rotated_pixbuf; @@ -194,18 +191,21 @@ pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, static void pixbuf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document, - gint page, - gint suggested_width, - gint *width, - gint *height) + EvRenderContext *rc, + gint *width, + gint *height) { PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document); - gdouble page_ratio; - - page_ratio = ((double)gdk_pixbuf_get_height (pixbuf_document->pixbuf)) / - gdk_pixbuf_get_width (pixbuf_document->pixbuf); - *width = suggested_width; - *height = (gint) (suggested_width * page_ratio); + gint p_width = gdk_pixbuf_get_width (pixbuf_document->pixbuf); + gint p_height = gdk_pixbuf_get_height (pixbuf_document->pixbuf); + + if (rc->rotation == 90 || rc->rotation == 270) { + *width = (gint) (p_height * rc->scale); + *height = (gint) (p_width * rc->scale); + } else { + *width = (gint) (p_width * rc->scale); + *height = (gint) (p_height * rc->scale); + } } static void diff --git a/backend/ps/ps-document.c b/backend/ps/ps-document.c index d1b456d2..0e79ec57 100644 --- a/backend/ps/ps-document.c +++ b/backend/ps/ps-document.c @@ -516,15 +516,11 @@ ps_document_render_thumbnail (PSDocument *ps_document) static GdkPixbuf * ps_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails, - gint page, - gint rotation, - gint size, + EvRenderContext *rc, gboolean border) { PSDocument *ps_document; GdkPixbuf *pixbuf = NULL; - gdouble page_width, page_height; - gdouble scale; ps_document = PS_DOCUMENT (document_thumbnails); @@ -543,19 +539,9 @@ ps_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails, ps_document->thumbs_mutex = g_mutex_new (); ps_document->thumbs_cond = g_cond_new (); - ps_document_get_page_size (EV_DOCUMENT (ps_document), page, - &page_width, &page_height); - scale = size / page_width; - - rotation = (rotation + ps_document_get_page_rotation (ps_document, page)) % 360; - - if (!ps_document->thumbs_rc) { - ps_document->thumbs_rc = ev_render_context_new (rotation, page, scale); - } else { - ev_render_context_set_page (ps_document->thumbs_rc, page); - ev_render_context_set_scale (ps_document->thumbs_rc, scale); - ev_render_context_set_rotation (ps_document->thumbs_rc, rotation); - } + if (ps_document->thumbs_rc) + g_object_unref (ps_document->thumbs_rc); + ps_document->thumbs_rc = g_object_ref (rc); ev_document_doc_mutex_unlock (); g_mutex_lock (ps_document->thumbs_mutex); @@ -572,7 +558,7 @@ ps_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails, if (border) { GdkPixbuf *border_pixbuf; - border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, rotation, pixbuf); + border_pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf); g_object_unref (pixbuf); pixbuf = border_pixbuf; } @@ -582,8 +568,7 @@ ps_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails, static void ps_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails, - gint page, - gint size, + EvRenderContext *rc, gint *width, gint *height) { @@ -593,10 +578,16 @@ ps_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails ps_document = PS_DOCUMENT (document_thumbnails); ps_document_get_page_size (EV_DOCUMENT (ps_document), - page, + rc->page, &page_width, &page_height); - *width = size; - *height = (int) (size * page_height / page_width); + + 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 void diff --git a/backend/tiff/tiff-document.c b/backend/tiff/tiff-document.c index 24af05fb..9348ed4e 100644 --- a/backend/tiff/tiff-document.c +++ b/backend/tiff/tiff-document.c @@ -67,15 +67,15 @@ static TIFFErrorHandler orig_warning_handler = NULL; static void push_handlers (void) { - orig_error_handler = TIFFSetErrorHandler (NULL); - orig_warning_handler = TIFFSetWarningHandler (NULL); + orig_error_handler = TIFFSetErrorHandler (NULL); + orig_warning_handler = TIFFSetWarningHandler (NULL); } static void pop_handlers (void) { - TIFFSetErrorHandler (orig_error_handler); - TIFFSetWarningHandler (orig_warning_handler); + TIFFSetErrorHandler (orig_error_handler); + TIFFSetWarningHandler (orig_warning_handler); } static gboolean @@ -83,44 +83,44 @@ tiff_document_load (EvDocument *document, const char *uri, GError **error) { - TiffDocument *tiff_document = TIFF_DOCUMENT (document); - gchar *filename; - TIFF *tiff; - - push_handlers (); - filename = g_filename_from_uri (uri, NULL, error); - if (!filename) - { - pop_handlers (); - return FALSE; - } - - tiff = TIFFOpen (filename, "r"); - if (tiff) - { - guint32 w, h; - /* FIXME: unused data? why bother here */ - TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &w); - TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &h); - } - if (!tiff) - { - pop_handlers (); - return FALSE; - } - tiff_document->tiff = tiff; - g_free (tiff_document->uri); - g_free (filename); - tiff_document->uri = g_strdup (uri); - - pop_handlers (); - return TRUE; + TiffDocument *tiff_document = TIFF_DOCUMENT (document); + gchar *filename; + TIFF *tiff; + + push_handlers (); + filename = g_filename_from_uri (uri, NULL, error); + if (!filename) { + pop_handlers (); + return FALSE; + } + + tiff = TIFFOpen (filename, "r"); + if (tiff) { + guint32 w, h; + + /* FIXME: unused data? why bother here */ + TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &w); + TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &h); + } + + if (!tiff) { + pop_handlers (); + return FALSE; + } + + tiff_document->tiff = tiff; + g_free (tiff_document->uri); + g_free (filename); + tiff_document->uri = g_strdup (uri); + + pop_handlers (); + return TRUE; } static gboolean tiff_document_save (EvDocument *document, - const char *uri, - GError **error) + const char *uri, + GError **error) { TiffDocument *tiff_document = TIFF_DOCUMENT (document); @@ -130,24 +130,23 @@ tiff_document_save (EvDocument *document, static int tiff_document_get_n_pages (EvDocument *document) { - TiffDocument *tiff_document = TIFF_DOCUMENT (document); - - g_return_val_if_fail (TIFF_IS_DOCUMENT (document), 0); - g_return_val_if_fail (tiff_document->tiff != NULL, 0); - - if (tiff_document->n_pages == -1) - { - push_handlers (); - tiff_document->n_pages = 0; - do - { - tiff_document->n_pages ++; + TiffDocument *tiff_document = TIFF_DOCUMENT (document); + + g_return_val_if_fail (TIFF_IS_DOCUMENT (document), 0); + g_return_val_if_fail (tiff_document->tiff != NULL, 0); + + if (tiff_document->n_pages == -1) { + push_handlers (); + tiff_document->n_pages = 0; + + do { + tiff_document->n_pages ++; + } + while (TIFFReadDirectory (tiff_document->tiff)); + pop_handlers (); } - while (TIFFReadDirectory (tiff_document->tiff)); - pop_handlers (); - } - return tiff_document->n_pages; + return tiff_document->n_pages; } static void @@ -156,117 +155,111 @@ tiff_document_get_page_size (EvDocument *document, double *width, double *height) { - guint32 w, h; - gfloat x_res, y_res; - TiffDocument *tiff_document = TIFF_DOCUMENT (document); - - g_return_if_fail (TIFF_IS_DOCUMENT (document)); - g_return_if_fail (tiff_document->tiff != NULL); - - push_handlers (); - if (TIFFSetDirectory (tiff_document->tiff, page) != 1) - { - pop_handlers (); - return; - } - - TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &w); - TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &h); - TIFFGetField (tiff_document->tiff, TIFFTAG_XRESOLUTION, &x_res); - TIFFGetField (tiff_document->tiff, TIFFTAG_YRESOLUTION, &y_res); - h = h * (x_res / y_res); - - *width = w; - *height = h; - - pop_handlers (); + guint32 w, h; + gfloat x_res, y_res; + TiffDocument *tiff_document = TIFF_DOCUMENT (document); + + g_return_if_fail (TIFF_IS_DOCUMENT (document)); + g_return_if_fail (tiff_document->tiff != NULL); + + push_handlers (); + if (TIFFSetDirectory (tiff_document->tiff, page) != 1) { + pop_handlers (); + return; + } + + TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &w); + TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &h); + TIFFGetField (tiff_document->tiff, TIFFTAG_XRESOLUTION, &x_res); + TIFFGetField (tiff_document->tiff, TIFFTAG_YRESOLUTION, &y_res); + h = h * (x_res / y_res); + + *width = w; + *height = h; + + pop_handlers (); } static GdkPixbuf * tiff_document_render_pixbuf (EvDocument *document, EvRenderContext *rc) { - TiffDocument *tiff_document = TIFF_DOCUMENT (document); - int width, height; - float x_res, y_res; - gint rowstride, bytes; - guchar *pixels = NULL; - GdkPixbuf *pixbuf; - GdkPixbuf *scaled_pixbuf; - GdkPixbuf *rotated_pixbuf; - - g_return_val_if_fail (TIFF_IS_DOCUMENT (document), 0); - g_return_val_if_fail (tiff_document->tiff != NULL, 0); - - push_handlers (); - if (TIFFSetDirectory (tiff_document->tiff, rc->page) != 1) - { - pop_handlers (); - return NULL; - } - - if (!TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &width)) - { - pop_handlers (); - return NULL; - } - - if (! TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &height)) - { - pop_handlers (); - return NULL; - } - - if (!TIFFGetField (tiff_document->tiff, TIFFTAG_XRESOLUTION, &x_res)) - { - pop_handlers (); - return NULL; - } - - if (! TIFFGetField (tiff_document->tiff, TIFFTAG_YRESOLUTION, &y_res)) - { - pop_handlers (); - return NULL; - } - - pop_handlers (); - - /* Sanity check the doc */ - if (width <= 0 || height <= 0) - return NULL; - - rowstride = width * 4; - if (rowstride / 4 != width) - /* overflow */ - return NULL; - - bytes = height * rowstride; - if (bytes / rowstride != height) - /* overflow */ - return NULL; - - pixels = g_try_malloc (bytes); - if (!pixels) - return NULL; + TiffDocument *tiff_document = TIFF_DOCUMENT (document); + int width, height; + float x_res, y_res; + gint rowstride, bytes; + guchar *pixels = NULL; + GdkPixbuf *pixbuf; + GdkPixbuf *scaled_pixbuf; + GdkPixbuf *rotated_pixbuf; + + g_return_val_if_fail (TIFF_IS_DOCUMENT (document), NULL); + g_return_val_if_fail (tiff_document->tiff != NULL, NULL); + + push_handlers (); + if (TIFFSetDirectory (tiff_document->tiff, rc->page) != 1) { + pop_handlers (); + return NULL; + } - pixbuf = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE, 8, - width, height, rowstride, - (GdkPixbufDestroyNotify) g_free, NULL); + if (!TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &width)) { + pop_handlers (); + return NULL; + } - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height); - TIFFReadRGBAImageOriented (tiff_document->tiff, width, height, (uint32 *)gdk_pixbuf_get_pixels (pixbuf), ORIENTATION_TOPLEFT, 1); - pop_handlers (); + if (! TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &height)) { + pop_handlers (); + return NULL; + } - scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, - width * rc->scale, - height * rc->scale * (x_res/y_res), - GDK_INTERP_BILINEAR); - g_object_unref (pixbuf); + if (!TIFFGetField (tiff_document->tiff, TIFFTAG_XRESOLUTION, &x_res)) { + pop_handlers (); + return NULL; + } - rotated_pixbuf = gdk_pixbuf_rotate_simple (scaled_pixbuf, 360 - rc->rotation); - g_object_unref (scaled_pixbuf); + if (! TIFFGetField (tiff_document->tiff, TIFFTAG_YRESOLUTION, &y_res)) { + pop_handlers (); + return NULL; + } - return rotated_pixbuf; + pop_handlers (); + + /* Sanity check the doc */ + if (width <= 0 || height <= 0) + return NULL; + + rowstride = width * 4; + if (rowstride / 4 != width) + /* overflow */ + return NULL; + + bytes = height * rowstride; + if (bytes / rowstride != height) + /* overflow */ + return NULL; + + pixels = g_try_malloc (bytes); + if (!pixels) + return NULL; + + pixbuf = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE, 8, + width, height, rowstride, + (GdkPixbufDestroyNotify) g_free, NULL); + + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height); + TIFFReadRGBAImageOriented (tiff_document->tiff, width, height, (uint32 *)gdk_pixbuf_get_pixels (pixbuf), ORIENTATION_TOPLEFT, 1); + pop_handlers (); + + scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, + width * rc->scale, + height * rc->scale * (x_res/y_res), + GDK_INTERP_BILINEAR); + g_object_unref (pixbuf); + + rotated_pixbuf = gdk_pixbuf_rotate_simple (scaled_pixbuf, 360 - rc->rotation); + g_object_unref (scaled_pixbuf); + + return rotated_pixbuf; } static void @@ -321,57 +314,49 @@ tiff_document_document_iface_init (EvDocumentIface *iface) static GdkPixbuf * tiff_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - gint page, - gint rotation, - gint size, + EvRenderContext *rc, gboolean border) { - EvRenderContext *rc; - GdkPixbuf *pixbuf; - gdouble w, h; - - tiff_document_get_page_size (EV_DOCUMENT (document), - page, - &w, &h); - - rc = ev_render_context_new (rotation, page, size/w); - pixbuf = tiff_document_render_pixbuf (EV_DOCUMENT (document), rc); - g_object_unref (G_OBJECT (rc)); - - if (border) - { - GdkPixbuf *tmp_pixbuf = pixbuf; - pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, 0, tmp_pixbuf); - g_object_unref (tmp_pixbuf); - } - - return pixbuf; + GdkPixbuf *pixbuf; + + pixbuf = tiff_document_render_pixbuf (EV_DOCUMENT (document), rc); + + if (border) { + GdkPixbuf *tmp_pixbuf = pixbuf; + + pixbuf = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf); + g_object_unref (tmp_pixbuf); + } + + return pixbuf; } static void tiff_document_thumbnails_get_dimensions (EvDocumentThumbnails *document, - gint page, - gint suggested_width, + EvRenderContext *rc, gint *width, gint *height) { - gdouble page_ratio; - gdouble w, h; - - tiff_document_get_page_size (EV_DOCUMENT (document), - page, - &w, &h); - g_return_if_fail (w > 0); - page_ratio = h/w; - *width = suggested_width; - *height = (gint) (suggested_width * page_ratio); + gdouble page_width, page_height; + + tiff_document_get_page_size (EV_DOCUMENT (document), + rc->page, + &page_width, &page_height); + + 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 void tiff_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface) { - iface->get_thumbnail = tiff_document_thumbnails_get_thumbnail; - iface->get_dimensions = tiff_document_thumbnails_get_dimensions; + iface->get_thumbnail = tiff_document_thumbnails_get_thumbnail; + iface->get_dimensions = tiff_document_thumbnails_get_dimensions; } /* postscript exporter implementation */ @@ -433,5 +418,5 @@ tiff_document_document_file_exporter_iface_init (EvFileExporterIface *iface) static void tiff_document_init (TiffDocument *tiff_document) { - tiff_document->n_pages = -1; + tiff_document->n_pages = -1; } diff --git a/libdocument/ev-document-misc.c b/libdocument/ev-document-misc.c index fd6f4493..89ff5fa8 100644 --- a/libdocument/ev-document-misc.c +++ b/libdocument/ev-document-misc.c @@ -12,7 +12,6 @@ GdkPixbuf * ev_document_misc_get_thumbnail_frame (int width, int height, - int rotation, GdkPixbuf *source_pixbuf) { GdkPixbuf *retval; @@ -21,9 +20,6 @@ ev_document_misc_get_thumbnail_frame (int width, int i; int width_r, height_r; - rotation = rotation % 360; - - if (source_pixbuf) g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL); @@ -31,15 +27,8 @@ ev_document_misc_get_thumbnail_frame (int width, width_r = gdk_pixbuf_get_width (source_pixbuf); height_r = gdk_pixbuf_get_height (source_pixbuf); } else { - if (rotation == 0 || rotation == 180) { - width_r = width; - height_r = height; - } else if (rotation == 90 || rotation == 270) { - width_r = height; - height_r = width; - } else { - g_assert_not_reached (); - } + width_r = width; + height_r = height; } /* make sure no one is passing us garbage */ diff --git a/libdocument/ev-document-misc.h b/libdocument/ev-document-misc.h index 41f1caed..5d846717 100644 --- a/libdocument/ev-document-misc.h +++ b/libdocument/ev-document-misc.h @@ -31,7 +31,6 @@ G_BEGIN_DECLS GdkPixbuf *ev_document_misc_get_thumbnail_frame (int width, int height, - int rotation, GdkPixbuf *source_pixbuf); void ev_document_misc_get_page_border_size (gint page_width, gint page_height, diff --git a/libdocument/ev-document-thumbnails.c b/libdocument/ev-document-thumbnails.c index c560cec1..1ed1974f 100644 --- a/libdocument/ev-document-thumbnails.c +++ b/libdocument/ev-document-thumbnails.c @@ -18,8 +18,6 @@ * */ -#include "config.h" - #include "ev-document-thumbnails.h" GType @@ -45,35 +43,34 @@ ev_document_thumbnails_get_type (void) } GdkPixbuf * -ev_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - gint page, - int rotation, - gint size, - gboolean border) +ev_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, + EvRenderContext *rc, + gboolean border) { EvDocumentThumbnailsIface *iface; g_return_val_if_fail (EV_IS_DOCUMENT_THUMBNAILS (document), NULL); + g_return_val_if_fail (EV_IS_RENDER_CONTEXT (rc), NULL); iface = EV_DOCUMENT_THUMBNAILS_GET_IFACE (document); - return iface->get_thumbnail (document, page, rotation, size, border); + return iface->get_thumbnail (document, rc, border); } void ev_document_thumbnails_get_dimensions (EvDocumentThumbnails *document, - gint page, - gint suggested_width, + EvRenderContext *rc, gint *width, gint *height) { EvDocumentThumbnailsIface *iface; g_return_if_fail (EV_IS_DOCUMENT_THUMBNAILS (document)); + g_return_if_fail (EV_IS_RENDER_CONTEXT (rc)); g_return_if_fail (width != NULL); g_return_if_fail (height != NULL); iface = EV_DOCUMENT_THUMBNAILS_GET_IFACE (document); - iface->get_dimensions (document, page, suggested_width, width, height); + iface->get_dimensions (document, rc, width, height); } diff --git a/libdocument/ev-document-thumbnails.h b/libdocument/ev-document-thumbnails.h index 6e15a327..648c0ebb 100644 --- a/libdocument/ev-document-thumbnails.h +++ b/libdocument/ev-document-thumbnails.h @@ -27,51 +27,39 @@ G_BEGIN_DECLS -#define EV_TYPE_DOCUMENT_THUMBNAILS (ev_document_thumbnails_get_type ()) -#define EV_DOCUMENT_THUMBNAILS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_DOCUMENT_THUMBNAILS, EvDocumentThumbnails)) -#define EV_DOCUMENT_THUMBNAILS_IFACE(k) (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_DOCUMENT_THUMBNAILS, EvDocumentThumbnailsIface)) -#define EV_IS_DOCUMENT_THUMBNAILS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EV_TYPE_DOCUMENT_THUMBNAILS)) -#define EV_IS_DOCUMENT_THUMBNAILS_IFACE(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_DOCUMENT_THUMBNAILS)) +#define EV_TYPE_DOCUMENT_THUMBNAILS (ev_document_thumbnails_get_type ()) +#define EV_DOCUMENT_THUMBNAILS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_DOCUMENT_THUMBNAILS, EvDocumentThumbnails)) +#define EV_DOCUMENT_THUMBNAILS_IFACE(k) (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_DOCUMENT_THUMBNAILS, EvDocumentThumbnailsIface)) +#define EV_IS_DOCUMENT_THUMBNAILS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EV_TYPE_DOCUMENT_THUMBNAILS)) +#define EV_IS_DOCUMENT_THUMBNAILS_IFACE(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_DOCUMENT_THUMBNAILS)) #define EV_DOCUMENT_THUMBNAILS_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EV_TYPE_DOCUMENT_THUMBNAILS, EvDocumentThumbnailsIface)) -typedef struct _EvDocumentThumbnails EvDocumentThumbnails; -typedef struct _EvDocumentThumbnailsIface EvDocumentThumbnailsIface; +typedef struct _EvDocumentThumbnails EvDocumentThumbnails; +typedef struct _EvDocumentThumbnailsIface EvDocumentThumbnailsIface; -struct _EvDocumentThumbnailsIface -{ +struct _EvDocumentThumbnailsIface { GTypeInterface base_iface; /* Methods */ GdkPixbuf * (* get_thumbnail) (EvDocumentThumbnails *document, - gint page, - gint rotation, - gint size, - gboolean border); + EvRenderContext *rc, + gboolean border); void (* get_dimensions) (EvDocumentThumbnails *document, - gint page, - gint suggested_width, - gint *width, - gint *height); + EvRenderContext *rc, + gint *width, + gint *height); }; -GType ev_document_thumbnails_get_type (void); - -/* FIXME: This is a little bit busted. We call get_thumbnail w/ a suggested - * width, but we should call it with a scale so that different sized pages get - * sized proportionally. - */ +GType ev_document_thumbnails_get_type (void) G_GNUC_CONST; GdkPixbuf *ev_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - gint page, - gint rotation, - gint size, + EvRenderContext *rc, gboolean border); void ev_document_thumbnails_get_dimensions (EvDocumentThumbnails *document, - gint page, - gint size, + EvRenderContext *rc, gint *width, gint *height); G_END_DECLS -#endif +#endif /* EV_DOCUMENT_THUMBNAILS_H */ diff --git a/shell/ev-jobs.c b/shell/ev-jobs.c index 9fb242a0..6ad4dfca 100644 --- a/shell/ev-jobs.c +++ b/shell/ev-jobs.c @@ -167,6 +167,11 @@ ev_job_thumbnail_dispose (GObject *object) job->thumbnail = NULL; } + if (job->rc) { + g_object_unref (job->rc); + job->rc = NULL; + } + (* G_OBJECT_CLASS (ev_job_thumbnail_parent_class)->dispose) (object); } @@ -354,19 +359,15 @@ ev_job_render_run (EvJobRender *job) } EvJob * -ev_job_thumbnail_new (EvDocument *document, - gint page, - int rotation, - gint requested_width) +ev_job_thumbnail_new (EvDocument *document, + EvRenderContext *rc) { EvJobThumbnail *job; job = g_object_new (EV_TYPE_JOB_THUMBNAIL, NULL); EV_JOB (job)->document = g_object_ref (document); - job->page = page; - job->rotation = rotation; - job->requested_width = requested_width; + job->rc = g_object_ref (rc); return EV_JOB (job); } @@ -380,10 +381,7 @@ ev_job_thumbnail_run (EvJobThumbnail *job) job->thumbnail = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (EV_JOB (job)->document), - job->page, - job->rotation, - job->requested_width, - TRUE); + job->rc, TRUE); EV_JOB (job)->finished = TRUE; ev_document_doc_mutex_unlock (); diff --git a/shell/ev-jobs.h b/shell/ev-jobs.h index 779c3736..1f210ece 100644 --- a/shell/ev-jobs.h +++ b/shell/ev-jobs.h @@ -148,9 +148,7 @@ struct _EvJobThumbnail { EvJob parent; - gint page; - gint rotation; - gint requested_width; + EvRenderContext *rc; GdkPixbuf *thumbnail; }; @@ -233,11 +231,9 @@ void ev_job_render_run (EvJobRender *thumbnail); /* EvJobThumbnail */ GType ev_job_thumbnail_get_type (void) G_GNUC_CONST; -EvJob *ev_job_thumbnail_new (EvDocument *document, - gint page, - int rotation, - gint requested_width); -void ev_job_thumbnail_run (EvJobThumbnail *thumbnail); +EvJob *ev_job_thumbnail_new (EvDocument *document, + EvRenderContext *rc); +void ev_job_thumbnail_run (EvJobThumbnail *thumbnail); /* EvJobFonts */ GType ev_job_fonts_get_type (void) G_GNUC_CONST; diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c index aa83dee4..325c1633 100644 --- a/shell/ev-sidebar-thumbnails.c +++ b/shell/ev-sidebar-thumbnails.c @@ -220,6 +220,20 @@ clear_range (EvSidebarThumbnails *sidebar_thumbnails, gtk_tree_path_free (path); } +static gdouble +get_scale_for_page (EvSidebarThumbnails *sidebar_thumbnails, + gint page) +{ + EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv; + gint width, height; + + ev_page_cache_get_size (priv->page_cache, + page, priv->rotation, + 1.0, &width, &height); + + return (gdouble)THUMBNAIL_WIDTH / (gdouble)width; +} + static void add_range (EvSidebarThumbnails *sidebar_thumbnails, gint start_page, @@ -237,7 +251,7 @@ add_range (EvSidebarThumbnails *sidebar_thumbnails, for (result = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->list_store), &iter, path); result && page <= end_page; result = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->list_store), &iter), page ++) { - EvJobThumbnail *job; + EvJob *job; gboolean thumbnail_set; gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store), &iter, @@ -246,9 +260,14 @@ add_range (EvSidebarThumbnails *sidebar_thumbnails, -1); if (job == NULL && !thumbnail_set) { - /* FIXME: Need rotation */ - job = (EvJobThumbnail *)ev_job_thumbnail_new (priv->document, page, priv->rotation, THUMBNAIL_WIDTH); + EvRenderContext *rc; + + rc = ev_render_context_new (priv->rotation, page, + get_scale_for_page (sidebar_thumbnails, page)); + job = ev_job_thumbnail_new (priv->document, rc); ev_job_queue_add_job (EV_JOB (job), EV_JOB_PRIORITY_HIGH); + g_object_unref (rc); + g_object_set_data_full (G_OBJECT (job), "tree_iter", gtk_tree_iter_copy (&iter), (GDestroyNotify) gtk_tree_iter_free); @@ -258,6 +277,7 @@ add_range (EvSidebarThumbnails *sidebar_thumbnails, gtk_list_store_set (priv->list_store, &iter, COLUMN_JOB, job, -1); + /* The queue and the list own a ref to the job now */ g_object_unref (job); } else if (job) { @@ -383,20 +403,35 @@ ev_sidebar_thumbnails_set_loading_icon (EvSidebarThumbnails *sidebar_thumbnails) g_object_unref (sidebar_thumbnails->priv->loading_icon); if (sidebar_thumbnails->priv->document) { + EvRenderContext *rc; + + rc = ev_render_context_new (sidebar_thumbnails->priv->rotation, 0, + get_scale_for_page (sidebar_thumbnails, 0)); + /* We get the dimensions of the first doc so that we can make a blank * icon. */ ev_document_doc_mutex_lock (); ev_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (sidebar_thumbnails->priv->document), - 0, THUMBNAIL_WIDTH, &width, &height); + rc, &width, &height); ev_document_doc_mutex_unlock (); + + g_object_unref (rc); + sidebar_thumbnails->priv->loading_icon = - ev_document_misc_get_thumbnail_frame (width, height, sidebar_thumbnails->priv->rotation, NULL); + ev_document_misc_get_thumbnail_frame (width, height, NULL); } else { sidebar_thumbnails->priv->loading_icon = NULL; } } +static gboolean +refresh (EvSidebarThumbnails *sidebar_thumbnails) +{ + adjustment_changed_cb (sidebar_thumbnails); + return FALSE; +} + void ev_sidebar_thumbnails_refresh (EvSidebarThumbnails *sidebar_thumbnails, int rotation) @@ -413,7 +448,7 @@ ev_sidebar_thumbnails_refresh (EvSidebarThumbnails *sidebar_thumbnails, /* Trigger a redraw */ sidebar_thumbnails->priv->start_page = 0; sidebar_thumbnails->priv->end_page = 0; - adjustment_changed_cb (sidebar_thumbnails); + g_idle_add ((GSourceFunc)refresh, sidebar_thumbnails); } static void diff --git a/shell/ev-window.c b/shell/ev-window.c index b9d6dfe0..ab14e271 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -1053,8 +1053,10 @@ ev_window_setup_document (EvWindow *ev_window) document = ev_window->priv->document; ev_window->priv->page_cache = ev_page_cache_get (ev_window->priv->document); - g_signal_connect (ev_window->priv->page_cache, "page-changed", G_CALLBACK (page_changed_cb), ev_window); - g_signal_connect (ev_window->priv->page_cache, "history-changed", G_CALLBACK (history_changed_cb), ev_window); + g_signal_connect (ev_window->priv->page_cache, "page-changed", + G_CALLBACK (page_changed_cb), ev_window); + g_signal_connect (ev_window->priv->page_cache, "history-changed", + G_CALLBACK (history_changed_cb), ev_window); if (EV_IS_DOCUMENT_FIND (document)) { g_signal_connect_object (G_OBJECT (document), @@ -1064,12 +1066,24 @@ ev_window_setup_document (EvWindow *ev_window) } if (EV_IS_DOCUMENT_THUMBNAILS (document)) { + EvRenderContext *rc; + gint page_width, page_height; + gdouble scale; + ev_window_clear_thumbnail_job (ev_window); - ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, 0, 0, 100); + + ev_page_cache_get_size (ev_window->priv->page_cache, + 1, 0, 1.0, + &page_width, &page_height); + scale = (gdouble)128 / (gdouble)page_width; + + rc = ev_render_context_new (0, 0, scale); + ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, rc); g_signal_connect (ev_window->priv->thumbnail_job, "finished", G_CALLBACK (ev_window_set_icon_from_thumbnail), ev_window); ev_job_queue_add_job (EV_JOB (ev_window->priv->thumbnail_job), EV_JOB_PRIORITY_LOW); + g_object_unref (rc); } ev_sidebar_set_document (sidebar, document); diff --git a/thumbnailer/evince-thumbnailer.c b/thumbnailer/evince-thumbnailer.c index 1c0ba0b4..f8368b51 100644 --- a/thumbnailer/evince-thumbnailer.c +++ b/thumbnailer/evince-thumbnailer.c @@ -34,6 +34,8 @@ static gboolean evince_thumbnail_pngenc_get (const char *uri, const char *thumbnail, int size) { EvDocument *document = NULL; + EvRenderContext *rc; + double width, height; GError *error = NULL; GdkPixbuf *pixbuf; @@ -58,8 +60,13 @@ evince_thumbnail_pngenc_get (const char *uri, const char *thumbnail, int size) return FALSE; } + ev_document_get_page_size (document, 0, &width, &height); + rc = ev_render_context_new (0, 0, THUMBNAIL_SIZE / width); + pixbuf = ev_document_thumbnails_get_thumbnail - (EV_DOCUMENT_THUMBNAILS (document), 0, 0, size, FALSE); + (EV_DOCUMENT_THUMBNAILS (document), rc, FALSE); + + g_object_unref (rc); if (pixbuf != NULL) { const char *overlaid_icon_name = NULL; @@ -86,15 +93,15 @@ evince_thumbnail_pngenc_get (const char *uri, const char *thumbnail, int size) 1, 1, GDK_INTERP_NEAREST, 100); - gdk_pixbuf_unref (overlaid_pixbuf); + g_object_unref (overlaid_pixbuf); } } if (gdk_pixbuf_save (pixbuf, thumbnail, "png", NULL, NULL)) { - gdk_pixbuf_unref (pixbuf); + g_object_unref (pixbuf); g_object_unref (document); return TRUE; } else { - gdk_pixbuf_unref (pixbuf); + g_object_unref (pixbuf); g_object_unref (document); } }