I can reproduce with Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; rv:2.0b6pre) Gecko/20100904 Firefox/4.0b6pre. Seems to be canvas-specific.
Status: UNCONFIRMED → NEW
Component: General → Canvas: 2D
Ever confirmed: true
Product: Firefox → Core
QA Contact: general → canvas.2d
Version: unspecified → Trunk
This is a bug in the strokeStyle getter. It does: 971 PRUint32 alpha = NS_GET_A(aColor) * 100000 / 255; 972 CopyUTF8toUTF16(nsPrintfCString(100, "rgba(%d, %d, %d, 0.%d)", 973 NS_GET_R(aColor), 974 NS_GET_G(aColor), 975 NS_GET_B(aColor), 976 alpha), 977 aStr); In particular, this will give the wrong answer for any alpha channel value less than or equal to 26 (which corresponds to a floating-point alpha of 0.098 or less).
Summary: canvas strokeStyle opacity 0.09 is interpreted as 0.9 → canvas strokeStyle getter mishandles opacity values smaller than 0.098
The right solution is probably to stop using an nsPrintfCString for this. In fact, I wish we could just reuse the nsCSSValue stringification code here, but that uses "transparent" for NS_RGBA(0,0,0,), which we may not want here. If we didn't have to do the #rrggbb thing for the alpha == 1 case, we could at least factor out the nsCSSValue code....
Why do we even -have- that code in there.. what's wrong with just a %f with a precision!
It's from bug 329593, too bad I didn't decide to fix it properly then: http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/content/canvas/src/nsCanvasRenderingContext2D.cpp&rev=1.128#570 570 // "%0.5f" in nsPrintfCString would use the locale-specific 571 // decimal separator. That's why we have to do this:
Created attachment 472634 [details] [diff] [review] Fix
Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED
Attachment #472634 - Flags: review?(vladimir)
Priority: -- → P1
Whiteboard: [need review]
Comment on attachment 472634 [details] [diff] [review] Fix Looks great, thanks -- sorry for the slow review!
Whiteboard: [need review] → [need landing]
Pushed http://hg.mozilla.org/mozilla-central/rev/bcff46a05021 And then bustage fixes: http://hg.mozilla.org/mozilla-central/rev/5eb5819ad5bd http://hg.mozilla.org/mozilla-central/rev/39db042d6737
Status: ASSIGNED → RESOLVED
Last Resolved: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla2.0b8
Whiteboard: [need landing]
Target Milestone: mozilla2.0b8 → mozilla2.0b7
You need to log in before you can comment on or make changes to this bug.