[evince] libview: Add new zoom mode that optimizes for readability
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] libview: Add new zoom mode that optimizes for readability
- Date: Thu, 3 Jan 2013 10:06:11 +0000 (UTC)
commit 0cad8758e9d96a1cf3b8a07776e64b6ae602b4e7
Author: William Jon McCann <jmccann redhat com>
Date: Sat Dec 29 16:04:13 2012 +0100
libview: Add new zoom mode that optimizes for readability
This "Automatic" zoom mode will use fit width when
the window is smaller than 100% of the actual page size
and then use the actual page size up to the point the
window is large enough to hold two entire pages side
by side.
https://bugzilla.gnome.org/show_bug.cgi?id=689468
libview/ev-document-model.h | 1 +
libview/ev-view.c | 107 +++++++++++++++++++++++++++++++++++--------
2 files changed, 89 insertions(+), 19 deletions(-)
---
diff --git a/libview/ev-document-model.h b/libview/ev-document-model.h
index c91478b..b371d8b 100644
--- a/libview/ev-document-model.h
+++ b/libview/ev-document-model.h
@@ -38,6 +38,7 @@ typedef enum {
EV_SIZING_BEST_FIT = EV_SIZING_FIT_PAGE, /* Deprecated */
EV_SIZING_FIT_WIDTH,
EV_SIZING_FREE,
+ EV_SIZING_AUTOMATIC,
} EvSizingMode;
typedef struct _EvDocumentModel EvDocumentModel;
diff --git a/libview/ev-view.c b/libview/ev-view.c
index 3e4822b..1aa3b41 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -246,6 +246,11 @@ static double zoom_for_size_fit_page (gdouble doc_width,
gdouble doc_height,
int target_width,
int target_height);
+static double zoom_for_size_automatic (GdkScreen *screen,
+ gdouble doc_width,
+ gdouble doc_height,
+ int target_width,
+ int target_height);
static void ev_view_zoom (EvView *view,
gdouble factor);
static void ev_view_zoom_for_size (EvView *view,
@@ -3040,6 +3045,7 @@ ev_view_size_request_continuous_dual_page (EvView *view,
switch (view->sizing_mode) {
case EV_SIZING_FIT_WIDTH:
case EV_SIZING_FIT_PAGE:
+ case EV_SIZING_AUTOMATIC:
requisition->width = 1;
break;
@@ -3069,6 +3075,7 @@ ev_view_size_request_continuous (EvView *view,
switch (view->sizing_mode) {
case EV_SIZING_FIT_WIDTH:
case EV_SIZING_FIT_PAGE:
+ case EV_SIZING_AUTOMATIC:
requisition->width = 1;
break;
@@ -3163,7 +3170,8 @@ ev_view_size_request (GtkWidget *widget,
*/
if (!view->internal_size_request &&
(view->sizing_mode == EV_SIZING_FIT_WIDTH ||
- view->sizing_mode == EV_SIZING_FIT_PAGE)) {
+ view->sizing_mode == EV_SIZING_FIT_PAGE ||
+ view->sizing_mode == EV_SIZING_AUTOMATIC)) {
GtkAllocation allocation;
gtk_widget_get_allocation (widget, &allocation);
@@ -3229,7 +3237,8 @@ ev_view_size_allocate (GtkWidget *widget,
return;
if (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
- view->sizing_mode == EV_SIZING_FIT_PAGE) {
+ view->sizing_mode == EV_SIZING_FIT_PAGE ||
+ view->sizing_mode == EV_SIZING_AUTOMATIC) {
GtkRequisition req;
ev_view_zoom_for_size (view,
@@ -5590,6 +5599,33 @@ zoom_for_size_fit_page (gdouble doc_width,
return MIN (w_scale, h_scale);
}
+static double
+zoom_for_size_automatic (GdkScreen *screen,
+ gdouble doc_width,
+ gdouble doc_height,
+ int target_width,
+ int target_height)
+{
+ double fit_width_scale;
+ double scale;
+
+ fit_width_scale = zoom_for_size_fit_width (doc_width, doc_height, target_width, target_height);
+
+ if (doc_height < doc_width) {
+ double fit_height_scale;
+
+ fit_height_scale = zoom_for_size_fit_height (doc_width, doc_height, target_width, target_height);
+ scale = MIN (fit_width_scale, fit_height_scale);
+ } else {
+ double actual_scale;
+
+ actual_scale = ev_document_misc_get_screen_dpi (screen) / 72.0;
+ scale = MIN (fit_width_scale, actual_scale);
+ }
+
+ return scale;
+}
+
static void
ev_view_zoom_for_size_continuous_and_dual_page (EvView *view,
int width,
@@ -5617,12 +5653,20 @@ ev_view_zoom_for_size_continuous_and_dual_page (EvView *view,
sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ switch (view->sizing_mode) {
+ case EV_SIZING_FIT_WIDTH:
scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
- } else if (view->sizing_mode == EV_SIZING_FIT_PAGE)
+ break;
+ case EV_SIZING_FIT_PAGE:
scale = zoom_for_size_fit_page (doc_width, doc_height, width - sb_size, height);
- else
+ break;
+ case EV_SIZING_AUTOMATIC:
+ scale = zoom_for_size_automatic (gtk_widget_get_screen (GTK_WIDGET (view)),
+ doc_width, doc_height, width - sb_size, height);
+ break;
+ default:
g_assert_not_reached ();
+ }
ev_document_model_set_scale (view->model, scale);
}
@@ -5653,12 +5697,20 @@ ev_view_zoom_for_size_continuous (EvView *view,
sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ switch (view->sizing_mode) {
+ case EV_SIZING_FIT_WIDTH:
scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
- } else if (view->sizing_mode == EV_SIZING_FIT_PAGE)
+ break;
+ case EV_SIZING_FIT_PAGE:
scale = zoom_for_size_fit_page (doc_width, doc_height, width - sb_size, height);
- else
+ break;
+ case EV_SIZING_AUTOMATIC:
+ scale = zoom_for_size_automatic (gtk_widget_get_screen (GTK_WIDGET (view)),
+ doc_width, doc_height, width - sb_size, height);
+ break;
+ default:
g_assert_not_reached ();
+ }
ev_document_model_set_scale (view->model, scale);
}
@@ -5672,6 +5724,7 @@ ev_view_zoom_for_size_dual_page (EvView *view,
gdouble doc_width, doc_height;
gdouble scale;
gint other_page;
+ gint sb_size;
other_page = view->current_page ^ 1;
@@ -5692,15 +5745,22 @@ ev_view_zoom_for_size_dual_page (EvView *view,
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) {
- gint sb_size;
-
+ switch (view->sizing_mode) {
+ case EV_SIZING_FIT_WIDTH:
sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
- } else if (view->sizing_mode == EV_SIZING_FIT_PAGE)
+ break;
+ case EV_SIZING_FIT_PAGE:
scale = zoom_for_size_fit_page (doc_width, doc_height, width, height);
- else
+ break;
+ case EV_SIZING_AUTOMATIC:
+ sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
+ scale = zoom_for_size_automatic (gtk_widget_get_screen (GTK_WIDGET (view)),
+ doc_width, doc_height, width - sb_size, height);
+ break;
+ default:
g_assert_not_reached ();
+ }
ev_document_model_set_scale (view->model, scale);
}
@@ -5713,6 +5773,7 @@ ev_view_zoom_for_size_single_page (EvView *view,
gdouble doc_width, doc_height;
GtkBorder border;
gdouble scale;
+ gint sb_size;
get_doc_page_size (view, view->current_page, &doc_width, &doc_height);
@@ -5722,15 +5783,22 @@ ev_view_zoom_for_size_single_page (EvView *view,
width -= (border.left + border.right + 2 * view->spacing);
height -= (border.top + border.bottom + 2 * view->spacing);
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
- gint sb_size;
-
+ switch (view->sizing_mode) {
+ case EV_SIZING_FIT_WIDTH:
sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
- } else if (view->sizing_mode == EV_SIZING_FIT_PAGE)
+ break;
+ case EV_SIZING_FIT_PAGE:
scale = zoom_for_size_fit_page (doc_width, doc_height, width, height);
- else
+ break;
+ case EV_SIZING_AUTOMATIC:
+ sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
+ scale = zoom_for_size_automatic (gtk_widget_get_screen (GTK_WIDGET (view)),
+ doc_width, doc_height, width - sb_size, height);
+ break;
+ default:
g_assert_not_reached ();
+ }
ev_document_model_set_scale (view->model, scale);
}
@@ -5742,7 +5810,8 @@ ev_view_zoom_for_size (EvView *view,
{
g_return_if_fail (EV_IS_VIEW (view));
g_return_if_fail (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
- view->sizing_mode == EV_SIZING_FIT_PAGE);
+ view->sizing_mode == EV_SIZING_FIT_PAGE ||
+ view->sizing_mode == EV_SIZING_AUTOMATIC);
g_return_if_fail (width >= 0);
g_return_if_fail (height >= 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]