GNOME Bugzilla – Bug 608586
Calculation of dpi
Last modified: 2018-05-22 13:46:17 UTC
dpi is defined in get_screen_dpi() at shell/ev-utils.c as the average between the horizontal lines per inch and vertical lines per inch. As far as I'm concerned, this definition is not correct. I haven't found an authoritative source of information about dpi/ppi but some pages [1][2]. Theoretically, this should be calculated as the division between the resolution of screen in pixels and the diagonal size in inches. This can be done easily using the Pythagorean theorem.[1]. AFAIK, this is the standard way of calculating dpi/ppi. Another calculation I've found is using the squared root of the area in pixeles and inches [2]. Because the horizontal and vertical lines per inch are usually very balanced on current screens, the dpi calculated with get_screen_dpi() isn't very far from the "real" dpi. This is a example showing different results: Screen: 800x480 pixeles 6x3 inches Method used by get_screen_dpi() (800÷6)+(420÷3)/2 = 203.333333333 Method using the diagonal √(800²+420²)÷√(6²+3²) = 134.693066719 Method using the area √((800×420)/(6×3)) = 136.626010213 References [1] http://en.wikipedia.org/wiki/Pixel_density [2] http://www.ehow.com/how_4965210_calculate-ppi.html
Created attachment 152670 [details] [review] Poposed patch for calculating the dpi with the comparison of the diagonal in pixels and inches
s/as the division between the resolution of screen in pixels and the diagonal size in inches/as the division between the diagonal of screen in pixels and the diagonal in inches/
Pushed to git master. Thanks Juanjo!
Hey, I don't think this is actually fixed... The current computation gives 96 dpi on my machine (1600x900 13.3" screen)... which is quite wrong (it should be around 138)
I'll take a look later on The patched function get_screen_dpi() was moved and splitted http://git.gnome.org/browse/evince/diff/?id=8ee88d8e916cb126a0a12e4816b9d1043cbd6472 shell/ev-window.c: +static gdouble +get_screen_dpi (EvWindow *window) +{ + GdkScreen *screen; + + screen = gtk_window_get_screen (GTK_WINDOW (window)); + return ev_document_misc_get_screen_dpi (screen); +} libdocument/ev-document-misc.c +gdouble +ev_document_misc_get_screen_dpi (GdkScreen *screen) +{ + gdouble dp, di; + + /*diagonal in pixels*/ + dp = hypot (gdk_screen_get_width (screen), gdk_screen_get_height (screen)); + + /*diagonal in inches*/ + di = hypot (gdk_screen_get_width_mm(screen), gdk_screen_get_height_mm (screen)) / 25.4; + + return (dp / di); +} In theory, if gtk_window_get_screen() and the gdk_screen_get functions are working properly (and no other bug from our side :-) ) dp must be √(1600²+900²) = 1835.756~ and di must be 13.3 so dp/di should be around 138 Could you check the values of dp and di ?
Juanjo.. my bad.. new versions of X server assume 96 dpi somewhere... and thus the mm width and heights you find with gdk_screen_width_mm are wrong (basically, the x server takes the width and height and multiply this by the user specified dpi, but if you have no conf. file it just assume 96... Maybe we want to use randr to get the real size of the screen, but this probably belong to gdk.
More experience with gdk_screen api (and reading through the code) shows that gdk_screen_get_monitor_width(height)_mm will (at least in X11 systems with RandR support) give the correct dimensions for the screen monitor. So, does it make sense to change that? or to open a bug in gdk_screen to make the computation work as expected? Besides, I think evince should probably be using the settings from a monitor and not a screen... because different monitors will have different physical DPI, in general, and thus, we might want to get the dpi of the current monitor instead of the screen (which, will fail on recent X11 without conf files)
I think this could work, but I think is good idea to ask to the gdk hackers for advice. I don't know neither if we take into a account if we move an Evince window from one monitor to another one in a multi-head configuration.
*** Bug 526972 has been marked as a duplicate of this bug. ***
Review of attachment 152670 [details] [review]: this was already committed by Carlos
*** Bug 722009 has been marked as a duplicate of this bug. ***
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/evince/issues/132.