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.
This commit is contained in:
parent
246d565e3b
commit
3660aaac85
@ -135,9 +135,6 @@ function adjustToUnicode(properties, builtInEncoding) {
|
|||||||
if (properties.isInternalFont) {
|
if (properties.isInternalFont) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (properties.hasIncludedToUnicodeMap) {
|
|
||||||
return; // The font dictionary has a `ToUnicode` entry.
|
|
||||||
}
|
|
||||||
if (builtInEncoding === properties.defaultEncoding) {
|
if (builtInEncoding === properties.defaultEncoding) {
|
||||||
return; // No point in trying to adjust `toUnicode` if the encodings match.
|
return; // No point in trying to adjust `toUnicode` if the encodings match.
|
||||||
}
|
}
|
||||||
@ -147,11 +144,17 @@ function adjustToUnicode(properties, builtInEncoding) {
|
|||||||
const toUnicode = [],
|
const toUnicode = [],
|
||||||
glyphsUnicodeMap = getGlyphsUnicode();
|
glyphsUnicodeMap = getGlyphsUnicode();
|
||||||
for (const charCode in builtInEncoding) {
|
for (const charCode in builtInEncoding) {
|
||||||
if (
|
if (properties.hasIncludedToUnicodeMap) {
|
||||||
properties.hasEncoding &&
|
if (properties.toUnicode.has(charCode)) {
|
||||||
properties.differences[charCode] !== undefined
|
continue; // The font dictionary has a `ToUnicode` entry.
|
||||||
) {
|
}
|
||||||
continue; // The font dictionary has an `Encoding`/`Differences` entry.
|
} else {
|
||||||
|
if (
|
||||||
|
properties.hasEncoding &&
|
||||||
|
properties.differences[charCode] !== undefined
|
||||||
|
) {
|
||||||
|
continue; // The font dictionary has an `Encoding`/`Differences` entry.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const glyphName = builtInEncoding[charCode];
|
const glyphName = builtInEncoding[charCode];
|
||||||
const unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
|
const unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
|
||||||
@ -159,7 +162,9 @@ function adjustToUnicode(properties, builtInEncoding) {
|
|||||||
toUnicode[charCode] = String.fromCharCode(unicode);
|
toUnicode[charCode] = String.fromCharCode(unicode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
properties.toUnicode.amend(toUnicode);
|
if (toUnicode.length > 0) {
|
||||||
|
properties.toUnicode.amend(toUnicode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Glyph {
|
class Glyph {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user