Bug 93263

Summary: [Qt] Monospace font does not render in proper sizes
Product: WebKit Reporter: mdesign <m.karoly>
Component: TextAssignee: Allan Sandfeld Jensen <allan.jensen>
Status: RESOLVED FIXED    
Severity: Normal CC: allan.jensen, ap, mitz, noam, pierre.rossi, trevor, webkit.org, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 36532    
Attachments:
Description Flags
Test html file
none
Firefox 14 - renders right
none
qtwebkit fails
none
WebKit-r124698 fails
none
Patch
none
Patch jturcotte: review+

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:

Overview:
 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:
http://www.smashingmagazine.com/2012/04/24/a-closer-look-at-font-rendering/

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:
/src/3rdparty/webkit/WebCore/platform/graphics/qt/FontPlatformDataQt.cpp
font.setStyleStrategy(QFont::ForceIntegerMetrics);
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]
Patch
Comment 13 Jocelyn Turcotte 2013-03-19 06:15:50 PDT
Comment on attachment 193767 [details]
Patch

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

Pierre, any opinion?

> Source/WebCore/platform/graphics/qt/FontPlatformDataQt.cpp:74
> +#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)

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]
Patch
Comment 15 Pierre Rossi 2013-03-19 07:12:16 PDT
Comment on attachment 193814 [details]
Patch

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>