{"record":{"id":"34a2a6472ed1ca46","repo":"parallax/jsPDF","slug":"no-unicode-cmap-for-font","errorCode":null,"errorMessage":"No unicode cmap for font","messagePattern":"No unicode cmap for font","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/libs/ttffont.js","lineNumber":128,"sourceCode":"      _ref === 5 ||\n      _ref === 7;\n    this.isScript = this.familyClass === 10;\n    this.flags = 0;\n    if (this.post.isFixedPitch) {\n      this.flags |= 1 << 0;\n    }\n    if (this.isSerif) {\n      this.flags |= 1 << 1;\n    }\n    if (this.isScript) {\n      this.flags |= 1 << 3;\n    }\n    if (this.italicAngle !== 0) {\n      this.flags |= 1 << 6;\n    }\n    this.flags |= 1 << 5;\n    if (!this.cmap.unicode) {\n      throw new Error(\"No unicode cmap for font\");\n    }\n  };\n  TTFFont.prototype.characterToGlyph = function(character) {\n    var _ref;\n    return (\n      ((_ref = this.cmap.unicode) != null ? _ref.codeMap[character] : void 0) ||\n      0\n    );\n  };\n  TTFFont.prototype.widthOfGlyph = function(glyph) {\n    var scale;\n    scale = 1000.0 / this.head.unitsPerEm;\n    return this.hmtx.forGlyph(glyph).advance * scale;\n  };\n  TTFFont.prototype.widthOfString = function(string, size, charSpace) {\n    var charCode, i, scale, width, _ref;\n    string = \"\" + string;\n    width = 0;","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/libs/ttffont.js#L110-L146","documentation":"Thrown in TTFFont.registerTTF after parsing when the font's cmap table has no Unicode subtable (this.cmap.unicode is falsy). jsPDF's text layout relies on a Unicode cmap to map characters to glyph IDs; without one it cannot render arbitrary text, so it aborts. Symbol/fonts with only platform-specific or Mac Roman encodings trigger this.","triggerScenarios":"Registering a TTF that lacks a Unicode (platform 3 encoding 1, or platform 0) cmap subtable -- e.g. pure symbol fonts, some old Mac-only fonts, or a subset that dropped the Unicode cmap.","commonSituations":"Using a dingbat/symbol font; subsetting a font with a tool that omitted the Unicode cmap; embedding a font converted from an obscure source.","solutions":["Use a font that includes a Unicode cmap (most modern .ttf do; verify with fonttools `ttdump`/`ttx`).","Re-subset the font ensuring the 'cmap' table's format 4 / format 12 Unicode subtable is retained.","If you only need glyphs, switch to a standard jsPDF font that already has Unicode support."],"exampleFix":"// before (symbol font with no unicode cmap)\ndoc.addFileToVFS('MySymbols.ttf', bytes);\ndoc.addFont('MySymbols.ttf', 'MySymbols', 'normal'); // throws on registerTTF\n\n// after (re-export font with a unicode cmap subtable, then register)\ndoc.addFileToVFS('MySymbols-uni.ttf', bytesWithUnicodeCmap);\ndoc.addFont('MySymbols-uni.ttf', 'MySymbols', 'normal');","handlingStrategy":"try-catch","validationCode":"// Lightweight pre-check: parse the cmap table to confirm a unicode subtable.\n// In practice, wrap registration in try/catch (see tryCatchPattern).\nnull;","typeGuard":"// Requires parsing; no cheap guard. Use try/catch around TTFFont.open / addFont.","tryCatchPattern":"try {\n  doc.addFont(fontKey, family, style);\n} catch (e) {\n  if (/No unicode cmap for font/.test(e.message)) {\n    console.warn('Font lacks a unicode cmap; use a font with format 4/12 cmap');\n    return;\n  }\n  throw e;\n}","preventionTips":["Use fonts known to ship a Unicode cmap (format 4 or 12).","When subsetting, retain the Unicode cmap subtable.","Avoid pure symbol/Mac-encoded fonts for general text."],"tags":["font","ttf","cmap","unicode","validation"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}