[evince/gnome3-style] 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/gnome3-style] libview: Add new zoom mode that optimizes for readability
- Date: Sat, 29 Dec 2012 15:18:26 +0000 (UTC)
commit f566de762970b199916811c66576626f43333596
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 5c50404..54a1c25 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -240,6 +240,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 gboolean ev_view_can_zoom (EvView *view,
gdouble factor);
static void ev_view_zoom (EvView *view,
@@ -3030,6 +3035,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;
@@ -3059,6 +3065,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;
@@ -3153,7 +3160,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);
@@ -3219,7 +3227,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,
@@ -5456,6 +5465,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,
@@ -5483,12 +5519,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);
}
@@ -5519,12 +5563,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);
}
@@ -5538,6 +5590,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;
@@ -5558,15 +5611,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);
}
@@ -5579,6 +5639,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);
@@ -5588,15 +5649,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);
}
@@ -5608,7 +5676,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]