summaryrefslogtreecommitdiff
path: root/src/pdf.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:56:29 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:02:08 -0300
commitb4863573f775c73ca4e9aa233af2f6e5113c06b3 (patch)
tree6a7ea6cc424e73a9e48f3740fc6262854fb576ec /src/pdf.zig
parent98d22582eb7305973925f3e014bde3549320fee0 (diff)
downloadpardes-b4863573f775c73ca4e9aa233af2f6e5113c06b3.tar.gz
pardes-b4863573f775c73ca4e9aa233af2f6e5113c06b3.zip
pdf: a render request crosses the bridge as one pardes_pdf_request, where its six sizes were six arguments of each of the four calls (measure, render, highlight paint and rows) and of the geometry, each call checking them itself (pardes_pdf_request_ok now); boundedRequest makes the struct the Zig side passes
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/pdf.zig')
-rw-r--r--src/pdf.zig62
1 files changed, 10 insertions, 52 deletions
diff --git a/src/pdf.zig b/src/pdf.zig
index 30828f92..a68bf48a 100644
--- a/src/pdf.zig
+++ b/src/pdf.zig
@@ -893,12 +893,7 @@ pub const Document = struct {
if (c.pardes_pdf_measure_render(
document.handle,
@intCast(page),
- bounded.dpi,
- bounded.minimum_width,
- bounded.minimum_height,
- bounded.max_dimension,
- bounded.display_width,
- bounded.display_height,
+ &bounded,
&raw_layout,
) != c.PARDES_PDF_OK) return error.RenderFailed;
// The page's shape, not an allocation: a page taller than
@@ -932,12 +927,7 @@ pub const Document = struct {
const status = c.pardes_pdf_render_into(
document.handle,
@intCast(page),
- bounded.dpi,
- bounded.minimum_width,
- bounded.minimum_height,
- bounded.max_dimension,
- bounded.display_width,
- bounded.display_height,
+ &bounded,
highlight_ptr,
highlights.len,
rgba.ptr,
@@ -975,12 +965,7 @@ pub const Document = struct {
if (c.pardes_pdf_paint_highlights(
document.handle,
@intCast(page),
- bounded.dpi,
- bounded.minimum_width,
- bounded.minimum_height,
- bounded.max_dimension,
- bounded.display_width,
- bounded.display_height,
+ &bounded,
if (highlights.len == 0) null else @ptrCast(highlights.ptr),
highlights.len,
rgba.ptr,
@@ -1010,12 +995,7 @@ pub const Document = struct {
if (c.pardes_pdf_highlight_rows(
document.handle,
@intCast(page),
- bounded.dpi,
- bounded.minimum_width,
- bounded.minimum_height,
- bounded.max_dimension,
- bounded.display_width,
- bounded.display_height,
+ &bounded,
if (highlights.len == 0) null else @ptrCast(highlights.ptr),
highlights.len,
&row_start,
@@ -1024,20 +1004,13 @@ pub const Document = struct {
return .{ .start = @intCast(row_start), .end = @intCast(row_end) };
}
- const BoundedRequest = struct {
- dpi: c_int,
- minimum_width: c_int,
- minimum_height: c_int,
- max_dimension: c_int,
- display_width: c_int,
- display_height: c_int,
- };
-
+ /// `request` as the bridge takes it, refused when the page or a size is
+ /// out of range.
fn boundedRequest(
document: *Document,
page: usize,
request: RenderRequest,
- ) !BoundedRequest {
+ ) !c.pardes_pdf_request {
_ = try document.checkedPage(page);
if (request.dpi == 0 or request.max_dimension == 0 or
request.max_dimension > absolute_max_render_dimension)
@@ -1794,19 +1767,9 @@ test "RGBA allocation and buffer-validation failures leave the document renderab
document.render(failing.allocator(), 0, .{}, &.{}),
);
- const request: RenderRequest = .{};
+ const request = try document.boundedRequest(0, .{});
var raw_layout: c.pardes_pdf_raster_layout = std.mem.zeroes(c.pardes_pdf_raster_layout);
- try std.testing.expectEqual(c.PARDES_PDF_OK, c.pardes_pdf_measure_render(
- document.handle,
- 0,
- request.dpi,
- request.minimum_width,
- request.minimum_height,
- request.max_dimension,
- 0,
- 0,
- &raw_layout,
- ));
+ try std.testing.expectEqual(c.PARDES_PDF_OK, c.pardes_pdf_measure_render(document.handle, 0, &request, &raw_layout));
const layout = try checkedRasterLayout(raw_layout);
{
const scratch = try std.testing.allocator.alloc(u8, layout.len);
@@ -1815,12 +1778,7 @@ test "RGBA allocation and buffer-validation failures leave the document renderab
try std.testing.expectEqual(c.PARDES_PDF_ERROR, c.pardes_pdf_render_into(
document.handle,
0,
- request.dpi,
- request.minimum_width,
- request.minimum_height,
- request.max_dimension,
- 0,
- 0,
+ &request,
null,
0,
scratch.ptr,