Table of Contents

Class DashPattern

Namespace
Egami.Drawing
Assembly
Egami.Drawing.dll

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

intervals ReadOnlySpan<float>

The lengths: drawn, skipped, drawn, skipped and so on.

phase float

How far into the pattern each contour starts; negative values count back from the pattern's end.

Exceptions

ArgumentException

intervals is empty, or a length is negative or not finite.

ArgumentOutOfRangeException

phase is not finite.

Properties

Intervals

Gets the lengths as given: drawn, skipped, drawn, skipped and so on.

public IReadOnlyList<float> Intervals { get; }

Property Value

IReadOnlyList<float>

Phase

Gets how far into the pattern each contour starts.

public float Phase { get; }

Property Value

float

Methods

Equals(DashPattern?)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(DashPattern? other)

Parameters

other DashPattern

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

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

factor float

The factor, such as the stroke's width.

Returns

DashPattern

The scaled pattern.

Exceptions

ArgumentOutOfRangeException

factor is negative or not finite.