Closed Bug 442133 Opened 16 years ago Closed 16 years ago

Canvas text sizes depend on browser text zoom

Categories

(Core :: Graphics: Canvas2D, defect)

x86
Linux
defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: philip, Assigned: ebutler)

References

()

Details

Attachments

(2 files, 1 obsolete file)

To reproduce:
* Open http://philip.html5.org/tests/canvas/misc/changing-font-size.html
* Zoom the page in/out

Expected results:
The text drawn into the canvas should be a consistent size in canvas coordinate space units - "16px" should always correspond to 16 canvas units.

Actual results:
The canvas text size is affected by the browser's zoom.

This is a problem since it makes careful layouts much less reliable: people will assume a 16px font is about the same size as a rect(0, 0, w, 16), but if a user zooms in (or increases their text-only zoom) to 200% then that assumption will be very wrong.
Attached patch Patch (obsolete) — Splinter Review
use |AppUnitsPerCSSPixel()| instead of |AppUnitsPerDevPixel()| when creating |gfxFontStyle|.
Attachment #327323 - Flags: review?(vladimir)
Comment on attachment 327323 [details] [diff] [review]
Patch

Looks right to me, Eric can you confirm?
Attachment #327323 - Flags: superreview+
Attachment #327323 - Flags: review?(vladimir)
Attachment #327323 - Flags: review?(ebutler)
Comment on attachment 327323 [details] [diff] [review]
Patch

Worked when I tested it, and measureText and drawText seem to behave consistently under different zooms.
Attachment #327323 - Flags: review?(ebutler) → review+
Assignee: nobody → taken.spc
Keywords: checkin-needed
Comment on attachment 327323 [details] [diff] [review]
Patch

I just noticed that while the text draws correctly, measureText returns erroneous results when text-only zoom is used. measureText should return the same value regardless of zoom. This is because dev pixels are used in the drawText and measureText instead of CSS pixels
Attachment #327323 - Flags: review+ → review-
Keywords: checkin-needed
Attached patch ver 1.0Splinter Review
Includes the correction from the previous patch for full-page zoom, as well as a new correct for text-only zoom. Canvas text will now be completely unaffected by text zoom.
Attachment #327323 - Attachment is obsolete: true
Attachment #327875 - Flags: review?(vladimir)
Thanks ebutler for your patch!
# I'm being busy temporary :-(.
Assignee: taken.spc → ebutler
Pushed changeset 94b3ceae4041

http://hg.mozilla.org/index.cgi/mozilla-central/rev/94b3ceae4041
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
Verified fix on Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b2pre) Gecko/20081023 Minefield/3.1b2pre.
Status: RESOLVED → VERIFIED
I was working on a hack to figure out whether a character were supported in a given font (by converting to canvas to see whether boxed hex code patterns were shown or not), and I ran across the fact that measureText returns a different value depending on zoom if the character is not supported in the font.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: