From 1c45f048d906fa3923620fc0a75cd2b56f960eec Mon Sep 17 00:00:00 2001 From: Victor Kareh Date: Thu, 5 Mar 2026 16:18:56 -0500 Subject: libview: Allow zooming to the limits of the scale If the current zoom level was within one zoom factor of the limit, it was not possible to scroll towards the limit. This made smooth scrolling near the limit awkward, as unless the scroll event had a large delta it was impossible to reach the zoom limit. Non-smooth scrolling was also affected, but it was just much more difficult to trigger. Fix this by allowing zooming while the current zoom level is within one zoom factor of the limit. Add a new ev_view_can_zoom() function to make zooming by a factor (as with smooth scrolling) more convenient. Backported from https://gitlab.gnome.org/GNOME/evince/-/commit/6d299b69 --- libview/ev-view.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/libview/ev-view.c b/libview/ev-view.c index 68ca0970..5301079d 100644 --- a/libview/ev-view.c +++ b/libview/ev-view.c @@ -229,6 +229,8 @@ static double zoom_for_size_automatic (GdkScreen *screen, gdouble doc_height, int target_width, int target_height); +static gboolean ev_view_can_zoom (EvView *view, + gdouble factor); static void ev_view_zoom_for_size (EvView *view, int width, int height); @@ -3819,8 +3821,7 @@ ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event) gdouble delta = event->delta_x + event->delta_y; gdouble factor = pow (delta < 0 ? ZOOM_IN_FACTOR : ZOOM_OUT_FACTOR, fabs (delta)); - if ((factor < 1.0 && ev_view_can_zoom_out (view)) || - (factor >= 1.0 && ev_view_can_zoom_in (view))) + if (ev_view_can_zoom (view, factor)) ev_view_zoom (view, factor); } break; @@ -6472,8 +6473,7 @@ zoom_gesture_scale_changed_cb (GtkGestureZoom *gesture, gtk_gesture_get_bounding_box_center (GTK_GESTURE (gesture), &view->zoom_center_x, &view->zoom_center_y); - if ((factor < 1.0 && ev_view_can_zoom_out (view)) || - (factor >= 1.0 && ev_view_can_zoom_in (view))) + if (ev_view_can_zoom (view, factor)) ev_view_zoom (view, factor); } @@ -6906,8 +6906,8 @@ update_can_zoom (EvView *view) min_scale = ev_document_model_get_min_scale (view->model); max_scale = ev_document_model_get_max_scale (view->model); - can_zoom_in = (view->scale * ZOOM_IN_FACTOR) <= max_scale; - can_zoom_out = (view->scale * ZOOM_OUT_FACTOR) > min_scale; + can_zoom_in = view->scale <= max_scale; + can_zoom_out = view->scale > min_scale; if (can_zoom_in != view->can_zoom_in) { view->can_zoom_in = can_zoom_in; @@ -7099,6 +7099,19 @@ ev_view_reload (EvView *view) /*** Zoom and sizing mode ***/ +static gboolean +ev_view_can_zoom (EvView *view, gdouble factor) +{ + if (factor == 1.0) + return TRUE; + + else if (factor < 1.0) { + return ev_view_can_zoom_out (view); + } else { + return ev_view_can_zoom_in (view); + } +} + gboolean ev_view_can_zoom_in (EvView *view) { -- cgit v1.2.1