X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=shell%2Fev-page-cache.c;h=a43876a40fbe2b319021bdb909de566640e53d9b;hb=f675370b1c2f1e29dfb3a3b97eda5d46f6a4a4ae;hp=ebf0de7f9b69f8d2409e51d69f75dabb0438d4aa;hpb=aa9dd5bfb5ea0ca5d0a0e5be577f2e028d0549ee;p=evince.git diff --git a/shell/ev-page-cache.c b/shell/ev-page-cache.c index ebf0de7f..a43876a4 100644 --- a/shell/ev-page-cache.c +++ b/shell/ev-page-cache.c @@ -1,15 +1,23 @@ +#include #include "ev-page-cache.h" -#include "ev-job-queue.h" +#include "ev-document-thumbnails.h" +#include "ev-page.h" #include #include +#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 +46,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 @@ -174,10 +190,14 @@ build_height_to_page (EvPageCache *page_cache) } page_cache->height_to_page [i] = i * uniform_height; } else { - if (!swap) { - page_height = page_cache->size_cache [i].height; + if (i < page_cache->n_pages) { + if (!swap) { + page_height = page_cache->size_cache [i].height; + } else { + page_height = page_cache->size_cache [i].width; + } } else { - page_height = page_cache->size_cache [i].width; + page_height = 0; } page_cache->height_to_page [i] = saved_height; saved_height += page_height; @@ -238,6 +258,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); @@ -255,6 +278,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); @@ -262,18 +286,25 @@ 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; + EvPage *page; + double page_width = 0; + double page_height = 0; + 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); + ev_document_get_page_size (document, page, &page_width, &page_height); - page_cache->page_labels[i] = ev_document_get_page_label (document, i); + page_cache->page_labels[i] = ev_document_get_page_label (document, page); if (page_cache->page_labels[i] != NULL) { - page_cache->max_label_chars = MAX(page_cache->max_label_chars, - g_utf8_strlen (page_cache->page_labels[i], 256)); + page_cache->max_label_chars = MAX (page_cache->max_label_chars, + g_utf8_strlen (page_cache->page_labels[i], 256)); if (!page_cache->has_labels) { gchar *expected_label; @@ -318,6 +349,61 @@ ev_page_cache_new (EvDocument *document) info->width = page_width; info->height = page_height; } + + if (!has_thumbs) { + g_object_unref (page); + continue; + } + + 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 (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; + } + + g_object_unref (page); + } + + if (rc) { + g_object_unref (rc); } build_height_to_page (page_cache); @@ -396,6 +482,15 @@ ev_page_cache_set_page_label (EvPageCache *page_cache, } } + /* Second, look for a match with case insensitively */ + for (i = 0; i < page_cache->n_pages; i++) { + if (page_cache->page_labels[i] != NULL && + ! strcasecmp (page_label, page_cache->page_labels[i])) { + ev_page_cache_set_current_page (page_cache, i); + return TRUE; + } + } + /* Next, parse the label, and see if the number fits */ value = strtol (page_label, &endptr, 10); if (endptr[0] == '\0') { @@ -502,6 +597,9 @@ ev_page_cache_get_height_to_page (EvPageCache *page_cache, gint *dual_height) { g_return_if_fail (EV_IS_PAGE_CACHE (page_cache)); + g_return_if_fail (page >= 0); + g_return_if_fail (!height || page <= page_cache->n_pages); + g_return_if_fail (!dual_height || page <= page_cache->n_pages + 1); if (page_cache->rotation != rotation) { page_cache->rotation = rotation; @@ -515,6 +613,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) {