W3C home > Mailing lists > Public > whatwg@whatwg.org > November 2013

Re: [whatwg] CanvasRenderingContext2D with addPath, currentPath

From: Rik Cabanier <cabanier@gmail.com>
Date: Mon, 4 Nov 2013 20:22:21 -0800
Message-ID: <CAGN7qDBZsZRHfw=YffWRw5+3C94X5bD5iNUYK+btPLuAPetMEQ@mail.gmail.com>
To: "Robert O'Callahan" <robert@ocallahan.org>
Cc: "whatwg@whatwg.org" <whatwg@whatwg.org>, Jürg Lehni <lists@scratchdisk.com>, Ian Hickson <ian@hixie.ch>
On Mon, Nov 4, 2013 at 7:29 PM, Rik Cabanier <cabanier@gmail.com> wrote:

> On Mon, Nov 4, 2013 at 5:21 PM, Robert O'Callahan <robert@ocallahan.org>wrote:
>> If you return a path in user-space, what do you get if you call
>> getCurrentPath with a singular transform?
>>   ctx.moveTo(0,0);
>>   ctx.lineTo(1,1);
>>   ctx.scale(0,0);
>>   var p = ctx.getCurrentPath();
> I mixed up my terms :-)
> getCurrentPath should return the path in device coordinates (not user).
> However, for your example, I'm unsure what the right solution is. The
> canvas specification is silent on what the behavior is for non-invertible
> matrices.
> I think setting scale(0,0) or another matrix operation that is not
> reversible, should remove drawing operations from the state because:
> - how would you stroke with such a matrix?
> - how do patterns operate? the same for gradient fills.
> - how would you pass this to the underlying graphics library?
> - certain operators such as 'arc' rely on doing the transform in reverse.
> I seem to remember that for SVG we decided that non-invertible matrices
> don't draw either.

After pondering this some more and looking at the different
implementations, I propose the following:
if the user sets a non-invertible matrix, the canvas context should be in a
state that ignores all path drawing operations, stroke/fill calls and all
other ctm operations (apart from setTransform). setCurrentPath is also
ignored and getCurrentPath should return an empty path.
If the ctm becomes invertible again (from a setTransform or a restore),
drawing operations pick up again with the currentPoint that was active when
the non-invertible matrix was set.

I could be convinced that set/getCurrentPath should still work...

so If I expand your example a bit:

var p = ctx.getCurrentPath(); // return empty path

ctx.stroke(); // nothing happens

p = ctx.getCurrentPath(); // return path with moveto/lineto
ctx.stroke(); // draw line

This would match what WebKit and Blink are doing.
Firefox gets in a bad state as soon as you set a non-invertible matrix but
we could fix that ;-)
IE keeps drawing and even strokes when scale(0,0) is set.

It would be nice to have interop...
Received on Tuesday, 5 November 2013 04:22:48 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 17:00:13 UTC