]> www.fi.muni.cz Git - evince.git/commitdiff
Also store in page-cache the dimensions of the thumbnails so that they can
authorCarlos Garcia Campos <carlosgc@gnome.org>
Fri, 17 Aug 2007 20:23:46 +0000 (20:23 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Fri, 17 Aug 2007 20:23:46 +0000 (20:23 +0000)
2007-08-17  Carlos Garcia Campos  <carlosgc@gnome.org>
* shell/ev-page-cache.c: (ev_page_cache_new),
(ev_page_cache_get_thumbnail_size):
* shell/ev-sidebar-thumbnails.c: (get_scale_for_page),
(ev_sidebar_thumbnails_set_loading_icon):
Also store in page-cache the dimensions of the thumbnails so that
they can be used to create the correct loading icon in the side
pane. Fixes bug #466857.

svn path=/trunk/; revision=2630

ChangeLog
shell/ev-page-cache.c
shell/ev-page-cache.h
shell/ev-sidebar-thumbnails.c

index 991e3330a3716dd8448e306398ccd0c4fb7174cf..b860ab53d92fe7767fe11d4a6a21093a098da8d0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-08-17  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * shell/ev-page-cache.c: (ev_page_cache_new),
+       (ev_page_cache_get_thumbnail_size):
+       * shell/ev-sidebar-thumbnails.c: (get_scale_for_page),
+       (ev_sidebar_thumbnails_set_loading_icon):
+
+       Also store in page-cache the dimensions of the thumbnails so that
+       they can be used to create the correct loading icon in the side
+       pane. Fixes bug #466857.
+       
 2007-08-17  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * backend/pdf/ev-poppler.cc:
index ddbeb0fce950c31db7c3257d90cde5bcd830bc49..e88ef523f6c012087ca8d739dc8162e5bc1ee1b2 100644 (file)
@@ -1,15 +1,22 @@
 #include "ev-page-cache.h"
 #include "ev-job-queue.h"
+#include "ev-document-thumbnails.h"
 #include <stdlib.h>
 #include <string.h>
 
+#define THUMBNAIL_WIDTH 100
+
 typedef struct _EvPageCacheInfo
 {
        double width;
        double height;
-}
-EvPageCacheInfo;
+} EvPageCacheInfo;
 
+typedef struct _EvPageThumbsInfo
+{
+       gint width;
+       gint height;
+} EvPageThumbsInfo;
 
 struct _EvPageCache
 {
@@ -38,6 +45,14 @@ struct _EvPageCache
 
        EvPageCacheInfo *size_cache;
        EvDocumentInfo *page_info;
+
+       /* Thumbnail dimensions */
+       gboolean thumbs_uniform;
+       gint thumbs_uniform_width;
+       gint thumbs_uniform_height;
+       gint thumbs_max_width;
+       gint thumbs_max_height;
+       EvPageThumbsInfo *thumbs_size_cache;
 };
 
 struct _EvPageCacheClass
@@ -242,6 +257,9 @@ ev_page_cache_new (EvDocument *document)
 {
        EvPageCache *page_cache;
        EvPageCacheInfo *info;
+       EvPageThumbsInfo *thumb_info;
+       EvRenderContext *rc = NULL;
+       gboolean has_thumbs;
        gint i;
 
        page_cache = (EvPageCache *) g_object_new (EV_TYPE_PAGE_CACHE, NULL);
@@ -259,6 +277,7 @@ ev_page_cache_new (EvDocument *document)
        page_cache->max_width = 0;
        page_cache->max_height = 0;
        page_cache->page_info = ev_document_get_info (document);
+       page_cache->thumbs_uniform = TRUE;
 
        if (page_cache->page_info->fields_mask & EV_DOCUMENT_INFO_TITLE) {
                page_cache->title = g_strdup (page_cache->page_info->title);
@@ -266,10 +285,14 @@ ev_page_cache_new (EvDocument *document)
                page_cache->title = NULL;
        }
 
+       has_thumbs = EV_IS_DOCUMENT_THUMBNAILS (document);
+       
        for (i = 0; i < page_cache->n_pages; i++) {
                double page_width = 0;
                double page_height = 0;
-               
+               gint   thumb_width = 0;
+               gint   thumb_height = 0;
+
                ev_document_get_page_size (document, i, &page_width, &page_height);
 
                page_cache->page_labels[i] = ev_document_get_page_label (document, i);
@@ -322,6 +345,57 @@ ev_page_cache_new (EvDocument *document)
                        info->width = page_width;
                        info->height = page_height;
                }
+
+               if (!has_thumbs)
+                       continue;
+
+               if (!rc) {
+                       rc = ev_render_context_new (0, i, (gdouble)THUMBNAIL_WIDTH / page_width);
+               } else {
+                       ev_render_context_set_page (rc, i);
+                       ev_render_context_set_scale (rc, (gdouble)THUMBNAIL_WIDTH / page_width);
+               }
+
+               ev_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (document),
+                                                      rc, &thumb_width, &thumb_height);
+               
+               if (thumb_width > page_cache->thumbs_max_width) {
+                       page_cache->thumbs_max_width = thumb_width;
+               }
+
+               if (thumb_height > page_cache->thumbs_max_height) {
+                       page_cache->thumbs_max_height = thumb_height;
+               }
+                       
+               if (i == 0) {
+                       page_cache->thumbs_uniform_width = thumb_width;
+                       page_cache->thumbs_uniform_height = thumb_height;
+               } else if (page_cache->thumbs_uniform &&
+                          (page_cache->thumbs_uniform_width != thumb_width ||
+                           page_cache->thumbs_uniform_height != thumb_height)) {
+                       /* It's a different thumbnail size.  Backfill the array. */
+                       int j;
+
+                       page_cache->thumbs_size_cache = g_new0 (EvPageThumbsInfo, page_cache->n_pages);
+
+                       for (j = 0; j < i; j++) {
+                               thumb_info = &(page_cache->thumbs_size_cache [j]);
+                               thumb_info->width = page_cache->thumbs_uniform_width;
+                               thumb_info->height = page_cache->thumbs_uniform_height;
+                       }
+                       page_cache->thumbs_uniform = FALSE;
+               }
+
+               if (! page_cache->thumbs_uniform) {
+                       thumb_info = &(page_cache->thumbs_size_cache [i]);
+
+                       thumb_info->width = thumb_width;
+                       thumb_info->height = thumb_height;
+               }
+       }
+
+       if (rc) {
+               g_object_unref (rc);
        }
 
        build_height_to_page (page_cache);
