For CFF fonts without proper ToUnicode
/Encoding
data, utilize the "charset"/"Encoding"-data from the font file to improve text-selection (issue 13260)
This patch extends the approach, implemented in PR 7550, to also apply to CFF fonts.
This commit is contained in:
parent
fd82adccfa
commit
7fab73ed23
@ -2853,7 +2853,7 @@ class PartialEvaluator {
|
||||
}
|
||||
|
||||
if (baseEncodingName) {
|
||||
properties.defaultEncoding = getEncoding(baseEncodingName).slice();
|
||||
properties.defaultEncoding = getEncoding(baseEncodingName);
|
||||
} else {
|
||||
var isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
|
||||
var isNonsymbolicFont = !!(properties.flags & FontFlags.Nonsymbolic);
|
||||
|
@ -200,9 +200,6 @@ function adjustToUnicode(properties, builtInEncoding) {
|
||||
if (properties.hasIncludedToUnicodeMap) {
|
||||
return; // The font dictionary has a `ToUnicode` entry.
|
||||
}
|
||||
if (properties.hasEncoding) {
|
||||
return; // The font dictionary has an `Encoding` entry.
|
||||
}
|
||||
if (builtInEncoding === properties.defaultEncoding) {
|
||||
return; // No point in trying to adjust `toUnicode` if the encodings match.
|
||||
}
|
||||
@ -212,6 +209,12 @@ function adjustToUnicode(properties, builtInEncoding) {
|
||||
var toUnicode = [],
|
||||
glyphsUnicodeMap = getGlyphsUnicode();
|
||||
for (var charCode in builtInEncoding) {
|
||||
if (
|
||||
properties.hasEncoding &&
|
||||
properties.differences[charCode] !== undefined
|
||||
) {
|
||||
continue; // The font dictionary has an `Encoding`/`Differences` entry.
|
||||
}
|
||||
var glyphName = builtInEncoding[charCode];
|
||||
var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
|
||||
if (unicode !== -1) {
|
||||
@ -4012,6 +4015,7 @@ var CFFFont = (function CFFFontClosure() {
|
||||
// anyway and hope the font loaded.
|
||||
this.data = file;
|
||||
}
|
||||
this._createBuiltInEncoding();
|
||||
}
|
||||
|
||||
CFFFont.prototype = {
|
||||
@ -4057,6 +4061,32 @@ var CFFFont = (function CFFFontClosure() {
|
||||
hasGlyphId: function CFFFont_hasGlyphID(id) {
|
||||
return this.cff.hasGlyphId(id);
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_createBuiltInEncoding() {
|
||||
const { charset, encoding } = this.cff;
|
||||
if (!charset || !encoding) {
|
||||
return;
|
||||
}
|
||||
const charsets = charset.charset,
|
||||
encodings = encoding.encoding;
|
||||
const map = [];
|
||||
|
||||
for (const charCode in encodings) {
|
||||
const glyphId = encodings[charCode];
|
||||
if (glyphId >= 0) {
|
||||
const glyphName = charsets[glyphId];
|
||||
if (glyphName) {
|
||||
map[charCode] = glyphName;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (map.length > 0) {
|
||||
this.properties.builtInEncoding = map;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return CFFFont;
|
||||
|
Loading…
Reference in New Issue
Block a user