X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-sidebar-thumbnails.c;h=a860c5e1fcf6390e1826081b7c22ee27c8809dfa;hb=e769474337c9a6ffdaed2327056e8de2f7ca9ee4;hp=4aaeebab191409a8b5cc404b8527859b6fb64c9a;hpb=d76bef42ca0d292a7a04d61663d4da7536136479;p=evince.git diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c index 4aaeebab..a860c5e1 100644 --- a/shell/ev-sidebar-thumbnails.c +++ b/shell/ev-sidebar-thumbnails.c @@ -32,7 +32,6 @@ #include #include "ev-document-misc.h" -#include "ev-document-thumbnails.h" #include "ev-job-scheduler.h" #include "ev-sidebar-page.h" #include "ev-sidebar-thumbnails.h" @@ -113,72 +112,47 @@ G_DEFINE_TYPE_EXTENDED (EvSidebarThumbnails, /* Thumbnails dimensions cache */ #define EV_THUMBNAILS_SIZE_CACHE_KEY "ev-thumbnails-size-cache" +static void +get_thumbnail_size_for_page (EvDocument *document, + guint page, + gint *width, + gint *height) +{ + gdouble scale; + gdouble w, h; + + ev_document_get_page_size (document, page, &w, &h); + scale = (gdouble)THUMBNAIL_WIDTH / w; + + *width = MAX ((gint)(w * scale + 0.5), 1); + *height = MAX ((gint)(h * scale + 0.5), 1); +} + static EvThumbsSizeCache * ev_thumbnails_size_cache_new (EvDocument *document) { EvThumbsSizeCache *cache; - EvRenderContext *rc = NULL; - gint i, n_pages; - EvThumbsSize *thumb_size; + gint i, n_pages; + EvThumbsSize *thumb_size; cache = g_new0 (EvThumbsSizeCache, 1); - n_pages = ev_document_get_n_pages (document); + if (ev_document_is_page_size_uniform (document)) { + cache->uniform = TRUE; + get_thumbnail_size_for_page (document, 0, + &cache->uniform_width, + &cache->uniform_height); + return cache; + } - /* Assume all pages are the same size until proven otherwise */ - cache->uniform = TRUE; + n_pages = ev_document_get_n_pages (document); + cache->sizes = g_new0 (EvThumbsSize, n_pages); for (i = 0; i < n_pages; i++) { - EvPage *page; - gdouble page_width, page_height; - gint thumb_width = 0; - gint thumb_height = 0; - - page = ev_document_get_page (document, i); - - ev_document_get_page_size (document, i, &page_width, &page_height); - - if (!rc) { - rc = ev_render_context_new (page, 0, (gdouble)THUMBNAIL_WIDTH / page_width); - } else { - ev_render_context_set_page (rc, page); - 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 (i == 0) { - cache->uniform_width = thumb_width; - cache->uniform_height = thumb_height; - } else if (cache->uniform && - (cache->uniform_width != thumb_width || - cache->uniform_height != thumb_height)) { - /* It's a different thumbnail size. Backfill the array. */ - int j; - - cache->sizes = g_new0 (EvThumbsSize, n_pages); - - for (j = 0; j < i; j++) { - thumb_size = &(cache->sizes[j]); - thumb_size->width = cache->uniform_width; - thumb_size->height = cache->uniform_height; - } - cache->uniform = FALSE; - } - - if (! cache->uniform) { - thumb_size = &(cache->sizes[i]); - - thumb_size->width = thumb_width; - thumb_size->height = thumb_height; - } - - g_object_unref (page); - } - - if (rc) { - g_object_unref (rc); + thumb_size = &(cache->sizes[i]); + get_thumbnail_size_for_page (document, i, + &thumb_size->width, + &thumb_size->height); } return cache; @@ -299,11 +273,9 @@ static void ev_sidebar_thumbnails_class_init (EvSidebarThumbnailsClass *ev_sidebar_thumbnails_class) { GObjectClass *g_object_class; - GtkObjectClass *gtk_object_class; GtkWidgetClass *widget_class; g_object_class = G_OBJECT_CLASS (ev_sidebar_thumbnails_class); - gtk_object_class = GTK_OBJECT_CLASS (ev_sidebar_thumbnails_class); widget_class = GTK_WIDGET_CLASS (ev_sidebar_thumbnails_class); g_object_class->dispose = ev_sidebar_thumbnails_dispose; @@ -847,8 +819,7 @@ ev_sidebar_thumbnails_document_changed_cb (EvDocumentModel *model, EvDocument *document = ev_document_model_get_document (model); EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv; - if (!EV_IS_DOCUMENT_THUMBNAILS (document) || - ev_document_get_n_pages (document) <= 0 || + if (ev_document_get_n_pages (document) <= 0 || !ev_document_check_dimensions (document)) { return; } @@ -956,7 +927,7 @@ static gboolean ev_sidebar_thumbnails_support_document (EvSidebarPage *sidebar_page, EvDocument *document) { - return (EV_IS_DOCUMENT_THUMBNAILS (document)); + return TRUE; } static const gchar*