summaryrefslogtreecommitdiff
path: root/src/pdf.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdf.zig')
-rw-r--r--src/pdf.zig67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/pdf.zig b/src/pdf.zig
index 712750dc..de5e6d86 100644
--- a/src/pdf.zig
+++ b/src/pdf.zig
@@ -1017,6 +1017,73 @@ pub const Document = struct {
) != c.PARDES_PDF_OK) return error.RenderFailed;
}
+ /// Only the highlight pass of `renderIntoAtWithPaper`, over `rgba`, which
+ /// holds `band` of this page as that render left it before highlighting
+ /// (opaque paper). Rendering with highlights equals rendering without and
+ /// then this, row for row: the render draws highlights over the finished
+ /// page, and so does this.
+ pub fn paintHighlightsAt(
+ document: *Document,
+ page: usize,
+ request: RenderRequest,
+ raster: Raster,
+ band: Raster.Band,
+ highlights: []const Highlight,
+ rgba: []u8,
+ ) !void {
+ if (rgba.len != band.len) return error.BadPixmap;
+ if (band.height == 0 or band.y + band.height > raster.height)
+ return error.BadPixmap;
+ const bounded = try boundedRequest(document, page, request);
+ if (highlights.len > c.PARDES_PDF_MAX_RESULT_QUADS) return error.RenderFailed;
+ if (c.pardes_pdf_paint_highlights(
+ document.handle,
+ @intCast(page),
+ bounded.dpi,
+ bounded.minimum_width,
+ bounded.minimum_height,
+ bounded.max_dimension,
+ if (highlights.len == 0) null else @ptrCast(highlights.ptr),
+ highlights.len,
+ rgba.ptr,
+ rgba.len,
+ @intCast(raster.width),
+ @intCast(raster.height),
+ @intCast(raster.stride),
+ @intCast(band.y),
+ @intCast(band.height),
+ ) != c.PARDES_PDF_OK) return error.RenderFailed;
+ }
+
+ pub const Rows = struct { start: usize, end: usize };
+
+ /// The rows of `request`'s raster that painting `highlights` can touch,
+ /// by the transform the render itself uses (rotation included). Empty
+ /// when nothing would paint.
+ pub fn highlightRows(
+ document: *Document,
+ page: usize,
+ request: RenderRequest,
+ highlights: []const Highlight,
+ ) !Rows {
+ const bounded = try boundedRequest(document, page, request);
+ var row_start: c_int = 0;
+ var row_end: c_int = 0;
+ if (c.pardes_pdf_highlight_rows(
+ document.handle,
+ @intCast(page),
+ bounded.dpi,
+ bounded.minimum_width,
+ bounded.minimum_height,
+ bounded.max_dimension,
+ if (highlights.len == 0) null else @ptrCast(highlights.ptr),
+ highlights.len,
+ &row_start,
+ &row_end,
+ ) != c.PARDES_PDF_OK) return error.RenderFailed;
+ return .{ .start = @intCast(row_start), .end = @intCast(row_end) };
+ }
+
const BoundedRequest = struct {
dpi: c_int,
minimum_width: c_int,