Replace monitor "dpi" with "ppi"

This should avoid some confusion with the font DPI
This commit is contained in:
Jeremie Knuesel 2018-02-12 10:55:05 +01:00
parent d625c0d9bd
commit b4eca29d3a
7 changed files with 46 additions and 44 deletions

View file

@ -226,7 +226,7 @@ cb_monitors_changed(GdkScreen* screen, gpointer data)
return; return;
} }
zathura_update_view_dpi(zathura); zathura_update_view_ppi(zathura);
} }
void void
@ -251,7 +251,7 @@ cb_widget_screen_changed(GtkWidget* widget, GdkScreen* UNUSED(previous_screen),
"monitors-changed", G_CALLBACK(cb_monitors_changed), zathura); "monitors-changed", G_CALLBACK(cb_monitors_changed), zathura);
} }
zathura_update_view_dpi(zathura); zathura_update_view_ppi(zathura);
} }
void void
@ -273,7 +273,7 @@ cb_scale_factor(GObject* object, GParamSpec* UNUSED(pspec), gpointer data)
fabs(new_factor - current.y) >= DBL_EPSILON) { fabs(new_factor - current.y) >= DBL_EPSILON) {
zathura_document_set_device_factors(zathura->document, new_factor, new_factor); zathura_document_set_device_factors(zathura->document, new_factor, new_factor);
girara_debug("New device scale factor: %d", new_factor); girara_debug("New device scale factor: %d", new_factor);
zathura_update_view_dpi(zathura); zathura_update_view_ppi(zathura);
render_all(zathura); render_all(zathura);
} }
} }

View file

@ -83,7 +83,7 @@ void cb_refresh_view(GtkWidget* view, gpointer data);
* This function gets called when the monitors associated with the GdkScreen * This function gets called when the monitors associated with the GdkScreen
* change. * 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 screen The GDK screen
* @param gpointer The zathura instance * @param gpointer The zathura instance
@ -95,7 +95,7 @@ void cb_monitors_changed(GdkScreen* screen, gpointer data);
* changes. * changes.
* *
* It udpates updates the connection on the monitors-changed ignal and the * 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 widget The view widget
* @param previous_screen The widget's previous screen * @param previous_screen The widget's previous screen

View file

@ -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) */ 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_width; /**< width of current viewport */
unsigned int view_height; /**< height of current viewport */ unsigned int view_height; /**< height of current viewport */
double view_dpi; /**<DPI of the current viewport */ double view_ppi; /**< PPI of the current viewport */
zathura_device_factors_t device_factors; /**< x and y device scale factors (for e.g. HiDPI) */ zathura_device_factors_t device_factors; /**< x and y device scale factors (for e.g. HiDPI) */
unsigned int pages_per_row; /**< number of pages in a row */ unsigned int pages_per_row; /**< number of pages in a row */
unsigned int first_page_column; /**< column of the first page */ unsigned int first_page_column; /**< column of the first page */
@ -135,7 +135,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri,
document->cell_height = 0.0; document->cell_height = 0.0;
document->view_height = 0; document->view_height = 0;
document->view_width = 0; document->view_width = 0;
document->view_dpi = 0.0; document->view_ppi = 0.0;
document->device_factors.x = 1.0; document->device_factors.x = 1.0;
document->device_factors.y = 1.0; document->device_factors.y = 1.0;
document->position_x = 0.0; document->position_x = 0.0;
@ -417,14 +417,14 @@ zathura_document_get_scale(zathura_document_t* document)
return 0; 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 */ * physical page size */
if (document->view_dpi > DBL_EPSILON) { if (document->view_ppi > DBL_EPSILON) {
/* scale 1 means: 1 point = 1 pixel, and there are 72 points in one inch */ /* scale = pixels per point, and there are 72 points in one inch */
return document->zoom * document->view_dpi / 72.0; return document->zoom * document->view_ppi / 72.0;
} }
/* No DPI information -> scale == zoom */ /* No PPI information -> scale == zoom */
return document->zoom; return document->zoom;
} }
@ -516,12 +516,12 @@ zathura_document_set_viewport_height(zathura_document_t* document, unsigned int
} }
void 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) { if (document == NULL) {
return; return;
} }
document->view_dpi = dpi; document->view_ppi = ppi;
} }
void void
@ -534,12 +534,12 @@ zathura_document_get_viewport_size(zathura_document_t* document,
} }
double double
zathura_document_get_viewport_dpi(zathura_document_t* document) zathura_document_get_viewport_ppi(zathura_document_t* document)
{ {
if (document == NULL) { if (document == NULL) {
return 0.0; return 0.0;
} }
return document->view_dpi; return document->view_ppi;
} }
void void

