Skip to main content

Font

Namespace: PinataLabs.Typography. Guide: Loading fonts.

Font​

public sealed class Font

A font family at one size and one style. Make one with FontFamily.CreateFont, SystemFonts.CreateFont, or one of the constructors.

Constructors​

ConstructorDescription
Font(FontFamily family, float size)A regular font of family at size points.
Font(FontFamily family, float size, FontStyle style)A font of family in style at size points.
Font(Font prototype, float size)A copy of prototype at a new size.
Font(Font prototype, FontStyle style)A copy of prototype in a new style.
Font(Font prototype, float size, FontStyle style)A copy of prototype at a new size and in a new style.

Properties​

PropertyDescription
FamilyThe family of the font.
NameThe full name of the font face that is used, for example Open Sans Bold.
SizeThe size in points.
IsBoldtrue if the face that is used is bold.
IsItalictrue if the face that is used is italic.
FontMetricsThe metrics of the face that is used.

When the family does not have the requested style, the font uses the nearest style that it has: for bold italic it tries italic, then bold, then regular. Name, IsBold, IsItalic and FontMetrics describe the face that is really used.

Methods​

MethodDescription
TryGetGlyphs(CodePoint codePoint, out IReadOnlyList<Glyph>? glyphs)Gets the glyphs for a code point. A color glyph can have more than one. A code point that the font does not have gives its missing glyph, with GlyphType.Fallback.
TryGetGlyphs(CodePoint, ColorFontSupport, out …)As above, with or without color layers.
TryGetGlyphs(CodePoint, TextAttributes, ColorFontSupport, out …)As above, for subscript or superscript.
TryGetGlyphs(CodePoint, TextAttributes, LayoutMode, ColorFontSupport, out …)As above, for a layout mode.
TryGetGlyphs(CodePoint, TextAttributes, TextDecorations, LayoutMode, ColorFontSupport, out …)As above, with decorations.
TryGetKerningOffset(Glyph previous, Glyph current, float dpi, out Vector2 vector)Gets the kerning between two glyphs from the font's kern table, in pixels at dpi.
TryGetPath(out string? path)Gets the file that the font was loaded from. Returns false for a font loaded from a stream.

The overload of TryGetGlyphs without ColorFontSupport does not return color layers.

FontStyle​

public enum FontStyle

ValueNumber
Regular0
Bold1
Italic2
BoldItalic3 (Bold | Italic)