[whatwg] Stroking algorithm in Canvas 2d

Rik Cabanier cabanier at gmail.com
Fri Sep 27 20:58:49 PDT 2013

```On Fri, Sep 27, 2013 at 3:35 PM, Ian Hickson <ian at hixie.ch> wrote:

> On Mon, 9 Sep 2013, Rik Cabanier wrote:
> > On Mon, Sep 9, 2013 at 9:33 AM, Ian Hickson <ian at hixie.ch> wrote:
> > > On Thu, 5 Sep 2013, Rik Cabanier wrote:
> > > >
> > > > we've looked over the algorithm in the Canvas spec that describes
> > > > how strokes are computed. [1] We think that this section is making
> > > > some incorrect assumptions. For instance, the dashes are calculated
> > > > over the total lenght of all subpaths, but each subpath should be
> > > > treated separately.
> > >
> > > That's intentional, otherwise if you stroke an already-dashed line,
> > > you get weird results.
> >
> > As Stephan said, when would this happen? Are you thinking of a case
> > where you did the dashing yourself and then dash/stroke it again? If so,
> > that is expected to give different results.
>
> Expected by whom?
>
> The idea here is that this line:
>
>   ------------------------------
>
> ...would result in this dash (assuming equally spaced on-off):
>
>   ---   ---   ---   ---   ---
>
> ...while this line, dashed with the same stroke:
>
>   ---   ---   ---   ---   ---
>
> ...would result in this different line, rather than result in no change:
>
>   ---         ---         ---
>
> ...and this line, dashed with the same stroke:
>
>   --  --  --  --  --  --  --  --
>
> ...would result in something more like:
>
>   --  -       --  -       --  -
>
> ...rather than, again, resulting in no change.
>

Yep, this is where assumptions went wrong. Dashes are calculated per
subpath, not per 'line'/whole path.

>
>
> > > > It's also a bit strange that the spec is trying to describe how to
> > > > stroke.
> > >
> > > It's trying to describe sufficient detail to get interoperable
> > > behaviour.
> > >
> > > > For instance, it goes in minute detail on how dashes are applied but
> > > > the hardest part of stroking ("inflating the paths in path
> > > > perpendicular to the direction") is not described at all.
> > >
> > > Is there any ambiguity in the part that's not described?
> >
> > Yes. What is "inflating"?
>
> The dictionary definition is what I intended. To grow, increase in size,
> get bigger in all directions. Inflate.
>
> If you have any better suggestion for how to word this, I'm all for it.
>

I think Stephan could come up with a formula.
Not sure if we should do this though. You can see a stroke as if you're
drawing with a marker with a round, square or flat tip (= end caps). Maybe
it's OK the say that in the spec?

>
>
> > A stroked bezier curve is no longer a bezier and has to be calculated.
>
> Yes. The idea of defining it in terms of the earlier path is that there's
> no need to be explicit about the maths here.

How is a UA going to implement that? I can imagine many ways to "inflate" a
path

```