diff options
| author | Victor Kareh <[email protected]> | 2026-03-06 13:58:16 -0500 |
|---|---|---|
| committer | Victor Kareh <[email protected]> | 2026-03-06 14:40:27 -0500 |
| commit | df950f0861445c3ddbd4006041f3e0ccf37bb38d (patch) | |
| tree | 943eb145de31dac511e26ee90beed2ca2ff1fcab | |
| parent | b5a8856440b34b7ced9b98f709d12a1593ce58fc (diff) | |
| download | atril-zoom-limits.tar.bz2 atril-zoom-limits.tar.xz | |
ev-window: Limit max zoom based on largest page sizezoom-limits
Cairo surfaces have a limit of 32767px in any dimension, so we make sure
that we don't end up zooming in past the point where the rendered
surface is larger than that limit.
| -rw-r--r-- | shell/ev-window.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/shell/ev-window.c b/shell/ev-window.c index f472c210..00eb1dc2 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -4664,12 +4664,21 @@ ev_window_setup_gtk_settings (EvWindow *window) g_free (menubar_accel_accel); } +/* + * Cairo image surfaces don't reliably work on + * images larger than 32767 in width or height. + * See https://gitlab.freedesktop.org/cairo/cairo/-/commit/9e45673e + */ +#define CAIRO_MAX_IMAGE_SIZE 32767 + static void ev_window_update_max_min_scale (EvWindow *window) { gdouble dpi; + gint scale; GtkAction *action; gdouble min_width, min_height; + gdouble max_width, max_height; gdouble max_scale; guint page_cache_mb; @@ -4678,10 +4687,16 @@ ev_window_update_max_min_scale (EvWindow *window) page_cache_mb = g_settings_get_uint (window->priv->settings, GS_PAGE_CACHE_SIZE); dpi = get_monitor_dpi (window) / 72.0; + scale = gtk_widget_get_scale_factor (GTK_WIDGET (window)); ev_document_get_min_page_size (window->priv->document, &min_width, &min_height); max_scale = sqrt ((page_cache_mb * 1024 * 1024) / (min_width * dpi * 4 * min_height * dpi)); + /* Cap zoom so rendered pages stay within cairo's pixel limit. + * Use the largest page since any page could be rendered. */ + ev_document_get_max_page_size (window->priv->document, &max_width, &max_height); + max_scale = MIN (max_scale, (gdouble)(CAIRO_MAX_IMAGE_SIZE - 1) / (MAX (max_width, max_height) * dpi * scale)); + G_GNUC_BEGIN_IGNORE_DEPRECATIONS; action = gtk_action_group_get_action (window->priv->action_group, ZOOM_CONTROL_ACTION); |
