{"record":{"id":"f4eb24e096afc13f","repo":"AvaloniaUI/Avalonia","slug":"no-cmap-table-found","errorCode":null,"errorMessage":"No cmap table found.","messagePattern":"No cmap table found\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/Fonts/Tables/Cmap/CmapTable.cs","lineNumber":21,"sourceCode":"\nnamespace Avalonia.Media.Fonts.Tables.Cmap\n{\n    /// <summary>\n    /// Represents the 'cmap' table in an OpenType font, which maps character codes to glyph indices.\n    /// </summary>\n    /// <remarks>The 'cmap' table is a critical component of an OpenType font, enabling the mapping of\n    /// character codes (e.g., Unicode) to glyph indices used for rendering text. This class provides functionality to\n    /// load and parse the 'cmap' table from a font's platform-specific typeface.</remarks>\n    internal sealed class CmapTable\n    {\n        internal const string TableName = \"cmap\";\n        internal static OpenTypeTag Tag { get; } = OpenTypeTag.Parse(TableName);\n\n        public static CharacterToGlyphMap Load(GlyphTypeface glyphTypeface)\n        {\n            if (!glyphTypeface.PlatformTypeface.TryGetTable(Tag, out var table))\n            {\n                throw new InvalidOperationException(\"No cmap table found.\");\n            }\n\n            var reader = new BigEndianBinaryReader(table.Span);\n\n            reader.ReadUInt16(); // version\n\n            var numTables = reader.ReadUInt16();\n\n            var entries = new CmapSubtableEntry[numTables];\n\n            for (var i = 0; i < numTables; i++)\n            {\n                var platformID = (PlatformID)reader.ReadUInt16();\n                var encodingID = (CmapEncoding)reader.ReadUInt16();\n                var offset = (int)reader.ReadUInt32();\n\n                var position = reader.Position;\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/Fonts/Tables/Cmap/CmapTable.cs#L3-L39","documentation":"CmapTable.Load throws InvalidOperationException when the font's platform typeface has no 'cmap' table. The cmap table maps character codes (Unicode) to glyph indices and is essential for text rendering — a font without it cannot be used for character-to-glyph mapping. This is an internal API typically reached during GlyphTypeface construction.","triggerScenarios":"Loading a GlyphTypeface from a font file/stream that lacks a 'cmap' table. Happens with malformed fonts, some legacy/symbol fonts, bitmap-only fonts, or truncated/corrupt font data. Reached internally when the font manager creates a typeface for rendering.","commonSituations":"Bundling a corrupt or non-standard font file. Using a bitmap-only font (FON/FNT) that has no cmap. A truncated download of a font resource. A font file that is actually a collection where the selected face lacks cmap. Embedding a font in avares: that got damaged.","solutions":["Use a valid, standard TrueType/OpenType font that includes a cmap table (verify with a font inspector like FontForge).","If loading from a stream/resource, verify the data is complete and not truncated.","Catch the exception at font-loading boundaries and fall back to a known-good system font.","For custom font collections, ensure each face exposes a cmap subtable."],"exampleFix":"// before\nvar typeface = new GlyphTypeface(new Uri(\"avares://App/Assets/brokenfont.ttf\"));\n\n// after\nGlyphTypeface typeface;\ntry\n{\n    typeface = new GlyphTypeface(new Uri(\"avares://App/Assets/myfont.ttf\"));\n}\ncatch (InvalidOperationException)\n{\n    typeface = new GlyphTypeface(new Uri(\"avares://App/Assets/fallback.ttf\"));\n}","handlingStrategy":"try-catch","validationCode":"// Validate the font has a cmap table before constructing a GlyphTypeface\n// (no public pre-check exists; validate the source file with a font library, or catch):","typeGuard":null,"tryCatchPattern":"GlyphTypeface typeface;\ntry\n{\n    typeface = new GlyphTypeface(fontUri);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"cmap\"))\n{\n    typeface = new GlyphTypeface(fallbackFontUri);\n}","preventionTips":["Validate font files with a font inspector (FontForge, OpenType.js) before bundling.","Bundle a known-good fallback font for corrupt/unloadable cases.","Catch InvalidOperationException at font-loading boundaries and degrade gracefully.","Avoid bitmap-only or legacy fonts that lack cmap tables."],"tags":["font","opentype","cmap","typeface","media","corrupt-data"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}