summaryrefslogtreecommitdiff
path: root/src/pdf_bridge.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdf_bridge.h')
-rw-r--r--src/pdf_bridge.h95
1 files changed, 90 insertions, 5 deletions
diff --git a/src/pdf_bridge.h b/src/pdf_bridge.h
index cda426aa..3ab87376 100644
--- a/src/pdf_bridge.h
+++ b/src/pdf_bridge.h
@@ -167,6 +167,8 @@ enum {
PARDES_PDF_OK = 0,
PARDES_PDF_ERROR = -1,
PARDES_PDF_LIMIT_EXCEEDED = -2,
+ /* A render stopped early through its cookie (pardes_pdf_set_cookie). */
+ PARDES_PDF_ABORTED = -3,
/* Per-document MuPDF eviction cache; render buffers are separate. */
PARDES_PDF_STORE_LIMIT_BYTES = 64 * 1024 * 1024,
@@ -183,13 +185,42 @@ enum {
PARDES_PDF_MAX_OUTLINE_ITEMS = 8192,
PARDES_PDF_MAX_OUTLINE_DEPTH = 64,
PARDES_PDF_MAX_OUTLINE_BYTES = 4 * 1024 * 1024,
- PARDES_PDF_MAX_LINK_URI_BYTES = 64 * 1024
+ PARDES_PDF_MAX_LINK_URI_BYTES = 64 * 1024,
+
+ /* No page raster is taller than this, whatever it is shown at. */
+ PARDES_PDF_MAX_RASTER_ROWS = 1 << 20
};
-pardes_pdf_document *pardes_pdf_open(const char *path, int *page_count);
pardes_pdf_document *pardes_pdf_open_memory(const unsigned char *bytes, size_t length, int *page_count);
void pardes_pdf_close(pardes_pdf_document *document);
+/*
+ * A render lane: a context cloned from `base`'s (fz_clone_context: the store,
+ * the allocator and the locks shared) and a document of its OWN, opened from
+ * the bytes `base` holds (the fz_buffer shared, read only). MuPDF allows one
+ * thread at a time in a context and in a document; a lane is used by one
+ * thread at a time and never shares either with `base` or another lane, so
+ * lanes render while `base` serves the UI thread. Clone on the thread that
+ * owns `base` (the clone reads its context); `pardes_pdf_lane_open` then runs
+ * on the lane's thread. Close every lane before `base`. NULL: no lane (out of
+ * memory).
+ */
+pardes_pdf_document *pardes_pdf_lane_clone(pardes_pdf_document *base);
+int pardes_pdf_lane_open(pardes_pdf_document *lane);
+
+/* Mirrors fz_cookie (checked in the bridge): set `abort` nonzero from any
+ * thread and a render running under it stops at its next operator. */
+typedef struct pardes_pdf_cookie {
+ int abort;
+ int progress;
+ size_t progress_max;
+ int errors;
+ int incomplete;
+} pardes_pdf_cookie;
+
+/* The cookie the document's renders run under (NULL: none), until set again. */
+void pardes_pdf_set_cookie(pardes_pdf_document *document, pardes_pdf_cookie *cookie);
+
/* Page dimensions in PDF points after crop/rotation, without rasterizing. */
int pardes_pdf_get_page_size(
pardes_pdf_document *document,
@@ -199,7 +230,11 @@ int pardes_pdf_get_page_size(
/*
* Start at dpi, raise the uniform scale until both optional minimum pixel
- * dimensions are met, then clamp the page's longest side to max_dimension.
+ * dimensions are met, then clamp the page's width to max_dimension, and its
+ * height too unless that would draw it smaller than the optional display size
+ * (the width or height it is shown at): a tall page is then as tall as it is
+ * shown, and its owner renders it in bands. Every function below takes the
+ * same request and computes the same raster from it.
* Measuring may populate the page cache, but never advances adaptive display
* list promotion; only a successful render_into does that.
*/
@@ -210,6 +245,8 @@ int pardes_pdf_measure_render(
int minimum_width,
int minimum_height,
int max_dimension,
+ int display_width,
+ int display_height,
pardes_pdf_raster_layout *out
);
@@ -222,8 +259,9 @@ int pardes_pdf_measure_render(
* MuPDF wraps but never owns or frees samples. Every successful pixel is
* opaque unless transparent_paper is nonzero. That mode preserves content
* coverage and returns straight-alpha RGBA over an unpainted page.
- * The CTM does not depend on the band, so a band's rows are bit-identical to
- * the same rows of the whole page: it is a clip, not a different rendering.
+ * The CTM does not depend on the band, so a band is a clip of the same
+ * rendering -- but not a bit-exact one: its edge rows and resampled images can
+ * differ from the whole page's (see pardes_pdf_render_into).
*/
int pardes_pdf_render_into(
pardes_pdf_document *document,
@@ -232,6 +270,8 @@ int pardes_pdf_render_into(
int minimum_width,
int minimum_height,
int max_dimension,
+ int display_width,
+ int display_height,
const pardes_pdf_highlight *highlights,
size_t highlight_count,
unsigned char *samples,
@@ -244,6 +284,51 @@ int pardes_pdf_render_into(
int transparent_paper
);
+/*
+ * The highlight pass of `pardes_pdf_render_into` alone, over caller-supplied
+ * rows of that page's opaque raster: render_into(h) == paint(render_into({}), h)
+ * row for row, because a render draws its highlights over the finished page.
+ */
+int pardes_pdf_paint_highlights(
+ pardes_pdf_document *document,
+ int page,
+ int dpi,
+ int minimum_width,
+ int minimum_height,
+ int max_dimension,
+ int display_width,
+ int display_height,
+ const pardes_pdf_highlight *highlights,
+ size_t highlight_count,
+ unsigned char *samples,
+ size_t samples_len,
+ int width,
+ int height,
+ int stride,
+ int band_y,
+ int band_height
+);
+
+/*
+ * The raster rows [*row_start, *row_end) that painting `highlights` can touch
+ * under the same request, in the coordinates `pardes_pdf_render_into` bands
+ * use. An empty set (or only transparent ones) yields start == end == 0.
+ */
+int pardes_pdf_highlight_rows(
+ pardes_pdf_document *document,
+ int page,
+ int dpi,
+ int minimum_width,
+ int minimum_height,
+ int max_dimension,
+ int display_width,
+ int display_height,
+ const pardes_pdf_highlight *highlights,
+ size_t highlight_count,
+ int *row_start,
+ int *row_end
+);
+
int pardes_pdf_page_text(
pardes_pdf_document *document,
int page,