Closed Bug 1646926 Opened 5 years ago Closed 5 years ago

Canvas.measureText returns actualBoundingBoxLeft values with wrong sign

Categories

(Core :: Graphics: Canvas2D, defect)

77 Branch
x86_64
macOS
defect

Tracking

()

RESOLVED FIXED
mozilla79
Tracking Status
firefox79 --- fixed

People

(Reporter: mozillabugs, Assigned: jfkthame)

Details

Attachments

(4 files)

The method CanvasRenderingContext2D.measureText() returns values for the actualBoundingBoxLeft property of the returned TextMetrics object that consistently have the wrong sign.

The specification says: “The distance parallel to the baseline from the alignment point given by the textAlign attribute to the left side of the bounding rectangle of the given text, in CSS pixels; positive numbers indicating a distance going left from the given alignment point.”

To reproduce:

– Go to
https://lindenbergsoftware.com/mozilla/canvas.metrics.html
On this page, a number of Javanese strings are rendered with Noto Sans Javanese, in the “Text” column as normal web content, in the “Canvas” column by drawing into a canvas. The actualBoundingBox* properties of the TextMetrics object returned by CanvasRenderingContext2D.measureText() are shown in the rightmost column.

– Compare the renderings in the “Text” column with the “left” values in the rightmost column.

Expected result:

– Where a base character stands by itself, or has a mark attached that does not extend to the left of the base character, the “left” value should normally be slightly negative, indicating that there’s some white space between the origin and the left side of the glyph. Where a subjoined consonant extends to the left of the base consonant, the “left” value should normally be positive to indicate that the mark’s left side is at “a distance going left from the given alignment point”.

Actual result:

– The actual results are the opposite: Where a base character stands by itself, or has a mark attached that does not extend to the left of the base character, the “left” value is slightly positive. Where a subjoined consonant extends to the left of the base consonant, the “left” value is negative. See attached screenshots.

Configuration:

Firefox 77.0.1 on macOS 10.14.6 on iMac 27".

Hi Norbert, thank you for the bug report!

Could you please attach a copy of your about:support information? Do you know whether this has always been incorrect, or whether it is a regression?

Severity: -- → S3
Flags: needinfo?(mozillabugs)

Looks like we simply overlooked the reversed sign of the actualBoundingBoxLeft attribute when this was implemented in bug 1102584. Not a regression, just a bug in a recently-implemented feature.

Assignee: nobody → jfkthame
Status: NEW → ASSIGNED

This should fix the behavior; with the patch, Norbert's testcase looks much better (and more similar to Chrome's results, though text measurements are often not exactly identical).

If there's no existing testcase that covers this, we should add one; I'll see what tryserver has to say about it.

Thank you for fixing this so quickly, Jonathan! Looks like no additional info is needed from me.

Flags: needinfo?(mozillabugs)
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/2a19f4355aed Fix the sign of canvas TextMetrics.actualBoundingBoxLeft return value. r=lsalzman

Marking leave-open for now, pending review on the wpt-update patch.

Keywords: leave-open
Keywords: leave-open
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/89c951097806 Additional tests for actualBoundingBox* attributes, including sign of Left value. r=lsalzman
Failed to create upstream wpt PR due to merge conflicts. This requires fixup from a wpt sync admin.
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla79
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: