Class SvgFontOptions
Where a document's text finds its fonts (question 13): the caller's Collection first, then the fonts installed on the machine unless UseSystemFonts is off, then per-character fallback through the same fonts. A server that renders untrusted files should pass its own collection and turn system fonts off, so output never depends on the machine.
public sealed record SvgFontOptions : IEquatable<SvgFontOptions>
- Inheritance
-
SvgFontOptions
- Implements
- Inherited Members
Examples
// A server passes its own fonts and turns the machine's off, so text renders the same everywhere.
Egami.Fonts.FontCollection fonts = new();
fonts.AddFile(System.IO.Path.Combine(folder, "NotoSans-Regular.ttf"));
SvgLoadOptions options = new()
{
Fonts = new SvgFontOptions { Collection = fonts, UseSystemFonts = false, DefaultFamily = "Noto Sans" },
};
SvgDocument label = SvgDocument.Parse(
"<svg xmlns='http://www.w3.org/2000/svg' width='120' height='40'><text x='60' y='26' text-anchor='middle'>Label</text></svg>",
options);
using Raster<Rgba8> raster = label.Rasterize<Rgba8>(new SvgRenderOptions { TextAsPaths = false });
Properties
Collection
Gets the caller's fonts, searched before any other, or null for none.
public FontCollection? Collection { get; init; }
Property Value
Default
Gets the defaults: no collection of the caller's, the installed fonts, Times New Roman when no family is named.
public static SvgFontOptions Default { get; }
Property Value
DefaultFamily
Gets the family used when text names none, as a browser's default font; Times New Roman by default. When no font
has it, the serif family stands in.
public string DefaultFamily { get; init; }
Property Value
GenericFamilies
Gets the family each generic name (serif, sans-serif, monospace, cursive, fantasy) stands for, or null to use the usual families of the operating system, as Match(GenericFamily, FontStyle) picks them.
public IReadOnlyDictionary<GenericFamily, string>? GenericFamilies { get; init; }
Property Value
UseSystemFonts
Gets a value indicating whether the fonts installed on the machine are searched after Collection. Defaults to true.
public bool UseSystemFonts { get; init; }