]> www.fi.muni.cz Git - evince.git/commitdiff
Make the page cache aware of page orientation.
authorMarco Pesenti Gritti <mpg@redhat.com>
Fri, 29 Jul 2005 15:05:35 +0000 (15:05 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Fri, 29 Jul 2005 15:05:35 +0000 (15:05 +0000)
2005-07-29  Marco Pesenti Gritti  <mpg@redhat.com>

        * shell/ev-page-cache.c: (build_height_to_page),
        (ev_page_cache_new), (ev_page_cache_get_size),
        (ev_page_cache_get_max_width), (ev_page_cache_get_max_height),
        (ev_page_cache_get_height_to_page):
        * shell/ev-page-cache.h:
        * shell/ev-view.c: (get_page_y_offset), (get_page_extents),
        (ev_view_size_request_continuous_dual_page),
        (ev_view_size_request_continuous),
        (ev_view_zoom_for_size_continuous_and_dual_page),
        (ev_view_zoom_for_size_continuous):

        Make the page cache aware of page orientation.

ChangeLog
shell/ev-page-cache.c
shell/ev-page-cache.h
shell/ev-view.c

index b6d26dccca32c21438ced49d8dc9b786eae2da69..fde394956d639323127689638a38b5f89a15343f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2005-07-29  Marco Pesenti Gritti  <mpg@redhat.com>
+
+       * shell/ev-page-cache.c: (build_height_to_page),
+       (ev_page_cache_new), (ev_page_cache_get_size),
+       (ev_page_cache_get_max_width), (ev_page_cache_get_max_height),
+       (ev_page_cache_get_height_to_page):
+       * shell/ev-page-cache.h:
+       * shell/ev-view.c: (get_page_y_offset), (get_page_extents),
+       (ev_view_size_request_continuous_dual_page),
+       (ev_view_size_request_continuous),
+       (ev_view_zoom_for_size_continuous_and_dual_page),
+       (ev_view_zoom_for_size_continuous):
+
+       Make the page cache aware of page orientation.
+
 2005-07-29  Marco Pesenti Gritti  <mpg@redhat.com>
 
        * backend/ev-document-thumbnails.c:
index 41acecfc30bd0be36c9f8c13c1d55cc17c749477..1b0f8e4604adc130f952c3e5f94b8ef8fed3ba42 100644 (file)
@@ -29,9 +29,12 @@ struct _EvPageCache
 
        double  max_width;
        double  max_height;
+
        double* height_to_page;
        double* dual_height_to_page;
 
+       EvOrientation orientation;
+
        EvPageCacheInfo *size_cache;
        EvDocumentInfo *page_info;
 };
@@ -100,13 +103,79 @@ ev_page_cache_finalize (GObject *object)
        ev_document_info_free (page_cache->page_info);
 }
 
+static void
+build_height_to_page (EvPageCache *page_cache)
+{
+       gboolean swap;
+       int i;
+       double uniform_height, page_height, next_page_height;
+       double saved_height;
+
+       swap = (page_cache->orientation == EV_ORIENTATION_LANDSCAPE ||
+               page_cache->orientation == EV_ORIENTATION_SEASCAPE);
+
+       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);
+       page_cache->dual_height_to_page = g_new0(double, page_cache->n_pages / 2 + 1);
+       
+       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 + 1) * uniform_height;
+               } else {
+                       if (swap) {
+                               page_height = page_cache->size_cache [i].height;
+                       } else {
+                               page_height = page_cache->size_cache [i].width;
+                       }
+                       page_cache->height_to_page [i] = saved_height + page_height;
+                       saved_height = page_cache->height_to_page [i];
+               }
+       }
+       
+       saved_height = 0;
+       for (i = 0; i < page_cache->n_pages; 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 / 2] = (i / 2 + 1) * uniform_height;
+               } else {
+                       if (!swap) {
+                               page_height = page_cache->size_cache [i].height;
+                               next_page_height = page_cache->size_cache [i + 1].height;
+                       } else {
+                               page_height = page_cache->size_cache [i].width;
+                               next_page_height = page_cache->size_cache [i + 1].width;
+                       }
+                       if (i == page_cache->n_pages - 1) {
+                               page_cache->dual_height_to_page [i / 2] =
+                                       saved_height + page_height;
+                       }
+                       else {
+                               page_cache->dual_height_to_page [i / 2] = saved_height +
+                                      MAX(page_height, next_page_height);                                  
+                               saved_height = page_cache->dual_height_to_page [i / 2];
+                       }
+               }
+       }
+}
+
 EvPageCache *
 ev_page_cache_new (EvDocument *document)
 {
        EvPageCache *page_cache;
        EvPageCacheInfo *info;
        gint i;
-       double saved_height;
 
        page_cache = (EvPageCache *) g_object_new (EV_TYPE_PAGE_CACHE, NULL);
 
@@ -117,6 +186,7 @@ ev_page_cache_new (EvDocument *document)
        /* Assume all pages are the same size until proven otherwise */
        page_cache->uniform = TRUE;
        page_cache->has_labels = FALSE;
+       page_cache->orientation = ev_document_get_orientation (document);
        page_cache->n_pages = ev_document_get_n_pages (document);
        page_cache->page_labels = g_new0 (char *, page_cache->n_pages);
        page_cache->max_width = 0;
@@ -187,38 +257,7 @@ ev_page_cache_new (EvDocument *document)
                }
        }
 
-       page_cache->height_to_page = g_new0(double, page_cache->n_pages);
-       page_cache->dual_height_to_page = g_new0(double, page_cache->n_pages / 2 + 1);
-       
-       saved_height = 0;
-       for (i = 0; i < page_cache->n_pages; i++) {
-
-               if (page_cache->uniform) {
-                       page_cache->height_to_page [i] = (i + 1) * page_cache->uniform_height;
-               } else {
-                       page_cache->height_to_page [i] = saved_height + page_cache->size_cache [i].height;
-                       saved_height = page_cache->height_to_page [i];
-               }
-       }
-       
-       saved_height = 0;
-       for (i = 0; i < page_cache->n_pages; i += 2) {
-
-               if (page_cache->uniform) {
-                       page_cache->dual_height_to_page [i / 2] = (i / 2 + 1) * page_cache->uniform_height;
-               } else {
-                       if (i == page_cache->n_pages - 1) {
-                               page_cache->dual_height_to_page [i / 2] =
-                                       saved_height + page_cache->size_cache [i].height;
-                       }
-                       else {
-                               page_cache->dual_height_to_page [i / 2] = saved_height +
-                                      MAX(page_cache->size_cache [i].height,                               
-                                          page_cache->size_cache [i + 1].height);
-                               saved_height = page_cache->dual_height_to_page [i / 2];
-                       }
-               }
-       }
+       build_height_to_page (page_cache);
 
        /* make some sanity check assertions */
        if (! page_cache->uniform)
@@ -348,48 +387,74 @@ ev_page_cache_get_size (EvPageCache  *page_cache,
                        *height = info->height;
        }
 
-       if (width)
-               *width = (int) ((*width) * scale + 0.5);
-       if (width)
-               *height = (int) ((*height) * scale + 0.5);
-
+       if (orientation == EV_ORIENTATION_PORTRAIT ||
+           orientation == EV_ORIENTATION_UPSIDEDOWN) {
+               if (width)
+                       *width = (int) ((*width) * scale + 0.5);
+               if (height)
+                       *height = (int) ((*height) * scale + 0.5);
+       } else {
+               if (width)
+                       *width = (int) ((*height) * scale + 0.5);
+               if (height)
+                       *height = (int) ((*width) * scale + 0.5);
+       }
 }
 
-
 void
-ev_page_cache_get_max_width      (EvPageCache *page_cache,
-                                 gfloat       scale,
-                                 gint        *width)
+ev_page_cache_get_max_width (EvPageCache   *page_cache,
+                            EvOrientation  orientation,
+                            gfloat         scale,
+                            gint          *width)
 {
        g_return_if_fail (EV_IS_PAGE_CACHE (page_cache));
 
-       if (width)
-               *width = page_cache->max_width * scale;
+       if (width) {
+               if (orientation == EV_ORIENTATION_PORTRAIT ||
+                   orientation == EV_ORIENTATION_UPSIDEDOWN) {
+                       *width = page_cache->max_width * scale;
+               } else {
+                       *width = page_cache->max_height * scale;
+               }
+       }
 }
 
 void
-ev_page_cache_get_max_height      (EvPageCache *page_cache,
-                                  gfloat       scale,
-                                  gint        *height)
+ev_page_cache_get_max_height (EvPageCache   *page_cache,
+                             EvOrientation  orientation,
+                             gfloat         scale,
+                             gint          *height)
 {
        g_return_if_fail (EV_IS_PAGE_CACHE (page_cache));
 
-       if (height)
-               *height = page_cache->max_height * scale;
+       if (height) {
+               if (orientation == EV_ORIENTATION_PORTRAIT ||
+                   orientation == EV_ORIENTATION_UPSIDEDOWN) {
+                       *height = page_cache->max_height * scale;
+               } else {
+                       *height = page_cache->max_width * scale;
+               }
+       }
 }
 
 void    
