summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorVictor Kareh <[email protected]>2026-03-06 13:58:16 -0500
committerVictor Kareh <[email protected]>2026-04-10 11:37:36 -0400
commitfab6729b836bee2be0fa29122902569f0c5f98d8 (patch)
tree00a7aff384d2e60e5dc9f4d9d4f88d8e7805159c /shell
parenta17adb8c5b7b42a2b9e050d2f128d7639f00efae (diff)
downloadatril-fab6729b836bee2be0fa29122902569f0c5f98d8.tar.bz2
atril-fab6729b836bee2be0fa29122902569f0c5f98d8.tar.xz
ev-window: Limit max zoom based on largest page size
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.
Diffstat (limited to 'shell')
-rw-r--r--shell/ev-window.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 77093d42..2e9432a6 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);