From b4eca29d3ac2956016032d02e2cc8933171f844d Mon Sep 17 00:00:00 2001 From: Jeremie Knuesel Date: Mon, 12 Feb 2018 10:55:05 +0100 Subject: [PATCH] Replace monitor "dpi" with "ppi" This should avoid some confusion with the font DPI --- zathura/callbacks.c | 6 +++--- zathura/callbacks.h | 4 ++-- zathura/document.c | 22 +++++++++++----------- zathura/document.h | 28 +++++++++++++++------------- zathura/render.c | 6 +++--- zathura/zathura.c | 20 ++++++++++---------- zathura/zathura.h | 4 ++-- 7 files changed, 46 insertions(+), 44 deletions(-) diff --git a/zathura/callbacks.c b/zathura/callbacks.c index bd25819..04106c1 100644 --- a/zathura/callbacks.c +++ b/zathura/callbacks.c @@ -226,7 +226,7 @@ cb_monitors_changed(GdkScreen* screen, gpointer data) return; } - zathura_update_view_dpi(zathura); + zathura_update_view_ppi(zathura); } void @@ -251,7 +251,7 @@ cb_widget_screen_changed(GtkWidget* widget, GdkScreen* UNUSED(previous_screen), "monitors-changed", G_CALLBACK(cb_monitors_changed), zathura); } - zathura_update_view_dpi(zathura); + zathura_update_view_ppi(zathura); } void @@ -273,7 +273,7 @@ cb_scale_factor(GObject* object, GParamSpec* UNUSED(pspec), gpointer data) fabs(new_factor - current.y) >= DBL_EPSILON) { zathura_document_set_device_factors(zathura->document, new_factor, new_factor); girara_debug("New device scale factor: %d", new_factor); - zathura_update_view_dpi(zathura); + zathura_update_view_ppi(zathura); render_all(zathura); } } diff --git a/zathura/callbacks.h b/zathura/callbacks.h index ab0210c..ba49f9d 100644 --- a/zathura/callbacks.h +++ b/zathura/callbacks.h @@ -83,7 +83,7 @@ void cb_refresh_view(GtkWidget* view, gpointer data); * This function gets called when the monitors associated with the GdkScreen * change. * - * It udpates the stored value for the monitor DPI. + * It udpates the stored value for the monitor PPI. * * @param screen The GDK screen * @param gpointer The zathura instance @@ -95,7 +95,7 @@ void cb_monitors_changed(GdkScreen* screen, gpointer data); * changes. * * It udpates updates the connection on the monitors-changed ignal and the - * stored value for the monitor DPI. + * stored value for the monitor PPI. * * @param widget The view widget * @param previous_screen The widget's previous screen diff --git a/zathura/document.c b/zathura/document.c index 7eca627..d315273 100644 --- a/zathura/document.c +++ b/zathura/document.c @@ -37,7 +37,7 @@ struct zathura_document_s { double cell_height; /**< height of a page cell in the document (not transformed by scale and rotation) */ unsigned int view_width; /**< width of current viewport */ unsigned int view_height; /**< height of current viewport */ - double view_dpi; /**cell_height = 0.0; document->view_height = 0; document->view_width = 0; - document->view_dpi = 0.0; + document->view_ppi = 0.0; document->device_factors.x = 1.0; document->device_factors.y = 1.0; document->position_x = 0.0; @@ -417,14 +417,14 @@ zathura_document_get_scale(zathura_document_t* document) return 0; } - /* If monitor DPI information is available, use it to match 100% zoom to + /* If monitor PPI information is available, use it to match 100% zoom to * physical page size */ - if (document->view_dpi > DBL_EPSILON) { - /* scale 1 means: 1 point = 1 pixel, and there are 72 points in one inch */ - return document->zoom * document->view_dpi / 72.0; + if (document->view_ppi > DBL_EPSILON) { + /* scale = pixels per point, and there are 72 points in one inch */ + return document->zoom * document->view_ppi / 72.0; } - /* No DPI information -> scale == zoom */ + /* No PPI information -> scale == zoom */ return document->zoom; } @@ -516,12 +516,12 @@ zathura_document_set_viewport_height(zathura_document_t* document, unsigned int } void -zathura_document_set_viewport_dpi(zathura_document_t* document, double dpi) +zathura_document_set_viewport_ppi(zathura_document_t* document, double ppi) { if (document == NULL) { return; } - document->view_dpi = dpi; + document->view_ppi = ppi; } void @@ -534,12 +534,12 @@ zathura_document_get_viewport_size(zathura_document_t* document, } double -zathura_document_get_viewport_dpi(zathura_document_t* document) +zathura_document_get_viewport_ppi(zathura_document_t* document) { if (document == NULL) { return 0.0; } - return document->view_dpi; + return document->view_ppi; } void diff --git a/zathura/document.h b/zathura/document.h index 629083d..a4a66dd 100644 --- a/zathura/document.h +++ b/zathura/document.h @@ -151,7 +151,7 @@ double zathura_document_get_zoom(zathura_document_t* document); /** * Returns the current scale value of the document (based on zoom and screen - * DPI) + * PPI) * * @param document The document * @return The current scale value @@ -248,15 +248,6 @@ zathura_document_set_viewport_width(zathura_document_t* document, unsigned int w void zathura_document_set_viewport_height(zathura_document_t* document, unsigned int height); -/** - * Sets the viewport DPI (value based on the physical resolution of the monitor). - * - * @param[in] document The document instance - * @param[in] height The viewport DPI - */ -void -zathura_document_set_viewport_dpi(zathura_document_t* document, double dpi); - /** * Return the size of the viewport in pixels. * @@ -268,13 +259,24 @@ zathura_document_get_viewport_size(zathura_document_t* document, unsigned int *height, unsigned int* width); /** - * Return the size of the viewport in pixels. + Sets the viewport PPI (pixels per inch: the resolution of the monitor, after + scaling with the device factor). * * @param[in] document The document instance - * @return The viewport DPI (value based on the physical resolution of the monitor) + * @param[in] height The viewport PPI + */ +void +zathura_document_set_viewport_ppi(zathura_document_t* document, double ppi); + +/** + * Return the viewport PPI (pixels per inch: the resolution of the monitor, + * after scaling with the device factor). + * + * @param[in] document The document instance + * @return The viewport PPI */ double -zathura_document_get_viewport_dpi(zathura_document_t* document); +zathura_document_get_viewport_ppi(zathura_document_t* document); /** * Set the device scale factors (e.g. for HiDPI). These are generally integers diff --git a/zathura/render.c b/zathura/render.c index e586f3d..a250efc 100644 --- a/zathura/render.c +++ b/zathura/render.c @@ -740,9 +740,9 @@ 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 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 + /* page size in user pixels based on document zoom: if PPI information is + * available, 100% zoom results in 72 documents points per inch of screen + * (i.e. document size on screen matching the physical paper size). If PPI * 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, diff --git a/zathura/zathura.c b/zathura/zathura.c index 8439714..d24a95d 100644 --- a/zathura/zathura.c +++ b/zathura/zathura.c @@ -139,7 +139,7 @@ create_directories(zathura_t* zathura) } void -zathura_update_view_dpi(zathura_t* zathura) +zathura_update_view_ppi(zathura_t* zathura) { if (zathura == NULL) { return; @@ -155,7 +155,7 @@ zathura_update_view_dpi(zathura_t* zathura) return; } - double dpi = 0.0; + double ppi = 0.0; #if GTK_CHECK_VERSION(3,22,0) GdkMonitor* monitor = gdk_display_get_monitor_at_window(display, window); @@ -170,11 +170,11 @@ zathura_update_view_dpi(zathura_t* zathura) GdkRectangle monitor_geom; gdk_monitor_get_geometry(monitor, &monitor_geom); - /* calculate dpi, knowing that 1 inch = 25.4 mm */ + /* calculate ppi, knowing that 1 inch = 25.4 mm */ if (width_mm == 0) { - girara_debug("cannot calculate DPI: monitor has zero width"); + girara_debug("cannot calculate PPI: monitor has zero width"); } else { - dpi = monitor_geom.width * 25.4 / width_mm; + ppi = monitor_geom.width * 25.4 / width_mm; } #endif @@ -184,19 +184,19 @@ zathura_update_view_dpi(zathura_t* zathura) * */ if (GDK_IS_WAYLAND_DISPLAY(display)) { - girara_debug("on Wayland, correcting DPI for device scale factor"); + girara_debug("on Wayland, correcting PPI for device scale factor"); /* not using the cached value for the scale factor here to avoid issues * if this function is called before the cached value is updated */ int device_factor = gtk_widget_get_scale_factor(zathura->ui.session->gtk.view); if (device_factor != 0) { - dpi /= device_factor; + ppi /= device_factor; } } #endif - girara_debug("monitor width: %d mm, pixels: %d, dpi: %f", width_mm, monitor_geom.width, dpi); + girara_debug("monitor width: %d mm, pixels: %d, ppi: %f", width_mm, monitor_geom.width, ppi); - zathura_document_set_viewport_dpi(zathura->document, dpi); + zathura_document_set_viewport_ppi(zathura->document, ppi); } static bool @@ -1030,7 +1030,7 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* const unsigned int view_height = (unsigned int)floor(gtk_adjustment_get_page_size(vadjustment)); zathura_document_set_viewport_height(zathura->document, view_height); - zathura_update_view_dpi(zathura); + zathura_update_view_ppi(zathura); /* call screen-changed callback to connect monitors-changed signal on initial screen */ cb_widget_screen_changed(zathura->ui.session->gtk.view, NULL, zathura); diff --git a/zathura/zathura.h b/zathura/zathura.h index 03785d0..e05be81 100644 --- a/zathura/zathura.h +++ b/zathura/zathura.h @@ -288,11 +288,11 @@ void zathura_set_plugin_dir(zathura_t* zathura, const char* dir); void zathura_set_argv(zathura_t* zathura, char** argv); /** - * Calculate and store the monitor DPI for the view widget + * Calculate and store the monitor PPI for the view widget * * @param zathura The zathura session */ -void zathura_update_view_dpi(zathura_t* zathura); +void zathura_update_view_ppi(zathura_t* zathura); /** * Opens a file