@@ -1333,67 +1333,59 @@ var Type1Parser = function() {
1333
1333
* extracted from and eexec encrypted block of data
1334
1334
*/
1335
1335
this .extractFontProgram = function t1_extractFontProgram (stream ) {
1336
- var eexecString = decrypt (stream , kEexecEncryptionKey , 4 );
1337
- var subrs = [], glyphs = [];
1338
- var inGlyphs = false ;
1339
- var inSubrs = false ;
1340
- var glyph = "" ;
1336
+ var eexec = decrypt (stream , kEexecEncryptionKey , 4 );
1337
+ var eexecString = "" ;
1338
+ for (var i = 0 ; i < eexec .length ; i ++)
1339
+ eexecString += String .fromCharCode (eexec [i ]);
1340
+
1341
+ var glyphsSection = false , subrsSection = false ;
1342
+ var extracted = {
1343
+ subrs : [],
1344
+ charstrings : []
1345
+ };
1341
1346
1347
+ var glyph = "" ;
1342
1348
var token = "" ;
1343
- var index = 0 ;
1344
1349
var length = 0 ;
1345
1350
1346
1351
var c = "" ;
1347
1352
var count = eexecString .length ;
1348
1353
for (var i = 0 ; i < count ; i ++) {
1349
1354
var c = eexecString [i ];
1350
1355
1351
- if (inSubrs && c == 0x52 ) {
1352
- length = parseInt (length );
1353
- var data = eexecString .slice (i + 3 , i + 3 + length );
1354
- var encodedSubr = decrypt (data , kCharStringsEncryptionKey , 4 );
1355
- var str = decodeCharString (encodedSubr );
1356
-
1357
- subrs .push (str .charstring );
1358
- i += 3 + length ;
1359
- } else if (inGlyphs && c == 0x52 ) {
1360
- length = parseInt (length );
1361
- var data = eexecString .slice (i + 3 , i + 3 + length );
1362
- var encodedCharstring = decrypt (data , kCharStringsEncryptionKey , 4 );
1363
- var str = decodeCharString (encodedCharstring );
1364
-
1365
- glyphs .push ({
1356
+ if ((glyphsSection || subrsSection ) && c == "R" ) {
1357
+ var data = eexec .slice (i + 3 , i + 3 + length );
1358
+ var encoded = decrypt (data , kCharStringsEncryptionKey , 4 );
1359
+ var str = decodeCharString (encoded );
1360
+
1361
+ if (glyphsSection ) {
1362
+ extracted .charstrings .push ({
1366
1363
glyph : glyph ,
1367
1364
data : str .charstring ,
1368
1365
lsb : str .lsb ,
1369
1366
width : str .width
1370
- });
1371
- i += 3 + length ;
1372
- } else if (inGlyphs && c == 0x2F ) {
1373
- token = "" ;
1374
- glyph = "" ;
1375
-
1376
- while ((c = eexecString [++i ]) != 0x20 )
1377
- glyph += String .fromCharCode (c );
1378
- } else if (!inSubrs && !inGlyphs && c == 0x2F && eexecString [i +1 ] == 0x53 ) {
1379
- while ((c = eexecString [++i ]) != 0x20 ) {};
1380
- inSubrs = true ;
1381
- } else if (c == 0x20 ) {
1382
- index = length ;
1383
- length = token ;
1367
+ });
1368
+ } else {
1369
+ extracted .subrs .push (str .charstring );
1370
+ }
1371
+ i += length + 3 ;
1372
+ } else if (c == " " ) {
1373
+ length = parseInt (token );
1384
1374
token = "" ;
1385
- } else if (c == 0x2F && eexecString [i +1 ] == 0x43 && eexecString [i +2 ] == 0x68 ) {
1386
- while ((c = eexecString [++i ]) != 0x20 ) {};
1387
- inSubrs = false ;
1388
- inGlyphs = true ;
1389
1375
} else {
1390
- token += String .fromCharCode (c );
1376
+ token += c ;
1377
+ if (!glyphsSection ) {
1378
+ glyphsSection = token .indexOf ("/CharString" ) != -1 ;
1379
+ subrsSection = subrsSection || token .indexOf ("Subrs" ) != -1 ;
1380
+ } else if (c == "/" ) {
1381
+ token = glyph = "" ;
1382
+ while ((c = eexecString [++i ]) != " " )
1383
+ glyph += c ;
1384
+ }
1391
1385
}
1392
1386
}
1393
- return {
1394
- subrs : subrs ,
1395
- charstrings : glyphs
1396
- }
1387
+
1388
+ return extracted ;
1397
1389
}
1398
1390
};
1399
1391
0 commit comments