+/* this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2009 Carlos Garcia Campos
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
#include <config.h>
+
+#include "ev-jobs.h"
+#include "ev-job-scheduler.h"
+#include "ev-mapping.h"
+#include "ev-selection.h"
+#include "ev-document-links.h"
+#include "ev-document-forms.h"
+#include "ev-document-images.h"
+#include "ev-document-annotations.h"
#include "ev-page-cache.h"
-#include "ev-document-thumbnails.h"
-#include "ev-page.h"
-#include <stdlib.h>
-#include <string.h>
-#define THUMBNAIL_WIDTH 100
+typedef struct _EvPageCacheData {
+ EvJob *job;
+ gboolean done : 1;
-typedef struct _EvPageCacheInfo
-{
- double width;
- double height;
-} EvPageCacheInfo;
-
-typedef struct _EvPageThumbsInfo
-{
- gint width;
- gint height;
-} EvPageThumbsInfo;
+ GList *link_mapping;
+ GList *image_mapping;
+ GList *form_field_mapping;
+ GList *annot_mapping;
+ GdkRegion *text_mapping;
+} EvPageCacheData;
-struct _EvPageCache
-{
+struct _EvPageCache {
GObject parent;
- gint current_page;
- int n_pages;
- char *title;
- char **page_labels;
-
- gint max_label_chars;
- gboolean has_labels;
- gboolean uniform;
- gboolean dual_even_left;
-
- double uniform_width;
- double uniform_height;
-
- double max_width;
- double max_height;
-
- double* height_to_page;
- double* dual_height_to_page;
-
- int rotation;
-
- 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;
+ EvDocument *document;
+ EvPageCacheData *page_list;
+ gint n_pages;
+ EvJobPageDataFlags flags;
};
-struct _EvPageCacheClass
-{
+struct _EvPageCacheClass {
GObjectClass parent_class;
-
- void (* page_changed) (EvPageCache *page_cache, gint page);
- void (* history_changed) (EvPageCache *page_cache, gint page);
-};
-
-enum
-{
- PAGE_CHANGED,
- HISTORY_CHANGED,
- N_SIGNALS,
};
-static guint signals[N_SIGNALS] = {0, };
-
-static void ev_page_cache_init (EvPageCache *page_cache);
-static void ev_page_cache_class_init (EvPageCacheClass *page_cache);
-static void ev_page_cache_finalize (GObject *object);
+static void job_page_data_finished_cb (EvJob *job,
+ EvPageCache *cache);
G_DEFINE_TYPE (EvPageCache, ev_page_cache, G_TYPE_OBJECT)
static void
-ev_page_cache_init (EvPageCache *page_cache)
+ev_page_cache_data_free (EvPageCacheData *data)
{
- page_cache->current_page = -1;
- page_cache->max_label_chars = 0;
-}
-
-static void
-ev_page_cache_class_init (EvPageCacheClass *class)
-{
- GObjectClass *object_class;
-
- object_class = G_OBJECT_CLASS (class);
-
- object_class->finalize = ev_page_cache_finalize;
-
- signals [PAGE_CHANGED] =
- g_signal_new ("page-changed",
- EV_TYPE_PAGE_CACHE,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EvPageCacheClass, page_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__INT,
- G_TYPE_NONE, 1,
- G_TYPE_INT);
-
- signals [HISTORY_CHANGED] =
- g_signal_new ("history-changed",
- EV_TYPE_PAGE_CACHE,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EvPageCacheClass, history_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__INT,
- G_TYPE_NONE, 1,
- G_TYPE_INT);
-
-}
-
-static void
-ev_page_cache_finalize (GObject *object)
-{
- EvPageCache *page_cache;
-
- page_cache = EV_PAGE_CACHE (object);
-
- if (page_cache->title) {
- g_free (page_cache->title);
- page_cache->title = NULL;
+ if (data->job) {
+ g_object_unref (data->job);
+ data->job = NULL;
}
- if (page_cache->size_cache) {
- g_free (page_cache->size_cache);
- page_cache->size_cache = NULL;
+ if (data->link_mapping) {
+ ev_mapping_list_free (data->link_mapping, g_object_unref);
+ data->link_mapping = NULL;
}
- if (page_cache->thumbs_size_cache) {
- g_free (page_cache->thumbs_size_cache);
- page_cache->thumbs_size_cache = NULL;
+ if (data->image_mapping) {
+ ev_mapping_list_free (data->image_mapping, g_object_unref);
+ data->image_mapping = NULL;
}
- if (page_cache->height_to_page) {
- g_free (page_cache->height_to_page);
- page_cache->height_to_page = NULL;
+ if (data->form_field_mapping) {
+ ev_mapping_list_free (data->form_field_mapping, g_object_unref);
+ data->form_field_mapping = NULL;
}
- if (page_cache->dual_height_to_page) {
- g_free (page_cache->dual_height_to_page);
- page_cache->dual_height_to_page = NULL;
+ if (data->annot_mapping) {
+ ev_mapping_list_free (data->annot_mapping, g_object_unref);
+ data->annot_mapping = NULL;
}
- if (page_cache->page_labels) {
- gint i;
-
- for (i = 0; i < page_cache->n_pages; i++) {
- if (page_cache->page_labels[i])
- g_free (page_cache->page_labels[i]);
- }
- g_free (page_cache->page_labels);
- page_cache->page_labels = NULL;
+ if (data->text_mapping) {
+ gdk_region_destroy (data->text_mapping);
+ data->text_mapping = NULL;
}
-
- if (page_cache->page_info) {
- ev_document_info_free (page_cache->page_info);
- page_cache->page_info = NULL;
- }
-
- G_OBJECT_CLASS (ev_page_cache_parent_class)->finalize (object);
}
static void
-build_height_to_page (EvPageCache *page_cache)
-{
- gboolean swap;
- int i;
- double uniform_height, page_height, next_page_height;
- double saved_height;
-
- swap = (page_cache->rotation == 90 ||
- page_cache->rotation == 270);
-
- g_free (page_cache->height_to_page);
- g_free (page_cache->dual_height_to_page);
-
- page_cache->height_to_page = g_new0(double, page_cache->n_pages + 1);
- page_cache->dual_height_to_page = g_new0(double, page_cache->n_pages + 2);
-
- saved_height = 0;
- for (i = 0; i <= page_cache->n_pages; i++) {
- if (page_cache->uniform) {
- if (!swap) {
- uniform_height = page_cache->uniform_height;
- } else {
- uniform_height = page_cache->uniform_width;
- }
- page_cache->height_to_page [i] = i * uniform_height;
- } else {
- 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 = 0;
- }
- page_cache->height_to_page [i] = saved_height;
- saved_height += page_height;
- }
- }
-
- if (page_cache->dual_even_left && !page_cache->uniform) {
- if (!swap) {
- saved_height = page_cache->size_cache [0].height;
- } else {
- saved_height = page_cache->size_cache [0].width;
- }
- } else {
- saved_height = 0;
- }
- for (i = page_cache->dual_even_left; i < page_cache->n_pages + 2; i += 2) {
- if (page_cache->uniform) {
- if (!swap) {
- uniform_height = page_cache->uniform_height;
- } else {
- uniform_height = page_cache->uniform_width;
- }
- page_cache->dual_height_to_page [i] = ((i + page_cache->dual_even_left) / 2) * uniform_height;
- if (i + 1 < page_cache->n_pages + 2)
- page_cache->dual_height_to_page [i + 1] = ((i + page_cache->dual_even_left) / 2) * uniform_height;
- } else {
- if (i + 1 < page_cache->n_pages) {
- if (!swap) {
- next_page_height = page_cache->size_cache [i + 1].height;
- } else {
- next_page_height = page_cache->size_cache [i + 1].width;
- }
- } else {
- next_page_height = 0;
- }
- 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 = 0;
- }
- if (i + 1 < page_cache->n_pages + 2) {
- page_cache->dual_height_to_page [i] = saved_height;
- page_cache->dual_height_to_page [i + 1] = saved_height;
- saved_height += MAX(page_height, next_page_height);
- } else {
- page_cache->dual_height_to_page [i] = saved_height;
- }
- }
- }
-}
-
-EvPageCache *
-ev_page_cache_new (EvDocument *document)
+ev_page_cache_finalize (GObject *object)
{
- 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);
-
- 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);
- }
- }
+ EvPageCache *cache = EV_PAGE_CACHE (object);
+ gint i;
- 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 (cache->page_list) {
+ for (i = 0; i < cache->n_pages; i++) {
+ EvPageCacheData *data;
- if (! page_cache->thumbs_uniform) {
- thumb_info = &(page_cache->thumbs_size_cache [i]);
+ data = &cache->page_list[i];
- thumb_info->width = thumb_width;
- thumb_info->height = thumb_height;
+ if (data->job)
+ g_signal_handlers_disconnect_by_func (data->job,
+ G_CALLBACK (job_page_data_finished_cb),
+ cache);
+ ev_page_cache_data_free (data);
}
- g_object_unref (page);
+ g_free (cache->page_list);
+ cache->page_list = NULL;
+ cache->n_pages = 0;
}
- if (rc) {
- g_object_unref (rc);
+ if (cache->document) {
+ g_object_unref (cache->document);
+ cache->document = NULL;
}
- build_height_to_page (page_cache);
-
- /* make some sanity check assertions */
- if (! page_cache->uniform)
- g_assert (page_cache->size_cache != NULL);
-
- ev_document_doc_mutex_unlock ();
-
- if (page_cache->n_pages > 0)
- ev_page_cache_set_current_page (page_cache, 0);
-
- return page_cache;
+ G_OBJECT_CLASS (ev_page_cache_parent_class)->finalize (object);
}
-gboolean
-ev_page_cache_check_dimensions (EvPageCache *page_cache)
+static void
+ev_page_cache_init (EvPageCache *cache)
{
- gint document_width, document_height;
-
- if (page_cache->uniform && page_cache->n_pages > 0)
- if (page_cache->uniform_width <= 0 || page_cache->uniform_height <= 0)
- return TRUE;
-
- ev_page_cache_get_max_width (page_cache,
- 0, 1.0,
- &document_width);
- ev_page_cache_get_max_height (page_cache,
- 0, 1.0,
- &document_height);
-
- if (document_width <= 0 || document_height <= 0)
- return TRUE;
-
- return FALSE;
}
-gint
-ev_page_cache_get_n_pages (EvPageCache *page_cache)
+static void
+ev_page_cache_class_init (EvPageCacheClass *klass)
{
- g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), 0);
+ GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
- return page_cache->n_pages;
+ g_object_class->finalize = ev_page_cache_finalize;
}
-gint
-ev_page_cache_get_current_page (EvPageCache *page_cache)
+static EvJobPageDataFlags
+get_flags_for_document (EvDocument *document)
{
- g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), 0);
-
- return page_cache->current_page;
+ EvJobPageDataFlags flags = EV_PAGE_DATA_INCLUDE_NONE;
+
+ if (EV_IS_DOCUMENT_LINKS (document))
+ flags |= EV_PAGE_DATA_INCLUDE_LINKS;
+ if (EV_IS_DOCUMENT_IMAGES (document))
+ flags |= EV_PAGE_DATA_INCLUDE_IMAGES;
+ if (EV_IS_DOCUMENT_FORMS (document))
+ flags |= EV_PAGE_DATA_INCLUDE_FORMS;
+ if (EV_IS_DOCUMENT_ANNOTATIONS (document))
+ flags |= EV_PAGE_DATA_INCLUDE_ANNOTS;
+ if (EV_IS_SELECTION (document))
+ flags |= EV_PAGE_DATA_INCLUDE_TEXT;
+
+ return flags;
}
-void
-ev_page_cache_set_current_page (EvPageCache *page_cache,
- int page)
+EvPageCache *
+ev_page_cache_new (EvDocument *document)
{
- g_return_if_fail (EV_IS_PAGE_CACHE (page_cache));
- g_return_if_fail (page >= 0 || page < page_cache->n_pages);
+ EvPageCache *cache;
- if (page == page_cache->current_page)
- return;
+ g_return_val_if_fail (EV_IS_DOCUMENT (document), NULL);
- page_cache->current_page = page;
- g_signal_emit (page_cache, signals[PAGE_CHANGED], 0, page);
+ cache = EV_PAGE_CACHE (g_object_new (EV_TYPE_PAGE_CACHE, NULL));
+ cache->document = g_object_ref (document);
+ cache->n_pages = ev_document_get_n_pages (document);
+ cache->flags = get_flags_for_document (document);
+
+ if (cache->flags != EV_PAGE_DATA_INCLUDE_NONE) {
+ cache->page_list = g_new0 (EvPageCacheData, cache->n_pages);
+ }
+
+ return cache;
}
-void
-ev_page_cache_set_current_page_history (EvPageCache *page_cache,
- int page)
+static void
+job_page_data_finished_cb (EvJob *job,
+ EvPageCache *cache)
{
- if (abs (page - page_cache->current_page) > 1)
- g_signal_emit (page_cache, signals [HISTORY_CHANGED], 0, page);
-
- ev_page_cache_set_current_page (page_cache, page);
+ EvJobPageData *job_data = EV_JOB_PAGE_DATA (job);
+ EvPageCacheData *data;
+
+ data = &cache->page_list[job_data->page];
+ data->link_mapping = job_data->link_mapping;
+ data->image_mapping = job_data->image_mapping;
+ data->form_field_mapping = job_data->form_field_mapping;
+ data->annot_mapping = job_data->annot_mapping;
+ data->text_mapping = job_data->text_mapping;
+ data->done = TRUE;
+
+ g_object_unref (data->job);
+ data->job = NULL;
}
-gboolean
-ev_page_cache_set_page_label (EvPageCache *page_cache,
- const char *page_label)
+void
+ev_page_cache_set_page_range (EvPageCache *cache,
+ gint start,
+ gint end)
{
- gint i, page;
- long value;
- char *endptr = NULL;
-
- g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), FALSE);
- g_return_val_if_fail (page_label != NULL, FALSE);
-
- /* First, look for a literal label match */
- for (i = 0; i < page_cache->n_pages; i ++) {
- if (page_cache->page_labels[i] != NULL &&
- ! strcmp (page_label, page_cache->page_labels[i])) {
- ev_page_cache_set_current_page (page_cache, i);
- return TRUE;
- }
- }
+ gint i;
- /* 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;
- }
- }
+ if (cache->flags == EV_PAGE_DATA_INCLUDE_NONE)
+ return;
- /* Next, parse the label, and see if the number fits */
- value = strtol (page_label, &endptr, 10);
- if (endptr[0] == '\0') {
- /* Page number is an integer */
- page = MIN (G_MAXINT, value);
-
- /* convert from a page label to a page offset */
- page --;
- if (page >= 0 &&
- page < page_cache->n_pages) {
- ev_page_cache_set_current_page (page_cache, page);
- return TRUE;
- }
- }
+ for (i = start; i <= end; i++) {
+ EvPageCacheData *data = &cache->page_list[i];
+
+ if (data->done || data->job)
+ continue;
- return FALSE;
+ data->job = ev_job_page_data_new (cache->document, i, cache->flags);
+ g_signal_connect (data->job, "finished",
+ G_CALLBACK (job_page_data_finished_cb),
+ cache);
+ ev_job_scheduler_push_job (data->job, EV_JOB_PRIORITY_NONE);
+ }
}
-const char *
-ev_page_cache_get_title (EvPageCache *page_cache)
+EvJobPageDataFlags
+ev_page_cache_get_flags (EvPageCache *cache)
{
- g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), NULL);
-
- return page_cache->title;
+ return cache->flags;
}
void
-ev_page_cache_get_size (EvPageCache *page_cache,
- gint page,
- gint rotation,
- gfloat scale,
- gint *width,
- gint *height)
+ev_page_cache_set_flags (EvPageCache *cache,
+ EvJobPageDataFlags flags)
{
- double w, h;
+ cache->flags = flags;
+}
- g_return_if_fail (EV_IS_PAGE_CACHE (page_cache));
- g_return_if_fail (page >= 0 && page < page_cache->n_pages);
+GList *
+ev_page_cache_get_link_mapping (EvPageCache *cache,
+ gint page)
+{
+ EvPageCacheData *data;
- if (page_cache->uniform) {
- w = page_cache->uniform_width;
- h = page_cache->uniform_height;
- } else {
- EvPageCacheInfo *info;
+ g_return_val_if_fail (EV_IS_PAGE_CACHE (cache), NULL);
+ g_return_val_if_fail (page >= 0 && page < cache->n_pages, NULL);
- info = &(page_cache->size_cache [page]);
-
- w = info->width;
- h = info->height;
- }
+ if (!(cache->flags & EV_PAGE_DATA_INCLUDE_LINKS))
+ return NULL;
- w = w * scale + 0.5;
- h = h * scale + 0.5;
+ data = &cache->page_list[page];
+ if (data->done)
+ return data->link_mapping;
- if (rotation == 0 || rotation == 180) {
- if (width) *width = (int)w;
- if (height) *height = (int)h;
- } else {
- if (width) *width = (int)h;
- if (height) *height = (int)w;
- }
+ if (data->job)
+ return EV_JOB_PAGE_DATA (data->job)->link_mapping;
+
+ return data->link_mapping;
}
-void
-ev_page_cache_get_max_width (EvPageCache *page_cache,
- gint rotation,
- gfloat scale,
- gint *width)
+GList *
+ev_page_cache_get_image_mapping (EvPageCache *cache,
+ gint page)
{
- g_return_if_fail (EV_IS_PAGE_CACHE (page_cache));
+ EvPageCacheData *data;
- if (width) {
- if (rotation == 0 || rotation == 180) {
- *width = page_cache->max_width * scale;
- } else {
- *width = page_cache->max_height * scale;
- }
- }
-}
+ g_return_val_if_fail (EV_IS_PAGE_CACHE (cache), NULL);
+ g_return_val_if_fail (page >= 0 && page < cache->n_pages, NULL);
-void
-ev_page_cache_get_max_height (EvPageCache *page_cache,
- gint rotation,
- gfloat scale,
- gint *height)
-{
- g_return_if_fail (EV_IS_PAGE_CACHE (page_cache));
+ if (!(cache->flags & EV_PAGE_DATA_INCLUDE_IMAGES))
+ return NULL;
- if (height) {
- if (rotation == 0 || rotation == 180) {
- *height = page_cache->max_height * scale;
- } else {
- *height = page_cache->max_width * scale;
- }
- }
-}
+ data = &cache->page_list[page];
+ if (data->done)
+ return data->image_mapping;
-void
-ev_page_cache_get_height_to_page (EvPageCache *page_cache,
- gint page,
- gint rotation,
- gfloat scale,
- gint *height,
- 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;
- build_height_to_page (page_cache);
- }
-
- if (height)
- *height = page_cache->height_to_page [page] * scale;
+ if (data->job)
+ return EV_JOB_PAGE_DATA (data->job)->image_mapping;
- if (dual_height)
- *dual_height = page_cache->dual_height_to_page [page] * scale;
+ return data->image_mapping;
}
-void
-ev_page_cache_get_thumbnail_size (EvPageCache *page_cache,
- gint page,
- gint rotation,
- gint *width,
- gint *height)
+GList *
+ev_page_cache_get_form_field_mapping (EvPageCache *cache,
+ gint page)
{
- gint w, h;
+ EvPageCacheData *data;
- g_return_if_fail (EV_IS_PAGE_CACHE (page_cache));
- g_return_if_fail (page >= 0 && page < page_cache->n_pages);
+ g_return_val_if_fail (EV_IS_PAGE_CACHE (cache), NULL);
+ g_return_val_if_fail (page >= 0 && page < cache->n_pages, NULL);
- if (page_cache->thumbs_uniform) {
- w = page_cache->thumbs_uniform_width;
- h = page_cache->thumbs_uniform_height;
- } else {
- EvPageThumbsInfo *info;
+ if (!(cache->flags & EV_PAGE_DATA_INCLUDE_FORMS))
+ return NULL;
- info = &(page_cache->thumbs_size_cache [page]);
-
- w = info->width;
- h = info->height;
- }
+ data = &cache->page_list[page];
+ if (data->done)
+ return data->form_field_mapping;
- if (rotation == 0 || rotation == 180) {
- if (width) *width = w;
- if (height) *height = h;
- } else {
- if (width) *width = h;
- if (height) *height = w;
- }
-}
+ if (data->job)
+ return EV_JOB_PAGE_DATA (data->job)->form_field_mapping;
-gint
-ev_page_cache_get_max_label_chars (EvPageCache *page_cache)
-{
- g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), 0);
-
- return page_cache->max_label_chars;
+ return data->form_field_mapping;
}
-gboolean
-ev_page_cache_get_dual_even_left (EvPageCache *page_cache)
+GList *
+ev_page_cache_get_annot_mapping (EvPageCache *cache,
+ gint page)
{
- g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), 0);
-
- return page_cache->dual_even_left;
-}
+ EvPageCacheData *data;
-gchar *
-ev_page_cache_get_page_label (EvPageCache *page_cache,
- gint page)
-{
- g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), NULL);
- g_return_val_if_fail (page >= 0 && page < page_cache->n_pages, NULL);
+ g_return_val_if_fail (EV_IS_PAGE_CACHE (cache), NULL);
+ g_return_val_if_fail (page >= 0 && page < cache->n_pages, NULL);
- if (page_cache->page_labels[page] == NULL)
- return g_strdup_printf ("%d", page + 1);
+ if (!(cache->flags & EV_PAGE_DATA_INCLUDE_ANNOTS))
+ return NULL;
- return g_strdup (page_cache->page_labels[page]);
-}
+ data = &cache->page_list[page];
+ if (data->done)
+ return data->annot_mapping;
-gboolean
-ev_page_cache_has_nonnumeric_page_labels (EvPageCache *page_cache)
-{
- g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), FALSE);
- return page_cache->has_labels;
+ if (data->job)
+ return EV_JOB_PAGE_DATA (data->job)->annot_mapping;
+
+ return data->annot_mapping;
}
-const EvDocumentInfo *
-ev_page_cache_get_info (EvPageCache *page_cache)
+GdkRegion *
+ev_page_cache_get_text_mapping (EvPageCache *cache,
+ gint page)
{
- g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), NULL);
-
- return page_cache->page_info;
-}
+ EvPageCacheData *data;
-#define PAGE_CACHE_STRING "ev-page-cache"
+ g_return_val_if_fail (EV_IS_PAGE_CACHE (cache), NULL);
+ g_return_val_if_fail (page >= 0 && page < cache->n_pages, NULL);
-EvPageCache *
-ev_page_cache_get (EvDocument *document)
-{
- EvPageCache *page_cache;
+ if (!(cache->flags & EV_PAGE_DATA_INCLUDE_TEXT))
+ return NULL;
- g_return_val_if_fail (EV_IS_DOCUMENT (document), NULL);
+ data = &cache->page_list[page];
+ if (data->done)
+ return data->text_mapping;
- page_cache = g_object_get_data (G_OBJECT (document), PAGE_CACHE_STRING);
- if (page_cache == NULL) {
- page_cache = ev_page_cache_new (document);
- g_object_set_data_full (G_OBJECT (document), PAGE_CACHE_STRING, page_cache, g_object_unref);
- }
+ if (data->job)
+ return EV_JOB_PAGE_DATA (data->job)->text_mapping;
- return page_cache;
+ return data->text_mapping;
}
+