Table of Contents

Class FontPalette

Namespace
Egami.Fonts
Assembly
Egami.Fonts.dll

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

index int

The CPAL palette, 0 for the first.

overrides ReadOnlySpan<FontPaletteEntry>

Entries to replace, or none.

Exceptions

ArgumentOutOfRangeException

index is negative.

Properties

Background

Gets which background the palette is chosen for. Defaults to Any.

public FontPaletteBackground Background { get; init; }

Property Value

FontPaletteBackground

Dark

Gets the first palette usable with a dark background (light ink), else the first.

public static FontPalette Dark { get; }

Property Value

FontPalette

Default

Gets the font's first palette, unchanged.

public static FontPalette Default { get; }

Property Value

FontPalette

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

int

Light

Gets the first palette usable with a light background (dark ink), else the first.

public static FontPalette Light { get; }

Property Value

FontPalette

Overrides

Gets the entries replaced.

public IReadOnlyList<FontPaletteEntry> Overrides { get; }

Property Value

IReadOnlyList<FontPaletteEntry>

Methods

Equals(FontPalette?)

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

public bool Equals(FontPalette? other)

Parameters

other FontPalette

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.