summaryrefslogtreecommitdiff
path: root/src/pdf_bridge.c
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-25 10:59:53 -0300
committerGabriel Schneider <[email protected]>2026-10-25 10:59:53 -0300
commit53539a43789d402a9f774d8cf30c0a102331b5b3 (patch)
tree641057065b9f82504c96bd720156dc4e6cb00f61 /src/pdf_bridge.c
parent1dbfb9a468859fb0e0ce228740731e0876bcdcf6 (diff)
downloadpardes-53539a43789d402a9f774d8cf30c0a102331b5b3.tar.gz
pardes-53539a43789d402a9f774d8cf30c0a102331b5b3.zip
pdfrender 2: a PDF opens without its page-size pass: the strip is laid out on the first page's size, the last lane measures every page (its first job) and the sizes land as a relayout that keeps the view's page and offset and the strip's glide (a retarget, not a reset; a one-size document never relayouts); MuPDF's page-tree map is off in every document (its first lookup parsed all 5363 page objects of the SDM: 735 ms in Debug, the first page's size alone and every lane's first page)
Diffstat (limited to 'src/pdf_bridge.c')
-rw-r--r--src/pdf_bridge.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/pdf_bridge.c b/src/pdf_bridge.c
index 57711245..a35dfa71 100644
--- a/src/pdf_bridge.c
+++ b/src/pdf_bridge.c
@@ -353,6 +353,20 @@ pardes_pdf_grown_capacity(size_t current, size_t needed, size_t maximum)
return capacity;
}
+/*
+ * MuPDF's first page lookup loads a map of EVERY page object (the page tree
+ * flattened, each page's dictionary parsed out of its object stream): the
+ * SDM's 5363 took 735 ms in Debug, the first page's size alone. Walking the
+ * tree by its /Count for each lookup loads only the nodes on the way.
+ */
+static void
+pardes_pdf_walk_page_tree(fz_context *ctx, fz_document *doc)
+{
+ pdf_document *pdf = pdf_specifics(ctx, doc);
+ if (pdf != NULL)
+ pdf_set_page_tree_cache(ctx, pdf, 0);
+}
+
pardes_pdf_document *
pardes_pdf_open_memory(const unsigned char *bytes, size_t length, int *page_count)
{
@@ -398,6 +412,7 @@ pardes_pdf_open_memory(const unsigned char *bytes, size_t length, int *page_coun
buffer = fz_new_buffer_from_copied_data(ctx, bytes, length);
stream = fz_open_buffer(ctx, buffer);
doc = fz_open_document_with_stream(ctx, "application/pdf", stream);
+ pardes_pdf_walk_page_tree(ctx, doc);
pages = fz_count_pages(ctx, doc);
if (pages < 1)
fz_throw(ctx, FZ_ERROR_FORMAT, "PDF has no pages");
@@ -490,6 +505,7 @@ pardes_pdf_lane_open(pardes_pdf_document *lane)
{
stream = fz_open_buffer(ctx, lane->base->buffer);
doc = fz_open_document_with_stream(ctx, "application/pdf", stream);
+ pardes_pdf_walk_page_tree(ctx, doc);
if (fz_count_pages(ctx, doc) != lane->page_count)
fz_throw(ctx, FZ_ERROR_FORMAT, "PDF lane counts other pages");
}