Class FontPalette
The palette a color font draws with: a CPAL palette by index or by the background it suits, with entries overridden, as CSS's font-palette and @font-palette-values.
public sealed record FontPalette : IEquatable<FontPalette>
- Inheritance
-
FontPalette
- Implements
- Inherited Members
Examples
// Color glyphs draw in color by themselves: COLR (layers and gradients), sbix and CBDT (images), per glyph.
using (RasterCanvas<Rgba8> canvas = image.CreateCanvas())
{
canvas.DrawText("Ship it", new Vector2(8, 40), new Font(text, 24), Rgba8.Black);
canvas.DrawText("\U0001F680\U0001F389", new Vector2(100, 42), new Font(emoji, 32), Rgba8.Black);
}
// The palette is a font setting; the paint's color fills a glyph's foreground parts and its alpha the whole glyph.
var darkMode = new Font(emoji, 32) { Palette = FontPalette.Dark };
ColorGlyphFormats formats = emoji.ColorFormats;
// The paint graph is there to walk, for writers that draw color glyphs their own way.
emoji.TryGetColorGlyph(emoji.GetGlyph(0x1F680), darkMode.Palette, out ColorGlyph? rocket);
Constructors
FontPalette(int, params ReadOnlySpan<FontPaletteEntry>)
Initializes a new instance of the FontPalette class.
public FontPalette(int index = 0, params ReadOnlySpan<FontPaletteEntry> overrides)
Parameters
indexintThe CPAL palette, 0 for the first.
overridesReadOnlySpan<FontPaletteEntry>Entries to replace, or none.
Exceptions
- ArgumentOutOfRangeException
indexis negative.
Properties
Background
Gets which background the palette is chosen for. Defaults to Any.
public FontPaletteBackground Background { get; init; }
Property Value
Dark
Gets the first palette usable with a dark background (light ink), else the first.
public static FontPalette Dark { get; }
Property Value
Default
Gets the font's first palette, unchanged.
public static FontPalette Default { get; }
Property Value
Index
Gets the CPAL palette's index, used when Background is Any or finds no palette; past the font's palettes, the first.
public int Index { get; }
Property Value
Light
Gets the first palette usable with a light background (dark ink), else the first.
public static FontPalette Light { get; }
Property Value
Overrides
Gets the entries replaced.
public IReadOnlyList<FontPaletteEntry> Overrides { get; }
Property Value
Methods
Equals(FontPalette?)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(FontPalette? other)
Parameters
otherFontPaletteAn 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.