]> www.fi.muni.cz Git - evince.git/commitdiff
Rework sizing to deal with documents with not uniform page size.
authorMarco Pesenti Gritti <mpg@redhat.com>
Fri, 15 Apr 2005 13:45:48 +0000 (13:45 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Fri, 15 Apr 2005 13:45:48 +0000 (13:45 +0000)
2005-04-15  Marco Pesenti Gritti <mpg@redhat.com>

        * shell/ev-view.c: (compute_zoom_factor), (ev_view_size_request),
        (page_changed_cb), (ev_view_zoom), (ev_view_zoom_in),
        (ev_view_zoom_out), (ev_view_set_size):

        Rework sizing to deal with documents with not uniform page
        size.

ChangeLog
shell/ev-view.c

index 26608b5158eb486919ac669c3b778e5221e7edf9..889371a77ddc9d7d9a413ff3de7fa948cd91a1a1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2005-04-15  Marco Pesenti Gritti <mpg@redhat.com>
+
+       * shell/ev-view.c: (compute_zoom_factor), (ev_view_size_request),
+       (page_changed_cb), (ev_view_zoom), (ev_view_zoom_in),
+       (ev_view_zoom_out), (ev_view_set_size):
+
+       Rework sizing to deal with documents with not uniform page
+       size.
+
 2005-04-15  Marco Pesenti Gritti <mpg@redhat.com>
 
        * backend/ev-page-cache.c: (_ev_page_cache_new):
index b615b6c4b0bc92ea6f4a4cbc9d5acbcf8956266b..a3033ad896c4ff9b70ce7a43304f31c56f5eb61e 100644 (file)
@@ -281,6 +281,53 @@ doc_rect_to_view_rect (EvView *view, EvRectangle *doc_rect, GdkRectangle *view_r
        view_rect->height = ceil (doc_rect->y2 * view->scale) + y_offset - view_rect->y;
 }
 
+static void
+compute_zoom_factor (EvView *view)
+{
+       int doc_width, doc_height;
+       double scale, scale_w, scale_h;
+       GtkBorder border;
+
+       if (view->width <= 0 && view->height <= 0) {
+               return;
+       }
+
+       doc_width = doc_height = 0;
+       scale = scale_w = scale_h = 1.0;
+       ev_page_cache_get_size (view->page_cache,
+                               view->current_page,
+                               1.0,
+                               &doc_width,
+                               &doc_height);
+
+       /* FIXME: The border size isn't constant.  Ugh.  Still, if we have extra
+        * space, we just cut it from the border */
+       ev_document_misc_get_page_border_size (doc_width, doc_height, &border);
+
+       if (doc_width == 0 || doc_height == 0) {
+               return;
+       }
+
+       if (view->width >= 0) {
+               int target_width;
+
+               target_width = view->width - (view->spacing * 2 + border.left + border.right);
+               scale = scale_w = (double)target_width / doc_width;
+       }
+
+       if (view->height >= 0) {
+               int target_height;
+
+               target_height = view->height - (view->spacing * 2 + border.top + border.bottom);
+               scale = scale_h = (double)target_height / doc_height;
+       }
+
+       if (view->width >= 0 && view->height >= 0) {
+               scale = (scale_w < scale_h) ? scale_w : scale_h;
+       }
+
+       view->scale = scale;
+}
 
 /* Called by size_request to make sure we have appropriate jobs running.
  */
@@ -301,6 +348,8 @@ ev_view_size_request (GtkWidget      *widget,
                return;
        }
 
+       compute_zoom_factor (view);
+
        ev_page_cache_get_size (view->page_cache,
                                view->current_page,
                                view->scale,
@@ -1410,6 +1459,8 @@ page_changed_cb (EvPageCache *page_cache,
        view->current_page = new_page;
        view->has_selection = FALSE;
 
+       compute_zoom_factor (view);
+
        ev_pixbuf_cache_set_page_range (view->pixbuf_cache,
                                        view->current_page,
                                        view->current_page,
@@ -1518,83 +1569,34 @@ ev_view_zoom (EvView   *view,
        scale = CLAMP (scale, MIN_SCALE, MAX_SCALE);
 
        view->scale = scale;
+       view->width = view->height = -1;
        gtk_widget_queue_resize (GTK_WIDGET (view));
 }
 
 void
 ev_view_zoom_in (EvView *view)
 {
-       view->width = view->height = -1;
        ev_view_zoom (view, ZOOM_IN_FACTOR, TRUE);
 }
 
 void
 ev_view_zoom_out (EvView *view)
 {
-       view->width = view->height = -1;
        ev_view_zoom (view, ZOOM_OUT_FACTOR, TRUE);
 }
 
-static double
-size_to_zoom_factor (EvView *view, int width, int height)
-{
-       int doc_width, doc_height;
-       double scale, scale_w, scale_h;
-       GtkBorder border;
-
-       doc_width = doc_height = 0;
-       scale = scale_w = scale_h = 1.0;
-       ev_page_cache_get_size (view->page_cache,
-                               view->current_page,
-                               view->scale,
-                               &doc_width,
-                               &doc_height);
-
-       /* FIXME: The border size isn't constant.  Ugh.  Still, if we have extra
-        * space, we just cut it from the border */
-       ev_document_misc_get_page_border_size (doc_width, doc_height, &border);
-
-       if (doc_width == 0 && doc_height == 0) {
-               return 0;
-       }
-
-       if (width >= 0) {
-               int target_width;
-
-               target_width = width - (view->spacing * 2 + border.left + border.right);
-               scale = scale_w = (double)target_width * view->scale / doc_width;
-       }
-
-       if (height >= 0) {
-               int target_height;
-
-               target_height = height - (view->spacing * 2 + border.top + border.bottom);
-               scale = scale_h = (double)target_height * view->scale / doc_height;
-       }
-
-       if (width >= 0 && height >= 0) {
-               scale = (scale_w < scale_h) ? scale_w : scale_h;
-       }
-
-       return scale;
-}
-
 void
 ev_view_set_size (EvView     *view,
                  int         width,
                  int         height)
 {
-       double factor;
-
-       if (!view->document)
+       if (!view->document) {
                return;
+       }
 
-       if (view->width != width ||
-           view->height != height) {
+       if (width != view->width || height != view->height) {
                view->width = width;
                view->height = height;
-               factor = size_to_zoom_factor (view, width, height);
-               ev_view_zoom (view, factor, FALSE);
                gtk_widget_queue_resize (GTK_WIDGET (view));
        }
 }