+
+
+static double
+zoom_for_size_fit_width (int doc_width,
+ int doc_height,
+ int target_width,
+ int target_height,
+ int vsb_width)
+{
+ double scale;
+
+ scale = (double)target_width / doc_width;
+
+ if (doc_height * scale > target_height)
+ scale = (double) (target_width - vsb_width) / doc_width;
+
+ return scale;
+}
+
+static double
+zoom_for_size_best_fit (int doc_width,
+ int doc_height,
+ int target_width,
+ int target_height,
+ int vsb_width,
+ int hsb_width)
+{
+ double w_scale;
+ double h_scale;
+
+ w_scale = (double)target_width / doc_width;
+ h_scale = (double)target_height / doc_height;
+
+ if (doc_height * w_scale > target_height)
+ w_scale = (double) (target_width - vsb_width) / doc_width;
+ if (doc_width * h_scale > target_width)
+ h_scale = (double) (target_height - hsb_width) / doc_height;
+
+ return MIN (w_scale, h_scale);
+}
+
+static void
+ev_view_zoom_for_size_continuous_and_dual_page (EvView *view,
+ int width,
+ int height,
+ int vsb_width,
+ int hsb_height)
+{
+ int doc_width, doc_height;
+ GtkBorder border;
+ gdouble scale;
+
+ ev_page_cache_get_max_width_size (view->page_cache,
+ 1.0,
+ &doc_width, NULL);
+ ev_page_cache_get_max_height_size (view->page_cache,
+ 1.0,
+ NULL, &doc_height);
+ compute_border (view, doc_width, doc_height, &border);
+
+ doc_width = doc_width * 2;
+ width -= ((border.left + border.right)* 2 + 3 * view->spacing);
+ height -= (border.top + border.bottom + 2 * view->spacing);
+
+ /* FIXME: We really need to calculat the overall height here, not the
+ * page height. We assume there's always a vertical scrollbar for
+ * now. We need to fix this. */
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width - vsb_width, height, 0);
+ else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ scale = zoom_for_size_best_fit (doc_width, doc_height, width - vsb_width, height, 0, hsb_height);
+ else
+ g_assert_not_reached ();
+
+ ev_view_zoom (view, scale, FALSE);
+}
+
+static void
+ev_view_zoom_for_size_continuous (EvView *view,
+ int width,
+ int height,
+ int vsb_width,
+ int hsb_height)
+{
+ int doc_width, doc_height;
+ GtkBorder border;
+ gdouble scale;
+
+ ev_page_cache_get_max_width_size (view->page_cache,
+ 1.0,
+ &doc_width, NULL);
+ ev_page_cache_get_max_height_size (view->page_cache,
+ 1.0,
+ NULL, &doc_height);
+ compute_border (view, doc_width, doc_height, &border);
+
+ width -= (border.left + border.right + 2 * view->spacing);
+ height -= (border.top + border.bottom + 2 * view->spacing);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width, height, vsb_width);
+ else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ scale = zoom_for_size_best_fit (doc_width, doc_height, width, height, vsb_width, hsb_height);
+ else
+ g_assert_not_reached ();
+
+ ev_view_zoom (view, scale, FALSE);
+}
+
+static void
+ev_view_zoom_for_size_dual_page (EvView *view,
+ int width,
+ int height,
+ int vsb_width,
+ int hsb_height)
+{
+ GtkBorder border;
+ gint doc_width, doc_height;
+ gdouble scale;
+ gint other_page;
+
+ other_page = view->current_page ^ 1;
+
+ /* Find the largest of the two. */
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ 1.0,
+ &doc_width, &doc_height);
+
+ if (other_page < ev_page_cache_get_n_pages (view->page_cache)) {
+ gint width_2, height_2;
+ ev_page_cache_get_size (view->page_cache,
+ other_page,
+ 1.0,
+ &width_2, &height_2);
+ if (width_2 > doc_width)
+ doc_width = width_2;
+ if (height_2 > doc_height)
+ doc_height = height_2;
+ }
+ compute_border (view, doc_width, doc_height, &border);
+
+ doc_width = doc_width * 2;
+ width -= ((border.left + border.right)* 2 + 3 * view->spacing);
+ height -= (border.top + border.bottom + 2 * view->spacing);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width, height, vsb_width);
+ else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ scale = zoom_for_size_best_fit (doc_width, doc_height, width, height, vsb_width, hsb_height);
+ else
+ g_assert_not_reached ();
+
+ ev_view_zoom (view, scale, FALSE);
+}
+
+static void
+ev_view_zoom_for_size_single_page (EvView *view,
+ int width,
+ int height,
+ int vsb_width,
+ int hsb_height)
+{
+ int doc_width, doc_height;
+ GtkBorder border;
+ gdouble scale;
+
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ 1.0,
+ &doc_width,
+ &doc_height);
+ /* Get an approximate border */
+ compute_border (view, width, height, &border);
+
+ width -= (border.left + border.right + 2 * view->spacing);
+ height -= (border.top + border.bottom + 2 * view->spacing);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width, height, vsb_width);
+ else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ scale = zoom_for_size_best_fit (doc_width, doc_height, width, height, vsb_width, hsb_height);
+ else
+ g_assert_not_reached ();
+
+ ev_view_zoom (view, scale, FALSE);
+}
+
+