Constrain minimum zoom level

This commit is contained in:
pieterd 2025-12-23 13:41:44 +01:00 • committed by Sophie Herold
parent 6e2f38de56
commit f34f9dd988
3 changed files with 51 additions and 2 deletions

View file

@ -95,6 +95,27 @@ impl imp::LpImage {
decoder::tiling::zoom_normalize(zoom) / self.scaling()
}
/// Minimal zoom allowed for this image
pub(super) fn min_zoom(&self) -> f64 {
let (width, height) = self.untransformed_dimensions();
// If the image is smaller than the smallest rendered pixel size,
// block zooming out entirely
if (width as f64) < SMALLEST_RENDERED_PIXEL_SIZE
|| (height as f64) < SMALLEST_RENDERED_PIXEL_SIZE
{
1.0
}
// Prevent the rendered size from going below SMALLEST_RENDERED_PIXEL_SIZE
// Original size * zoom factor = rendered size
// <=> Zoom factor = rendered size / original size
else if width < height {
SMALLEST_RENDERED_PIXEL_SIZE / (width as f64)
} else {
SMALLEST_RENDERED_PIXEL_SIZE / (height as f64)
}
}
/// Maximal zoom allowed for this image
pub(super) fn max_zoom(&self) -> f64 {
let obj = self.obj();
@ -214,6 +235,15 @@ impl imp::LpImage {
tracing::trace!(zoom, animated, snap_best_fit, force_cursor_center, fit_mode=?obj.fit_mode(), "Zoom instruction");
let min_zoom = self.min_zoom();
if zoom <= min_zoom {
tracing::trace!(zoom, min_zoom, "Zoom reached minimum zoom level");
zoom = min_zoom;
obj.set_is_min_zoom(true);
} else {
obj.set_is_min_zoom(false);
}
let max_zoom = self.max_zoom();
if zoom >= max_zoom {
tracing::trace!(zoom, max_zoom, "Zoom reached maximum zoom level");