1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #19427 from calixteman/bug1946181

Add some unicode mapping for ligatures when writing the cmap table in the font (bug 1946181)
This commit is contained in:
calixteman 2025-02-14 17:46:07 +01:00 committed by GitHub
commit 92ff26e4ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);