View file

@ -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 * Returns the current scale value of the document (based on zoom and screen
* DPI) * PPI)
* *
* @param document The document * @param document The document
* @return The current scale value * @return The current scale value
@ -248,15 +248,6 @@ zathura_document_set_viewport_width(zathura_document_t* document, unsigned int w
void void
zathura_document_set_viewport_height(zathura_document_t* document, unsigned int height); 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. * 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); 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 * @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 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 * Set the device scale factors (e.g. for HiDPI). These are generally integers

View file

@ -740,9 +740,9 @@ render(render_job_t* job, ZathuraRenderRequest* request, ZathuraRenderer* render
const double height = zathura_page_get_height(page); const double height = zathura_page_get_height(page);
const double width = zathura_page_get_width(page); const double width = zathura_page_get_width(page);
/* page size in user pixels based on document zoom: if DPI information is /* page size in user pixels based on document zoom: if PPI information is
* available, 100% results in 72 documents points per inch of screen (i.e. * available, 100% zoom results in 72 documents points per inch of screen
* document size on screen matching the physical paper size). If DPI * (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 * information is unavailable, the page size in pixels will be 1 pixel per
* document point. */ * document point. */
const double real_scale = page_calc_height_width(document, height, width, const double real_scale = page_calc_height_width(document, height, width,

View file

@ -139,7 +139,7 @@ create_directories(zathura_t* zathura)
} }
void void
zathura_update_view_dpi(zathura_t* zathura) zathura_update_view_ppi(zathura_t* zathura)
{ {
if (zathura == NULL) { if (zathura == NULL) {
return; return;
@ -155,7 +155,7 @@ zathura_update_view_dpi(zathura_t* zathura)
return; return;
} }
double dpi = 0.0; double ppi = 0.0;
#if GTK_CHECK_VERSION(3,22,0) #if GTK_CHECK_VERSION(3,22,0)
GdkMonitor* monitor = gdk_display_get_monitor_at_window(display, window); GdkMonitor* monitor = gdk_display_get_monitor_at_window(display, window);
@ -170,11 +170,11 @@ zathura_update_view_dpi(zathura_t* zathura)
GdkRectangle monitor_geom; GdkRectangle monitor_geom;
gdk_monitor_get_geometry(monitor, &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) { if (width_mm == 0) {
girara_debug("cannot calculate DPI: monitor has zero width"); girara_debug("cannot calculate PPI: monitor has zero width");
} else { } else {
dpi = monitor_geom.width * 25.4 / width_mm; ppi = monitor_geom.width * 25.4 / width_mm;
} }
#endif #endif
@ -184,19 +184,19 @@ zathura_update_view_dpi(zathura_t* zathura)
* */ * */
if (GDK_IS_WAYLAND_DISPLAY(display)) 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 /* not using the cached value for the scale factor here to avoid issues
* if this function is called before the cached value is updated */ * if this function is called before the cached value is updated */
int device_factor = gtk_widget_get_scale_factor(zathura->ui.session->gtk.view); int device_factor = gtk_widget_get_scale_factor(zathura->ui.session->gtk.view);
if (device_factor != 0) { if (device_factor != 0) {
dpi /= device_factor; ppi /= device_factor;
} }
} }
#endif #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 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)); const unsigned int view_height = (unsigned int)floor(gtk_adjustment_get_page_size(vadjustment));
zathura_document_set_viewport_height(zathura->document, view_height); 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 */ /* call screen-changed callback to connect monitors-changed signal on initial screen */
cb_widget_screen_changed(zathura->ui.session->gtk.view, NULL, zathura); cb_widget_screen_changed(zathura->ui.session->gtk.view, NULL, zathura);

View file

@ -288,11 +288,11 @@ void zathura_set_plugin_dir(zathura_t* zathura, const char* dir);
void zathura_set_argv(zathura_t* zathura, char** argv); 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 * @param zathura The zathura session
*/ */
void zathura_update_view_dpi(zathura_t* zathura); void zathura_update_view_ppi(zathura_t* zathura);
/** /**
* Opens a file * Opens a file