From 42694963a3b55398aac068820d00cd710685e4fb Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:29:32 -0300 Subject: image: nativeGeometry's contain is containGeometry, where it repeated it line for line Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/image.zig | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/image.zig b/src/image.zig index 9163730d..fe515073 100644 --- a/src/image.zig +++ b/src/image.zig @@ -603,32 +603,14 @@ pub fn nativeGeometry( return switch (fit) { .width => fitWidth(src_w, src_h, body_pixel_w, body_pixel_h, pan_y), .height => fitHeight(src_w, src_h, body_pixel_w, body_pixel_h, pan_x), - .contain => blk: { - if (src_w <= body_pixel_w and src_h <= body_pixel_h) break :blk .{ - .src = .{ .w = src_w, .h = src_h }, - .dst = .{ .w = src_w, .h = src_h }, - }; - - // Compare scale ratios without floating point. The tighter bound - // is exact; the other is rounded inward. Contain intentionally - // ignores pan and keeps the historical top-left placement. - const dst: PixelRect = if (@as(u64, body_pixel_w) * src_h <= @as(u64, body_pixel_h) * src_w) - .{ - .w = body_pixel_w, - .h = @intCast(@max(1, @as(u64, src_h) * body_pixel_w / src_w)), - } - else - .{ - .w = @intCast(@max(1, @as(u64, src_w) * body_pixel_h / src_h)), - .h = body_pixel_h, - }; - break :blk .{ .src = .{ .w = src_w, .h = src_h }, .dst = dst }; - }, + // Pan is not contain's: it keeps the top-left placement. + .contain => containGeometry(iw, ih, body_pixel_w, body_pixel_h), }; } -/// The ordinary image-pane policy, separate from the PDF-only fit/pan -/// machinery so feature-off backends retain their original contain-only path. +/// The ordinary image-pane policy: shrunk only when it must be, at the top +/// left. The scale ratios are compared without floating point: the tighter +/// bound is exact, the other rounded inward. pub fn containGeometry(iw: usize, ih: usize, max_w: u32, max_h: u32) ?NativeGeometry { if (iw == 0 or ih == 0 or max_w == 0 or max_h == 0 or iw > std.math.maxInt(u32) or ih > std.math.maxInt(u32)) return null; -- cgit v1.3