Bug 57485 - [test case] Wrong font selected when HTML specifies fontconfig aliases
Summary: [test case] Wrong font selected when HTML specifies fontconfig aliases
Status: RESOLVED UNMAINTAINED
Alias: None
Product: konqueror
Classification: Applications
Component: khtml renderer (show other bugs)
Version: 3.1.2
Platform: RedHat Enterprise Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
: 74286 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-04-20 22:59 UTC by Philippe A
Modified: 2012-06-18 14:11 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Fontconfig config file. (8.29 KB, text/plain)
2003-04-20 23:00 UTC, Philippe A
Details
Sample HTML (1.45 KB, text/html)
2003-04-20 23:01 UTC, Philippe A
Details
Shows how strings are rendered on my system. (30.47 KB, image/png)
2003-04-20 23:02 UTC, Philippe A
Details
Sample html testing font selection in Konqueror 3.5.2. (839 bytes, text/html)
2006-04-19 01:51 UTC, Philippe A
Details
Shows how Konqueror 3.5.2 renders fonts. (39.28 KB, image/png)
2006-04-19 01:51 UTC, Philippe A
Details
New testcase (296 bytes, text/html)
2008-04-06 03:52 UTC, Michael Leupold
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe A 2003-04-20 22:59:26 UTC
Version:           3.1.12 Red Hat (Using KDE 3.1-10 Red Hat) (using KDE KDE 3.1.1)
Installed from:    RedHat RPMs
OS:          Linux

Consider the simple HTML code and fontconfig files in attachment. I expect this combination of configuration and HTLM to yield the following results:

A. Since the preferred sans-serif font is defined as "Luxi Sans", strings 1,2,3,4 should all be rendered with this font, and so the "TEST" word should look exactly the same in these four strings.

B. Since the preferred serif font is defined as "Nimbus Roman No9 L", strings 5 and 6 should be rendered with this font, and so the "TEST" word should look exactly the same in these two strings.

C. Since the preferred monospace font is defined as "Luxi Mono", strings 7,8,9 should be rendered with this font, and so the "TEST" word should look exactly the same in these three strings.

------------------------------------
The actual results are the following
------------------------------------

B. [GOOD] Strings 5 and 6 are rendered with the default serif font. They look identical when they're compared with xmag.

A. Two out of four strings that should be rendered with the sans-serif font are rendered incorrectly. [BAD] String 3 seems to be rendered with the default serif font, though it is bigger than strings 5 and 6. [BAD] String 4 is rendered with the Comic Sans MS font. [GOOD] Strings 1 and 2 look identical in xmag.

C. One of the strings that should be rendered with the monospace font is rendered incorrectly. [BAD] String 8 seems to be rendered with "Andale Mono", which is my 2nd preferred monospace font. It should be rendered with Luxi Mono. [GOOD] Strings 7 and 9 look identical in xmag.

---------------
Further testing
---------------

In fonts.conf, uncomment the following block of text near the top of the file.

	<match target="pattern">
		<test qual="any" name="family">
			<string>sans-serif</string>
		</test>
		<edit name="family" mode="assign">
			<string>serif</string>
		</edit>
	</match>

Stop all running instances of Konqueror and reopen the html page. This change of configuration should force 'sans', 'sans serif' and 'sans-serif' faces to adopt the default 'serif' font. In other words, strings 2,3,4 should be made identical to strings 5 and 6. It is not exactly what will happen:

[GOOD] It will work for string 2 (using 'sans-serif' face).

[BAD] String 3 will be using a serif face, but it's size will be different than strings 2,5,6.

[BAD] String 4 will still render with Comic Sans.

-------------------------------------
Configuration details and final notes
-------------------------------------

rh9 as base distrib
corefonts.sourceforge.net TTF package 
fontconfig 2.1.94
freetype 2.1.4
openoffice from rh9 distrib, from which the Andale Mono is coming from

Default fontconfig and freetype packages from rh9 distribution have been upgraded in an attempt to solve the problem. 

I noticed that removing the corefonts package changed the results, but there still was font selection problems.

I've mentionned this problem on fontconfig@fontconfig.org mailing list already (apr 19th, 20th 2003).
Comment 1 Philippe A 2003-04-20 23:00:24 UTC
Created attachment 1393 [details]
Fontconfig config file.
Comment 2 Philippe A 2003-04-20 23:01:24 UTC
Created attachment 1394 [details]
Sample HTML
Comment 3 Philippe A 2003-04-20 23:02:54 UTC
Created attachment 1395 [details]
Shows how strings are rendered on my system.
Comment 4 Philippe A 2003-04-20 23:10:16 UTC
I forgot to mentionned one thing. I did the same test with Mozilla 1.3. It is
generally better than Konqueror at picking the right font. However even Mozilla
has a problem selecting the right font when requesting the 'monospace' face.

It is also worthy of note that I have not defined user CSS and that I have not
setup specific fonts in Konqueror, other than general family names "Sans", "Sans
serif" and "Monospace".
Comment 5 Philippe A 2004-03-18 04:34:16 UTC
I still have font selection problems in :
KDE 3.2.1 
Konqueror 3.2.1-0.1
RedHat binary RPMs 
OS Fedora 1

