@@ -401,6 +401,48 @@ var symbolsFonts = {
401
401
'Dingbats' : true , 'Symbol' : true , 'ZapfDingbats' : true
402
402
};
403
403
404
+ var CMapConverterList = {
405
+ 'H' : jis7ToUnicode ,
406
+ 'V' : jis7ToUnicode ,
407
+ 'EUC-H' : eucjpToUnicode ,
408
+ 'EUC-V' : eucjpToUnicode ,
409
+ '90ms-RKSJ-H' : sjisToUnicode ,
410
+ '90ms-RKSJ-V' : sjisToUnicode ,
411
+ '90msp-RKSJ-H' : sjisToUnicode ,
412
+ '90msp-RKSJ-V' : sjisToUnicode
413
+ };
414
+
415
+ var decodeBytes ;
416
+ if (typeof TextDecoder !== 'undefined' ) {
417
+ decodeBytes = function (bytes , encoding ) {
418
+ return new TextDecoder (encoding ).decode (bytes );
419
+ };
420
+ } else if (typeof FileReaderSync !== 'undefined' ) {
421
+ decodeBytes = function (bytes , encoding ) {
422
+ return new FileReaderSync ().readAsText (new Blob ( [bytes ]), encoding );
423
+ };
424
+ } else {
425
+ // Clear the list so that decodeBytes will never be called.
426
+ CMapConverterList = {};
427
+ }
428
+
429
+ function jis7ToUnicode (str ) {
430
+ var bytes = stringToBytes (str );
431
+ var length = bytes .length ;
432
+ for (var i = 0 ; i < length ; ++i ) {
433
+ bytes [i ] |= 0x80 ;
434
+ }
435
+ return decodeBytes (bytes , 'euc-jp' );
436
+ }
437
+
438
+ function eucjpToUnicode (str ) {
439
+ return decodeBytes (stringToBytes (str ), 'euc-jp' );
440
+ }
441
+
442
+ function sjisToUnicode (str ) {
443
+ return decodeBytes (stringToBytes (str ), 'shift_jis' );
444
+ }
445
+
404
446
// Some characters, e.g. copyrightserif, mapped to the private use area and
405
447
// might not be displayed using standard fonts. Mapping/hacking well-known chars
406
448
// to the similar equivalents in the normal characters range.
@@ -2282,6 +2324,7 @@ var Font = (function FontClosure() {
2282
2324
2283
2325
// Trying to fix encoding using glyph CIDSystemInfo.
2284
2326
this .loadCidToUnicode (properties );
2327
+ this .cidEncoding = properties .cidEncoding ;
2285
2328
2286
2329
if (properties .toUnicode )
2287
2330
this .toUnicode = properties .toUnicode ;
@@ -4128,8 +4171,8 @@ var Font = (function FontClosure() {
4128
4171
}
4129
4172
4130
4173
var cidEncoding = properties .cidEncoding ;
4131
- if (cidEncoding && cidEncoding .indexOf ('Uni ' ) = == 0 ) {
4132
- // input is already Unicode for Uni* CMap encodings.
4174
+ if (cidEncoding && cidEncoding .indexOf ('Identity- ' ) ! == 0 ) {
4175
+ // input is already Unicode for non-Identity CMap encodings.
4133
4176
// However, Unicode-to-CID conversion is needed
4134
4177
// regardless of the CMap encoding. So we can't reset
4135
4178
// unicodeToCID.
@@ -4304,8 +4347,20 @@ var Font = (function FontClosure() {
4304
4347
charsCache = this .charsCache = Object .create (null );
4305
4348
4306
4349
glyphs = [] ;
4307
-
4308
- if (this .wideChars ) {
4350
+ var charsCacheKey = chars ;
4351
+
4352
+ var converter ;
4353
+ var cidEncoding = this .cidEncoding ;
4354
+ if (cidEncoding ) {
4355
+ converter = CMapConverterList [cidEncoding ];
4356
+ if (converter ) {
4357
+ chars = converter (chars );
4358
+ } else if (cidEncoding .indexOf ('Uni' ) !== 0 &&
4359
+ cidEncoding .indexOf ('Identity-' ) !== 0 ) {
4360
+ warn ('Unsupported CMap: ' + cidEncoding );
4361
+ }
4362
+ }
4363
+ if (!converter && this .wideChars ) {
4309
4364
// composite fonts have multi-byte strings convert the string from
4310
4365
// single-byte to multi-byte
4311
4366
// XXX assuming CIDFonts are two-byte - later need to extract the
@@ -4332,7 +4387,7 @@ var Font = (function FontClosure() {
4332
4387
}
4333
4388
4334
4389
// Enter the translated string into the cache
4335
- return (charsCache [chars ] = glyphs );
4390
+ return (charsCache [charsCacheKey ] = glyphs );
4336
4391
}
4337
4392
};
4338
4393
0 commit comments