]> www.fi.muni.cz Git - evince.git/commitdiff
Move part of the EvPageCache to EvDocument
authorCarlos Garcia Campos <carlosgc@gnome.org>
Wed, 19 Aug 2009 13:29:40 +0000 (15:29 +0200)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Tue, 15 Sep 2009 13:56:01 +0000 (15:56 +0200)
The static data about the document is stored now in EvDocument class

17 files changed:
backend/pdf/ev-poppler.cc
libdocument/ev-document.c
libdocument/ev-document.h
libmisc/ev-page-action-widget.c
libmisc/ev-page-action-widget.h
libmisc/ev-page-action.c
libview/ev-page-cache.c
libview/ev-page-cache.h
libview/ev-pixbuf-cache.c
libview/ev-view.c
shell/ev-print-operation.c
shell/ev-properties-dialog.c
shell/ev-sidebar-links.c
shell/ev-sidebar-thumbnails.c
shell/ev-window-title.c
shell/ev-window.c
thumbnailer/evince-thumbnailer.c

index 84314ce9b65f3098733696ffd0164a1564f49e1d..93064456aede70e507db2309163f1793144e8cba 100644 (file)
@@ -588,13 +588,9 @@ pdf_document_get_info (EvDocument *document)
        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;
index 9d2e259e41f71ee951727209f485620e38f7a973..a74a0e397c79f9932089a2964b16838204cd3605 100644 (file)
 
 #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;
 
@@ -51,16 +88,54 @@ ev_document_impl_get_info (EvDocument *document)
        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 *