If you find my long explanation hard to understand, just
open the sample html files. See how the "TEST" string 
renders with different spellings of font families. Even
though the family is the same, different fonts will be
picked.
Comment 6 Stephan Kulow 2004-03-18 10:35:49 UTC
mozilla requests the font with font config when it has to render them. 
konqueror removes all fonts in the specified list that aren't present on the system. As fontconfig doesn't give "mono", "sans-serif" or whatever back to the
applications, konqueror doesn't see them and falls back to the default font: sans in your case.

Comment 7 Philippe A 2004-05-22 16:11:00 UTC
Konq still has this behavior in KDE 3.2.2.
Comment 8 Marijn Schouten 2006-04-18 18:05:36 UTC
I good short description with less examples would be nice if this is still an issue.
Comment 9 Philippe A 2006-04-19 01:51:36 UTC
Created attachment 15681 [details]
Sample html testing font selection in Konqueror 3.5.2.
Comment 10 Philippe A 2006-04-19 01:51:52 UTC
Created attachment 15682 [details]
Shows how Konqueror 3.5.2 renders fonts.
Comment 11 Philippe A 2006-04-19 02:07:58 UTC
Things have improved as of KDE 3.5.2 (RPM packages from kde-redhat.sf.net, FC4), but not everything is ok. Allow me to reexplain clearly. 

In my ~/.fonts.conf file, I have specified what fonts I want whenever generic font family names are used.

<!-- serif font shall be Times New Roman -->
<alias>
  <family>serif</family>
  <prefer>
   <family>Times New Roman</family>
  </prefer>
</alias>

<!-- sans-serif font shall be verdana -->
<alias>
  <family>sans-serif</family>
  <prefer>
   <family>verdana</family>
  </prefer>
</alias>

<!-- monospace font shall be courier new -->
<alias>
  <family>monospace</family>
  <prefer>
   <family>Courier New</family>
  </prefer>
</alias>

To see how Konqueror copes with that, I have written a small html file (id=15681). It displays "TEST" multiple times with equivalent font faces. Open the png and you will see what the result is in Konqueror:
[ok] The 4 strings using sans serif fonts all use the same font.
[ok] The 2 strings using serif fonts all use the same font.
[ko] One of the three strings using monospace font does not render correctly.

This is in spite of the following definition in /etc/fonts/fonts.conf:

<match target="pattern">
  <test qual="any" name="family">
    <string>mono</string>
  </test>
  <edit name="family" mode="assign">
    <string>monospace</string>
  </edit>
</match>

If you open the same html in Firefox, the result will be correct.
Comment 12 apodtele 2007-11-03 05:18:08 UTC
One long-standing bug, heh? Modern fontconfig has FcFontMatch.
http://www.fontconfig.org/fontconfig-devel/r2109.html
Shouldn't konqueror just use that to select a font? 

It seems that it doesn't, because otherwise it would use Liberation Sans when asked for Arial,sans-serif on my system. Despite default DejaVu Sans, available Liberation Sans is a better match for Arial and fontconfig knows it.

 
Comment 13 Michael Leupold 2008-04-06 03:50:46 UTC
This bug is reproducible using a simpler testcase.
Add the following to your ~/.fonts.conf:
<fontconfig> <!-- should already be present -->
  <match target="pattern">
    <test qual="any" name="family">
      <string>nonexistantbugfont</string>
    </test>
    <edit name="family" mode="assign">
      <string>monospace</string>
    </edit>
  </match>

  <!-- rest of file -->
</fontconfig> <!-- should already be present -->
Comment 14 Michael Leupold 2008-04-06 03:52:18 UTC
Created attachment 24218 [details]
New testcase

When the changes to ~/fonts.conf have been made both lines on this page should
be displayed the same, however konqueror doesn't recognize the alias we defined
and renders the second line using the default font.
Comment 15 Michael Leupold 2008-04-06 06:18:52 UTC
Confirmed on trunk r793971.
Comment 16 apodtele 2008-04-07 20:18:09 UTC
If you "translate" some fontconfig configuration files into some Qt configuration files, you may be able to workaround the problem. AFAIK, konqueror understandably relies on Qt rather than fontconfig.

There is even a python script for that on the internet, I believe.

So the bug is actually in Qt. Qt should either improve its font intelligence, or, more realistically, should respect and rely on fontconfig.


 
Comment 17 Michael Leupold 2008-04-13 18:27:23 UTC
*** Bug 74286 has been marked as a duplicate of this bug. ***
Comment 18 Rex Dieter 2009-01-14 15:30:53 UTC
qt-copy's 0263-fix-fontconfig-handling.diff may (or may not?) be relevant here.
Comment 19 Myriam Schweingruber 2012-06-18 14:11:55 UTC
Message from the Bugsquad and Konqueror teams:
This bug is closed as outdated, as we do not have the manpower to maintain the KDE3 version anymore.
If you still can reproduce this issue with Konqueror 4.8.4 or later, please open a new report.
Thank you for your understanding.