diff options
| author | Gabriel Schneider <[email protected]> | 2026-08-02 20:50:04 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-10 09:17:07 -0300 |
| commit | 5d5f2a25011c751452fb4ff42e28ee84d4bb4fdf (patch) | |
| tree | 9078fed09c1eb4604d28b1e3ac57e26389e18ac3 /src/pdf_bridge.c | |
| parent | a93b796a3389acaf45775d302f559e01c19ddbfc (diff) | |
| download | pardes-5d5f2a25011c751452fb4ff42e28ee84d4bb4fdf.tar.gz pardes-5d5f2a25011c751452fb4ff42e28ee84d4bb4fdf.zip | |
tune PDF raster resolution per native backend
Diffstat (limited to 'src/pdf_bridge.c')
| -rw-r--r-- | src/pdf_bridge.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/pdf_bridge.c b/src/pdf_bridge.c index a26fea55..320919b1 100644 --- a/src/pdf_bridge.c +++ b/src/pdf_bridge.c @@ -234,17 +234,24 @@ int pardes_pdf_render( pardes_pdf_document *document, int page_number, + int dpi, + int minimum_width, + int minimum_height, int max_dimension, pardes_pdf_pixmap *out) { return pardes_pdf_render_with_highlights( - document, page_number, max_dimension, NULL, 0, out); + document, page_number, dpi, minimum_width, minimum_height, + max_dimension, NULL, 0, out); } int pardes_pdf_render_with_highlights( pardes_pdf_document *document, int page_number, + int dpi, + int minimum_width, + int minimum_height, int max_dimension, const pardes_pdf_highlight *highlights, size_t highlight_count, @@ -256,12 +263,15 @@ pardes_pdf_render_with_highlights( fz_path *path = NULL; fz_matrix ctm; fz_rect bounds; + float page_width; + float page_height; float longest; - float scale = 2.0f; /* 144 dpi; PDF user space is 72 dpi. */ + float scale; size_t i; if (document == NULL || out == NULL || page_number < 0 || - page_number >= document->page_count || max_dimension < 1 || + page_number >= document->page_count || dpi < 1 || + minimum_width < 0 || minimum_height < 0 || max_dimension < 1 || (highlight_count != 0 && highlights == NULL) || highlight_count > PARDES_PDF_MAX_RESULT_QUADS) return PARDES_PDF_ERROR; @@ -275,9 +285,16 @@ pardes_pdf_render_with_highlights( { pardes_pdf_cache_page(document, page_number, 0); bounds = document->cached_bounds; - longest = fmaxf(bounds.x1 - bounds.x0, bounds.y1 - bounds.y0); + page_width = bounds.x1 - bounds.x0; + page_height = bounds.y1 - bounds.y0; + longest = fmaxf(page_width, page_height); if (!(longest > 0.0f)) fz_throw(ctx, FZ_ERROR_FORMAT, "PDF page has empty bounds"); + scale = (float)dpi / 72.0f; + if (minimum_width > 0) + scale = fmaxf(scale, (float)minimum_width / page_width); + if (minimum_height > 0) + scale = fmaxf(scale, (float)minimum_height / page_height); if (longest * scale > (float)max_dimension) scale = (float)max_dimension / longest; /* |