@@ -157,6 +232,81 @@ ev_document_load (EvDocument  *document,
                                             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;
@@ -182,50 +332,87 @@ ev_document_save (EvDocument  *document,
        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 *
@@ -237,6 +424,87 @@ ev_document_render (EvDocument      *document,
        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)
 
index 74bd3bb7ebb0268bd652aff046e62ed1463c1742..2ce1cf18905baee1669a4da225fcc6b0b8df471c 100644 (file)
@@ -47,6 +47,8 @@ G_BEGIN_DECLS
 
 typedef struct _EvDocument        EvDocument;
 typedef struct _EvDocumentClass   EvDocumentClass;
+typedef struct _EvDocumentPrivate EvDocumentPrivate;
+
 typedef struct _EvPageCache       EvPageCache;
 typedef struct _EvPageCacheClass  EvPageCacheClass;
 
@@ -70,6 +72,8 @@ typedef struct _EvRectangle EvRectangle;
 struct _EvDocument
 {
        GObject base;
+
+       EvDocumentPrivate *priv;
 };
 
 struct _EvDocumentClass
@@ -97,42 +101,52 @@ 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
index c24c75658c886e35d83ba5f1c717ea48e4349683..249775cb8fb6d602b5664cd544d86d6848637f32 100644 (file)
@@ -42,9 +42,11 @@ struct _EvPageActionWidget
 {
        GtkToolItem parent;
 
+       EvDocument *document;
+       EvPageCache *page_cache;
+
        GtkWidget *entry;
        GtkWidget *label;
-       EvPageCache *page_cache;
        guint signal_id;
        GtkTreeModel *filter_model;
        GtkTreeModel *model;
@@ -56,14 +58,13 @@ G_DEFINE_TYPE (EvPageActionWidget, ev_page_action_widget, GTK_TYPE_TOOL_ITEM)
 
 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);
@@ -77,14 +78,14 @@ page_changed_cb (EvPageCache        *page_cache,
                 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);
@@ -93,7 +94,7 @@ page_changed_cb (EvPageCache        *page_cache,
                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
@@ -104,7 +105,7 @@ page_scroll_cb (EvPageActionWidget *action_widget, GdkEventScroll *event)
 
        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--;
@@ -139,8 +140,8 @@ activate_cb (EvPageActionWidget *action_widget)
        /* 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);
@@ -159,6 +160,7 @@ ev_page_action_widget_init (EvPageActionWidget *action_widget)
        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);
@@ -186,9 +188,16 @@ ev_page_action_widget_init (EvPageActionWidget *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,
@@ -200,21 +209,16 @@ ev_page_action_widget_set_page_cache (EvPageActionWidget *action_widget,
                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
@@ -233,6 +237,11 @@ ev_page_action_widget_finalize (GObject *object)
                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);
 }
 
index 066cf5c3af4826b8edcf988e697d6fab3db0b56e..1c9ee35db1c0643eb8d917bda6a505114ffa19e8 100644 (file)
@@ -41,6 +41,6 @@ GType ev_page_action_widget_get_type      (void) G_GNUC_CONST;
 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);
index ced16663ffddedabb046aa79d57e2670798bd819..090712e2537f84b72f02a8d23d07ed27684b20dc 100644 (file)
@@ -33,7 +33,7 @@
 
 struct _EvPageActionPrivate
 {
-       EvPageCache *page_cache;
+       EvDocument *document;
        GtkTreeModel *model;
 };
 
@@ -55,7 +55,7 @@ G_DEFINE_TYPE (EvPageAction, ev_page_action, GTK_TYPE_ACTION)
 
 enum {
        PROP_0,
-       PROP_PAGE_CACHE,
+       PROP_DOCUMENT,
        PROP_MODEL,
 };
 
@@ -70,9 +70,10 @@ create_tool_item (GtkAction *action)
 }
 
 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
@@ -97,14 +98,12 @@ 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);
@@ -118,9 +117,9 @@ ev_page_action_dispose (GObject *object)
 {
        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);
@@ -133,18 +132,18 @@ ev_page_action_set_property (GObject      *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;
@@ -165,13 +164,13 @@ ev_page_action_get_property (GObject    *object,
                             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);
@@ -185,13 +184,8 @@ ev_page_action_get_property (GObject    *object,
 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);
 }
@@ -251,11 +245,11 @@ ev_page_action_class_init (EvPageActionClass *class)
                                               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,
index c3bb60c1504e5c79f6b9e11c1b8ea45a4c8eed17..9d271a042fc6e3019066661f475d7cf46a4f977f 100644 (file)
@@ -7,12 +7,6 @@
 
 #define THUMBNAIL_WIDTH 100
 
-typedef struct _EvPageCacheInfo
-{
-       double width;
-       double height;
-} EvPageCacheInfo;
-
 typedef struct _EvPageThumbsInfo
 {
        gint width;
@@ -23,30 +17,17 @@ struct _EvPageCache
 {
        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;
@@ -83,7 +64,6 @@ static void
 ev_page_cache_init (EvPageCache *page_cache)
 {
        page_cache->current_page = -1;
-       page_cache->max_label_chars = 0;
 }
 
 static void
@@ -120,19 +100,9 @@ ev_page_cache_class_init (EvPageCacheClass *class)
 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);
@@ -149,216 +119,132 @@ ev_page_cache_finalize (GObject *object)
                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);
@@ -369,7 +255,7 @@ ev_page_cache_new (EvDocument *document)
 
                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;
                }
@@ -377,7 +263,7 @@ ev_page_cache_new (EvDocument *document)
                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;
@@ -387,10 +273,10 @@ ev_page_cache_new (EvDocument *document)
                        /* 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;
                        }
@@ -398,7 +284,7 @@ ev_page_cache_new (EvDocument *document)
                }
 
                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;
@@ -411,15 +297,7 @@ ev_page_cache_new (EvDocument *document)
                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;
@@ -428,31 +306,12 @@ ev_page_cache_new (EvDocument *document)
 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
@@ -468,7 +327,6 @@ ev_page_cache_set_current_page (EvPageCache *page_cache,
                                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;
@@ -489,59 +347,20 @@ ev_page_cache_set_current_page_history (EvPageCache *page_cache,
 
 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,
@@ -553,19 +372,8 @@ ev_page_cache_get_size (EvPageCache  *page_cache,
        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;
@@ -585,15 +393,15 @@ ev_page_cache_get_max_width (EvPageCache   *page_cache,
                             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
@@ -602,18 +410,18 @@ ev_page_cache_get_max_height (EvPageCache   *page_cache,
                              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,
@@ -623,19 +431,17 @@ ev_page_cache_get_height_to_page (EvPageCache   *page_cache,
 {
        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
@@ -648,7 +454,6 @@ ev_page_cache_get_thumbnail_size (EvPageCache  *page_cache,
        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;
@@ -671,48 +476,12 @@ ev_page_cache_get_thumbnail_size (EvPageCache  *page_cache,
        }
 }
 
-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"
index 03e43d77b393e871ae14d15986e9e123f4b7c6c1..96e8c43b873eda68bb7fbae68b6ef9e11d398960 100644 (file)
@@ -35,10 +35,6 @@ G_BEGIN_DECLS
 
 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,
@@ -64,12 +60,6 @@ void           ev_page_cache_get_thumbnail_size  (EvPageCache   *page_cache,
                                                  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 */
@@ -79,7 +69,7 @@ void           ev_page_cache_set_current_page    (EvPageCache *page_cache,
 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);
 
index 41ccadcef8ee415d5d78d3e0c5ee27f9d6866f4d..763ec047365d271698b62bc13ddeb325ce2d2779 100644 (file)
@@ -97,8 +97,8 @@ static gboolean      new_selection_surface_needed(EvPixbufCache      *pixbuf_cac
 /* 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)
 
@@ -392,15 +392,12 @@ ev_pixbuf_cache_update_range (EvPixbufCache *pixbuf_cache,
        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);
@@ -432,7 +429,7 @@ ev_pixbuf_cache_update_range (EvPixbufCache *pixbuf_cache,
        }
 
        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,
@@ -620,7 +617,6 @@ get_selection_colors (GtkWidget *widget, GdkColor **text, GdkColor **base)
 static void
 add_job (EvPixbufCache *pixbuf_cache,
         CacheJobInfo  *job_info,
-        EvPageCache   *page_cache,
         GdkRegion     *region,
         gint           width,
         gint           height,
@@ -696,7 +692,7 @@ add_job_if_needed (EvPixbufCache *pixbuf_cache,
            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);
 }
@@ -731,7 +727,7 @@ ev_pixbuf_cache_add_jobs_if_needed (EvPixbufCache *pixbuf_cache,
                                   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;
 
@@ -750,14 +746,10 @@ ev_pixbuf_cache_set_page_range (EvPixbufCache  *pixbuf_cache,
                                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
@@ -1113,7 +1105,6 @@ void
 ev_pixbuf_cache_set_selection_list (EvPixbufCache *pixbuf_cache,
                                    GList         *selection_list)
 {
-       EvPageCache *page_cache;
        EvViewSelection *selection;
        GList *list = selection_list;
        int page;
@@ -1124,8 +1115,6 @@ ev_pixbuf_cache_set_selection_list (EvPixbufCache *pixbuf_cache,
        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++) {
@@ -1171,7 +1160,7 @@ ev_pixbuf_cache_set_selection_list (EvPixbufCache *pixbuf_cache,
        }
 
        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;
@@ -1198,7 +1187,6 @@ ev_pixbuf_cache_set_selection_list (EvPixbufCache *pixbuf_cache,
 GList *
 ev_pixbuf_cache_get_selection_list (EvPixbufCache *pixbuf_cache)
 {
-       EvPageCache *page_cache;
        EvViewSelection *selection;
        GList *retval = NULL;
        int page;
@@ -1206,8 +1194,6 @@ ev_pixbuf_cache_get_selection_list (EvPixbufCache *pixbuf_cache)
 
        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++) {
@@ -1243,7 +1229,7 @@ ev_pixbuf_cache_get_selection_list (EvPixbufCache *pixbuf_cache)
        }
 
        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) {
@@ -1261,7 +1247,7 @@ ev_pixbuf_cache_get_selection_list (EvPixbufCache *pixbuf_cache)
        return retval;
 }
 
-void           
+void
 ev_pixbuf_cache_reload_page (EvPixbufCache *pixbuf_cache,
                             GdkRegion     *region,
                             gint           page,
@@ -1269,18 +1255,17 @@ ev_pixbuf_cache_reload_page (EvPixbufCache *pixbuf_cache,
                             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);
 }
index e1c84037e2209902e708ce14e4bee609cfc4e6be..eb3156fa5080cc496002637f8d90a9106637f5a9 100644 (file)
@@ -460,7 +460,7 @@ view_update_range_and_current_page (EvView *view)
                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);
 
@@ -487,7 +487,7 @@ view_update_range_and_current_page (EvView *view)
        } 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;
@@ -630,7 +630,7 @@ ev_view_scroll (EvView        *view,
        /* 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) {
@@ -818,7 +818,7 @@ get_page_extents (EvView       *view,
                        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,
@@ -1325,7 +1325,7 @@ goto_dest (EvView *view, EvLinkDest *dest)
        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;
@@ -1438,8 +1438,8 @@ ev_view_page_label_from_dest (EvView *view, EvLinkDest *dest)
                        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);
                        }
                }
@@ -1450,8 +1450,8 @@ ev_view_page_label_from_dest (EvView *view, EvLinkDest *dest)
                }
                        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;
@@ -2442,7 +2442,7 @@ ev_view_size_request_continuous_dual_page (EvView         *view,
                                     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);
@@ -2468,7 +2468,7 @@ ev_view_size_request_continuous (EvView         *view,
 
        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;
@@ -2497,7 +2497,7 @@ ev_view_size_request_dual_page (EvView         *view,
                                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,
@@ -3667,8 +3667,7 @@ ev_view_goto_entry_activate (GtkEntry *entry,
        
        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);
 }
 
@@ -3827,7 +3826,7 @@ ev_view_key_press_event (GtkWidget   *widget,
        }
 
        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;
                        
@@ -5405,7 +5404,7 @@ ev_view_zoom_for_size_dual_page (EvView *view,
                                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,
@@ -5541,7 +5540,7 @@ jump_to_find_page (EvView *view, EvViewFindDirection direction, gint shift)
 {
        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;
@@ -5653,7 +5652,7 @@ compute_new_selection_rect (EvView       *view,
        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;
@@ -5702,7 +5701,7 @@ compute_new_selection_text (EvView          *view,
 
        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. */
@@ -5955,7 +5954,7 @@ ev_view_select_all (EvView *view)
 
        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;
@@ -6245,7 +6244,7 @@ ev_view_next_page (EvView *view)
        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; 
index a6f8d53aecfeb818d9ac1ed0ea11cd0a6f0fcd99..fe5ef54003743eb60f0e1320f4e573b9db922d8f 100644 (file)
@@ -1428,7 +1428,7 @@ ev_print_operation_export_constructor (GType                  type,
                                                                                       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;
 }
@@ -1589,7 +1589,7 @@ ev_print_operation_print_begin_print (EvPrintOperationPrint *print,
        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);
 
@@ -1650,7 +1650,7 @@ ev_print_operation_print_draw_page (EvPrintOperationPrint *print,
        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);
 
@@ -1669,10 +1669,9 @@ ev_print_operation_print_draw_page (EvPrintOperationPrint *print,
        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);
index f48b96778c79f52233df525c2ac522dde7f86a28..0ca4661bad3209abd85104fa0ef8f1c2879ac829 100644 (file)
@@ -85,7 +85,7 @@ ev_properties_dialog_set_document (EvPropertiesDialog *properties,
 
        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"));
index 91986f8c0948d950ca6fe7331819fc2bc8f52bc6..8993e5f8309913809fda876a2d3c71b103152dca 100644 (file)
@@ -316,11 +316,11 @@ print_section_cb (GtkWidget *menuitem, EvSidebarLinks *sidebar)
                                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)) {
@@ -479,8 +479,8 @@ fill_page_labels (GtkTreeModel *tree_model,
        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);
index d86e6a553befb0ed62d4af8071f7161dc4acfed9..e43b008fccbc0aeeb5af9be739e8db1f45180621 100644 (file)
@@ -263,13 +263,11 @@ get_scale_for_page (EvSidebarThumbnails *sidebar_thumbnails,
                    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
@@ -417,7 +415,7 @@ ev_sidebar_thumbnails_fill_model (EvSidebarThumbnails *sidebar_thumbnails)
                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,
@@ -565,9 +563,8 @@ static gboolean
 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
@@ -655,8 +652,8 @@ thumbnail_job_completed_callback (EvJobThumbnail      *job,
 }
 
 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);
 
@@ -665,13 +662,13 @@ ev_sidebar_thumbnails_set_document (EvSidebarPage *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,
index baafa74f399278d607418375085c43efb0c1d0d0..2e28c63b002f8199e2f00bf4120abda268bd6c13 100644 (file)
@@ -122,14 +122,11 @@ ev_window_title_update (EvWindowTitle *window_title)
 {
        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) {
@@ -139,6 +136,8 @@ ev_window_title_update (EvWindowTitle *window_title)
                            g_utf8_validate (doc_title, -1, NULL)) {
                                title = g_strdup (doc_title);
                        }
+
+                       g_free (doc_title);
                }
        }
 
index 027ddb8d4f5358d2a09d6a36e9bf039179cc3a3f..133212299755afbff95e417d23c2ef41cc6d2b1d 100644 (file)
@@ -339,11 +339,11 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window)
 
        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) {
@@ -425,7 +425,7 @@ ev_window_update_actions (EvWindow *ev_window)
 
        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;
        }
 
@@ -802,7 +802,7 @@ ev_window_add_history (EvWindow *window, gint page, EvLink *link)
        } 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)
