summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons/pdf/pdf.zig7
-rw-r--r--test/panes.zig57
2 files changed, 63 insertions, 1 deletions
diff --git a/addons/pdf/pdf.zig b/addons/pdf/pdf.zig
index c9a49b7c..1e0fb311 100644
--- a/addons/pdf/pdf.zig
+++ b/addons/pdf/pdf.zig
@@ -1209,7 +1209,12 @@ fn layout(st: *Pdf, l: *Layout, k: usize) void {
}
if (l.rev != st.rev) { // a pixel's: P:F rounds
const sp = stripOf(st, ownOf(st), k);
- l.top = @round(f64Of(sp.y[st.page]) + std.math.clamp(st.frac, 0, 1) * f64Of(sp.ph[st.page]));
+ // Laid as the active view is (a window of its size in another
+ // process): the active's top as it is, a fraction and all, so the
+ // two show the same pixels (from P:F, rounded, one showed its page
+ // a pixel off the other's).
+ const same = if (pixels(st, st.active)) |a| a != l and a.rev == st.rev and a.vw == vw and a.vh == vh and a.fit == l.fit else false;
+ l.top = if (same) st.views[st.active - 1].top else @round(f64Of(sp.y[st.page]) + std.math.clamp(st.frac, 0, 1) * f64Of(sp.ph[st.page]));
l.rev = st.rev;
}
l.top = std.math.clamp(l.top, 0, f64Of(l.height -| l.vh));
diff --git a/test/panes.zig b/test/panes.zig
index fb8adc36..34c81801 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -4178,6 +4178,63 @@ const PdfAddon = struct {
try std.testing.expect(notch > 0 and first > at[0] and first < at[1]);
try std.testing.expectApproxEqRel(notch / 4, at[2] - at[1], 0.05);
}
+
+ test "a window client the size of its session's window shows a PDF's pages where the session's window shows them, a fraction of a pixel scrolled and all" {
+ if (!addons.has_pdf) return error.SkipZigTest;
+ const R = pardes.replica;
+ const gpa = std.testing.allocator;
+ const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &host_vtable }, false);
+ defer a.deinit();
+ const win = try R.Replica.init(gpa, 2, try a.unit(0, 0), false);
+ defer win.deinit();
+ const land = struct {
+ a: *R.Authority,
+ r: *R.Replica,
+ fn step(l: @This(), ev: pardes.Event) !void {
+ l.r.confirm(try l.a.local(ev));
+ }
+ }{ .a = a, .r = win };
+ // The session's window, and the client's of its size on a view of its own.
+ const window: pardes.Event = .{ .frontend = .{ .windowed = true, .native_images = true } };
+ try land.step(window);
+ // The client has the addon (a test's replica finds no library of
+ // its own: it is handed the session's, loaded in this process).
+ var words: [64]pardes.Kind.LoadedWord = undefined;
+ var why: pardes.Kind.Buf(160) = .{};
+ const lib = pardes.Addon.readLoaded(pdf_lib, &words, &why);
+ try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } });
+ const kind = a.core.kinds.n - 1;
+ win.core().kinds.ops[kind] = a.core.kinds.ops[kind];
+ const id = try opened(a, land);
+ const k = try a.openView(2);
+ win.confirm(k.unit);
+ win.view = k.view;
+ win.confirm(try a.take(try win.input(window)));
+ try land.step(.tick);
+ // A touchpad's 0.6 of a notch in the client: its view's top a
+ // fraction of a pixel past a row (as a glide's half steps leave it).
+ const r = win.core().view().rects[id];
+ win.confirm(try a.take(try win.input(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = r.x + 4, .row = r.y + r.h - 2, .amount = 0.6 } })));
+ for (0..2) |_| {
+ try land.step(.tick);
+ try jobs(a.core, land);
+ }
+ win.settle();
+ try std.testing.expect(win.diverged == null);
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var at: [2][8][4]u32 = @splat(@splat(@splat(0)));
+ for ([_]*Pardes{ a.core, win.core() }, [_]u8{ 0, k.view }, &at) |core, view, *rows| {
+ core.toView(view);
+ var n: usize = 0;
+ for ((try core.render(arena.allocator())).placements.items) |pl| if (pl.pane == id and pl.raster.w > 1 and n < rows.len) {
+ rows[n] = if (pl.at) |x| .{ x.y, x.h, pl.src.y, pl.src.h } else .{ 0, 0, pl.src.y, pl.src.h };
+ n += 1;
+ };
+ try std.testing.expect(n > 0);
+ }
+ try std.testing.expectEqualSlices([4]u32, &at[0], &at[1]);
+ }
};
test {