@@ -522,6 +596,39 @@ ev_page_cache_get_height_to_page (EvPageCache   *page_cache,
                *dual_height = page_cache->dual_height_to_page [page] * scale;
 }
 
+void
+ev_page_cache_get_thumbnail_size (EvPageCache  *page_cache,
+                                 gint          page,
+                                 gint          rotation,
+                                 gint         *width,
+                                 gint         *height)
+{
+       gint w, h;
+
+       g_return_if_fail (EV_IS_PAGE_CACHE (page_cache));
+       g_return_if_fail (page >= 0 && page < page_cache->n_pages);
+
+       if (page_cache->thumbs_uniform) {
+               w = page_cache->thumbs_uniform_width;
+               h = page_cache->thumbs_uniform_height;
+       } else {
+               EvPageThumbsInfo *info;
+
+               info = &(page_cache->thumbs_size_cache [page]);
+               
+               w = info->width;
+               h = info->height;
+       }
+
+       if (rotation == 0 || rotation == 180) {
+               if (width) *width = w;
+               if (height) *height = h;
+       } else {
+               if (width) *width = h;
+               if (height) *height = w;
+       }
+}
+
 gint
 ev_page_cache_get_max_label_chars (EvPageCache *page_cache)
 {
index d0ee00216c2f675637bf4569915fc3a4502f1172..e20068b1daa9ed870f14f671cbbfbb5805b1fd41 100644 (file)
@@ -54,6 +54,11 @@ void           ev_page_cache_get_height_to_page  (EvPageCache   *page_cache,
                                                  gfloat         scale,
                                                  gint          *height,
                                                  gint          *dual_height);
+void           ev_page_cache_get_thumbnail_size  (EvPageCache   *page_cache,
+                                                 gint           page,
+                                                 gint           rotation,
+                                                 gint          *width,
+                                                 gint          *height);
 gint           ev_page_cache_get_max_label_chars (EvPageCache   *page_cache);
 char          *ev_page_cache_get_page_label      (EvPageCache   *page_cache,
                                                  gint           page);
index 192aa6f3d70e5af1cb9cd087742b18ee28f45c08..6c20706de181396faecf1833f3ff06e293d10be0 100644 (file)
@@ -228,7 +228,7 @@ get_scale_for_page (EvSidebarThumbnails *sidebar_thumbnails,
        gint width, height;
 
        ev_page_cache_get_size (priv->page_cache,
-                               page, priv->rotation,
+                               page, 0,
                                1.0, &width, &height);
        
        return (gdouble)THUMBNAIL_WIDTH / (gdouble)width;
@@ -407,18 +407,14 @@ ev_sidebar_thumbnails_set_loading_icon (EvSidebarThumbnails *sidebar_thumbnails)
                g_object_unref (sidebar_thumbnails->priv->loading_icon);
 
        if (sidebar_thumbnails->priv->document) {
-               gint width = THUMBNAIL_WIDTH;
-               gint height;
-               gint page_width, page_height;
+               gint width, height;
 
                /* We get the dimensions of the first page so that we can make a blank
                 * icon.  */
-               ev_page_cache_get_size (sidebar_thumbnails->priv->page_cache, 0,
-                                       sidebar_thumbnails->priv->rotation,
-                                       1.0, &page_width, &page_height);
+               ev_page_cache_get_thumbnail_size (sidebar_thumbnails->priv->page_cache, 0,
+                                                 sidebar_thumbnails->priv->rotation,
+                                                 &width, &height);
 
-               height = (gint) (page_height * ((gdouble)width / page_width));
-               
                sidebar_thumbnails->priv->loading_icon =
                        ev_document_misc_get_thumbnail_frame (width, height, NULL);
        } else {