Path declaration

A path declaration creates a new primitive shape. The declaration contains a number of moving and drawing operations that define a path (or several paths). These paths can be filled or stroked to actually draw the new primitive shape. Like shapes, paths can have parameters:

=Path Operations=
 * MOVETO(x, y) - Moves the current position to the point (x, y) without drawing, begins a new path sequence
 * LINETO(x, y) - Draws from the current position to the point (x, y)
 * ARCTO(x, y, x_radius, y_radius, ellipse_angle, flags) - draws an elliptical arc segment to the point (x, y), the ellipse has a radius (rx, ry) and is rotated by the ellipse angle (in degrees). The flags argument is optional.
 * ARCTO(x, y, radius, flags) - draws a circular arc segment with the specified radius to the point (x, y). The flags argument is optional.
 * CURVETO(x, y, CF::Continuous) - draw a smooth quadratic bezier curve to point (x, y) with a control point that is the mirror of the previous bezier curve &dagger;
 * CURVETO(x, y, x1, y1) - draw a quadratic bezier curve to point (x, y) with a control point at (x1, y1)
 * CURVETO(x, y, x2, y2, CF::Continuous) - draw a smooth cubic bezier curve to point (x, y) with a starting control point that is the mirror of the ending control point of the previous bezier curve and an ending control point at (x2, y2) &dagger;
 * CURVETO(x, y, x1, y1, x2, y2) - draw a cubic bezier curve to point (x, y) with a starting control point at (x1, y1) and an ending control point at (x2, y2)
 * CLOSEPOLY - Closes the path sequence by joining the end-point with the beginning of the sequence. If the end-point matches the beginning then they are simply joined (no end-caps if stroked). If the end-point does not match the beginning then there is an implicit LINETO to the beginning, followed by a join.
 * CLOSEPOLY(CF::Align) - Closes the path sequence. The end-point is changed to match the beginning if they do not match already. Useful if rounding errors cause the beginning and end to be different when your intent is for them to be the same

&dagger; The smooth forms of the quadratic and cubic curve operations infer the unspecified control point by looking at the preceding curve operation. If the preceding operation is not a curve operation (CURVETO, CURVEREL, ARCTO, or ARCREL) then a smooth curve operation is not permitted.

Relative Variants
The path operations all have relative variants: MOVEREL, LINEREL, ARCREL, and CURVEREL. In the relative path operations the end point (or bezier control points) are specified relative to the current position instead of in absolute terms.

Arc Flags
The basic arc drawing operation specifies a start point, an end point, and an ellipse. The ellipse is positioned such that the start point and end points touch the ellipse and the arc is drawn from the start to the finish. However, in general there are two possible ellipse positions for any pair of starting and ending points, and two different arcs on each ellipse that can be drawn. The CF::ArcCW and CF::ArcLarge flags indicate which of the four possible arcs are drawn.



Two of the four arcs are large, i.e., more than 180°. Specifying the CF::ArcLarge flag indicates that one of these arcs should be drawn. Otherwise one of the arcs that are less than 180° will be drawn. Two of the four arcs draw from start to end clockwise around the ellipse and two draw counter-clockwise. Specifying the CF::ArcCW flag indicates that a clockwise arc should be drawn. Otherwise a counter-clockwise arc will be drawn.

Setting the radius of the arc to be negative has the effect of inverting the arc drawing direction. A counter-clockwise arc will be drawn clockwise if the radius is negative. A clockwise arc will be drawn counter-clockwise if the radius is negative.

Bezier Control Points
The control points for bezier curve segments control the slope of the curve at the ends. For cubic bezier curves each end has its own control point and the slope at each end is indicated by the slope of the line from the end to the control point. For quadratic bezier curves both ends share a single control point and the slope at each end is indicated by the slope of the line from each end to the shared control point.



For smooth cubic bezier curves the starting control point is the mirror of the ending control point on the previous bezier curve or arc curve. For smooth quadratic bezier curves the single control point is the mirror of the ending control point on the previous bezier curve or arc curve. The preceding curve does not need to be of the same order (quadratic or cubic) as the smooth curve. The preceding curve can even be an ARCTO. Context Free will figure out what control point will match the slope and curvature between the smooth curve and the curve the precedes it. = Path Commands = After a path sequence there can be one or more path commands. Path commands instruct Context Free to draw (stroke or fill) all of the path sequences between the path command and the previous group of path commands.
 * STROKE(width, flags) [shape adjustments] - Stroke the preceding path sequences with a pen of the specified width. Stroke width is relative to the size of the shape. If the stroke size is not specified then the default of 0.1 is used. If color or shape modifications are specified then the path sequences are modified when they are drawn. The flags argument is also optional.
 * FILL(flags) [shape adjustments] - Fill the preceding path sequences. If color or shape modifications are specified then the path sequences are modified when they are drawn. If the path sequences are intersecting or self-intersecting then a filling rule determines whether a given piece is filled or not. The default filling rule is non-zero, but even-odd filling can also be specified (see below). The flags argument is optional.

Stroke Flags
Join types http://www.w3.org/TR/SVG11/images/painting/linejoin.png Cap types http://www.w3.org/TR/SVG11/images/painting/linecap.png
 * CF::MiterJoin flag - indicates that join between path sequence segments (and between the beginning and end of closed paths) should have miter joins.
 * CF::RoundJoin flag - indicates that join between path sequence segments (and between the beginning and end of closed paths) should have round joins.
 * CF::BevelJoin flag - indicates that join between path sequence segments (and between the beginning and end of closed paths) should have bevel joins.
 * CF::ButtCap flag - indicates that the end points of unclosed path sequences should have butt caps.
 * CF::RoundCap flag - indicates that the end points of unclosed path sequences should have round caps.
 * CF::SquareCap flag - indicates that the end points of unclosed path sequences should have square caps.
 * CF::IsoWidth flag - indicates that a transformed stroke is transformed before stroking, instead of afterward. This makes the stroke width the same for all orientations. If the stroke has been isomorphically transformed (no skews, no size x y) then this makes no difference. If the stroke has been anisomorphically transformed then the stroke width will vary unless the CF::IsoWidth flag is provided.

Fill Flags

 * CF::EvenOdd flag - Indicates that a FILL uses the even-odd filling rule, instead of the non-zero filling rule

Non-Zero filling http://www.w3.org/TR/SVG11/images/painting/fillrule-nonzero.png

Even-Odd filling http://www.w3.org/TR/SVG11/images/painting/fillrule-evenodd.png

Note that the shape adjustments in path commands can either be basic or ordered (see basic vs. ordered).

If a path is completed (by a closing curly brace, '}') with no path command following the last set of path sequences then an implicit fill command is appended to the path. =Control Flow= Paths support all of the control flow elements that shapes support: loops, if statements, switch statements, variables, and transform blocks.

=Subpaths= Paths can invoke other paths. The path sequences from the invoked path are inserted directly into the current path. This is useful for including the same path sequence into multiple paths. Also, subpath invocations can be passed to a path as a shape parameter, but only if the the subpath contains only path operations. A path can only invoke subpaths that occur earlier in the CFDG file. A path cannot invoke itself recursively or invoke paths that are after it in the file. Context Free cannot silently drop small path sequences the way that it can silently drop small shapes. If you manage to make a very large path sequence you will crash Context Free.