Docsv3.31.0
Back to API Reference
Class

ColorFontCore

Runtime for a color font (CBDT/sbix bitmap or COLRv0/COLRv1 vector). Plain UniTextFont.Core subclass — not a ScriptableObject; constructable on worker threads. Owns the color-glyph rasterization pipeline: color-format detection, FreeType/Blend2D rendering into the shared color atlas, and color glyph metrics. The system emoji font (EmojiFont) and the UniTextColorFont asset are both built on this base. A glyph an effect decorates also gets a silhouette field in the SDF atlas, derived from the same bitmap's alpha when it is packed.

Derived Types(2)

Types that inherit from ColorFontCore.

public int AtlasSize{ get }

Color atlas page side in pixels (square).

public int AtlasPadding{ get }
public bool IsColor{ get }
public int ColorPixelSize{ get }

Pixel size at which color glyphs are rasterised.

protected string DiagnosticNamePrefix{ get }

Diagnostic name prefix for this runtime's UniTextFont.Core.Name. Lets the system emoji font keep its own label.

public static ColorFontCore CreateFromPath(string fontPath, int faceIndex = 0, int pixelSize = DefaultSize)

Creates a color-font runtime from a font file path (.ttf,.ttc,.otf).

protected bool LoadFromPath(string fontPath, int faceIndex = 0, int pixelSize = DefaultSize)

Maps a font file and loads it into this runtime. Returns false if the file cannot be opened or decoded. Shared by the system emoji font and the color-font factory.

public static ColorFontCore CreateFromData(byte[] fontData, int faceIndex = 0, int pixelSize = DefaultSize, string sourceName = null)

Creates a color-font runtime from raw font file bytes. Detects the colour format (sbix, CBDT, COLRv0/v1) and picks the closest bitmap strike to pixelSize.

protected bool LoadFromData(byte[] fontData, int faceIndex, int pixelSize, string sourceName = null)

Loads and configures this runtime from raw font bytes: detects the colour format (sbix, CBDT, COLRv0/v1), picks the closest bitmap strike to pixelSize, builds face metrics, and creates the shared color atlas. Returns false when the bytes cannot be loaded. Shared by the system emoji font and the color-font asset.

protected static void ConfigureFont(ColorFontCore font, int fontUpem, int pixelSize, int[] availableSizes, short fontAscender = 0, short fontDescender = 0)
public override UniTextFontError LoadFontFace()
public override bool HasGlyphInAtlas(uint glyphIndex, UniTextRenderMode mode)

Returns whether the shared color atlas contains the glyph.

protected static void FitBitmapToAtlas(ref byte[] pixels, ref int width, ref int height, int maxSize)

Downscales a bitmap larger than the atlas content size in place (pooled buffers swapped), preserving its aspect.

protected virtual GlyphMetrics ComputeGlyphMetrics(uint glyphIndex, ColorFontCore.RenderedGlyphData rendered, bool renderedByCOLRv1 = false)

Design-unit metrics of a rendered bitmap. The bitmap's pixel-to-design ratio follows the colour format: the COLRv1 render size, the sbix strike, the CBDT advance, or the requested pixel size. The advance is the font's own, or the rasterizer's measured advance for a font with no face to measure.

protected void RegisterGlyphFromAtlas(uint glyphIndex, GlyphAtlas.GlyphEntry entry)
public override void ClearDynamicData()
public override void Dispose()

Releases color-renderer face pools together with the base runtime's shaping, FreeType and atlas resources.

public void DisposeFacePool()

Releases the parallel color-renderer pool and the shared sequential FreeType face when it currently represents this font.

public static const int DefaultSize

Default color-glyph pixel size — 128 on desktop/mobile, 64 on WebGL.

protected int colorPixelSize