+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;
+}