Table of Contents

Class SvgPathFormat

Namespace
Egami.Drawing
Assembly
Egami.Drawing.dll

How ToSvg(SvgPathFormat?) writes SVG path data.

public sealed record SvgPathFormat : IEquatable<SvgPathFormat>
Inheritance
SvgPathFormat
Implements
Inherited Members

Examples

// An icon from SVG path data, drawn four times larger, and written back as compact relative data.
Path heart = Path.ParseSvg("M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09" +
                           "C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z");
string d = heart.Transform(Matrix3x2.CreateScale(4)).ToSvg(new SvgPathFormat { Relative = true, Compact = true });

// Untrusted data: TryParseSvg says whether it is valid; lenient keeps what comes before an error, as browsers draw it.
bool valid = Path.TryParseSvg("M0 0 L10 10 L20", out Path? strict);
Path drawn = Path.ParseSvg("M0 0 L10 10 L20", lenient: true);
try
{
    Path.ParseSvg("M0 0 X");
}
catch (SvgPathException e)
{
    Console.WriteLine($"{e.Problem} at character {e.Position}");
}

Properties

Compact

Gets a value indicating whether to write the shortest data the grammar allows: no leading zero (.5), no space before a sign or before a second decimal point, H and V for lines along an axis, and no repeated command letters. Defaults to false.

public bool Compact { get; init; }

Property Value

bool

Default

Gets the default: absolute commands, three decimals, a space between every number.

public static SvgPathFormat Default { get; }

Property Value

SvgPathFormat

Precision

Gets the number of decimals written, from 0 to 9; trailing zeros are left out. Defaults to 3.

public int Precision { get; init; }

Property Value

int

Exceptions

ArgumentOutOfRangeException

The value is below 0 or above 9.

Relative

Gets a value indicating whether to write relative commands (lowercase), each point as an offset from the one before. Offsets are taken from the rounded points, so rounding errors never add up along the path. Defaults to false.

public bool Relative { get; init; }

Property Value

bool