Bug 125963

Summary: Subpixel layout: RenderLineBreak/RenderInline/RenderBlock::baselinePosition return value needs flooring (apple.com).
Product: WebKit Reporter: zalan <zalan>
Component: Layout and RenderingAssignee: zalan <zalan>
Status: RESOLVED INVALID    
Severity: Normal CC: hyatt, jonlee, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 126283    
Attachments:
Description Flags
test case
none
screenshots
none
screenshot (apple.com)
none
test case (apple.com) none

Description zalan 2013-12-18 16:44:29 PST
Created attachment 219589 [details]
test case

In RenderBlock::baselinePosition the baseline value is calculated as follows: font baseline + (lineHeight - fontHeight)/2
  return fontMetrics.ascent(baselineType) + (lineHeight(firstLine, direction, linePositionMode) - fontMetrics.height()) / 2;

The font metric values are CSS pixel values, lineHeight() returns LayoutUnit. While calculating the baseline, the CSS pixel values (font metrics) get converted to layout units  and at the end the result gets floored to CSS pixel value (return value). 
The floored return value can end up being different, if the /2 operation results in a negative value with fraction. 
subpixel on: ascent: 9px + offset: -0.5px = 8.5px -> 8px
subpixel off: ascent: 9px + offset: -0.5px -> 0px = 9px  

observed on cnn.com
Comment 1 zalan 2013-12-18 16:46:32 PST
<rdar://problem/15694755>
Comment 2 zalan 2013-12-18 19:36:14 PST
Created attachment 219605 [details]
screenshots

adding anim gif to demonstrate the off-by-one rendering.
Comment 3 zalan 2013-12-19 15:35:00 PST
Created attachment 219692 [details]
screenshot (apple.com)

RenderInline::baselinePosition has the exact same calculation as RenderBlock and the missing rounding shows up on apple.com (screenshot attached)
Comment 4 zalan 2013-12-19 15:53:07 PST
Created attachment 219694 [details]
test case (apple.com)
Comment 5 zalan 2013-12-23 13:38:45 PST
And by flooring, I meant bias vertical centering similar to bug 101848
Comment 6 zalan 2014-01-15 10:34:42 PST
The current subpixel rendering is closer to FF's rendering than it would be with the rounding (supbixel off in practice)