Table of Contents

Class SvgWriteOptions

Namespace
Egami.Svg
Assembly
Egami.Svg.dll

How SvgCanvas writes SVG: text, number precision, layout, image format and fallback resolution.

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

Examples

// Anything drawn on a Canvas can be written as SVG: gradients, clips, images and pictures go once into defs.
using (SvgCanvas canvas = new(file, 200, 120, new SvgWriteOptions { Precision = 2, ImageFormat = SvgImageFormat.Png }))
{
    canvas.FillRoundRect(new RoundRect(new RectF(10, 10, 180, 100), 12), new LinearGradient(new Vector2(10, 0), new Vector2(190, 0), new RgbaF32(0.1f, 0.4f, 0.9f, 1), new RgbaF32(0.9f, 0.2f, 0.5f, 1)));
    canvas.SaveLayer(0.5f);
    canvas.StrokePath(Egami.Drawing.Path.Oval(new RectF(30, 30, 140, 60)), new Stroke(6) { Dash = new DashPattern([10, 5]) }, new Rgba8(255, 255, 255, 255));
    canvas.Restore();

    // A sweep gradient has no SVG form: it is drawn by Egami and embedded as a PNG (Svg.FallbackImage).
    canvas.FillCircle(new Vector2(100, 60), 20, new SweepGradient(new Vector2(100, 60), [new GradientStop(0, new RgbaF32(1, 1, 0, 1)), new GradientStop(1, new RgbaF32(0, 1, 1, 1))]));
}

// Disposing writes the file; the stream stays open.

Properties

Compact

Gets a value indicating whether to write the smallest file: the shortest path data the grammar allows and no indentation. Defaults to false.

public bool Compact { get; init; }

Property Value

bool

Context

Gets the context whose diagnostics receive what the writer had to rasterize or approximate (Svg.FallbackImage, Svg.Approximated, Svg.FontNotEmbedded) when the canvas is disposed, or null for Default.

public EgamiContext? Context { get; init; }

Property Value

EgamiContext

Default

Gets the defaults: glyph outlines, 3 decimals, indented, PNG images, fallback images at the device resolution.

public static SvgWriteOptions Default { get; }

Property Value

SvgWriteOptions

EmbedSubset

Gets a value indicating whether Text embeds a subset of each font, with the glyphs the file uses, as OpenType font data in an @font-face rule, so the text looks the same where the font is not installed. A face whose license forbids embedding or subsetting is not embedded. Outlines need no fonts and ignore it. Defaults to false.

public bool EmbedSubset { get; init; }

Property Value

bool

FallbackScale

Gets the resolution of fallback images (calls SVG cannot express, drawn by Egami and embedded as PNG), in image pixels per device unit: 2 gives sharper fallbacks on high-density screens. Defaults to 1.

public float FallbackScale { get; init; }

Property Value

float

Exceptions

ArgumentOutOfRangeException

The value is not positive and finite.

ImageFormat

Gets the format drawn images are embedded in. Defaults to Png; fallback images are always PNG.

public SvgImageFormat ImageFormat { get; init; }

Property Value

SvgImageFormat

Exceptions

ArgumentOutOfRangeException

The value is not defined.

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.

Text

Gets how text is written. Defaults to Outlines.

public SvgTextMode Text { get; init; }

Property Value

SvgTextMode

Exceptions

ArgumentOutOfRangeException

The value is not defined.