After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 608586 - Calculation of dpi
Calculation of dpi
Status: RESOLVED OBSOLETE
Product: evince
Classification: Core
Component: general
2.29.x
Other Linux
: Normal normal
: ---
Assigned To: Evince Maintainers
Evince Maintainers
: 526972 722009 (view as bug list)
Depends on:
Blocks: 685553
 
 
Reported: 2010-01-31 11:41 UTC by Juanjo Marín
Modified: 2018-05-22 13:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Poposed patch for calculating the dpi with the comparison of the diagonal in pixels and inches (755 bytes, patch)
2010-01-31 11:53 UTC, Juanjo Marín
committed Details | Review

Description Juanjo Marín 2010-01-31 11:41:44 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
Comment 1 Juanjo Marín 2010-01-31 11:53:15 UTC
Created attachment 152670 [details] [review]
Poposed patch for calculating the dpi with the comparison of the diagonal in pixels and inches
Comment 2 Juanjo Marín 2010-02-15 22:59:06 UTC
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/
Comment 3 Carlos Garcia Campos 2010-02-21 11:37:57 UTC
Pushed to git master. Thanks Juanjo!
Comment 4 José Aliste 2012-11-26 00:57:14 UTC
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)
Comment 5 Juanjo Marín 2012-11-26 09:18:41 UTC
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 ?
Comment 6 José Aliste 2012-11-26 09:29:17 UTC
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.
Comment 7 José Aliste 2012-11-26 16:13:29 UTC
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)
Comment 8 Juanjo Marín 2012-11-26 16:35:59 UTC
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.
Comment 9 José Aliste 2013-02-06 12:26:59 UTC
*** Bug 526972 has been marked as a duplicate of this bug. ***
Comment 10 José Aliste 2013-04-25 00:07:31 UTC
Review of attachment 152670 [details] [review]:

this was already committed by Carlos
Comment 11 Germán Poo-Caamaño 2014-01-13 19:04:42 UTC
*** Bug 722009 has been marked as a duplicate of this bug. ***
Comment 12 GNOME Infrastructure Team 2018-05-22 13:46:17 UTC
-- 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.