Bug 93263 - [Qt] Monospace font does not render in proper sizes
Summary: [Qt] Monospace font does not render in proper sizes
Alias: None
Product: WebKit
Classification: Unclassified
Component: Text (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Allan Sandfeld Jensen
Depends on:
Blocks: 36532
  Show dependency treegraph
Reported: 2012-08-06 06:15 PDT by mdesign
Modified: 2013-04-03 05:34 PDT (History)
8 users (show)

See Also:

Test html file (6.45 KB, text/html)
2012-08-06 06:15 PDT, mdesign
no flags Details
Firefox 14 - renders right (29.26 KB, image/png)
2012-08-06 06:15 PDT, mdesign
no flags Details
qtwebkit fails (40.89 KB, image/png)
2012-08-06 06:16 PDT, mdesign
no flags Details
WebKit-r124698 fails (211.75 KB, image/jpeg)
2012-08-06 06:18 PDT, mdesign
no flags Details
Patch (1.88 KB, patch)
2013-03-19 02:18 PDT, Allan Sandfeld Jensen
no flags Details | Formatted Diff | Diff
Patch (2.00 KB, patch)
2013-03-19 06:52 PDT, Allan Sandfeld Jensen
jturcotte: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description mdesign 2012-08-06 06:15:05 PDT
Created attachment 156674 [details]
Test html file

Dear Devs!

Monospace font does not render in proper sizes:

 I can't set a monospace font (eg: Courier) to 10CPI size. Theoretically Courier 12pt = 10CPI. 

Steps to Reproduce: 
 Open the attachment in webkit

Actual Results:
 Notice that the text does not fill the grey box

Expected Results:
 Open the text html in Firefox 14, the block with 12pt Courier font exactly fills the box.
 Open a microsoft word or libreoffice writer, create a text with 12pt Courier font, it prints exactly the same size, like firefox.

Build Date & Platform:
 Linux 2.6.32-21-generic-pae #32-Ubuntu SMP Fri Apr 16 09:39:35 UTC 2010 i686 GNU/Linux

Additional Builds and Platforms:
 Linux 3.2.0-27-generic-pae #43-Ubuntu SMP Fri Jul 6 15:06:05 UTC 2012 i686 i686 i386 GNU/Linux
 Windows 7 (WebKit.exe#WebKit-r124698)
Comment 1 mdesign 2012-08-06 06:15:56 PDT
Created attachment 156675 [details]
Firefox 14 - renders right
Comment 2 mdesign 2012-08-06 06:16:17 PDT
Created attachment 156676 [details]
qtwebkit fails
Comment 3 mdesign 2012-08-06 06:18:07 PDT
Created attachment 156678 [details]
WebKit-r124698 fails
Comment 4 mdesign 2012-08-07 02:48:37 PDT
If anyone can help, where can i start hacking the code, don't hesitate, please share with me!:)
Comment 5 mdesign 2012-08-20 22:20:33 PDT
Does anyone know what libs responsible for the font rendering in webkit on different operating systems?

The proper rendering in Firefox 14 and Internet Explorer 9 is done via new DirectWrite API. Before using DirectWrite the monospace rendering failed same way like webkit.

There is a list about different browsers and rendering engines in this article:

I tested every browser on windows. Just the browsers with DirectWrite engine renders properly.
Comment 6 Allan Sandfeld Jensen 2012-12-05 05:43:04 PST
Interesting. Have you tried compiling WebKit yourself? If you do, you can try to activate SUBPIXEL_LAYOUT and see if that helps. It looks like sizes are rounded poorly.
Comment 7 mdesign 2012-12-05 05:52:14 PST
Im using webkit in Qt. I found a workaround:

Commenting out this row in this file makes the monospace fonts render correctly:
Comment 8 Trevor North 2013-01-28 09:25:49 PST
In my testing the workaround suggested in comment #7 also results in a general improvement in font kerning which was previously often very poor.
Comment 9 Stefan Neufeind 2013-02-09 13:23:37 PST
Any news on this?
Found it mentioned here: https://groups.google.com/forum/?fromgroups=#!topic/wkhtmltopdf-dev/SWLkI5eHi_4
Comment 10 mdesign 2013-02-12 07:23:44 PST
Dear Allan Sandfeld Jensen!

I using Qt, so i suggested a workaround for it.
But the issue exists in webkit too (as you can see it in the screenshots)

Best regards,
Károly Marton
Comment 11 Allan Sandfeld Jensen 2013-03-13 03:11:19 PDT
I think there a two ways about this. 

One, we need to establish if the bug #36532 still applies on Mac. Can we remove ForceIntegerMetrics.

Second, maybe ForceIntegerMetrics is being too aggressive, and should only force basic metrics to integers but not advances. I can confirm that removing the forced rounding on advances also solves this bug.
Comment 12 Allan Sandfeld Jensen 2013-03-19 02:18:31 PDT
Created attachment 193767 [details]
Comment 13 Jocelyn Turcotte 2013-03-19 06:15:50 PDT
Comment on attachment 193767 [details]

View in context: https://bugs.webkit.org/attachment.cgi?id=193767&action=review

Pierre, any opinion?

> Source/WebCore/platform/graphics/qt/FontPlatformDataQt.cpp:74

Please add a comment in the code explaining why the version guard is used.
Comment 14 Allan Sandfeld Jensen 2013-03-19 06:52:48 PDT
Created attachment 193814 [details]
Comment 15 Pierre Rossi 2013-03-19 07:12:16 PDT
Comment on attachment 193814 [details]

View in context: https://bugs.webkit.org/attachment.cgi?id=193814&action=review

LGTM. That seems like the sensible approach (not affecting < 5.1 behaviour I mean)

> Source/WebCore/platform/graphics/qt/FontPlatformDataQt.cpp:75
> +    // Kept enabled for Qt<5.1 to maintain stable baselines for 5.0.

coding style: Qt < 5.1. Ah wait no, I'm told it doesn't matter for comments ;)

> Source/WebCore/platform/graphics/qt/FontPlatformDataQt.cpp:76
> +    // FIXME: Remove when we depend on Qt 5.1.

not sure if that was strictly necessary... But it'll go away with the whole ifdef chunk soon enough :)
Comment 16 Allan Sandfeld Jensen 2013-03-19 07:31:00 PDT
Committed r146203: <http://trac.webkit.org/changeset/146203>
Comment 17 Allan Sandfeld Jensen 2013-04-03 05:34:04 PDT
Committed r147544: <http://trac.webkit.org/changeset/147544>