info->n_pages = ev_document_get_n_pages (document);
if (info->n_pages > 0) {
- page = ev_document_get_page (document, 0);
- ev_document_get_page_size (document, page,
+ ev_document_get_page_size (document, 0,
&(info->paper_width),
&(info->paper_height));
- g_object_unref (page);
-
-
// Convert to mm.
info->paper_width = info->paper_width / 72.0f * 25.4f;
info->paper_height = info->paper_height / 72.0f * 25.4f;
#include "config.h"
+#include <stdlib.h>
+#include <string.h>
+
#include "ev-document.h"
+#define EV_DOCUMENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EV_TYPE_DOCUMENT, EvDocumentPrivate))
+
+typedef struct _EvPageSize
+{
+ gdouble width;
+ gdouble height;
+} EvPageSize;
+
+struct _EvDocumentPrivate
+{
+ gint n_pages;
+
+ gboolean uniform;
+ gdouble uniform_width;
+ gdouble uniform_height;
+
+ gdouble max_width;
+ gdouble max_height;
+ gint max_label;
+
+ gchar **page_labels;
+ EvPageSize *page_sizes;
+ EvDocumentInfo *info;
+};
+
+static gint _ev_document_get_n_pages (EvDocument *document);
+static void _ev_document_get_page_size (EvDocument *document,
+ EvPage *page,
+ double *width,
+ double *height);
+static gchar *_ev_document_get_page_label (EvDocument *document,
+ EvPage *page);
+static EvDocumentInfo *_ev_document_get_info (EvDocument *document);
+
GMutex *ev_doc_mutex = NULL;
GMutex *ev_fc_mutex = NULL;
return g_new0 (EvDocumentInfo, 1);
}
+static void
+ev_document_finalize (GObject *object)
+{
+ EvDocument *document = EV_DOCUMENT (object);
+
+ if (document->priv->page_sizes) {
+ g_free (document->priv->page_sizes);
+ document->priv->page_sizes = NULL;
+ }
+
+ if (document->priv->page_labels) {
+ gint i;
+
+ for (i = 0; i < document->priv->n_pages; i++) {
+ g_free (document->priv->page_labels[i]);
+ }
+ g_free (document->priv->page_labels);
+ document->priv->page_labels = NULL;
+ }
+
+ if (document->priv->info) {
+ ev_document_info_free (document->priv->info);
+ document->priv->info = NULL;
+ }
+
+ G_OBJECT_CLASS (ev_document_parent_class)->finalize (object);
+}
+
static void
ev_document_init (EvDocument *document)
{
+ document->priv = EV_DOCUMENT_GET_PRIVATE (document);
+
+ /* Assume all pages are the same size until proven otherwise */
+ document->priv->uniform = TRUE;
}
static void
ev_document_class_init (EvDocumentClass *klass)
{
+ GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (g_object_class, sizeof (EvDocumentPrivate));
+
klass->get_page = ev_document_impl_get_page;
klass->get_info = ev_document_impl_get_info;
+
+ g_object_class->finalize = ev_document_finalize;
}
GMutex *
EV_DOCUMENT_ERROR_INVALID,
"Internal error in backend");
}
+ } else {
+ gint i;
+ EvDocumentPrivate *priv = document->priv;
+
+ /* Cache some info about the document to avoid
+ * going to the backends since it requires locks
+ */
+ priv->n_pages = _ev_document_get_n_pages (document);
+ priv->info = _ev_document_get_info (document);
+
+ for (i = 0; i < priv->n_pages; i++) {
+ EvPage *page = ev_document_get_page (document, i);
+ gdouble page_width = 0;
+ gdouble page_height = 0;
+ EvPageSize *page_size;
+ gchar *page_label;
+
+ _ev_document_get_page_size (document, page, &page_width, &page_height);
+
+ if (i == 0) {
+ priv->uniform_width = page_width;
+ priv->uniform_height = page_height;
+ } else if (priv->uniform &&
+ (priv->uniform_width != page_width ||
+ priv->uniform_height != page_height)) {
+ /* It's a different page size. Backfill the array. */
+ int j;
+
+ priv->page_sizes = g_new0 (EvPageSize, priv->n_pages);
+
+ for (j = 0; j < i; j++) {
+ page_size = &(priv->page_sizes[j]);
+ page_size->width = priv->uniform_width;
+ page_size->height = priv->uniform_height;
+ }
+ priv->uniform = FALSE;
+ }
+ if (!priv->uniform) {
+ page_size = &(priv->page_sizes[i]);
+
+ page_size->width = page_width;
+ page_size->height = page_height;
+
+ if (page_width > priv->max_width)
+ priv->max_width = page_width;
+
+ if (page_height > priv->max_height)
+ priv->max_height = page_height;
+ }
+
+ page_label = _ev_document_get_page_label (document, page);
+ if (page_label) {
+ if (priv->page_labels) {
+ priv->page_labels[i] = page_label;
+ } else {
+ gchar *numeric_label;
+
+ numeric_label = g_strdup_printf ("%d", i + 1);
+ if (strcmp (numeric_label, page_label) != 0) {
+ priv->page_labels = g_new0 (gchar *, priv->n_pages);
+ priv->page_labels[i] = page_label;
+ }
+ g_free (numeric_label);
+ }
+ priv->max_label = MAX (priv->max_label,
+ g_utf8_strlen (page_label, 256));
+ }
+
+ g_object_unref (page);
+ }
+
+ if (priv->uniform) {
+ priv->max_width = priv->uniform_width;
+ priv->max_height = priv->uniform_height;
+ }
}
return retval;
return klass->save (document, uri, error);
}
-int
-ev_document_get_n_pages (EvDocument *document)
+EvPage *
+ev_document_get_page (EvDocument *document,
+ gint index)
+{
+ EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
+
+ return klass->get_page (document, index);
+}
+
+static gint
+_ev_document_get_n_pages (EvDocument *document)
{
EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
return klass->get_n_pages (document);
}
-EvPage *
-ev_document_get_page (EvDocument *document,
- gint index)
+gint
+ev_document_get_n_pages (EvDocument *document)
+{
+ return document->priv->n_pages;
+}
+
+static void
+_ev_document_get_page_size (EvDocument *document,
+ EvPage *page,
+ double *width,
+ double *height)
{
EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
- return klass->get_page (document, index);
+ klass->get_page_size (document, page, width, height);
}
void
ev_document_get_page_size (EvDocument *document,
- EvPage *page,
+ gint page_index,
double *width,
double *height)
+{
+ if (width)
+ *width = document->priv->uniform ?
+ document->priv->uniform_width :
+ document->priv->page_sizes[page_index].width;
+ if (height)
+ *height = document->priv->uniform ?
+ document->priv->uniform_height :
+ document->priv->page_sizes[page_index].height;
+}
+
+static gchar *
+_ev_document_get_page_label (EvDocument *document,
+ EvPage *page)
{
EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
- klass->get_page_size (document, page, width, height);
+ return klass->get_page_label ?
+ klass->get_page_label (document, page) : NULL;
}
gchar *
ev_document_get_page_label (EvDocument *document,
- EvPage *page)
+ gint page_index)
+{
+ return (document->priv->page_labels && document->priv->page_labels[page_index]) ?
+ g_strdup (document->priv->page_labels[page_index]) :
+ g_strdup_printf ("%d", page_index + 1);
+}
+
+static EvDocumentInfo *
+_ev_document_get_info (EvDocument *document)
{
EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
- return klass->get_page_label ?
- klass->get_page_label (document, page) : NULL;
+ return klass->get_info (document);
}
EvDocumentInfo *
ev_document_get_info (EvDocument *document)
{
- EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
-
- return klass->get_info (document);
+ return document->priv->info;
}
cairo_surface_t *
return klass->render (document, rc);
}
+const gchar *
+ev_document_get_title (EvDocument *document)
+{
+ return (document->priv->info->fields_mask & EV_DOCUMENT_INFO_TITLE) ?
+ document->priv->info->title : NULL;
+}
+
+gboolean
+ev_document_is_page_size_uniform (EvDocument *document)
+{
+ return document->priv->uniform;
+}
+
+void
+ev_document_get_max_page_size (EvDocument *document,
+ gdouble *width,
+ gdouble *height)
+{
+ if (width)
+ *width = document->priv->max_width;
+ if (height)
+ *height = document->priv->max_height;
+}
+
+gint
+ev_document_get_max_label_len (EvDocument *document)
+{
+ return document->priv->max_label;
+}
+
+gboolean
+ev_document_has_text_page_labels (EvDocument *document)
+{
+ return document->priv->page_labels != NULL;
+}
+
+gboolean
+ev_document_find_page_by_label (EvDocument *document,
+ const gchar *page_label,
+ gint *page_index)
+{
+ gint i, page;
+ glong value;
+ gchar *endptr = NULL;
+ EvDocumentPrivate *priv = document->priv;
+
+ /* First, look for a literal label match */
+ for (i = 0; priv->page_labels && i < priv->n_pages; i ++) {
+ if (priv->page_labels[i] != NULL &&
+ ! strcmp (page_label, priv->page_labels[i])) {
+ *page_index = i;
+ return TRUE;
+ }
+ }
+
+ /* Second, look for a match with case insensitively */
+ for (i = 0; priv->page_labels && i < priv->n_pages; i++) {
+ if (priv->page_labels[i] != NULL &&
+ ! strcasecmp (page_label, priv->page_labels[i])) {
+ *page_index = 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 < priv->n_pages) {
+ *page_index = page;
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
/* EvDocumentInfo */
EV_DEFINE_BOXED_TYPE (EvDocumentInfo, ev_document_info, ev_document_info_copy, ev_document_info_free)
typedef struct _EvDocument EvDocument;
typedef struct _EvDocumentClass EvDocumentClass;
+typedef struct _EvDocumentPrivate EvDocumentPrivate;
+
typedef struct _EvPageCache EvPageCache;
typedef struct _EvPageCacheClass EvPageCacheClass;
struct _EvDocument
{
GObject base;
+
+ EvDocumentPrivate *priv;
};
struct _EvDocumentClass
EvDocumentInfo * (* get_info) (EvDocument *document);
};
-GType ev_document_get_type (void) G_GNUC_CONST;
-GQuark ev_document_error_quark (void);
+GType ev_document_get_type (void) G_GNUC_CONST;
+GQuark ev_document_error_quark (void);
/* Document mutex */
-GMutex *ev_document_get_doc_mutex (void);
-void ev_document_doc_mutex_lock (void);
-void ev_document_doc_mutex_unlock (void);
-gboolean ev_document_doc_mutex_trylock(void);
+GMutex *ev_document_get_doc_mutex (void);
+void ev_document_doc_mutex_lock (void);
+void ev_document_doc_mutex_unlock (void);
+gboolean ev_document_doc_mutex_trylock (void);
/* FontConfig mutex */
-GMutex *ev_document_get_fc_mutex (void);
-void ev_document_fc_mutex_lock (void);
-void ev_document_fc_mutex_unlock (void);
-gboolean ev_document_fc_mutex_trylock (void);
+GMutex *ev_document_get_fc_mutex (void);
+void ev_document_fc_mutex_lock (void);
+void ev_document_fc_mutex_unlock (void);
+gboolean ev_document_fc_mutex_trylock (void);
-EvDocumentInfo *ev_document_get_info (EvDocument *document);
-gboolean ev_document_load (EvDocument *document,
- const char *uri,
- GError **error);
-gboolean ev_document_save (EvDocument *document,
- const char *uri,
- GError **error);
-gint ev_document_get_n_pages (EvDocument *document);
-EvPage *ev_document_get_page (EvDocument *document,
- gint index);
-void ev_document_get_page_size (EvDocument *document,
- EvPage *page,
- double *width,
- double *height);
-gchar *ev_document_get_page_label (EvDocument *document,
- EvPage *page);
-cairo_surface_t *ev_document_render (EvDocument *document,
- EvRenderContext *rc);
+EvDocumentInfo *ev_document_get_info (EvDocument *document);
+gboolean ev_document_load (EvDocument *document,
+ const char *uri,
+ GError **error);
+gboolean ev_document_save (EvDocument *document,
+ const char *uri,
+ GError **error);
+gint ev_document_get_n_pages (EvDocument *document);
+EvPage *ev_document_get_page (EvDocument *document,
+ gint index);
+void ev_document_get_page_size (EvDocument *document,
+ gint page_index,
+ double *width,
+ double *height);
+gchar *ev_document_get_page_label (EvDocument *document,
+ gint page_index);
+cairo_surface_t *ev_document_render (EvDocument *document,
+ EvRenderContext *rc);
+const gchar *ev_document_get_title (EvDocument *document);
+gboolean ev_document_is_page_size_uniform (EvDocument *document);
+void ev_document_get_max_page_size (EvDocument *document,
+ gdouble *width,
+ gdouble *height);
+gint ev_document_get_max_label_len (EvDocument *document);
+gboolean ev_document_has_text_page_labels (EvDocument *document);
+gboolean ev_document_find_page_by_label (EvDocument *document,
+ const gchar *page_label,
+ gint *page_index);
-gint ev_rect_cmp (EvRectangle *a,
- EvRectangle *b);
+gint ev_rect_cmp (EvRectangle *a,
+ EvRectangle *b);
#define EV_TYPE_RECTANGLE (ev_rectangle_get_type ())
struct _EvRectangle
{
GtkToolItem parent;
+ EvDocument *document;
+ EvPageCache *page_cache;
+
GtkWidget *entry;
GtkWidget *label;
- EvPageCache *page_cache;
guint signal_id;
GtkTreeModel *filter_model;
GtkTreeModel *model;
static void
update_pages_label (EvPageActionWidget *action_widget,
- gint page,
- EvPageCache *page_cache)
+ gint page)
{
char *label_text;
gint n_pages;
- n_pages = page_cache ? ev_page_cache_get_n_pages (page_cache) : 0;
- if (page_cache && ev_page_cache_has_nonnumeric_page_labels (page_cache)) {
+ n_pages = ev_document_get_n_pages (action_widget->document);
+ if (ev_document_has_text_page_labels (action_widget->document)) {
label_text = g_strdup_printf (_("(%d of %d)"), page + 1, n_pages);
} else {
label_text = g_strdup_printf (_("of %d"), n_pages);
gint page,
EvPageActionWidget *action_widget)
{
- if (page_cache && page >= 0) {
+ if (page >= 0) {
gchar *page_label;
gtk_entry_set_width_chars (GTK_ENTRY (action_widget->entry),
- CLAMP (ev_page_cache_get_max_label_chars (page_cache),
+ CLAMP (ev_document_get_max_label_len (action_widget->document),
6, 12));
- page_label = ev_page_cache_get_page_label (page_cache, page);
+ page_label = ev_document_get_page_label (action_widget->document, page);
gtk_entry_set_text (GTK_ENTRY (action_widget->entry), page_label);
gtk_editable_set_position (GTK_EDITABLE (action_widget->entry), -1);
g_free (page_label);
gtk_entry_set_text (GTK_ENTRY (action_widget->entry), "");
}
- update_pages_label (action_widget, page, page_cache);
+ update_pages_label (action_widget, page);
}
static gboolean
pageno = ev_page_cache_get_current_page (page_cache);
if ((event->direction == GDK_SCROLL_DOWN) &&
- (pageno < ev_page_cache_get_n_pages (page_cache) - 1))
+ (pageno < ev_document_get_n_pages (action_widget->document) - 1))
pageno++;
if ((event->direction == GDK_SCROLL_UP) && (pageno > 0))
pageno--;
/* rest the entry to the current page if we were unable to
* change it */
page_cache = action_widget->page_cache;
- page_label = ev_page_cache_get_page_label (page_cache,
- ev_page_cache_get_current_page (page_cache));
+ page_label = ev_document_get_page_label (action_widget->document,
+ ev_page_cache_get_current_page (page_cache));
gtk_entry_set_text (GTK_ENTRY (action_widget->entry), page_label);
gtk_editable_set_position (GTK_EDITABLE (action_widget->entry), -1);
g_free (page_label);
gtk_widget_add_events (action_widget->entry,
GDK_BUTTON_MOTION_MASK);
gtk_entry_set_width_chars (GTK_ENTRY (action_widget->entry), 5);
+ gtk_entry_set_text (GTK_ENTRY (action_widget->entry), "");
g_signal_connect_swapped (action_widget->entry, "scroll-event",
G_CALLBACK (page_scroll_cb),
action_widget);
}
void
-ev_page_action_widget_set_page_cache (EvPageActionWidget *action_widget,
- EvPageCache *page_cache)
+ev_page_action_widget_set_document (EvPageActionWidget *action_widget,
+ EvDocument *document)
{
+ EvPageCache *page_cache = ev_page_cache_get (document);
+
+ g_object_ref (document);
+ if (action_widget->document)
+ g_object_unref (action_widget->document);
+ action_widget->document = document;
+
if (action_widget->page_cache != NULL) {
if (action_widget->signal_id > 0) {
g_signal_handler_disconnect (action_widget->page_cache,
action_widget->page_cache = NULL;
}
- if (page_cache != NULL) {
- action_widget->page_cache = page_cache;
- g_object_add_weak_pointer (G_OBJECT (page_cache),
- (gpointer)&action_widget->page_cache);
- action_widget->signal_id =
- g_signal_connect_object (page_cache, "page-changed",
- G_CALLBACK (page_changed_cb),
- action_widget, 0);
- page_changed_cb (page_cache,
- ev_page_cache_get_current_page (page_cache),
- action_widget);
- } else {
- action_widget->signal_id = 0;
- page_changed_cb (NULL, 0, action_widget);
- }
+ action_widget->page_cache = page_cache;
+ g_object_add_weak_pointer (G_OBJECT (page_cache),
+ (gpointer)&action_widget->page_cache);
+ action_widget->signal_id =
+ g_signal_connect_object (page_cache, "page-changed",
+ G_CALLBACK (page_changed_cb),
+ action_widget, 0);
+ page_changed_cb (page_cache,
+ ev_page_cache_get_current_page (page_cache),
+ action_widget);
}
static void
action_widget->page_cache = NULL;
}
+ if (action_widget->document) {
+ g_object_unref (action_widget->document);
+ action_widget->document = NULL;
+ }
+
G_OBJECT_CLASS (ev_page_action_widget_parent_class)->finalize (object);
}
void ev_page_action_widget_update_model (EvPageActionWidget *proxy,
GtkTreeModel *model);
-void ev_page_action_widget_set_page_cache (EvPageActionWidget *action_widget,
- EvPageCache *page_cache);
+void ev_page_action_widget_set_document (EvPageActionWidget *action_widget,
+ EvDocument *document);
void ev_page_action_widget_grab_focus (EvPageActionWidget *proxy);
struct _EvPageActionPrivate
{
- EvPageCache *page_cache;
+ EvDocument *document;
GtkTreeModel *model;
};
enum {
PROP_0,
- PROP_PAGE_CACHE,
+ PROP_DOCUMENT,
PROP_MODEL,
};
}
static void
-update_page_cache (EvPageAction *page, GParamSpec *pspec, EvPageActionWidget *proxy)
+update_document (EvPageAction *page, GParamSpec *pspec, EvPageActionWidget *proxy)
{
- ev_page_action_widget_set_page_cache (proxy, page->priv->page_cache);
+ if (page->priv->document)
+ ev_page_action_widget_set_document (proxy, page->priv->document);
}
static void
connect_proxy (GtkAction *action, GtkWidget *proxy)
{
if (GTK_IS_TOOL_ITEM (proxy)) {
- g_signal_connect_object (action, "notify::page-cache",
- G_CALLBACK (update_page_cache),
+ g_signal_connect_object (action, "notify::document",
+ G_CALLBACK (update_document),
proxy, 0);
g_signal_connect (proxy, "activate_link",
G_CALLBACK (activate_link_cb),
action);
- update_page_cache (EV_PAGE_ACTION (action), NULL,
- EV_PAGE_ACTION_WIDGET (proxy));
g_signal_connect_object (action, "notify::model",
G_CALLBACK (update_model),
proxy, 0);
{
EvPageAction *page = EV_PAGE_ACTION (object);
- if (page->priv->page_cache) {
- g_object_unref (page->priv->page_cache);
- page->priv->page_cache = NULL;
+ if (page->priv->document) {
+ g_object_unref (page->priv->document);
+ page->priv->document = NULL;
}
G_OBJECT_CLASS (ev_page_action_parent_class)->dispose (object);
GParamSpec *pspec)
{
EvPageAction *page;
- EvPageCache *page_cache;
+ EvDocument *document;
GtkTreeModel *model;
-
+
page = EV_PAGE_ACTION (object);
switch (prop_id)
{
- case PROP_PAGE_CACHE:
- page_cache = page->priv->page_cache;
- page->priv->page_cache = EV_PAGE_CACHE (g_value_dup_object (value));
- if (page_cache)
- g_object_unref (page_cache);
+ case PROP_DOCUMENT:
+ document = page->priv->document;
+ page->priv->document = EV_DOCUMENT (g_value_dup_object (value));
+ if (document)
+ g_object_unref (document);
break;
case PROP_MODEL:
model = page->priv->model;
GParamSpec *pspec)
{
EvPageAction *page;
-
+
page = EV_PAGE_ACTION (object);
switch (prop_id)
{
- case PROP_PAGE_CACHE:
- g_value_set_object (value, page->priv->page_cache);
+ case PROP_DOCUMENT:
+ g_value_set_object (value, page->priv->document);
break;
case PROP_MODEL:
g_value_set_object (value, page->priv->model);
void
ev_page_action_set_document (EvPageAction *page, EvDocument *document)
{
- EvPageCache *page_cache = NULL;
-
- if (document)
- page_cache = ev_page_cache_get (document);
-
g_object_set (page,
- "page-cache", page_cache,
+ "document", document,
"model", NULL,
NULL);
}
G_TYPE_OBJECT);
g_object_class_install_property (object_class,
- PROP_PAGE_CACHE,
- g_param_spec_object ("page-cache",
- "Page Cache",
- "Current page cache",
- EV_TYPE_PAGE_CACHE,
+ PROP_DOCUMENT,
+ g_param_spec_object ("document",
+ "Document",
+ "Current document",
+ EV_TYPE_DOCUMENT,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
#define THUMBNAIL_WIDTH 100
-typedef struct _EvPageCacheInfo
-{
- double width;
- double height;
-} EvPageCacheInfo;
-
typedef struct _EvPageThumbsInfo
{
gint width;
{
GObject parent;
+ EvDocument *document;
+
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;
+ gboolean dual_even_left;
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;
ev_page_cache_init (EvPageCache *page_cache)
{
page_cache->current_page = -1;
- page_cache->max_label_chars = 0;
}
static void
static void
ev_page_cache_finalize (GObject *object)
{
- EvPageCache *page_cache;
+ EvPageCache *page_cache = EV_PAGE_CACHE (object);
- page_cache = EV_PAGE_CACHE (object);
-
- if (page_cache->title) {
- g_free (page_cache->title);
- page_cache->title = NULL;
- }
-
- if (page_cache->size_cache) {
- g_free (page_cache->size_cache);
- page_cache->size_cache = NULL;
- }
+ page_cache->document = NULL;
if (page_cache->thumbs_size_cache) {
g_free (page_cache->thumbs_size_cache);
page_cache->dual_height_to_page = 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 (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;
+ gboolean swap, uniform, dual_even_left;
int i;
double uniform_height, page_height, next_page_height;
double saved_height;
+ gdouble u_width, u_height;
+ gint n_pages;
swap = (page_cache->rotation == 90 ||
page_cache->rotation == 270);
+ uniform = ev_document_is_page_size_uniform (page_cache->document);
+ n_pages = ev_document_get_n_pages (page_cache->document);
+ dual_even_left = (n_pages > 2);
+
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);
-
+ page_cache->height_to_page = g_new0 (double, n_pages + 1);
+ page_cache->dual_height_to_page = g_new0 (double, n_pages + 2);
+
+ if (uniform)
+ ev_document_get_page_size (page_cache->document, 0, &u_width, &u_height);
+
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;
+ for (i = 0; i <= n_pages; i++) {
+ if (uniform) {
+ uniform_height = swap ? u_width : u_height;
+ 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;
- }
+ if (i < n_pages) {
+ gdouble w, h;
+
+ ev_document_get_page_size (page_cache->document, i, &w, &h);
+ page_height = swap ? w : h;
} else {
page_height = 0;
}
- page_cache->height_to_page [i] = saved_height;
+ 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;
- }
+ if (dual_even_left && !uniform) {
+ gdouble w, h;
+
+ ev_document_get_page_size (page_cache->document, 0, &w, &h);
+ saved_height = swap ? w : h;
} 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;
+
+ for (i = dual_even_left; i < n_pages + 2; i += 2) {
+ if (uniform) {
+ uniform_height = swap ? u_width : u_height;
+ page_cache->dual_height_to_page[i] = ((i + dual_even_left) / 2) * uniform_height;
+ if (i + 1 < n_pages + 2)
+ page_cache->dual_height_to_page[i + 1] = ((i + 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;
- }
+ if (i + 1 < n_pages) {
+ gdouble w, h;
+
+ ev_document_get_page_size (page_cache->document, i + 1, &w, &h);
+ next_page_height = swap ? w : h;
} 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;
- }
+
+ if (i < n_pages) {
+ gdouble w, h;
+
+ ev_document_get_page_size (page_cache->document, i, &w, &h);
+ page_height = swap ? w : h;
} 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;
+
+ if (i + 1 < 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;
+ page_cache->dual_height_to_page[i] = saved_height;
}
}
}
}
-EvPageCache *
+static EvPageCache *
ev_page_cache_new (EvDocument *document)
{
EvPageCache *page_cache;
- EvPageCacheInfo *info;
EvPageThumbsInfo *thumb_info;
EvRenderContext *rc = NULL;
- gboolean has_thumbs;
- gint i;
+ gint i, n_pages;
page_cache = (EvPageCache *) g_object_new (EV_TYPE_PAGE_CACHE, NULL);
+ page_cache->document = document;
- ev_document_doc_mutex_lock ();
+ n_pages = ev_document_get_n_pages (document);
- /* We read page information out of the document */
+ build_height_to_page (page_cache);
+
+ if (!EV_IS_DOCUMENT_THUMBNAILS (document)) {
+ if (n_pages > 0)
+ ev_page_cache_set_current_page (page_cache, 0);
+ return page_cache;
+ }
/* 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++) {
+ for (i = 0; i < n_pages; i++) {
EvPage *page;
- double page_width = 0;
- double page_height = 0;
+ 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, 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;
- }
+ 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);
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;
/* It's a different thumbnail size. Backfill the array. */
int j;
- page_cache->thumbs_size_cache = g_new0 (EvPageThumbsInfo, page_cache->n_pages);
+ page_cache->thumbs_size_cache = g_new0 (EvPageThumbsInfo, n_pages);
for (j = 0; j < i; j++) {
- thumb_info = &(page_cache->thumbs_size_cache [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;
}
}
if (! page_cache->thumbs_uniform) {
- thumb_info = &(page_cache->thumbs_size_cache [i]);
+ thumb_info = &(page_cache->thumbs_size_cache[i]);
thumb_info->width = thumb_width;
thumb_info->height = thumb_height;
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);
-
- ev_document_doc_mutex_unlock ();
-
- if (page_cache->n_pages > 0)
+ if (n_pages > 0)
ev_page_cache_set_current_page (page_cache, 0);
return page_cache;
gboolean
ev_page_cache_check_dimensions (EvPageCache *page_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;
-}
+ gdouble document_width, document_height;
-gint
-ev_page_cache_get_n_pages (EvPageCache *page_cache)
-{
- g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), 0);
+ ev_document_get_max_page_size (page_cache->document,
+ &document_width, &document_height);
- return page_cache->n_pages;
+ return (document_width > 0 && document_height > 0);
}
gint
int page)
{
g_return_if_fail (EV_IS_PAGE_CACHE (page_cache));
- g_return_if_fail (page >= 0 || page < page_cache->n_pages);
if (page == page_cache->current_page)
return;
gboolean
ev_page_cache_set_page_label (EvPageCache *page_cache,
- const char *page_label)
+ const gchar *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;
- }
- }
+ gint page;
- /* 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;
- }
- }
+ g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), FALSE);
- /* 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;
- }
+ if (ev_document_find_page_by_label (page_cache->document, page_label, &page)) {
+ ev_page_cache_set_current_page (page_cache, page);
+ return TRUE;
}
return FALSE;
}
-const char *
-ev_page_cache_get_title (EvPageCache *page_cache)
-{
- g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), NULL);
-
- return page_cache->title;
-}
-
void
ev_page_cache_get_size (EvPageCache *page_cache,
gint page,
double 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->uniform) {
- w = page_cache->uniform_width;
- h = page_cache->uniform_height;
- } else {
- EvPageCacheInfo *info;
-
- info = &(page_cache->size_cache [page]);
-
- w = info->width;
- h = info->height;
- }
+ ev_document_get_page_size (page_cache->document, page, &w, &h);
w = w * scale + 0.5;
h = h * scale + 0.5;
gfloat scale,
gint *width)
{
+ double w, h;
+
g_return_if_fail (EV_IS_PAGE_CACHE (page_cache));
- if (width) {
- if (rotation == 0 || rotation == 180) {
- *width = page_cache->max_width * scale;
- } else {
- *width = page_cache->max_height * scale;
- }
- }
+ if (!width)
+ return;
+
+ ev_document_get_max_page_size (page_cache->document, &w, &h);
+ *width = (rotation == 0 || rotation == 180) ? w * scale : h * scale;
}
void
gfloat scale,
gint *height)
{
+ double w, h;
+
g_return_if_fail (EV_IS_PAGE_CACHE (page_cache));
- if (height) {
- if (rotation == 0 || rotation == 180) {
- *height = page_cache->max_height * scale;
- } else {
- *height = page_cache->max_width * scale;
- }
- }
+ if (!height)
+ return;
+
+ ev_document_get_max_page_size (page_cache->document, &w, &h);
+ *height = (rotation == 0 || rotation == 180) ? h * scale : w * scale;
}
-void
+void
ev_page_cache_get_height_to_page (EvPageCache *page_cache,
gint page,
gint rotation,
{
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;
+ *height = page_cache->height_to_page[page] * scale;
if (dual_height)
- *dual_height = page_cache->dual_height_to_page [page] * scale;
+ *dual_height = page_cache->dual_height_to_page[page] * scale;
}
void
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;
}
}
-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;
-}
-
gboolean
ev_page_cache_get_dual_even_left (EvPageCache *page_cache)
{
g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), 0);
-
- return page_cache->dual_even_left;
-}
-
-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_has_nonnumeric_page_labels (EvPageCache *page_cache)
-{
- g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), FALSE);
- return page_cache->has_labels;
-}
-
-const EvDocumentInfo *
-ev_page_cache_get_info (EvPageCache *page_cache)
-{
- g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), NULL);
- return page_cache->page_info;
+ return (ev_document_get_n_pages (page_cache->document) > 2);
}
#define PAGE_CACHE_STRING "ev-page-cache"
GType ev_page_cache_get_type (void) G_GNUC_CONST;
-/* Used by ev-document.c only */
-EvPageCache *ev_page_cache_new (EvDocument *document);
-gint ev_page_cache_get_n_pages (EvPageCache *page_cache);
-const char *ev_page_cache_get_title (EvPageCache *page_cache);
void ev_page_cache_get_size (EvPageCache *page_cache,
gint page,
gint rotation,
gint rotation,
gint *width,
gint *height);
-gint ev_page_cache_get_max_label_chars (EvPageCache *page_cache);
-char *ev_page_cache_get_page_label (EvPageCache *page_cache,
- gint page);
-gboolean ev_page_cache_has_nonnumeric_page_labels (EvPageCache *page_cache);
-const EvDocumentInfo *ev_page_cache_get_info (EvPageCache *page_cache);
-
gboolean ev_page_cache_get_dual_even_left (EvPageCache *page_cache);
/* Navigation */
void ev_page_cache_set_current_page_history (EvPageCache *page_cache,
int page);
gboolean ev_page_cache_set_page_label (EvPageCache *page_cache,
- const char *page_label);
+ const gchar *page_label);
EvPageCache *ev_page_cache_get (EvDocument *document);
/* These are used for iterating through the prev and next arrays */
#define FIRST_VISIBLE_PREV(pixbuf_cache) \
(MAX (0, pixbuf_cache->preload_cache_size - pixbuf_cache->start_page))
-#define VISIBLE_NEXT_LEN(pixbuf_cache, page_cache) \
- (MIN(pixbuf_cache->preload_cache_size, ev_page_cache_get_n_pages (page_cache) - (1 + pixbuf_cache->end_page)))
+#define VISIBLE_NEXT_LEN(pixbuf_cache) \
+ (MIN(pixbuf_cache->preload_cache_size, ev_document_get_n_pages (pixbuf_cache->document) - (1 + pixbuf_cache->end_page)))
#define PAGE_CACHE_LEN(pixbuf_cache) \
((pixbuf_cache->end_page - pixbuf_cache->start_page) + 1)
CacheJobInfo *new_job_list;
CacheJobInfo *new_prev_job;
CacheJobInfo *new_next_job;
- EvPageCache *page_cache;
int i, page;
if (pixbuf_cache->start_page == start_page &&
pixbuf_cache->end_page == end_page)
return;
- page_cache = ev_page_cache_get (pixbuf_cache->document);
-
new_job_list = g_new0 (CacheJobInfo, (end_page - start_page) + 1);
new_prev_job = g_new0 (CacheJobInfo, pixbuf_cache->preload_cache_size);
new_next_job = g_new0 (CacheJobInfo, pixbuf_cache->preload_cache_size);
}
for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
- if (page >= ev_page_cache_get_n_pages (page_cache)) {
+ if (page >= ev_document_get_n_pages (pixbuf_cache->document)) {
dispose_cache_job_info (pixbuf_cache->next_job + i, pixbuf_cache);
} else {
move_one_job (pixbuf_cache->next_job + i,
static void
add_job (EvPixbufCache *pixbuf_cache,
CacheJobInfo *job_info,
- EvPageCache *page_cache,
GdkRegion *region,
gint width,
gint height,
cairo_image_surface_get_height (job_info->surface) == height)
return;
- add_job (pixbuf_cache, job_info, page_cache, NULL,
+ add_job (pixbuf_cache, job_info, NULL,
width, height, page, rotation, scale,
priority);
}
EV_JOB_PRIORITY_LOW);
}
- for (i = 0; i < VISIBLE_NEXT_LEN(pixbuf_cache, page_cache); i++) {
+ for (i = 0; i < VISIBLE_NEXT_LEN(pixbuf_cache); i++) {
job_info = (pixbuf_cache->next_job + i);
page = pixbuf_cache->end_page + 1 + i;
gfloat scale,
GList *selection_list)
{
- EvPageCache *page_cache;
-
g_return_if_fail (EV_IS_PIXBUF_CACHE (pixbuf_cache));
- page_cache = ev_page_cache_get (pixbuf_cache->document);
-
- g_return_if_fail (start_page >= 0 && start_page < ev_page_cache_get_n_pages (page_cache));
- g_return_if_fail (end_page >= 0 && end_page < ev_page_cache_get_n_pages (page_cache));
+ g_return_if_fail (start_page >= 0 && start_page < ev_document_get_n_pages (pixbuf_cache->document));
+ g_return_if_fail (end_page >= 0 && end_page < ev_document_get_n_pages (pixbuf_cache->document));
g_return_if_fail (end_page >= start_page);
/* First, resize the page_range as needed. We cull old pages
ev_pixbuf_cache_set_selection_list (EvPixbufCache *pixbuf_cache,
GList *selection_list)
{
- EvPageCache *page_cache;
EvViewSelection *selection;
GList *list = selection_list;
int page;
if (!EV_IS_SELECTION (pixbuf_cache->document))
return;
- page_cache = ev_page_cache_get (pixbuf_cache->document);
-
/* We check each area to see what needs updating, and what needs freeing; */
page = pixbuf_cache->start_page - pixbuf_cache->preload_cache_size;
for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
}
for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
- if (page >= ev_page_cache_get_n_pages (page_cache))
+ if (page >= ev_document_get_n_pages (pixbuf_cache->document))
break;
selection = NULL;
GList *
ev_pixbuf_cache_get_selection_list (EvPixbufCache *pixbuf_cache)
{
- EvPageCache *page_cache;
EvViewSelection *selection;
GList *retval = NULL;
int page;
g_return_val_if_fail (EV_IS_PIXBUF_CACHE (pixbuf_cache), NULL);
- page_cache = ev_page_cache_get (pixbuf_cache->document);
-
/* We check each area to see what needs updating, and what needs freeing; */
page = pixbuf_cache->start_page - pixbuf_cache->preload_cache_size;
for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
}
for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
- if (page >= ev_page_cache_get_n_pages (page_cache))
+ if (page >= ev_document_get_n_pages (pixbuf_cache->document))
break;
if (pixbuf_cache->next_job[i].selection_points.x1 != -1) {
return retval;
}
-void
+void
ev_pixbuf_cache_reload_page (EvPixbufCache *pixbuf_cache,
GdkRegion *region,
gint page,
gdouble scale)
{
CacheJobInfo *job_info;
- EvPageCache *page_cache;
gint width, height;
job_info = find_job_cache (pixbuf_cache, page);
if (job_info == NULL)
return;
-
- page_cache = ev_page_cache_get (pixbuf_cache->document);
- ev_page_cache_get_size (page_cache, page, rotation, scale,
+
+ ev_page_cache_get_size (ev_page_cache_get (pixbuf_cache->document),
+ page, rotation, scale,
&width, &height);
- add_job (pixbuf_cache, job_info, page_cache, region,
+ add_job (pixbuf_cache, job_info, region,
width, height, page, rotation, scale,
EV_JOB_PRIORITY_URGENT);
}
current_area.y = view->vadjustment->value;
current_area.height = view->vadjustment->page_size;
- for (i = 0; i < ev_page_cache_get_n_pages (view->page_cache); i++) {
+ for (i = 0; i < ev_document_get_n_pages (view->document); i++) {
get_page_extents (view, i, &page_area, &border);
} else if (view->dual_page) {
if (view->current_page % 2 == ev_page_cache_get_dual_even_left (view->page_cache)) {
view->start_page = view->current_page;
- if (view->current_page + 1 < ev_page_cache_get_n_pages (view->page_cache))
+ if (view->current_page + 1 < ev_document_get_n_pages (view->document))
view->end_page = view->start_page + 1;
else
view->end_page = view->start_page;
/* Assign boolean for first and last page */
if (view->current_page == 0)
first_page = TRUE;
- if (view->current_page == ev_page_cache_get_n_pages (view->page_cache) - 1)
+ if (view->current_page == ev_document_get_n_pages (view->document) - 1)
last_page = TRUE;
switch (scroll) {
other_page = (page % 2 == ev_page_cache_get_dual_even_left (view->page_cache)) ? page + 1: page - 1;
/* First, we get the bounding box of the two pages */
- if (other_page < ev_page_cache_get_n_pages (view->page_cache)
+ if (other_page < ev_document_get_n_pages (view->document)
&& (0 <= other_page)) {
ev_page_cache_get_size (view->page_cache,
other_page,
int page, n_pages, current_page;
page = ev_link_dest_get_page (dest);
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ n_pages = ev_document_get_n_pages (view->document);
if (page < 0 || page >= n_pages)
return;
dest2 = ev_document_links_find_link_dest (EV_DOCUMENT_LINKS (view->document),
named_dest);
if (dest2) {
- msg = ev_page_cache_get_page_label (view->page_cache,
- ev_link_dest_get_page (dest2));
+ msg = ev_document_get_page_label (view->document,
+ ev_link_dest_get_page (dest2));
g_object_unref (dest2);
}
}
}
break;
default:
- msg = ev_page_cache_get_page_label (view->page_cache,
- ev_link_dest_get_page (dest));
+ msg = ev_document_get_page_label (view->document,
+ ev_link_dest_get_page (dest));
}
return msg;
view->scale, &max_width);
compute_border (view, max_width, max_width, &border);
- n_pages = ev_page_cache_get_n_pages (view->page_cache) + 1;
+ n_pages = ev_document_get_n_pages (view->document) + 1;
requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
get_page_y_offset (view, n_pages, view->scale, &requisition->height);
ev_page_cache_get_max_width (view->page_cache, view->rotation,
view->scale, &max_width);
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ n_pages = ev_document_get_n_pages (view->document);
compute_border (view, max_width, max_width, &border);
requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
view->rotation,
view->scale,
&width, &height);
- if (view->current_page + 1 < ev_page_cache_get_n_pages (view->page_cache)) {
+ if (view->current_page + 1 < ev_document_get_n_pages (view->document)) {
gint width_2, height_2;
ev_page_cache_get_size (view->page_cache,
view->current_page + 1,
ev_view_goto_window_hide (view);
- if (page >= 0 &&
- page < ev_page_cache_get_n_pages (view->page_cache))
+ if (page >= 0 && page < ev_document_get_n_pages (view->document))
ev_page_cache_set_current_page (view->page_cache, page);
}
}
if (current == view->presentation_state) {
- if (ev_page_cache_get_n_pages (view->page_cache) > 1 &&
+ if (ev_document_get_n_pages (view->document) > 1 &&
key_is_numeric (event->keyval)) {
gint x, y;
1.0,
&doc_width, &doc_height);
- if (other_page < ev_page_cache_get_n_pages (view->page_cache)) {
+ if (other_page < ev_document_get_n_pages (view->document)) {
gint width_2, height_2;
ev_page_cache_get_size (view->page_cache,
other_page,
{
int n_pages, i;
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ n_pages = ev_document_get_n_pages (view->document);
for (i = 0; i < n_pages; i++) {
int page;
view_rect.width = MAX (start->x, stop->x) - view_rect.x;
view_rect.width = MAX (start->y, stop->y) - view_rect.y;
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ n_pages = ev_document_get_n_pages (view->document);
for (i = 0; i < n_pages; i++) {
GdkRectangle page_area;
g_assert (view->selection_mode == EV_VIEW_SELECTION_TEXT);
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ n_pages = ev_document_get_n_pages (view->document);
/* First figure out the range of pages the selection
* affects. */
clear_selection (view);
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ n_pages = ev_document_get_n_pages (view->document);
for (i = 0; i < n_pages; i++) {
int width, height;
EvViewSelection *selection;
ev_view_reset_presentation_state (view);
page = ev_page_cache_get_current_page (view->page_cache);
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ n_pages = ev_document_get_n_pages (view->document);
if (view->dual_page && !view->presentation)
page = page + 2;
construct_params);
export = EV_PRINT_OPERATION_EXPORT (object);
op = EV_PRINT_OPERATION (object);
- export->n_pages = ev_page_cache_get_n_pages (ev_page_cache_get (op->document));
+ export->n_pages = ev_document_get_n_pages (op->document);
return object;
}
EvPrintOperation *op = EV_PRINT_OPERATION (print);
gint n_pages;
- n_pages = ev_page_cache_get_n_pages (ev_page_cache_get (op->document));
+ n_pages = ev_document_get_n_pages (op->document);
gtk_print_operation_set_n_pages (print->op, n_pages);
ev_print_operation_update_status (op, -1, n_pages, 0);
EvPrintOperation *op = EV_PRINT_OPERATION (print);
cairo_t *cr;
gdouble cr_width, cr_height;
- gint width, height;
+ gdouble width, height;
gtk_print_operation_set_defer_drawing (print->op);
cr = gtk_print_context_get_cairo_context (context);
cr_width = gtk_print_context_get_width (context);
cr_height = gtk_print_context_get_height (context);
- ev_page_cache_get_size (ev_page_cache_get (op->document),
- page, 0, 1.0,
- &width, &height);
- cairo_scale (cr, cr_width / (gdouble)width, cr_height / (gdouble)height);
+ ev_document_get_page_size (op->document, page,
+ &width, &height);
+ cairo_scale (cr, cr_width / width, cr_height / height);
ev_job_print_set_cairo (EV_JOB_PRINT (print->job_print), cr);
ev_job_scheduler_push_job (print->job_print, EV_JOB_PRIORITY_NONE);
properties->document = document;
- info = ev_page_cache_get_info (ev_page_cache_get (document));
+ info = ev_document_get_info (document);
if (properties->general_page == NULL) {
label = gtk_label_new (_("General"));
g_object_unref (link);
}
} else {
- last_page = ev_page_cache_get_n_pages (sidebar->priv->page_cache);
+ last_page = ev_document_get_n_pages (sidebar->priv->document);
}
if (last_page == -1)
- last_page = ev_page_cache_get_n_pages (sidebar->priv->page_cache);
+ last_page = ev_document_get_n_pages (sidebar->priv->document);
window = gtk_widget_get_toplevel (GTK_WIDGET (sidebar));
if (EV_IS_WINDOW (window)) {
if (page < 0)
return FALSE;
- page_label = ev_page_cache_get_page_label (sidebar_links->priv->page_cache,
- page);
+ page_label = ev_document_get_page_label (sidebar_links->priv->document,
+ page);
gtk_tree_store_set (GTK_TREE_STORE (tree_model), iter,
EV_DOCUMENT_LINKS_COLUMN_PAGE_LABEL, page_label,
-1);
gint page)
{
EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
- gint width, height;
+ gdouble width;
- ev_page_cache_get_size (priv->page_cache,
- page, 0,
- 1.0, &width, &height);
-
- return (gdouble)THUMBNAIL_WIDTH / (gdouble)width;
+ ev_document_get_page_size (priv->document, page, &width, NULL);
+
+ return (gdouble)THUMBNAIL_WIDTH / width;
}
static void
GdkPixbuf *loading_icon = NULL;
gint width, height;
- page_label = ev_page_cache_get_page_label (priv->page_cache, i);
+ page_label = ev_document_get_page_label (priv->document, i);
page_string = g_markup_printf_escaped ("<i>%s</i>", page_label);
ev_page_cache_get_thumbnail_size (sidebar_thumbnails->priv->page_cache, i,
sidebar_thumbnails->priv->rotation,
ev_sidebar_thumbnails_use_icon_view (EvSidebarThumbnails *sidebar_thumbnails)
{
EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
- if (ev_page_cache_get_n_pages (priv->page_cache) > MAX_ICON_VIEW_PAGE_COUNT)
- return FALSE;
- return TRUE;
+
+ return (ev_document_get_n_pages (priv->document) <= MAX_ICON_VIEW_PAGE_COUNT);
}
static void
}
static void
-ev_sidebar_thumbnails_set_document (EvSidebarPage *sidebar_page,
- EvDocument *document)
+ev_sidebar_thumbnails_set_document (EvSidebarPage *sidebar_page,
+ EvDocument *document)
{
EvSidebarThumbnails *sidebar_thumbnails = EV_SIDEBAR_THUMBNAILS (sidebar_page);
priv->page_cache = ev_page_cache_get (document);
if (!EV_IS_DOCUMENT_THUMBNAILS (document) ||
- ev_page_cache_get_n_pages (priv->page_cache) <= 0 ||
- ev_page_cache_check_dimensions (priv->page_cache)) {
+ ev_document_get_n_pages (document) <= 0 ||
+ !ev_page_cache_check_dimensions (priv->page_cache)) {
return;
}
priv->document = document;
- priv->n_pages = ev_page_cache_get_n_pages (priv->page_cache);
+ priv->n_pages = ev_document_get_n_pages (document);
priv->loading_icons = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify)g_free,
{
GtkWindow *window = GTK_WINDOW (window_title->window);
char *title = NULL, *password_title, *p;
- EvPageCache *page_cache;
if (window_title->document != NULL) {
- char *doc_title;
+ gchar *doc_title;
- page_cache = ev_page_cache_get (window_title->document);
- g_return_if_fail (page_cache != NULL);
- doc_title = (char *)ev_page_cache_get_title (page_cache);
+ doc_title = g_strdup (ev_document_get_title (window_title->document));
/* Make sure we get a valid title back */
if (doc_title != NULL) {
g_utf8_validate (doc_title, -1, NULL)) {
title = g_strdup (doc_title);
}
+
+ g_free (doc_title);
}
}
if (document) {
has_document = TRUE;
- info = ev_page_cache_get_info (ev_window->priv->page_cache);
+ info = ev_document_get_info (document);
}
if (has_document && ev_window->priv->page_cache) {
- has_pages = ev_page_cache_get_n_pages (ev_window->priv->page_cache) > 0;
+ has_pages = ev_document_get_n_pages (document) > 0;
}
if (!info || info->fields_mask == 0) {
if (ev_window->priv->document && ev_window->priv->page_cache) {
page = ev_page_cache_get_current_page (ev_window->priv->page_cache);
- n_pages = ev_page_cache_get_n_pages (ev_window->priv->page_cache);
+ n_pages = ev_document_get_n_pages (ev_window->priv->document);
has_pages = n_pages > 0;
}
} else {
dest = ev_link_dest_new_page (page);
action = ev_link_action_new_dest (dest);
- page_label = ev_page_cache_get_page_label (window->priv->page_cache, page);
+ page_label = ev_document_get_page_label (window->priv->document, page);
}
if (!page_label)
gint n_pages;
gint new_page;
- n_pages = ev_page_cache_get_n_pages (window->priv->page_cache);
+ n_pages = ev_document_get_n_pages (window->priv->document);
new_page = CLAMP (g_value_get_int (&page), 0, n_pages - 1);
ev_page_cache_set_current_page (window->priv->page_cache,
new_page);
if (ev_metadata_manager_get (uri, "window_width_ratio", &width_ratio, FALSE) &&
ev_metadata_manager_get (uri, "window_height_ratio", &height_ratio, FALSE)) {
- gint document_width;
- gint document_height;
+ gdouble document_width;
+ gdouble document_height;
GdkScreen *screen;
gint request_width;
gint request_height;
- ev_page_cache_get_max_width (window->priv->page_cache,
- 0, 1.0,
- &document_width);
- ev_page_cache_get_max_height (window->priv->page_cache,
- 0, 1.0,
- &document_height);
-
- request_width = g_value_get_double (&width_ratio) * document_width;
- request_height = g_value_get_double (&height_ratio) * document_height;
+ ev_document_get_max_page_size (window->priv->document,
+ &document_width, &document_height);
+
+ request_width = (gint)(g_value_get_double (&width_ratio) * document_width + 0.5);
+ request_height = (gint)(g_value_get_double (&height_ratio) * document_height + 0.5);
screen = gtk_window_get_screen (GTK_WINDOW (window));
static void
ev_window_refresh_window_thumbnail (EvWindow *ev_window, int rotation)
{
- gint page_width, page_height;
+ gdouble page_width;
gdouble scale;
EvDocument *document = ev_window->priv->document;
-
+
if (!EV_IS_DOCUMENT_THUMBNAILS (document) ||
- ev_page_cache_get_n_pages (ev_window->priv->page_cache) <= 0 ||
- ev_page_cache_check_dimensions (ev_window->priv->page_cache)) {
+ ev_document_get_n_pages (document) <= 0 ||
+ !ev_page_cache_check_dimensions (ev_window->priv->page_cache)) {
return;
}
-
+
ev_window_clear_thumbnail_job (ev_window);
-
- ev_page_cache_get_size (ev_window->priv->page_cache,
- 0, 0, 1.0,
- &page_width, &page_height);
- scale = (gdouble)128 / (gdouble)page_width;
-
+
+ ev_document_get_page_size (document, 0, &page_width, NULL);
+ scale = 128. / page_width;
+
ev_window->priv->thumbnail_job = ev_job_thumbnail_new (document, 0, rotation, scale);
g_signal_connect (ev_window->priv->thumbnail_job, "finished",
G_CALLBACK (ev_window_set_icon_from_thumbnail),
ev_window->priv->document);
}
- info = ev_page_cache_get_info (ev_window->priv->page_cache);
+ info = ev_document_get_info (document);
update_document_mode (ev_window, info->mode);
gtk_widget_grab_focus (ev_window->priv->view);
/* Restart the current page */
page = CLAMP (ev_link_dest_get_page (ev_window->priv->dest),
0,
- ev_page_cache_get_n_pages (ev_window->priv->page_cache) - 1);
+ ev_document_get_n_pages (ev_window->priv->document) - 1);
ev_page_cache_set_current_page (ev_window->priv->page_cache, page);
g_object_unref (ev_window->priv->dest);
ev_window->priv->dest = NULL;
}
- if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) <= 0) {
+ if (ev_document_get_n_pages (ev_window->priv->document) <= 0) {
ev_window_warning_message (ev_window, "%s",
_("The document contains no pages"));
- } else if (ev_page_cache_check_dimensions (ev_window->priv->page_cache)) {
+ } else if (!ev_page_cache_check_dimensions (ev_window->priv->page_cache)) {
ev_window_warning_message (ev_window, "%s",
_("The document contains only empty pages"));
} else {
page_cache = ev_page_cache_get (ev_window->priv->document);
current_page = ev_page_cache_get_current_page (page_cache);
- document_last_page = ev_page_cache_get_n_pages (page_cache);
+ document_last_page = ev_document_get_n_pages (ev_window->priv->document);
if (!ev_window->priv->print_settings) {
ev_window->priv->print_settings = gtk_print_settings_copy (
static void
ev_window_print (EvWindow *window)
{
- EvPageCache *page_cache;
- gint last_page;
-
- page_cache = ev_page_cache_get (window->priv->document);
- last_page = ev_page_cache_get_n_pages (page_cache);
-
- ev_window_print_range (window, 1, last_page);
+ ev_window_print_range (window, 1,
+ ev_document_get_n_pages (window->priv->document));
}
static void
static void
ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
{
- int n_pages;
-
g_return_if_fail (EV_IS_WINDOW (ev_window));
- n_pages = ev_page_cache_get_n_pages (ev_window->priv->page_cache);
- ev_page_cache_set_current_page (ev_window->priv->page_cache, n_pages - 1);
+ ev_page_cache_set_current_page (ev_window->priv->page_cache,
+ ev_document_get_n_pages (ev_window->priv->document) - 1);
}
static void
g_return_if_fail (EV_IS_WINDOW (ev_window));
- n_pages = ev_page_cache_get_n_pages (ev_window->priv->page_cache);
+ n_pages = ev_document_get_n_pages (ev_window->priv->document);
current_page = ev_page_cache_get_current_page (ev_window->priv->page_cache);
if (current_page + 10 < n_pages)
if (search_string && search_string[0]) {
ev_window->priv->find_job = ev_job_find_new (ev_window->priv->document,
ev_page_cache_get_current_page (ev_window->priv->page_cache),
- ev_page_cache_get_n_pages (ev_window->priv->page_cache),
+ ev_document_get_n_pages (ev_window->priv->document),
search_string,
case_sensitive);
g_signal_connect (ev_window->priv->find_job, "finished",
{
char *uri = window->priv->uri;
GdkWindowState state;
- int x, y, width, height, document_width, document_height;
+ gdouble document_width, document_height;
state = gdk_window_get_state (GTK_WIDGET (window)->window);
if (!(state & GDK_WINDOW_STATE_FULLSCREEN)) {
- gtk_window_get_position (GTK_WINDOW (window), &x, &y);
- gtk_window_get_size (GTK_WINDOW (window), &width, &height);
-
- if (!ev_window_is_empty (window) && window->priv->page_cache) {
- ev_page_cache_get_max_width (window->priv->page_cache,
- 0, 1.0,
- &document_width);
- ev_page_cache_get_max_height (window->priv->page_cache,
- 0, 1.0,
- &document_height);
- ev_metadata_manager_set_double (uri, "window_width_ratio",
- (double)width / document_width);
- ev_metadata_manager_set_double (uri, "window_height_ratio",
- (double)height / document_height);
-
- ev_metadata_manager_set_int (uri, "window_x", x);
- ev_metadata_manager_set_int (uri, "window_y", y);
- ev_metadata_manager_set_int (uri, "window_width", width);
- ev_metadata_manager_set_int (uri, "window_height", height);
+ if (!ev_window_is_empty (window) && window->priv->document) {
+ ev_document_get_max_page_size (window->priv->document,
+ &document_width, &document_height);
+ ev_metadata_manager_set_double (uri, "window_width_ratio",
+ (double)event->width / document_width);
+ ev_metadata_manager_set_double (uri, "window_height_ratio",
+ (double)event->height / document_height);
+
+ ev_metadata_manager_set_int (uri, "window_x", event->x);
+ ev_metadata_manager_set_int (uri, "window_y", event->y);
+ ev_metadata_manager_set_int (uri, "window_width", event->width);
+ ev_metadata_manager_set_int (uri, "window_height", event->height);
}
}
page = ev_document_get_page (document, 0);
- ev_document_get_page_size (document, page, &width, &height);
+ ev_document_get_page_size (document, 0, &width, &height);
rc = ev_render_context_new (page, 0, size / width);
pixbuf = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (document),