Bug 16715

Summary: [Gtk] Uneven glyph spacing with subpixel antialiasing
Product: WebKit Reporter: Sylvain Pasche <sylvain.pasche>
Component: TextAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: alp
Priority: P2 Keywords: Gtk
Version: 528+ (Nightly build)   
Hardware: PC   
OS: Linux   
URL: data:text/html,<div style="font-family: verdana;">simply participating</div>
Attachments:
Description Flags
screenshot showing verdana font
none
comparison webkit gecko
none
demonstrative hack (not for checkin)
none
Using font options from gdk screen alp: review+

Description Sylvain Pasche 2008-01-02 17:33:21 PST
I saw this initially on the gnome.org website when using the Gtk port. I have installed the msttcorefonts on the system, so I guess the Verdana.ttf font from there is used. I'll attach a screenshot.
Comment 1 Sylvain Pasche 2008-01-02 17:33:54 PST
Created attachment 18246 [details]
screenshot showing verdana font
Comment 2 Sylvain Pasche 2008-01-02 17:35:39 PST
On the screenshot, you can see that the "i" character is no centered between the "s" and the "m" for instance. The gap between the "p" and the "l" seems to large too.
Comment 3 Sylvain Pasche 2008-01-04 03:32:24 PST
Ok, this is not specific to Verdana font (but most visible with it at 14px).

Happens only when you have subpixel smoothing active (under GNOME in System > Preferences > Appearance > Fonts > Subpixel smoothing (LCD) ).
Comment 4 Sylvain Pasche 2008-01-04 04:08:23 PST
Created attachment 18261 [details]
comparison webkit gecko

Testcase: data:text/html,<div style="font-family: verdana;font-size: 14px">simply participating</div>

Webkit on top, gecko 1.9 on bottom
Comment 5 Sylvain Pasche 2008-01-04 04:23:42 PST
Created attachment 18262 [details]
demonstrative hack (not for checkin)

The attached patch fixes the issue (but will break in other situations).
Comment 6 Sylvain Pasche 2008-01-04 04:40:03 PST
Some explanations:

The scaled font needs a font_options_t object when it is created in FontPlatformData::FontPlatformData. The parameter in this font_options_t object should match the settings of the destination surface, like antialiasing, hinting and others.

For retrieving these settings, we need a surface (which can be obtained from the cairo_t object). The trouble is that we do not have the cairo_t object available yet when the scaled font is created. If we had it at this time, we could build the font_options object like:

    cairo_surface_t* target = cairo_get_target(cr);
    cairo_font_options_t* options = cairo_font_options_create();
    cairo_surface_get_font_options(target, options);
...
    cairo_font_options_destroy(options);

Comment 7 Sylvain Pasche 2008-01-11 17:18:35 PST
Created attachment 18401 [details]
Using font options from gdk screen

I found this gdk method to fetch the font option from a gdk screen.
Comment 8 Alp Toker 2008-01-11 18:20:05 PST
Comment on attachment 18401 [details]
Using font options from gdk screen

r=me

I'm making two small changes before landing this:

1) GTK_CHECK_VERSION(2,10,0)

2) null-check for gdk_screen_get_default() so we don't break headless operation.
Comment 9 Alp Toker 2008-01-11 18:23:16 PST
Landed in r29426.