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:
commit
92ff26e4ff
@ -485,6 +485,8 @@ function adjustMapping(charCodeToGlyphId, hasGlyph, newGlyphZeroId, toUnicode) {
|
|||||||
const isInPrivateArea = code =>
|
const isInPrivateArea = code =>
|
||||||
(PRIVATE_USE_AREAS[0][0] <= code && code <= PRIVATE_USE_AREAS[0][1]) ||
|
(PRIVATE_USE_AREAS[0][0] <= code && code <= PRIVATE_USE_AREAS[0][1]) ||
|
||||||
(PRIVATE_USE_AREAS[1][0] <= code && code <= PRIVATE_USE_AREAS[1][1]);
|
(PRIVATE_USE_AREAS[1][0] <= code && code <= PRIVATE_USE_AREAS[1][1]);
|
||||||
|
let LIGATURE_TO_UNICODE = null;
|
||||||
|
|
||||||
for (const originalCharCode in charCodeToGlyphId) {
|
for (const originalCharCode in charCodeToGlyphId) {
|
||||||
let glyphId = charCodeToGlyphId[originalCharCode];
|
let glyphId = charCodeToGlyphId[originalCharCode];
|
||||||
// For missing glyphs don't create the mappings so the glyph isn't
|
// 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.
|
// glyph ids to the correct unicode.
|
||||||
let unicode = toUnicode.get(originalCharCode);
|
let unicode = toUnicode.get(originalCharCode);
|
||||||
if (typeof unicode === "string") {
|
if (typeof unicode === "string") {
|
||||||
|
if (unicode.length === 1) {
|
||||||
unicode = unicode.codePointAt(0);
|
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)) {
|
if (unicode && !isInPrivateArea(unicode) && !usedGlyphIds.has(glyphId)) {
|
||||||
toUnicodeExtraMap.set(unicode, glyphId);
|
toUnicodeExtraMap.set(unicode, glyphId);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user