diff options
Diffstat (limited to 'src/pdf.zig')
| -rw-r--r-- | src/pdf.zig | 62 |
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, |