-ev_page_cache_get_height_to_page (EvPageCache *page_cache,
-                                 gint page,
-                                 gfloat       scale,
-                                 gint        *height,
-                                 gint        *dual_height)
+ev_page_cache_get_height_to_page (EvPageCache   *page_cache,
+                                 gint           page,
+                                 EvOrientation  orientation,
+                                 gfloat         scale,
+                                 gint          *height,
+                                 gint          *dual_height)
 {
        double result = 0.0;
        double dual_result = 0.0;
        
        g_return_if_fail (EV_IS_PAGE_CACHE (page_cache));
 
+       if (page_cache->orientation != orientation) {
+               page_cache->orientation = orientation;
+               build_height_to_page (page_cache);
+       }
+
        if (page > 0)
                result = page_cache->height_to_page [page - 1]; 
        
index af8532e4aa83a87a3c575c64fac0c5fdb7f5a98d..3360d821c5626c496f1fae3428834d5434529e76 100644 (file)
@@ -31,23 +31,26 @@ 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,
-                                                 EvOrientation orientation,
-                                                 gfloat        scale,
-                                                 gint         *width,
-                                                 gint         *height);
-void           ev_page_cache_get_max_width      (EvPageCache   *page_cache,
-                                                 gfloat        scale,
-                                                 gint         *width);
-void           ev_page_cache_get_max_height      (EvPageCache  *page_cache,
-                                                 gfloat        scale,
-                                                 gint         *height);
+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,
+                                                 EvOrientation  orientation,
+                                                 gfloat         scale,
+                                                 gint          *width,
+                                                 gint          *height);
+void           ev_page_cache_get_max_width       (EvPageCache   *page_cache,
+                                                 EvOrientation  orientation,
+                                                 gfloat         scale,
+                                                 gint          *width);
+void           ev_page_cache_get_max_height      (EvPageCache   *page_cache,
+                                                 EvOrientation  orientation,
+                                                 gfloat         scale,
+                                                 gint          *height);
 void           ev_page_cache_get_height_to_page  (EvPageCache   *page_cache,
-                                                                gint page,
+                                                 gint           page,
+                                                 EvOrientation  orientation,
                                                  gfloat         scale,
                                                  gint          *height,
                                                  gint          *dual_height);
index 3d24c5028a95101f5d558b0f17318fc2c9fcf2c4..09539990f65a072191bc2455a5b780de1dddb63a 100644 (file)
@@ -749,25 +749,25 @@ compute_border (EvView *view, int width, int height, GtkBorder *border)
        }
 }
 
-static void       get_page_y_offset                          (EvView *view,
-                                                             int page,
-                                                             double zoom,
-                                                             int *y_offset)
+static void
+get_page_y_offset (EvView *view, int page, double zoom, int *y_offset)
 {
        int max_width, offset;
        GtkBorder border;
 
        g_return_if_fail (y_offset != NULL);
 
-       ev_page_cache_get_max_width (view->page_cache, zoom, &max_width);
+       ev_page_cache_get_max_width (view->page_cache, view->orientation, zoom, &max_width);
 
        compute_border (view, max_width, max_width, &border);
 
        if (view->dual_page) {
-               ev_page_cache_get_height_to_page (view->page_cache, page, zoom, NULL, &offset);
+               ev_page_cache_get_height_to_page (view->page_cache, page,
+                                                 view->orientation, zoom, NULL, &offset);
                offset += (page / 2 + 1) * view->spacing + (page / 2) * (border.top + border.bottom);
        } else {
-               ev_page_cache_get_height_to_page (view->page_cache, page, zoom, &offset, NULL);
+               ev_page_cache_get_height_to_page (view->page_cache, page,
+                                                 view->orientation, zoom, &offset, NULL);
                offset += (page + 1) * view->spacing + page * (border.top + border.bottom);
        }
 
@@ -802,7 +802,8 @@ get_page_extents (EvView       *view,
                gint max_width;
                gint x, y;
 
-               ev_page_cache_get_max_width (view->page_cache, view->scale, &max_width);
+               ev_page_cache_get_max_width (view->page_cache, view->scale,
+                                            view->orientation, &max_width);
                max_width = max_width + border->left + border->right;
                /* Get the location of the bounding box */
                if (view->dual_page) {
@@ -1066,7 +1067,8 @@ ev_view_size_request_continuous_dual_page (EvView         *view,
        gint n_pages;
        GtkBorder border;
 
-       ev_page_cache_get_max_width (view->page_cache, view->scale, &max_width);
+       ev_page_cache_get_max_width (view->page_cache, view->orientation,
+                                    view->scale, &max_width);
        compute_border (view, max_width, max_width, &border);
 
        n_pages = ev_page_cache_get_n_pages (view->page_cache) + 1;
@@ -1093,7 +1095,8 @@ ev_view_size_request_continuous (EvView         *view,
        GtkBorder border;
 
 
-       ev_page_cache_get_max_width (view->page_cache, view->scale, &max_width);
+       ev_page_cache_get_max_width (view->page_cache, view->orientation,
+                                    view->scale, &max_width);
        n_pages = ev_page_cache_get_n_pages (view->page_cache);
        compute_border (view, max_width, max_width, &border);
 
@@ -2410,9 +2413,11 @@ ev_view_zoom_for_size_continuous_and_dual_page (EvView *view,
        gdouble scale;
 
        ev_page_cache_get_max_width (view->page_cache,
+                                    view->orientation,
                                     1.0,
                                     &doc_width);
        ev_page_cache_get_max_height (view->page_cache,
+                                     view->orientation,
                                      1.0,
                                      &doc_height);
        compute_border (view, doc_width, doc_height, &border);
@@ -2446,9 +2451,11 @@ ev_view_zoom_for_size_continuous (EvView *view,
        gdouble scale;
 
        ev_page_cache_get_max_width (view->page_cache,
+                                    view->orientation,
                                     1.0,
                                     &doc_width);
        ev_page_cache_get_max_height (view->page_cache,
+                                     view->orientation,
                                      1.0,
                                      &doc_height);
        compute_border (view, doc_width, doc_height, &border);