Skip to content

Commit

Permalink
Merge pull request #19427 from calixteman/bug1946181
Browse files Browse the repository at this point in the history
Add some unicode mapping for ligatures when writing the cmap table in the font (bug 1946181)
  • Loading branch information
calixteman authored Feb 14, 2025
2 parents 144e5fe + 185ec1f commit 92ff26e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 92ff26e

Please sign in to comment.