[whatwg] canvas 2d context additions proposal (fillRule, lineDash)

Howdy,

I'd like to propose adding a few simple 2D canvas context 
methods/parameters:

   attribute string fillRule;

Specifies the algorithm used for filling paths.  The options are 
"winding" or "even-odd"; the default is "winding".  Good descriptions 
for these are in the SVG spec: 
http://www.w3.org/TR/SVG/painting.html#FillProperties .  Hmm, they use 
"nonzero" and "evenodd"; we could use those instead for consistency.

A more complicated addition is a mechanism for dashed line drawing; I 
see this was discussed a few weeks ago:

   attribute variant lineDash; // array of numbers or a single number; 
default 0.0
   attribute float dashOffset;

lineDash specifies an array of lengths of the "on" and "off" portions of 
a stroked path.  Each value must be >= 0.0.  A single value of 0.0 
disables line dashing.

The array repeats, and if there are an odd number of values specified, 
the sense of each value is inverted; that is, if [5.0, 1.0, 3.0] is 
passed in, it is interepted to mean the same as [5.0, 1.0, 3.0, 5.0, 
1.0, 3.0] -- on 5, off 1, on 3, off 5, on 1, off 3.  (I'm doing a 
horrible job of explaining this, but hopefully it'll make sense.)  A 
single value is interpreted the same as an array with a single value, so 
5.0 -> [5.0] -> [5.0, 5.0], meaning a dash of 5.0 length followed by a 
space of 5.0 length.  These values are in user-space units.

It's an error to specify any negative dash values, or to provide an 
array with all values of 0.0.

Line caps are to be applied to dash ends.  (This means that given a dash 
pattern of [0.0, 5.0], a line width of 5.0, and a line cap of "round", 
the result should be a series of 5px diameter round dots -- the 0.0 "on" 
has no length, but it still has the round end caps drawn.)

Each subpath is treated independently for purposes of dashing.  The dash 
pattern restarts with each subpath.

The dashOffset specifies an offset into the dash pattern at which the 
stroke starts.  (That is, with a lineDash of [5.0, 5.0], and a 
dashOffset of 5.0, the first 5 units of the stroke will be a space, and 
not a dash.)

Thoughts?

     - Vlad

Received on Thursday, 24 May 2007 16:19:38 UTC