Bug 51566

Summary: TextMetrics::width is an integer, but the member is a float
Product: WebKit Reporter: Evan Martin <evan>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, hyatt, jamesr, mitz
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Bug Depends on:    
Bug Blocks: 51551    
Attachments:
Description Flags
Patch none

Description Evan Martin 2010-12-23 15:20:43 PST
In WebCore/html/TextMetrics.idl it says:
    readonly attribute float width;
in .../TextMetrics.h:
    float m_width;

But there's a getter with this confusing comment:

    // FIXME: Is coercing to an integer value intentional? If so, there should be a static_cast<unsigned>() here.
    unsigned width() const { return m_width; }

From my greps around, it appears this getter is unused, but I unsure how the idl interacts with this (perhaps the idl generates code that calls width().)
Comment 1 Evan Martin 2010-12-23 15:26:15 PST
CC hyatt, original author of the code (correct bug this time)
Comment 2 Evan Martin 2010-12-23 15:28:41 PST
in LayoutTests/fast/canvas/canvas-text-baseline.html
if I dump out all the widths found by ctx.measureText(text).width
they are always integers.  Not sure if it's intentional (or perhaps in Chrome we always have integer width fonts for other reasons)
Comment 3 Evan Martin 2010-12-23 16:26:23 PST
I tried changing it to a float and still got integers out.

Spec says the width should be "CSS pixels", which I think can be floating point.  I'll upload a patch and see what y'all think.

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-measuretext
Comment 4 Evan Martin 2010-12-23 16:43:13 PST
Created attachment 77385 [details]
Patch
Comment 5 Evan Martin 2010-12-23 16:44:34 PST
I tried modifying the test to use text of width 32.1 pixels, but even after this change the "width" field came out as an integer.  Again, this could be due to some other code in Chrome rounding text widths.
Comment 6 WebKit Commit Bot 2010-12-24 03:49:32 PST
The commit-queue encountered the following flaky tests while processing attachment 77385 [details]:

inspector/elements-panel-styles.html bug 50987 (author: pfeldman@chromium.org)
The commit-queue is continuing to process your patch.
Comment 7 WebKit Commit Bot 2010-12-24 03:50:48 PST
Comment on attachment 77385 [details]
Patch

Clearing flags on attachment: 77385

Committed r74628: <http://trac.webkit.org/changeset/74628>
Comment 8 WebKit Commit Bot 2010-12-24 03:50:55 PST
All reviewed patches have been landed.  Closing bug.