From 3660aaac85e6be571c238e969d9cf5ca598e4215 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 17 May 2021 14:34:08 +0200 Subject: [PATCH] Tweak `adjustToUnicode` to allow extending a built-in /ToUnicode map *This is somewhat similiar to the recent changes, in PR 13277, for fonts with an /Encoding entry.* Currently we're *completely* ignoring the `builtInEncoding`, from the font data itself, for fonts which have a built-in /ToUnicode map. While it (obviously) doesn't seem like a good idea in general to simply overwrite existing built-in /ToUnicode entries, it should however not hurt to use the `builtInEncoding` to supplement *missing* /ToUnicode entires. --- src/core/fonts.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/core/fonts.js b/src/core/fonts.js index 8b8ec434d..b391ab693 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -135,9 +135,6 @@ function adjustToUnicode(properties, builtInEncoding) { if (properties.isInternalFont) { return; } - if (properties.hasIncludedToUnicodeMap) { - return; // The font dictionary has a `ToUnicode` entry. - } if (builtInEncoding === properties.defaultEncoding) { return; // No point in trying to adjust `toUnicode` if the encodings match. } @@ -147,11 +144,17 @@ function adjustToUnicode(properties, builtInEncoding) { const toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode(); for (const charCode in builtInEncoding) { - if ( - properties.hasEncoding && - properties.differences[charCode] !== undefined - ) { - continue; // The font dictionary has an `Encoding`/`Differences` entry. + if (properties.hasIncludedToUnicodeMap) { + if (properties.toUnicode.has(charCode)) { + continue; // The font dictionary has a `ToUnicode` entry. + } + } else { + if ( + properties.hasEncoding && + properties.differences[charCode] !== undefined + ) { + continue; // The font dictionary has an `Encoding`/`Differences` entry. + } } const glyphName = builtInEncoding[charCode]; const unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap); @@ -159,7 +162,9 @@ function adjustToUnicode(properties, builtInEncoding) { toUnicode[charCode] = String.fromCharCode(unicode); } } - properties.toUnicode.amend(toUnicode); + if (toUnicode.length > 0) { + properties.toUnicode.amend(toUnicode); + } } class Glyph {