Search guides and the APICtrl K
  1. API reference
  2. Native GUI

gfx/stroke.h

Stroking: turning a path into the outline of a pen drawn along it.

#include <sonore/gfx/stroke.h>
On this page

Design notes

The approach, and why it is not the textbook one

The classic method builds ONE continuous outline: walk up the left side of the path, round the end, walk back down the right. It produces a minimal polygon, and it is where every stroking bug in every graphics library lives -- the outline self-intersects at tight corners, the inner side of a sharp bend folds through itself, and the fill rule then eats a notch out of the line.

This instead emits a QUAD PER SEGMENT plus a shape per joint, all into one path, and fills it with the non-zero rule. Overlaps are simply inside. A tight corner is two quads that overlap, which fills once and looks right; the pathological case of the textbook method does not exist.

The cost is more edges for the rasteriser. That is the correct trade for a UI: a plugin's interface is a few hundred short strokes per repaint, and correctness at corners is visible while the extra edges are not.

Joins and caps

Only the OUTER side of a bend needs a join: the inner side is already covered by the two segment quads overlapping. Getting that backwards draws a wedge sticking into the middle of the line.

Types 2

The pen a path is stroked with: width, how corners join, how open ends are capped, and an optional dash pattern. The reference's PathStrokeType, by another name.

Graphics::strokePath applies it in DEVICE space, after the transform, so width and the dash lengths are device pixels and do not grow when the drawing is scaled -- see the note on strokePath for why. A plain value; a width that is zero, negative or not a number draws nothing.

Builds the fillable outline of a stroked path.

Works on the FLATTENED contours, so curves are already segments and a stroked curve is a chain of stroked lines. The flattening tolerance therefore controls stroke quality too, which is why it follows the transform.

Enums 2

↑↓ to move↵ to openEvery public name in the headers, and every guide