Bug 32794

Summary: With text-rendering: optimizelegibility, sometimes lines run too long
Product: WebKit Reporter: mitz
Component: TextAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: bdakin, webkit.review.bot
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Mac   
OS: OS X 10.6   
Attachments:
Description Flags
Test case
none
Allow trailing space to affect kerning when measuring a word sam: review+

Description mitz 2009-12-20 08:55:46 PST
The attached test case shows the using text-rendering: optimizelegibility can cause lines to break too late, and the effect that it has on left-aligned and on justified text. Perhaps there is a discrepancy between how text is measured for the purpose of line breaking and how it’s actually rendered afterwards.
Comment 1 mitz 2009-12-20 08:56:38 PST
Created attachment 45282 [details]
Test case
Comment 2 mitz 2009-12-20 08:57:03 PST
<rdar://problem/7488126>
Comment 3 mitz 2010-01-06 17:17:47 PST
Created attachment 46010 [details]
Allow trailing space to affect kerning when measuring a word
Comment 4 WebKit Review Bot 2010-01-06 17:19:13 PST
style-queue ran check-webkit-style on attachment 46010 [details] without any errors.
Comment 5 Darin Adler 2010-01-06 17:29:22 PST
Comment on attachment 46010 [details]
Allow trailing space to affect kerning when measuring a word

> +            TextRenderingMode textRenderingMode = f.fontDescription().textRenderingMode();
> +            // Non-zero only when kerning is enabled, in which case we measure words with their trailing
> +            // space, then subtract its width.
> +            int wordTrailingSpaceWidth = textRenderingMode == OptimizeLegibility || textRenderingMode == GeometricPrecision ? f.spaceWidth() + wordSpacing : 0;

I think it would be clearer to have a function named allowsKerning or something like that. It could contain:

    TextRenderingMode textRenderingMode = f.fontDescription().textRenderingMode();
    textRenderingMode == OptimizeLegibility || textRenderingMode == GeometricPrecision

Then you could saw:

    wordTrailingSpaceWidth = allowsKerning(f) ? f.spaceWidth() + wordSpacing : 0;

Maybe there's a better name than "allows kerning", though.
Comment 6 mitz 2010-01-06 17:39:28 PST
(In reply to comment #5)
> (From update of attachment 46010 [details])
> > +            TextRenderingMode textRenderingMode = f.fontDescription().textRenderingMode();
> > +            // Non-zero only when kerning is enabled, in which case we measure words with their trailing
> > +            // space, then subtract its width.
> > +            int wordTrailingSpaceWidth = textRenderingMode == OptimizeLegibility || textRenderingMode == GeometricPrecision ? f.spaceWidth() + wordSpacing : 0;
> 
> I think it would be clearer to have a function named allowsKerning or something
> like that. It could contain:
> 
>     TextRenderingMode textRenderingMode =
> f.fontDescription().textRenderingMode();
>     textRenderingMode == OptimizeLegibility || textRenderingMode ==
> GeometricPrecision
> 
> Then you could saw:
> 
>     wordTrailingSpaceWidth = allowsKerning(f) ? f.spaceWidth() + wordSpacing :
> 0;
> 
> Maybe there's a better name than "allows kerning", though.

I intend to add two Font methods (one for kerning and one for ligatures) and deploy them here and in the many other places that currently access the TextRenderingMode.
Comment 7 mitz 2010-01-06 17:42:15 PST
Fixed in <http://trac.webkit.org/projects/webkit/changeset/52889>.