Skip to main content

GlyphTypeface Class

Definition​

Namespace:Avalonia.Media
Assembly:Avalonia.Base
Package:Avalonia

Represents a glyph typeface, providing access to font metrics, glyph mappings, and other font-related properties.

public class GlyphTypeface

Inheritance: object -> GlyphTypeface

Remarks​

The Avalonia.Media.GlyphTypeface class is used to encapsulate font data, including metrics, character-to-glyph mappings, and supported OpenType features. It supports platform-specific typefaces and applies optional font simulations such as bold or oblique. This class is typically used in text rendering and shaping scenarios.

Constructors​

NameDescription
GlyphTypefaceInitializes a new instance of the Avalonia.Media.GlyphTypeface class with the specified platform typeface and font simulations.

GlyphTypeface Constructor​

Initializes a new instance of the Avalonia.Media.GlyphTypeface class with the specified platform typeface and font simulations.

public GlyphTypeface(Avalonia.Media.IPlatformTypeface typeface, Avalonia.Media.FontSimulations fontSimulations)

Parameters​

typeface Avalonia.Media.IPlatformTypeface

The platform-specific typeface to be used for this Avalonia.Media.GlyphTypeface instance. This parameter cannot be null.

fontSimulations Avalonia.Media.FontSimulations

The font simulations to apply, such as bold or oblique. The default is Avalonia.Media.FontSimulations.None.

Remarks​

This constructor initializes the glyph typeface by loading various font tables, including OS/2, CMAP, and metrics tables, to calculate font metrics and other properties. It also determines font characteristics such as weight, style, stretch, and family names based on the provided typeface and font simulations.

Exceptions​

Methods​

NameDescription
CanShapeScriptDetermines whether this font can shape the specified script, not merely map its codepoints. Scripts that need OpenType complex shaping (e.g. Arabic joining, Indic conjuncts) require the font to declare the script in its GSUB/GPOS tables; scripts that render acceptably from cmap alone always return true. Used by the fallback itemizer to avoid selecting a font that has the glyphs but cannot form them correctly.
DeclaresLanguageCoverageDetermines whether this font self-declares coverage for the supplied culture via its OpenType meta table dlng or slng tag list.
DisposeNo summary available.
SupportsScriptDetermines whether the font advertises support for the supplied Unicode script.
TryGetGlyphMetrics (2 overloads)No summary available.
TryGetHorizontalGlyphAdvanceNo summary available.
TryGetHorizontalGlyphAdvancesNo summary available.

CanShapeScript Method​

Determines whether this font can shape the specified script, not merely map its codepoints. Scripts that need OpenType complex shaping (e.g. Arabic joining, Indic conjuncts) require the font to declare the script in its GSUB/GPOS tables; scripts that render acceptably from cmap alone always return true. Used by the fallback itemizer to avoid selecting a font that has the glyphs but cannot form them correctly.

public bool CanShapeScript(Avalonia.Media.TextFormatting.Unicode.Script script)

Parameters​

script Avalonia.Media.TextFormatting.Unicode.Script

Returns​

bool

DeclaresLanguageCoverage Method​

Determines whether this font self-declares coverage for the supplied culture via its OpenType meta table dlng or slng tag list.

public bool DeclaresLanguageCoverage(System.Globalization.CultureInfo culture)

Parameters​

culture System.Globalization.CultureInfo

The culture to check. If null the method returns false.

Returns​

bool

true when one of the declared language tags is a BCP-47 prefix of the culture's System.Globalization.CultureInfo.Name (or vice versa, when the font specifies a narrower tag).

Remarks​

The match is case-insensitive and BCP-47-aware: the comparison succeeds when one tag is a prefix of the other up to a subtag boundary (e.g. "ja" matches "ja-JP", and "zh-Hans" matches "zh-Hans-CN"). Returns false when the font declares no design or supported languages.

Dispose Method​

public void Dispose()

SupportsScript Method​

