Class DashPattern
The dashes of a stroke: lengths of drawn and skipped stretches in turn, in path units, and where in the pattern each contour
starts, as PDF's d, SVG's stroke-dasharray and stroke-dashoffset, and Skia's dash effect define them. An
odd number of lengths repeats once to make an even one, as SVG says, and a pattern whose lengths add up to 0 draws a solid line.
Each dash is an open piece of the path that follows its curves and gets the stroke's caps; the pattern starts afresh on each
contour.
public sealed record DashPattern : IEquatable<DashPattern>
- Inheritance
-
DashPattern
- Implements
- Inherited Members
Examples
// A dashed route: the pattern travels with the stroke, so a PDF backend writes [8 4] 0 d instead of hundreds of pieces.
Path route = new PathBuilder().MoveTo(10, 90).CubicTo(60, 0, 140, 160, 190, 60).ToPath();
Stroke dashed = new(3) { Cap = LineCap.Round, Dash = new DashPattern([8, 4]) };
using Raster<Rgba8> map = Raster.Create(200, 120, Rgba8.White);
using (RasterCanvas<Rgba8> canvas = map.CreateCanvas())
{
canvas.StrokePath(route, dashed, new Rgba8(200, 60, 30, 255));
}
// The outline the stroke fills, as a path: for hit testing, or to export without strokes.
Path outline = dashed.ToPath(route, simplify: true);
Constructors
DashPattern(ReadOnlySpan<float>, float)
Initializes a new instance of the DashPattern class.
public DashPattern(ReadOnlySpan<float> intervals, float phase = 0)
Parameters
intervalsReadOnlySpan<float>The lengths: drawn, skipped, drawn, skipped and so on.
phasefloatHow far into the pattern each contour starts; negative values count back from the pattern's end.
Exceptions
- ArgumentException
intervalsis empty, or a length is negative or not finite.- ArgumentOutOfRangeException
phaseis not finite.
Properties
Intervals
Gets the lengths as given: drawn, skipped, drawn, skipped and so on.
public IReadOnlyList<float> Intervals { get; }
Property Value
Phase
Gets how far into the pattern each contour starts.
public float Phase { get; }
Property Value
Methods
Equals(DashPattern?)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(DashPattern? other)
Parameters
otherDashPatternAn object to compare with this object.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
Scaled(float)
Returns the pattern with every length and the phase multiplied by a factor: give lengths in stroke widths and scale by the width, as Office's dash styles measure them.
public DashPattern Scaled(float factor)
Parameters
factorfloatThe factor, such as the stroke's width.
Returns
- DashPattern
The scaled pattern.
Exceptions
- ArgumentOutOfRangeException
factoris negative or not finite.