Class GlyphAtlasCache
Reads a TMPro.TMP_FontAsset and caches pre-packed glyph UV coordinates and metrics for efficient Cell stamping. When a cell's codepoint changes, the cache provides the atlas UV and metrics data without dictionary lookups on the GPU.
v0.1.0 Limitation: Only the primary atlas page (index 0) is used for rendering.
The AtlasIndex is stored per glyph for future multi-atlas
support, but the shader currently binds a single _FontAtlas texture. Fonts with
glyphs that overflow to additional atlas pages will render those glyphs with incorrect UVs.
Use font assets with sufficient atlas resolution to keep all needed glyphs on a single page.
Implements
Inherited Members
Namespace: Scylla.TextMode
Assembly: ScyllaTextMode.dll
Syntax
public sealed class GlyphAtlasCache : IDisposable
Properties
AdvanceWidth
Gets the monospace advance width in font metric units. For monospace fonts, all characters share the same advance.
Declaration
public float AdvanceWidth { get; }
Property Value
| Type | Description |
|---|---|
| float |
AscentLine
Gets the font ascent line in font units.
Declaration
public float AscentLine { get; }
Property Value
| Type | Description |
|---|---|
| float |
AtlasHeight
Gets the atlas texture height in pixels.
Declaration
public float AtlasHeight { get; }
Property Value
| Type | Description |
|---|---|
| float |
AtlasPadding
Gets the SDF atlas padding in pixels (padding added on each side of each glyph).
Declaration
public int AtlasPadding { get; }
Property Value
| Type | Description |
|---|---|
| int |
AtlasTexture
Gets the primary atlas texture.
Declaration
public Texture2D AtlasTexture { get; }
Property Value
| Type | Description |
|---|---|
| Texture2D |
AtlasTextures
Gets all atlas textures for multi-atlas support.
Declaration
public Texture2D[] AtlasTextures { get; }
Property Value
| Type | Description |
|---|---|
| Texture2D[] |
AtlasWidth
Gets the atlas texture width in pixels.
Declaration
public float AtlasWidth { get; }
Property Value
| Type | Description |
|---|---|
| float |
CachedGlyphCount
Gets the number of cached glyphs.
Declaration
public int CachedGlyphCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
DescentLine
Gets the font descent line in font units.
Declaration
public float DescentLine { get; }
Property Value
| Type | Description |
|---|---|
| float |
FontAsset
Gets the font asset used by this cache.
Declaration
public TMP_FontAsset FontAsset { get; }
Property Value
| Type | Description |
|---|---|
| TMP_FontAsset |
InkBottom
Gets the lowest point reached by any ordinary text glyph, in font units relative to the baseline (negative below it). This is the real bottom of the ink rather than the font's descent line, which usually sits some way below the deepest descender.
Declaration
public float InkBottom { get; }
Property Value
| Type | Description |
|---|---|
| float |
Remarks
Glyphs flagged EdgeBottom are excluded, for the same reason given on InkTop.
Falls back to DescentLine when no glyphs are cached.
InkTop
Gets the highest point reached by any ordinary text glyph, in font units above the baseline. This is the real top of the ink rather than the font's ascent line, which usually sits some way above the tallest glyph.
Declaration
public float InkTop { get; }
Property Value
| Type | Description |
|---|---|
| float |
Remarks
Glyphs flagged EdgeTop are excluded, because box-drawing and block-element characters deliberately overshoot the cell so that they tile seamlessly with the row above. Including them would report the overshoot as ink and leave the layout believing there is no spare room at the top of the line.
Falls back to AscentLine when no glyphs are cached.
LineHeight
Gets the font line height in font units.
Declaration
public float LineHeight { get; }
Property Value
| Type | Description |
|---|---|
| float |
PointSize
Gets the font point size used to generate the SDF atlas.
Declaration
public float PointSize { get; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
Dispose()
Releases cached data.
Declaration
public void Dispose()
GetGlyph(uint)
Gets the pre-packed glyph data for a codepoint. Returns the fallback glyph if the codepoint is not in the cache.
Declaration
public PackedGlyphData GetGlyph(uint codepoint)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | codepoint | Unicode codepoint. |
Returns
| Type | Description |
|---|---|
| PackedGlyphData | The packed glyph data. |
HasGlyph(uint)
Checks whether a codepoint has a cached glyph.
Declaration
public bool HasGlyph(uint codepoint)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | codepoint | Unicode codepoint. |
Returns
| Type | Description |
|---|---|
| bool | True if the codepoint is in the cache. |
Initialize(TMP_FontAsset)
Initializes the cache from a TMP font asset. Reads all characters from the font's character lookup table and pre-packs their atlas UV coordinates and metrics.
Declaration
public void Initialize(TMP_FontAsset fontAsset)
Parameters
| Type | Name | Description |
|---|---|---|
| TMP_FontAsset | fontAsset | The TMP font asset to read from. |
StampCell(ref Cell, uint)
Stamps the atlas UV and metrics data for a codepoint into a cell. This pre-populates the GPU-read fields so the shader needs no dictionary lookup.
Declaration
public void StampCell(ref Cell cell, uint codepoint)
Parameters
| Type | Name | Description |
|---|---|---|
| Cell | cell | Reference to the cell to stamp. |
| uint | codepoint | Unicode codepoint. |