@@ -957,7 +957,7 @@ setup_document_from_metadata (EvWindow *window)
                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);
@@ -972,21 +972,17 @@ setup_document_from_metadata (EvWindow *window)
 
        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));
                
@@ -1156,23 +1152,21 @@ ev_window_set_icon_from_thumbnail (EvJobThumbnail *job,
 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),
@@ -1214,7 +1208,7 @@ ev_window_setup_document (EvWindow *ev_window)
                                                   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);
@@ -1245,16 +1239,16 @@ ev_window_set_document (EvWindow *ev_window, EvDocument *document)
                /* 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 {
@@ -3022,7 +3016,7 @@ ev_window_print_range (EvWindow *ev_window,
 
        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 (
@@ -3060,13 +3054,8 @@ ev_window_print_range (EvWindow *ev_window,
 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
@@ -3854,12 +3843,10 @@ ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
 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
@@ -3869,7 +3856,7 @@ ev_window_cmd_go_forward (GtkAction *action, EvWindow *ev_window)
        
         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)
@@ -4530,7 +4517,7 @@ find_bar_search_changed_cb (EggFindBar *find_bar,
        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",
@@ -5334,30 +5321,23 @@ window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer
 {
        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);
                }
        }
 
index 457ceeaa0c9f341658ea783cb15f1182b1da4beb..31486bf63be08af0cd20be49dde04139fcce093f 100644 (file)
@@ -84,7 +84,7 @@ evince_thumbnail_pngenc_get (EvDocument *document, const char *thumbnail, int si
 
        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),