Bug 229207

Summary: Inconsistent text rendering with different DPIs and hinting
Product: [openSUSE] openSUSE 10.2 Reporter: Clinton Gormley <clint>
Component: GNOMEAssignee: Federico Mena Quintero <federico>
Status: RESOLVED WORKSFORME QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: jcea
Version: Final   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: Customer Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: 125 dpi, no hinting
125 dpi, slight hinting
125 dpi, medium hinting
125 dpi, full hinting
126 dpi, no hinting
126 dpi, slight hinting
126 dpi, medium hinting
126 dpi, full hinting
132 dpi, slight hinting, with Deja Vu fonts at size 8
hinting-and-rounding.png
no-hinting-no-rounding.png

Description Clinton Gormley 2006-12-16 16:03:55 UTC
I have a laptop with an Nvidia GeForce Go 7900 GS card and an SEC GH874 17" monitor. I'm using the Gnome desktop with the Nvidia driver.

The detected DPI is 132, which is correctly set, but the text displays too large. I've fiddled around with the DPI and hinting settings, and I get weird results.  There seems to be a big change between 125 dpi and 126, where the text suddenly gets a lot bigger.

And the hinting is weird - on 125dpi, going from no hinting to full makes the text finer, while on 126dpi, going from no hinting to full makes the text bolder.

Also, firefox doesn't take any notice of the hinting (in the toolbars etc, rather then the document), so on 125 dpi, the font is fine, and on 126, really bold.

I'm attaching screenshots comparing the different settings - apologies for the size...

Also, because so many websites use font-sizes in px, most text in websites is unreadable unless I set a minimum text size, in which case, the sites don't display properly.
Comment 1 Clinton Gormley 2006-12-16 16:04:47 UTC
Created attachment 109992 [details]
125 dpi, no hinting
Comment 2 Clinton Gormley 2006-12-16 16:05:25 UTC
Created attachment 109993 [details]
125 dpi, slight hinting
Comment 3 Clinton Gormley 2006-12-16 16:05:55 UTC
Created attachment 109994 [details]
125 dpi, medium hinting
Comment 4 Clinton Gormley 2006-12-16 16:06:23 UTC
Created attachment 109995 [details]
125 dpi, full hinting
Comment 5 Clinton Gormley 2006-12-16 16:06:50 UTC
Created attachment 109996 [details]
126 dpi, no hinting
Comment 6 Clinton Gormley 2006-12-16 16:07:16 UTC
Created attachment 109997 [details]
126 dpi, slight hinting
Comment 7 Clinton Gormley 2006-12-16 16:07:42 UTC
Created attachment 109998 [details]
126 dpi, medium hinting
Comment 8 Clinton Gormley 2006-12-16 16:08:06 UTC
Created attachment 109999 [details]
126 dpi, full hinting
Comment 9 Federico Mena Quintero 2007-01-04 01:08:04 UTC
CCing Mike Fabian.

Mike, I lost track of all the changes that went into our Fontconfig setup for 10.2.  Do you know what the problem might be here?
Comment 10 Mike Fabian 2007-01-04 18:25:51 UTC
Apparently you have the Microsoft Webfonts installed and therefore
the default "Sans" font in your case is "Arial".

