#include "ev-page-cache.h"
#include "ev-job-queue.h"
+#include <stdlib.h>
+#include <string.h>
typedef struct _EvPageCacheInfo
{
- gint width;
- gint height;
+ double width;
+ double height;
}
EvPageCacheInfo;
gint current_page;
int n_pages;
char *title;
+ char **page_labels;
gboolean uniform;
- gint uniform_width;
- gint uniform_height;
+ double uniform_width;
+ double uniform_height;
EvPageCacheInfo *size_cache;
};
page_cache->uniform = TRUE;
page_cache->n_pages = ev_document_get_n_pages (document);
page_cache->title = ev_document_get_title (document);
+ page_cache->page_labels = g_new0 (char *, page_cache->n_pages);
- ev_document_set_scale (document, 1.0);
for (i = 0; i < page_cache->n_pages; i++) {
- gint page_width = 0;
- gint page_height = 0;
+ double page_width = 0;
+ double page_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);
if (i == 0) {
page_cache->uniform_width = page_width;
page_cache->size_cache = g_new0 (EvPageCacheInfo, page_cache->n_pages);
- for (j = 1; j < i; j++) {
- info = &(page_cache->size_cache [j - 1]);
- info->width = page_width;
- info->height = page_height;
+ 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 - 1]);
+ info = &(page_cache->size_cache [i]);
info->width = page_width;
info->height = page_height;
g_signal_emit (page_cache, signals[PAGE_CHANGED], 0, page);
}
+gboolean
+ev_page_cache_set_page_label (EvPageCache *page_cache,
+ const char *page_label)
+{
+ 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;
+ }
+ }
+
+ /* 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 &&
+ page_cache->page_labels[page] == NULL) {
+ ev_page_cache_set_current_page (page_cache, page);
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
void
ev_page_cache_set_link (EvPageCache *page_cache,
EvLink *link)
*height = (*height) * scale;
}
+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);
+
+ if (page_cache->page_labels[page] == NULL)
+ return g_strdup_printf ("%d", page + 1);
+
+ return g_strdup (page_cache->page_labels[page]);
+}
+
gboolean
ev_page_cache_next_page (EvPageCache *page_cache)
{
g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), FALSE);
- if (page_cache->current_page > page_cache->n_pages)
+ if (page_cache->current_page >= page_cache->n_pages - 1)
return FALSE;
ev_page_cache_set_current_page (page_cache, page_cache->current_page + 1);