@@ -200,9 +200,6 @@ function adjustToUnicode(properties, builtInEncoding) {
200
200
if ( properties . hasIncludedToUnicodeMap ) {
201
201
return ; // The font dictionary has a `ToUnicode` entry.
202
202
}
203
- if ( properties . hasEncoding ) {
204
- return ; // The font dictionary has an `Encoding` entry.
205
- }
206
203
if ( builtInEncoding === properties . defaultEncoding ) {
207
204
return ; // No point in trying to adjust `toUnicode` if the encodings match.
208
205
}
@@ -212,6 +209,12 @@ function adjustToUnicode(properties, builtInEncoding) {
212
209
var toUnicode = [ ] ,
213
210
glyphsUnicodeMap = getGlyphsUnicode ( ) ;
214
211
for ( var charCode in builtInEncoding ) {
212
+ if (
213
+ properties . hasEncoding &&
214
+ properties . differences [ charCode ] !== undefined
215
+ ) {
216
+ continue ; // The font dictionary has an `Encoding`/`Differences` entry.
217
+ }
215
218
var glyphName = builtInEncoding [ charCode ] ;
216
219
var unicode = getUnicodeForGlyph ( glyphName , glyphsUnicodeMap ) ;
217
220
if ( unicode !== - 1 ) {
@@ -4012,6 +4015,7 @@ var CFFFont = (function CFFFontClosure() {
4012
4015
// anyway and hope the font loaded.
4013
4016
this . data = file ;
4014
4017
}
4018
+ this . _createBuiltInEncoding ( ) ;
4015
4019
}
4016
4020
4017
4021
CFFFont . prototype = {
@@ -4057,6 +4061,32 @@ var CFFFont = (function CFFFontClosure() {
4057
4061
hasGlyphId : function CFFFont_hasGlyphID ( id ) {
4058
4062
return this . cff . hasGlyphId ( id ) ;
4059
4063
} ,
4064
+
4065
+ /**
4066
+ * @private
4067
+ */
4068
+ _createBuiltInEncoding ( ) {
4069
+ const { charset, encoding } = this . cff ;
4070
+ if ( ! charset || ! encoding ) {
4071
+ return ;
4072
+ }
4073
+ const charsets = charset . charset ,
4074
+ encodings = encoding . encoding ;
4075
+ const map = [ ] ;
4076
+
4077
+ for ( const charCode in encodings ) {
4078
+ const glyphId = encodings [ charCode ] ;
4079
+ if ( glyphId >= 0 ) {
4080
+ const glyphName = charsets [ glyphId ] ;
4081
+ if ( glyphName ) {
4082
+ map [ charCode ] = glyphName ;
4083
+ }
4084
+ }
4085
+ }
4086
+ if ( map . length > 0 ) {
4087
+ this . properties . builtInEncoding = map ;
4088
+ }
4089
+ } ,
4060
4090
} ;
4061
4091
4062
4092
return CFFFont ;
0 commit comments