GlyphTypeface Class
Definition
Represents a glyph typeface, providing access to font metrics, glyph mappings, and other font-related properties.
public class 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
| Name | Description |
|---|---|
| GlyphTypeface | Initializes 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
| Name | Description |
|---|---|
| CanShapeScript | 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. |
| DeclaresLanguageCoverage | Determines whether this font self-declares coverage for the supplied culture via its OpenType meta table dlng or slng tag list. |
| Dispose | No summary available. |
| GetGlyphOutline | Retrieves the vector outline geometry for the specified glyph, in font design-unit space. |
| SupportsScript | Determines whether the font advertises support for the supplied Unicode script. |
| TryGetGlyphMetrics (2 overloads) | No summary available. |
| TryGetHorizontalGlyphAdvance | No summary available. |
| TryGetHorizontalGlyphAdvances | No summary available. |
| TryGetVerticalGlyphAdvance | No summary available. |
| TryGetVerticalGlyphAdvances | No summary available. |
| WithVariations | No 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()
GetGlyphOutline Method
Retrieves the vector outline geometry for the specified glyph, in font design-unit space.
public Avalonia.Platform.IGeometryImpl GetGlyphOutline(ushort glyphIndex)
Parameters
glyphIndex ushort
The identifier of the glyph to retrieve.
Returns
Avalonia.Platform.IGeometryImpl
An immutable Avalonia.Platform.IGeometryImpl outline — safe to cache and share, and drawable
via the DrawGeometry overload that takes an Avalonia.Platform.IGeometryImpl — or
null when no outline is available. Returned as the lightweight platform geometry
rather than a Avalonia.Media.Geometry (Avalonia.AvaloniaObject) so it can be cached
and used on the hot path; do not mutate it.
Remarks
Returns null when the glyph ID is out of range, the font has no glyf table
(e.g. CFF / CFF2), or the glyph data cannot be parsed (malformed font, cyclic composite,
depth limit exceeded). The outline is in font design units (Y-up): apply the
emSize / DesignEmHeight scale, the Y-flip, and the glyph position yourself — via
IGeometryImpl.WithTransform or a drawing-context transform. Variable-font axis
configuration is taken from the typeface instance itself.
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> glyphIndices, Span<Avalonia.Media.GlyphMetrics> metrics)
Parameters
glyphIndices 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 glyphIndex, ushort& advance)
Parameters
glyphIndex ushort
advance ushort&
Returns
bool
TryGetHorizontalGlyphAdvances Method
public bool TryGetHorizontalGlyphAdvances(ReadOnlySpan<ushort> glyphIndices, Span<ushort> advances)
Parameters
glyphIndices ReadOnlySpan<ushort>
advances Span<ushort>
Returns
bool
TryGetVerticalGlyphAdvance Method
public bool TryGetVerticalGlyphAdvance(ushort glyphIndex, ushort& advance)
Parameters
glyphIndex ushort
advance ushort&
Returns
bool
TryGetVerticalGlyphAdvances Method
public bool TryGetVerticalGlyphAdvances(ReadOnlySpan<ushort> glyphIndices, Span<ushort> advances)
Parameters
glyphIndices ReadOnlySpan<ushort>
advances Span<ushort>
Returns
bool
WithVariations Method
public Avalonia.Media.GlyphTypeface WithVariations(Avalonia.Media.FontVariationSettings settings, Nullable<int> instanceIndex)
Parameters
settings Avalonia.Media.FontVariationSettings
instanceIndex Nullable<int>
Returns
Properties
| Name | Description |
|---|---|
| CharacterToGlyphMap | Gets a read-only mapping of Unicode character codes to glyph indices for the font. |
| CodePageCoverage | Gets the codepage coverage advertised by the font via the OpenType OS/2.ulCodePageRange1/2 bitfields. |
| DesignLanguages | 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). |
| FaceNames | Gets a read-only mapping of culture-specific face names. |
| FamilyName | Gets the family name of the font. |
| FamilyNames | Gets a read-only mapping of localized culture-specific family names. |
| FontSimulations | Gets the font simulation settings applied to the Avalonia.Media.GlyphTypeface. |
| GlyphCount | Gets the number of glyphs held by this font. |
| Metrics | Gets the font metrics associated with this font. |
| NamedInstances | Gets the named variation instances declared by the font's fvar table, in declaration order. Empty for static fonts. |
| PlatformTypeface | Gets the platform-specific typeface associated with this font. |
| Stretch | Gets the font stretch. |
| Style | Gets the font style. |
| SupportedFeatures | Gets the list of OpenType feature tags supported by the font. |
| SupportedLanguages | Gets the BCP-47 language tags the font advertises as supported (the slng data tag in the OpenType meta table). |
| SupportedUnicodeRange | Gets the union of Unicode codepoint ranges covered by the font's character map. |
| TextShaperTypeface | Gets the typeface information used by the text shaper for this font. |
| TypographicFamilyName | Gets the typographic family name of the font. |
| VariationAxes | Gets the variation axes declared by the font's fvar table, in declaration order. Empty for static fonts. |
| Weight | Gets 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; }
NamedInstances Property
Gets the named variation instances declared by the font's fvar table, in
declaration order. Empty for static fonts.
public System.Collections.Generic.IReadOnlyList<Avalonia.Media.FontVariationInstance> NamedInstances { get; set; }
Remarks
Named instances are pre-defined points in variation space the font designer has
labeled (e.g. "SemiBold" at wght=600). Pass an instance's
Avalonia.Media.FontVariationInstance.Index to
Avalonia.Media.GlyphTypeface.CreateNormalizedPosition(Avalonia.Media.FontVariationSettings,Nullable{int}) as a shorthand for "give me the
position of this preset".
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.
For variation clones, the shaper is derived from the source's shaper via
Avalonia.Media.ITextShaperTypeface.WithVariation(Avalonia.Media.NormalizedVariationPosition) so face-level state (HarfBuzz
hb_face_t, parsed shaping tables) stays shared. The HarfBuzz shaper
returns a distinct shaping font carrying the clone's normalized coordinates,
which the clone owns and releases on Avalonia.Media.GlyphTypeface.Dispose. A shaper without
variation support returns the source's instance, and the clone is shaped at
the default instance.
TypographicFamilyName Property
Gets the typographic family name of the font.
public string TypographicFamilyName { get; set; }
VariationAxes Property
Gets the variation axes declared by the font's fvar table, in declaration
order. Empty for static fonts.
public System.Collections.Generic.IReadOnlyList<Avalonia.Media.FontVariationAxis> VariationAxes { get; set; }
Remarks
Axes describe the design dimensions the font exposes — common ones are
wght (weight), wdth (width), opsz (optical size),
ital (italic), and slnt (slant). Each Avalonia.Media.FontVariationAxis
carries its minimum / default / maximum user-space values and a human-readable
name. Desired user-space values are expressed as a
Avalonia.Media.FontVariationSettings; the renderer normalizes them per font when
the settings are applied.
Weight Property
Gets the font weight.
public Avalonia.Media.FontWeight Weight { get; set; }