- ev_document_doc_mutex_lock ();
-
- /* We read page information out of the document */
-
- /* Assume all pages are the same size until proven otherwise */
- page_cache->uniform = TRUE;
- page_cache->has_labels = FALSE;
- page_cache->n_pages = ev_document_get_n_pages (document);
- page_cache->dual_even_left = (page_cache->n_pages > 2);
- page_cache->page_labels = g_new0 (char *, page_cache->n_pages);
- 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);
- } else {
- page_cache->title = NULL;
- }
-
- has_thumbs = EV_IS_DOCUMENT_THUMBNAILS (document);
-
- for (i = 0; i < page_cache->n_pages; i++) {
- 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, page, &page_width, &page_height);
-
- 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));
- if (!page_cache->has_labels) {
- gchar *expected_label;
-
- expected_label = g_strdup_printf ("%d", i + 1);
- if (strcmp (expected_label, page_cache->page_labels[i]))
- page_cache->has_labels = TRUE;
- g_free (expected_label);
- }
- }
-
- if (page_width > page_cache->max_width) {
- page_cache->max_width = page_width;
- }
-
- if (page_height > page_cache->max_height) {
- page_cache->max_height = page_height;
- }
-
- if (i == 0) {
- page_cache->uniform_width = page_width;
- page_cache->uniform_height = page_height;
- } else if (page_cache->uniform &&
- (page_cache->uniform_width != page_width ||
- page_cache->uniform_height != page_height)) {
- /* It's a different page size. Backfill the array. */
- int j;
-
- page_cache->size_cache = g_new0 (EvPageCacheInfo, page_cache->n_pages);
-
- for (j = 0; j < i; j++) {
- info = &(page_cache->size_cache [j]);
- info->width = page_cache->uniform_width;
- info->height = page_cache->uniform_height;
- }
- page_cache->uniform = FALSE;
-
- }
-
- if (! page_cache->uniform) {
- info = &(page_cache->size_cache [i]);
-
- 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);
-
- /* make some sanity check assertions */
- if (! page_cache->uniform)
- g_assert (page_cache->size_cache != NULL);
- if (page_cache->uniform && page_cache->n_pages > 0)
- g_assert (page_cache->uniform_width > 0 && page_cache->uniform_height > 0);
-
- ev_document_doc_mutex_unlock ();
-
- if (page_cache->n_pages > 0)