From 250547cabd9d1ecbd1699f341ee9f7a7396977d8 Mon Sep 17 00:00:00 2001 From: Jeremie Knuesel Date: Sun, 11 Feb 2018 15:08:12 +0100 Subject: [PATCH] Use DPI to scale documents to physical size --- zathura/adjustment.c | 8 ++++++++ zathura/render.c | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/zathura/adjustment.c b/zathura/adjustment.c index 9a10da5..4ae7161 100644 --- a/zathura/adjustment.c +++ b/zathura/adjustment.c @@ -13,6 +13,14 @@ page_calc_height_width(zathura_document_t* document, double height, g_return_val_if_fail(document != NULL && page_height != NULL && page_width != NULL, 0.0); double scale = zathura_document_get_scale(document); + + /* If monitor DPI information is available, use it to match 100% zoom to physical page size */ + double dpi = zathura_document_get_viewport_dpi(document); + if (fabs(dpi) != DBL_EPSILON) { + /* real scale = 1 means: 1 point = 1 pixel, and there are 72 points in one inch */ + scale *= dpi / 72.0; + } + if (rotate == true && zathura_document_get_rotation(document) % 180 != 0) { *page_width = round(height * scale); *page_height = round(width * scale); diff --git a/zathura/render.c b/zathura/render.c index 5953de0..e586f3d 100644 --- a/zathura/render.c +++ b/zathura/render.c @@ -740,7 +740,11 @@ render(render_job_t* job, ZathuraRenderRequest* request, ZathuraRenderer* render const double height = zathura_page_get_height(page); const double width = zathura_page_get_width(page); - /* page size in user pixels base on document zoom: 100% results in 1 pixel per point */ + /* page size in user pixels based on document zoom: if DPI information is + * available, 100% results in 72 documents points per inch of screen (i.e. + * document size on screen matching the physical paper size). If DPI + * information is unavailable, the page size in pixels will be 1 pixel per + * document point. */ const double real_scale = page_calc_height_width(document, height, width, &page_height, &page_width, false);