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 551634 - gtk's interpretation of DPI differs when set to 'default' vs. when force-set to the X server's DPI value
gtk's interpretation of DPI differs when set to 'default' vs. when force-set ...
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Widget: Other
2.14.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2008-09-10 10:54 UTC by Brian Tarricone
Modified: 2015-08-16 13:24 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Brian Tarricone 2008-09-10 10:54:24 UTC
Context: we've implemented a new XSETTINGS daemon for Xfce 4.6.  Xfce 4.4 also didn't handle the Xft/DPI property (it only set the Xft.DPI xrdb resource), so we've added that as well.  The XSettings registry[1] states that the value set for this property should be the DPI value multiplied by 1024, or -1 to use the 'default' (I assume this means X-server-specified) value.

However, this doesn't work (visually).  If I set Xft/DPI to -1, I get what I assume are correctly-sized fonts.  'xdpyinfo' reports my screen DPI to be 107x107, which should be correct for a 12" laptop LCD panel at 1024x768 (well, ok, 106.667).  If I set Xft/DPI to (107*1024), my fonts increase in size by about 15% or so.  (It's definitely not rounding error; 106*1024 is still considerably larger than -1.)

The "correct" scaling factor seems to be a little bit less than 950.

So... is gtk (pango?) interpreting the DPI from Xorg incorrectly when Xft/DPI is set to -1?  Or is it doing something incorrectly when the DPI is forced to another value?  Or are we just doing something wrong here?

Running gtk 2.12.11 here, with pango 1.20.5.

[1] http://www.freedesktop.org/wiki/Specifications/XSettingsRegistry
Comment 1 Yves-Alexis Perez 2008-09-10 11:09:50 UTC
As I side note, when using "-1" here, I had problems with epiphany using gecko renderer. Some websites and the default apache folder listing show no fonts at all, as if the size was 0.
Comment 2 Mike Massonnet 2008-09-14 14:20:32 UTC
Can you reproduce that "gecko" bug in devhelp?  If yes, I set the font size to 0.1 in Edit>Preferences.  In a matter of facts, the higher I set the font size the smaller they get displayed :-S

Or this could be completely unrelated, hard to say...
Comment 3 Brian Tarricone 2008-09-15 03:44:35 UTC
(In reply to comment #1)
> As I side note, when using "-1" here, I had problems with epiphany using gecko
> renderer. Some websites and the default apache folder listing show no fonts at
> all, as if the size was 0.

Gecko sets its own DPI via another means.  That's not related to this bug.

Comment 4 Yves-Alexis Perez 2008-09-20 09:20:51 UTC
Using pango 1.21.6, the issue still exists.
Comment 5 Brian Tarricone 2008-10-20 06:29:20 UTC
Chatting about this with some people, and experimenting a bit, I'm now convinced of the opposite.  The behavior when Xft/DPI is set to -1 is incorrect, and the behavior when forcing a specific DPI value is correct.

Poking around in gdk/x11/gdkxftdefaults.c, init_xft_settings(), the DPI is calculated as (display_height) * 2.54 / (display_height_mm).  Then that value is multiplied by PANGO_SCALE, and then halved.  Why halved?
Comment 6 Yves-Alexis Perez 2008-11-14 23:59:43 UTC
Could some gtk developper comment on this one? Xfce 4.6 beta is bitten by this bug and it'd be nice to solve this issue before the release.

Cheers and thanks,
--
Yves-Alexis
Comment 7 Owen Taylor 2008-11-15 16:39:25 UTC
Brian:

 screen_x11->xft_dpi = (int)(0.5 + PANGO_SCALE * dpi_double);

That's "0.5 +" not "0.5 *".. it's there to get correct rounding.
Comment 8 Yves-Alexis Perez 2008-11-15 18:11:13 UTC
Using a test program it seems that gdk_screen_get_resolution() always return -1, wether we force the DPI or not in “Appearance Settings”.
Comment 9 Brian Tarricone 2008-11-15 20:55:50 UTC
(In reply to comment #7)
> Brian:
> 
>  screen_x11->xft_dpi = (int)(0.5 + PANGO_SCALE * dpi_double);
> 
> That's "0.5 +" not "0.5 *".. it's there to get correct rounding.

Gah, you're right of course.  I guess I was staring at it too long.

Any idea what the problem here could be, then?
Comment 10 Yves-Alexis Perez 2008-11-16 15:52:49 UTC
breaking on gdk_pango_context_get_for_screen it seems the resolution is correctly set in gdk.

gdk_screen_get_resolution() returns 125 if I force the DPI in xfce4-appearance-settings, and -1 if I don't.

So maybe the problem is pango/cairo related?

I have two screenshots which show the problem:

http://molly.corsac.net/~corsac/xfce/dpi=-1.png
http://molly.corsac.net/~corsac/xfce/dpi=125.png
Comment 11 Yves-Alexis Perez 2008-11-16 16:22:57 UTC
This is with gtk 2.14.4, pango 1.22.2 and cairo 1.8.2
Comment 12 Yves-Alexis Perez 2008-11-16 16:37:55 UTC
In pango/fonts.c, pango_font_description_get_size() always returns the same sizes whatever the DPI is (6144 for Liberation Sans 6) (which is not really coherent with the fact that it's not the same sizes on screen in both cases)
Comment 13 Behdad Esfahbod 2008-11-18 13:33:02 UTC
(In reply to comment #12)
> In pango/fonts.c, pango_font_description_get_size() always returns the same
> sizes whatever the DPI is (6144 for Liberation Sans 6) (which is not really
> coherent with the fact that it's not the same sizes on screen in both cases)

The font size returned by pango_font_description_get_size is in points and is independent of the DPI.
Comment 14 Yves-Alexis Perez 2008-11-18 15:21:23 UTC
(In reply to comment #13)
> The font size returned by pango_font_description_get_size is in points and is
> independent of the DPI.

Thanks. Do you know where can I find the final (displayed) size of the font, in pixels? Pango, Cairo or gtk?
Comment 15 Behdad Esfahbod 2008-11-18 17:53:33 UTC
(In reply to comment #14)
> (In reply to comment #13)
> > The font size returned by pango_font_description_get_size is in points and is
> > independent of the DPI.
> 
> Thanks. Do you know where can I find the final (displayed) size of the font, in
> pixels? Pango, Cairo or gtk?

Depends on what you mean by "find".  Pango computes the final size and passes it down to cairo.
Comment 16 Yves-Alexis Perez 2009-01-03 10:37:51 UTC
For the record, the same thing is reproducible with:
libglib 2.18.3
libpango 2.22.3
libgtk2.0 2.14.5
Comment 17 Yves-Alexis Perez 2009-02-13 07:38:39 UTC
Stephan Arts tracked the bug down to pango or fontconfig. http://bugzilla.xfce.org/show_bug.cgi?id=4374#c10 has all the info but basically:

----
When DPI == -1, Pango uses fontconfig to retrieve the DPI settings.

That this does not work right, is clear... But I don't know if this problem
should be solved in Pango or fontconfig. (eg, use X11 instead of fontconfig, or
let fontconfig return the correct DPI settings)
----

Not sure how it behaves under GNOME, but…
Comment 18 Matthias Clasen 2015-08-16 13:24:16 UTC
I don't think we'll change anything here for gtk 2 at this point. And in gtk 3, we've recently reduced the amount of fallback-through-various-layers madness that is going on with resolutions.