]> www.fi.muni.cz Git - evince.git/commitdiff
Use an EvRenderContext for rendering thumbnails instead of a suggested
authorCarlos Garcia Campos <carlosgc@gnome.org>
Fri, 16 Feb 2007 17:27:12 +0000 (17:27 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Fri, 16 Feb 2007 17:27:12 +0000 (17:27 +0000)
2007-02-16  Carlos Garcia Campos  <carlosgc@gnome.org>
* 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

18 files changed:
ChangeLog
backend/comics/comics-document.c
backend/djvu/djvu-document.c
backend/dvi/dvi-document.c
backend/impress/impress-document.c
backend/pdf/ev-poppler.cc
backend/pixbuf/pixbuf-document.c
backend/ps/ps-document.c
backend/tiff/tiff-document.c
libdocument/ev-document-misc.c
libdocument/ev-document-misc.h
libdocument/ev-document-thumbnails.c
libdocument/ev-document-thumbnails.h
shell/ev-jobs.c
shell/ev-jobs.h
shell/ev-sidebar-thumbnails.c
shell/ev-window.c
thumbnailer/evince-thumbnailer.c

index e83ae34a03d4f68c985360b98db6fdc405cdb686..08b37b5bbea9217dfa49facb80b5d24f5fec3b6c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,44 @@
+2007-02-16  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * 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  <carlosgc@gnome.org>
 
        * shell/ev-view.c: (ev_view_button_press_event),
index 7f53f85a1da0374307ec321a078cb76cbbab9232..e0fdd31ef781b0223b05afa746cbf11001efede9 100644 (file)
@@ -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
index bf74c9a209f0bbf6680b306f0161c41fd6f59547..8b45514b6652af06a4dd6cc0db77e6a04f4f6fb9 100644 (file)
@@ -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);
        }
        
index 4de5e64eddc74457ccbcb405063abf2abd8f9cf9..bd699709791a1000643e74fa1a98dad4c4b3af2b 100644 (file)
@@ -17,8 +17,6 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-#include <config.h>
-
 #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);
        }
 
index 9756a84d1b383d48ba04a1eff4aca387da78aa52..5f5982ed7fcc08b928e8012e6ec5b883cc0e5910 100644 (file)
@@ -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
index 7c2c5281fb25cac868fc30afb879b982a3cfb15f..715226add1a8e3592cd66f3aaf9a9843040e3c5f 100644 (file)
@@ -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);
 }
 
index e3d064da4f95cbc2e9dfdcdcc5e43bb20a5547ef..c1cace00baeee607f0750b3d8f35513144533740 100644 (file)
@@ -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
index d1b456d28478e74da4d077b6b92bc6300a5e398f..0e79ec571a8e9301705396bea690e881ad7e7904 100644 (file)
@@ -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
index 24af05fbc887705fee05f28162bb30d5c42cf087..9348ed4efb68e893fe6cb03b707970ca1269da8d 100644 (file)
@@ -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;
 }
index fd6f4493904059138f8fa14e28f86b7f8ab1adbf..89ff5fa8a76ff1ff14381a2608478cdb9d86db45 100644 (file)
@@ -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 */
index 41f1caed9ae3da1195e68453cd571ce7ac58fa8d..5d846717199a49550d1186c5f47c788342bb0f49 100644 (file)
@@ -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,
index c560cec10efa34e65ecd09fb4dde9f1c11ff1b24..1ed1974fc6e2db8094fc9fe3f0248e9efbda1502 100644 (file)
@@ -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);
 }
 
index 6e15a327606999c096e090d4dd9674148bab5e35..648c0ebb50f3fb2ad86d871a1fa9c2b29b79ab23 100644 (file)
 
 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 */
index 9fb242a0c6cd5a35dd2559f7e48c366a3c7afc08..6ad4dfcaa876e5a4f64ed7e59c9ecaf20809883b 100644 (file)
@@ -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 ();
index 779c3736dbd9880913dab41e25b7edb80d864f4d..1f210ece96ab99aa7ee728f3f5780d449531a029 100644 (file)
@@ -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;
index aa83dee4a4dc370d123a246ff95133df37ae1ce5..325c1633ee147351ca95b2bf9b8b6286f47a7ebe 100644 (file)
@@ -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
index b9d6dfe0460d26a94889f5d2633b7a7e96ac19dd..ab14e27183fd4f3328886853bbe039434c54712a 100644 (file)
@@ -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);
index 1c0ba0b4e1aa95bb823ceb8ef0f0437abfc9a934..f8368b5126c0f083cbba3fbe88982556680e75f8 100644 (file)
@@ -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);
                }
        }