+static void
+ev_view_get_offsets (EvView *view, int *x_offset, int *y_offset)
+{
+ EvDocument *document = view->document;
+ GtkWidget *widget = GTK_WIDGET (view);
+ int width, height, target_width, target_height;
+ GtkBorder border;
+
+ g_return_if_fail (EV_IS_DOCUMENT (document));
+
+ ev_document_get_page_size (document, -1, &width, &height);
+ ev_document_misc_get_page_border_size (width, height, &border);
+
+ *x_offset = view->spacing;
+ *y_offset = view->spacing;
+ target_width = width + border.left + border.right + view->spacing * 2;
+ target_height = height + border.top + border.bottom + view->spacing * 2;
+ *x_offset += MAX (0, (widget->allocation.width - target_width) / 2);
+ *y_offset += MAX (0, (widget->allocation.height - target_height) / 2);
+}
+
+static void
+view_rect_to_doc_rect (EvView *view, GdkRectangle *view_rect, GdkRectangle *doc_rect)
+{
+ int x_offset, y_offset;
+
+ ev_view_get_offsets (view, &x_offset, &y_offset);
+ doc_rect->x = (view_rect->x - x_offset) / view->scale;
+ doc_rect->y = (view_rect->y - y_offset) / view->scale;
+ doc_rect->width = view_rect->width / view->scale;
+ doc_rect->height = view_rect->height / view->scale;
+}
+
+static void
+doc_rect_to_view_rect (EvView *view, GdkRectangle *doc_rect, GdkRectangle *view_rect)
+{
+ int x_offset, y_offset;
+
+ ev_view_get_offsets (view, &x_offset, &y_offset);
+ view_rect->x = doc_rect->x * view->scale + x_offset;
+ view_rect->y = doc_rect->y * view->scale + y_offset;
+ view_rect->width = doc_rect->width * view->scale;
+ view_rect->height = doc_rect->height * view->scale;
+}
+