diff --git a/src/core/fonts.js b/src/core/fonts.js index 67f8c2b27..3769c88a6 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -485,6 +485,8 @@ function adjustMapping(charCodeToGlyphId, hasGlyph, newGlyphZeroId, toUnicode) { const isInPrivateArea = code => (PRIVATE_USE_AREAS[0][0] <= code && code <= PRIVATE_USE_AREAS[0][1]) || (PRIVATE_USE_AREAS[1][0] <= code && code <= PRIVATE_USE_AREAS[1][1]); + let LIGATURE_TO_UNICODE = null; + for (const originalCharCode in charCodeToGlyphId) { let glyphId = charCodeToGlyphId[originalCharCode]; // For missing glyphs don't create the mappings so the glyph isn't @@ -514,7 +516,23 @@ function adjustMapping(charCodeToGlyphId, hasGlyph, newGlyphZeroId, toUnicode) { // glyph ids to the correct unicode. let unicode = toUnicode.get(originalCharCode); if (typeof unicode === "string") { - unicode = unicode.codePointAt(0); + if (unicode.length === 1) { + unicode = unicode.codePointAt(0); + } else { + if (!LIGATURE_TO_UNICODE) { + LIGATURE_TO_UNICODE = new Map(); + // The code range [0xfb00, 0xfb4f] contains some ligature characters + // but not all. + // See https://www.compart.com/en/unicode/block/U+FB00. + for (let i = 0xfb00; i <= 0xfb4f; i++) { + const normalized = String.fromCharCode(i).normalize("NFKD"); + if (normalized.length > 1) { + LIGATURE_TO_UNICODE.set(normalized, i); + } + } + } + unicode = LIGATURE_TO_UNICODE.get(unicode) || unicode.codePointAt(0); + } } if (unicode && !isInPrivateArea(unicode) && !usedGlyphIds.has(glyphId)) { toUnicodeExtraMap.set(unicode, glyphId);