Determines whether the font advertises support for the supplied Unicode script.

public bool SupportsScript(Avalonia.Media.TextFormatting.Unicode.Script script)

Parameters​

script Avalonia.Media.TextFormatting.Unicode.Script

Returns​

bool

Remarks​

When the font ships an OS/2 table the answer is taken from the OS/2 ulUnicodeRange bitfield (the font's own self-declaration of script coverage). When OS/2 is absent or the bit is unset, this falls back to probing the cmap with a representative codepoint for the script. Returns true for scripts that don't have a meaningful per-script signal (for example Avalonia.Media.TextFormatting.Unicode.Script.Common or Avalonia.Media.TextFormatting.Unicode.Script.Unknown).

TryGetGlyphMetrics overloads​

TryGetGlyphMetrics Method​

public bool TryGetGlyphMetrics(ReadOnlySpan<ushort> glyphIds, Span<Avalonia.Media.GlyphMetrics> metrics)
Parameters​

glyphIds ReadOnlySpan<ushort>

metrics Span<Avalonia.Media.GlyphMetrics>

Returns​

bool

TryGetGlyphMetrics Method​

public bool TryGetGlyphMetrics(ushort glyph, Avalonia.Media.GlyphMetrics& metrics)
Parameters​

glyph ushort

metrics Avalonia.Media.GlyphMetrics&

Returns​

bool

TryGetHorizontalGlyphAdvance Method​

public bool TryGetHorizontalGlyphAdvance(ushort glyphId, ushort& advance)

Parameters​

glyphId ushort

advance ushort&

Returns​

bool

TryGetHorizontalGlyphAdvances Method​

public bool TryGetHorizontalGlyphAdvances(ReadOnlySpan<ushort> glyphIds, Span<ushort> advances)

Parameters​

glyphIds ReadOnlySpan<ushort>

advances Span<ushort>

Returns​

bool

Properties​

NameDescription
CharacterToGlyphMapGets a read-only mapping of Unicode character codes to glyph indices for the font.
CodePageCoverageGets the codepage coverage advertised by the font via the OpenType OS/2.ulCodePageRange1/2 bitfields.
DesignLanguagesGets the BCP-47 language tags the font's designer declared as the design target for the font (the dlng data tag in the OpenType meta table).
FaceNamesGets a read-only mapping of culture-specific face names.
FamilyNameGets the family name of the font.
FamilyNamesGets a read-only mapping of localized culture-specific family names.
FontSimulationsGets the font simulation settings applied to the Avalonia.Media.GlyphTypeface.
GlyphCountGets the number of glyphs held by this font.
MetricsGets the font metrics associated with this font.
PlatformTypefaceGets the platform-specific typeface associated with this font.
StretchGets the font stretch.
StyleGets the font style.
SupportedFeaturesGets the list of OpenType feature tags supported by the font.
SupportedLanguagesGets the BCP-47 language tags the font advertises as supported (the slng data tag in the OpenType meta table).
SupportedUnicodeRangeGets the union of Unicode codepoint ranges covered by the font's character map.
TextShaperTypefaceGets the typeface information used by the text shaper for this font.
TypographicFamilyNameGets the typographic family name of the font.
WeightGets the font weight.

CharacterToGlyphMap Property​

Gets a read-only mapping of Unicode character codes to glyph indices for the font.

public Avalonia.Media.Fonts.Tables.Cmap.CharacterToGlyphMap CharacterToGlyphMap { get; set; }

Remarks​

This dictionary provides the correspondence between Unicode code points and the glyphs defined in the font. The mapping can be used to look up the glyph index for a given character when rendering or processing text. The set of mapped characters depends on the font's supported character set.

CodePageCoverage Property​

Gets the codepage coverage advertised by the font via the OpenType OS/2.ulCodePageRange1/2 bitfields.

public Avalonia.Media.Fonts.FontCodePageCoverage CodePageCoverage { get; set; }

Remarks​

Returns Avalonia.Media.Fonts.FontCodePageCoverage.None when the font does not ship an OS/2 table or only supplies an OS/2 version < 1 (where the codepage range fields are not present).

DesignLanguages Property​

Gets the BCP-47 language tags the font's designer declared as the design target for the font (the dlng data tag in the OpenType meta table).

public ReadOnlySpan<string> DesignLanguages { get; set; }

Remarks​

Returns an empty span when the font does not ship a meta table or omits the dlng data tag.

FaceNames Property​

Gets a read-only mapping of culture-specific face names.

public System.Collections.Generic.IReadOnlyDictionary<System.Globalization.CultureInfo, string> FaceNames { get; set; }

Remarks​

Each entry in the dictionary maps a System.Globalization.CultureInfo to the corresponding localized face name. The dictionary is empty if no face names are defined.

FamilyName Property​

Gets the family name of the font.

public string FamilyName { get; set; }

FamilyNames Property​

Gets a read-only mapping of localized culture-specific family names.

public System.Collections.Generic.IReadOnlyDictionary<System.Globalization.CultureInfo, string> FamilyNames { get; set; }

Remarks​

The dictionary contains entries for each supported culture, where the key is a System.Globalization.CultureInfo representing the culture, and the value is the corresponding localized family name. The dictionary may be empty if no family names are available.

FontSimulations Property​

Gets the font simulation settings applied to the Avalonia.Media.GlyphTypeface.

public Avalonia.Media.FontSimulations FontSimulations { get; set; }

GlyphCount Property​

Gets the number of glyphs held by this font.

public int GlyphCount { get; set; }

Metrics Property​

Gets the font metrics associated with this font.

public Avalonia.Media.FontMetrics Metrics { get; set; }

PlatformTypeface Property​

Gets the platform-specific typeface associated with this font.

public Avalonia.Media.IPlatformTypeface PlatformTypeface { get; set; }

Stretch Property​

Gets the font stretch.

public Avalonia.Media.FontStretch Stretch { get; set; }

Style Property​

Gets the font style.

public Avalonia.Media.FontStyle Style { get; set; }

SupportedFeatures Property​

Gets the list of OpenType feature tags supported by the font.

public System.Collections.Generic.IReadOnlyList<Avalonia.Media.Fonts.OpenTypeTag> SupportedFeatures { get; set; }

Remarks​

The returned list reflects the features available in the underlying font and is read-only. The order of features in the list is not guaranteed. This property does not return null; if the font does not support any features, the list will be empty.

SupportedLanguages Property​

Gets the BCP-47 language tags the font advertises as supported (the slng data tag in the OpenType meta table).

public ReadOnlySpan<string> SupportedLanguages { get; set; }

Remarks​

Returns an empty span when the font does not ship a meta table or omits the slng data tag.

SupportedUnicodeRange Property​

Gets the union of Unicode codepoint ranges covered by the font's character map.

public Avalonia.Media.UnicodeRange SupportedUnicodeRange { get; set; }

Remarks​

The returned Avalonia.Media.UnicodeRange is derived from the cmap table and represents every codepoint for which the font defines a glyph. It is computed lazily on first access and cached for the lifetime of the Avalonia.Media.GlyphTypeface. Prefer this property over enumerating Avalonia.Media.GlyphTypeface.CharacterToGlyphMap when only coverage information (not glyph IDs) is required.

TextShaperTypeface Property​

Gets the typeface information used by the text shaper for this font.

public Avalonia.Media.ITextShaperTypeface TextShaperTypeface { get; set; }

Remarks​

The returned typeface is created on demand and cached for subsequent accesses. This property is typically used by text rendering components that require low-level font shaping details.

TypographicFamilyName Property​

Gets the typographic family name of the font.

public string TypographicFamilyName { get; set; }

Weight Property​

Gets the font weight.

public Avalonia.Media.FontWeight Weight { get; set; }