Comment 11 Clinton Gormley 2007-01-04 18:53:19 UTC
(In reply to comment #10)
> Apparently you have the Microsoft Webfonts installed and therefore
> the default "Sans" font in your case is "Arial".
> 

Indeed I do.  What would the default font be otherwise?  Also, i see no way of specifying your default choices for Sans, Serif etc?
Comment 12 Mike Fabian 2007-01-04 19:56:56 UTC
The system wide defaults are in /etc/fonts/suse-post-user.conf. The
section for "Sans" starts with:

	<alias>
		<family>sans-serif</family>
		<prefer>
			<family>Arial</family>
			<family>Albany AMT</family>
			<family>Verdana</family>
			<family>DejaVu Sans</family>
                        ...

"Arial" and "Verdana" are from the Microsoft Webfonts, i.e. of these
are installed the default will be "Arial". "Albany AMT" is from
the package "agfa-fonts.rpm" which is from the commercial add-on
directory of openSUSE 10.2. I.e. "Albany AMT" will be the default
if you install the commercial add-ons but not the Microsoft Webfonts.
"DejaVu Sans" is in dejavu.rpm and will be the default font for "Sans"
if you don't install any commercial add-ons.


To specify your own defaults, add rules as follows to the
file ~/.fonts.conf in your home directory:

        <alias>
                <family>sans-serif</family>
                <prefer>
                        <family>FreeSans</family>
                </prefer>
        </alias>
        <alias>
                <family>serif</family>
                <prefer>
                        <family>FreeSerif</family>
                </prefer>
        </alias>

        <alias>
                <family>monospace</family>
                <prefer>
                        <family>FreeMono</family>
                </prefer>
        </alias>


Instead of "FreeSans", "FreeSerif", "FreeMono", use the names of your favorite fonts
as listed by

    fc-list : family

(See also http://www.suse.de/~mfabian/suse-cjk/fonts-xft-fontconfig.html)

Comment 13 Mike Fabian 2007-01-04 19:59:37 UTC
Federico> Mike, I lost track of all the changes that went into our
Federico> Fontconfig setup for 10.2.  Do you know what the problem
Federico> might be here?

It has nothing to do with fontconfig, these effects can be reproduced
with ftview, i.e. by using freetype2 directly.

Comment 14 Clinton Gormley 2007-01-04 20:29:46 UTC
Created attachment 111561 [details]
132 dpi, slight hinting, with Deja Vu fonts at size 8

(In reply to comment #12)

I've set my user preferences (via ~/.fonts.conf) to prefer the DejaVu Sans fonts, and I have a good readable result (including in Firefox) at 132 dpi (which is the DPI that was detected) if i set the font sizes to 8 and hinting to slight.

See attachment.

One issue is that (eg) the file chooser opens up really small, and needs to be resized before being practically usable.
Comment 15 Clinton Gormley 2007-01-04 20:36:18 UTC
(In reply to comment #14)
> One issue is that (eg) the file chooser opens up really small, and needs to be
> resized before being practically usable.
> 

And, the Skype fonts are now enormous.
Comment 16 Mike Fabian 2007-01-05 15:37:40 UTC
Created attachment 111650 [details]
hinting-and-rounding.png

You can reproduce the “Problem” using only freetype (ftview) like this:

    ftview -r 125 10 /usr/share/fonts/truetype/arial.ttf
    ftview -r 126 10 /usr/share/fonts/truetype/arial.ttf

The screen shot shows the two ftview windows and two magnifications
with “xmag”.
Comment 17 Mike Fabian 2007-01-05 15:48:15 UTC
Created attachment 111651 [details]
no-hinting-no-rounding.png

The same screen shot as in comment #16 only with the hinting switched off
(‘h’ key in “ftview”).
Comment 18 Mike Fabian 2007-01-05 16:08:43 UTC
By changing the resolution, one can change the font sizes in very tiny
steps. You cannot do this with the point size because most user interfaces
(eg Gnome and KDE) only allow you to enter integer point sizes like
9, 10, ... but not floating point values like 10.13.

But as the resolution also influences the size, you can achieve small
size changes by changing the resolution in small steps.

If you do that with the font arial with hinting on, you see that the
line thickness jumps from 1 pixel to 2 pixels when the resolution goes
from 125 dpi to 126 dpi (while using a font size of 10 point).

This is completely normal as hinting tries to fit the lines to the
pixel grid. With full hinting, a vertical line will be only black with
no gray at the borders and will have an integer width (1, 2, 3,
... pixels). To make this possible, a vertical line may also be moved
a little bit to the left or to the right.

The same happens for horizontal lines.

Gray pixels are only added to diagonals to make the steps appear
smoother.

If you increase the size in very small increments, you will notice
that at a certain size the rounding in the hinter will switch from 1
to 2 pixels. Then it becomes noticeably bolder.

Without hinting you will never see a big effect when changing the font
size only a tiny bit because there is no rounding and no grid fitting.

Without hinting, gray pixels may be added to the left and the right of
vertical lines. Depending on the grayness value, the line may appear
to be for example 1.5 pixels wide when viewed from a distance where
your eyes cannot resolve the single pixels anymore.

But of course this reduces the contrast a lot.

With full hinting you have much less gray and more black and white,
i.e. much higher contrast. That is the point of hinting.  Most people
find that much easier to read because it looks less blurred.

The downside is that this high contrast can only be achieved by
distorting the glyphs a bit by rounding to integer line widths and
moving the lines a little bit.





Comment 19 Mike Fabian 2007-01-05 16:14:17 UTC
These rounding effects caused by hinting don't have anything to do
with the font “Arial”. It happens for all fonts.  If you try a
different font, for example “DejaVu Sans” and try with ftview, you
will see the same effect, only at a different resolution.

This is to be expected as the font has a different design and the
rounding to 2 pixels width instead of 1 pixel will therefore happen at
a different size.

Comment 20 Clinton Gormley 2007-01-05 16:20:28 UTC
For a hi resolution screen (such as my 1920 x 1200), should I be using hinting? or is it meant more for low resolution screens?

Also, why would Skype have such enormous letters? I am using Gnome, but I've tried using qtconfig to adjust the fonts, and it seems to have no effect on Skype.

thanks
Comment 21 Mike Fabian 2007-01-05 16:29:39 UTC
Clinton Gormey> I have a good readable result (including in Firefox)
Clinton Gormey> at 132 dpi (which is the DPI that was detected) if i
Clinton Gormey> set the font sizes to 8 and hinting to slight.

I like setting the hinting to "full" much better because of the higher
contrast but that seems to be a matter of taste.

Clinton Gormey> One issue is that (eg) the file chooser opens up
Clinton Gormey> really small, and needs to be resized before being
Clinton Gormey> practically usable.

The file chooser in firefox is influenced by the settings for the
“Application” font in gnome-font-properties.

I can set any font size I like there and it works in firefox as well.

(I have the problem that I have to restart firefox when doing this:
changes in gnome-font-properties are immediately applied to Gnome
applications including file choosers opened by them. This works fine
for most Gnome applications, for example “gedit”. But usually it
makes my firefox crash or hang. But after restarting firefox,
everything looks as expected.  I.e. this is a different, unrelated
bug).
Comment 22 Clinton Gormley 2007-01-05 16:35:59 UTC
> Clinton Gormey> One issue is that (eg) the file chooser opens up
> Clinton Gormey> really small, and needs to be resized before being
> Clinton Gormey> practically usable.
> 
> The file chooser in firefox is influenced by the settings for the
> “Application” font in gnome-font-properties.

Sorry, I was referring to the gnome file chooser, rather than the one for firefox (eg from gedit). I can resize it, but it doesn't remember its size.

> 
> I can set any font size I like there and it works in firefox as well.

Except for the hinting.  So the original issue I had was that I could have nice looking fonts at 132 dpi, but the toolbar fonts in Firefox would be horribly bold, and this changed dramatically between 125 and 126 dpi. And changing the hinting settings in Firefox's about:config made no difference at all.


Comment 23 Mike Fabian 2007-01-05 16:57:04 UTC
Clinton Gormey> Sorry, I was referring to the gnome file chooser,
Clinton Gormey> rather than the one for firefox (eg from gedit).

They look the same, don't they? I think this is the same file chooser.

Clinton Gormey> I can resize it, but it doesn't remember its size.

Same here. But this is a different problem, I believe it has nothing
to do with the fonts.
Comment 24 Mike Fabian 2007-01-05 17:06:15 UTC
Clinton Gormey> Except for the hinting.  So the original issue I had
Clinton Gormey> was that I could have nice looking fonts at 132 dpi,
Clinton Gormey> but the toolbar fonts in Firefox would be horribly
Clinton Gormey> bold, and this changed dramatically between 125 and
Clinton Gormey> 126 dpi. And changing the hinting settings in
Clinton Gormey> Firefox's about:config made no difference at all.

You are right, setting the hinting in gnome-font-properties doesn't
seem to have an influence on firefox. I can reproduce that
as well (I'm running a KDE session).

But you can solve the problem by adding the following to your
~/.fonts.conf:

<match target="font" >
  <edit mode="assign" name="rgba" >
   <const>rgb</const>
  </edit>
 </match>

 <match target="font" >
  <edit mode="assign" name="hinting" >
   <bool>true</bool>
  </edit>
 </match>

 <match target="font" >
  <edit mode="assign" name="autohint" >
   <bool>false</bool>
  </edit>
 </match>

 <match target="font" >
  <edit mode="assign" name="hintstyle" >
   <const>hintslight</const>
  </edit>
 </match>

 <match target="font" >
  <edit mode="assign" name="antialias" >
   <bool>true</bool>
  </edit>
 </match>

 <match target="font" >
  <edit mode="assign" name="dpi" >
   <double>132</double>
  </edit>
 </match>

Comment 25 Mike Fabian 2007-01-05 17:10:29 UTC
And restart firefox of course.

I don't know why the hintsettings from gnome-font-properties are not
applied to firefox although it is a GTK2 application.

In order to have consistent rendering throughout your system, I
recommend that you use the same settings in ~/.fonts.conf and in
gnome-font-properties. Then you will get the same appearance in Gnome
applications influenced by gnome-font-properties as in other
applications which are not (or only partly, like firefox) influenced
by gnome-font-properties (for example KDE/Qt applications and several
non-Gnome, non-KDE/Qt applications).
Comment 26 Mike Fabian 2007-01-05 17:21:45 UTC
Clinton Gormey> For a hi resolution screen (such as my 1920 x 1200),
Clinton Gormey> should I be using hinting?  or is it meant more for
Clinton Gormey> low resolution screens?

It's a matter of taste. I have 1920x1200 as well and prefer
full hinting.

Yes, hinting is a hack for low resolutions, but even a current
1920x1200 screen has still a rather low resolution.

To get good results without hinting one needs 600 dpi or more. 
Comment 27 Mike Fabian 2007-01-05 17:23:39 UTC
Clinton Gormey> Also, why would Skype have such enormous letters? I am
Clinton Gormey> using Gnome, but I've tried using qtconfig to adjust
Clinton Gormey> the fonts, and it seems to have no effect on Skype.

Skype is a qt3 application:

mfabian@magellan:~$ ldd /usr/bin/skype | grep qt
	libqt-mt.so.3 => /usr/lib/libqt-mt.so.3 (0xf7732000)
mfabian@magellan:~$

Therefore, you have to use the qt3 qtconfig to configure it,
not the qt4 qtconfig:

mfabian@magellan:~$ rpm -qf /usr/bin/qtconfig
libqt4-x11-4.2.1-18
mfabian@magellan:~$ rpm -qf /usr/lib/qt3/bin/qtconfig
qt3-3.3.7-12
mfabian@magellan:~$ 

Changing the font size for skype with /usr/lib/qt3/bin/qtconfig works
fine for me.
Comment 28 Mike Fabian 2007-01-05 17:47:05 UTC
I'll close this bug as WORKSFORME because there was no real problem
with the fonts here.

Of course it is not nice that one may need to setup the same
stuff in several places, i.e. ~/.fonts.conf and gnome-font-properties.

That is a known problem wich was already discussed several times (see
for example bug #193095 comment #31) but it will take some time to fix
this. Until then, setting the same values both in ~/.fonts.conf and
gnome-font-properties can be used as a workaround.