@@ -520,62 +520,63 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
520
520
return promise ;
521
521
}
522
522
523
- var loadedName = font .loadedName ;
524
- if (!loadedName ) {
525
- // keep track of each font we translated so the caller can
526
- // load them asynchronously before calling display on a page
527
- loadedName = 'g_font_' + this .uniquePrefix + (this .idCounters .font + 1 );
528
- font .loadedName = loadedName ;
523
+ if (font .loaded ) {
524
+ promise .resolve ({
525
+ font : font ,
526
+ dependencies : {}
527
+ });
528
+ return promise ;
529
+ }
529
530
531
+ // keep track of each font we translated so the caller can
532
+ // load them asynchronously before calling display on a page
533
+ font .loadedName = 'g_font_' + this .uniquePrefix +
534
+ (this .idCounters .font + 1 );
535
+
536
+ if (!font .translated ) {
530
537
var translated ;
531
538
try {
532
539
translated = this .translateFont (font , xref );
533
540
} catch (e ) {
534
541
if (e instanceof MissingDataException ) {
535
- font .loadedName = null ;
536
542
throw e ;
537
543
}
538
544
translated = new ErrorFont (e instanceof Error ? e .message : e );
539
545
}
540
546
font .translated = translated ;
547
+ }
541
548
542
- if (translated .loadCharProcs ) {
543
- delete translated .loadCharProcs ;
544
-
545
- var charProcs = font .get ('CharProcs' ).getAll ();
546
- var fontResources = font .get ('Resources' ) || resources ;
547
- var opListPromises = [];
548
- var charProcKeys = Object .keys (charProcs );
549
+ if (font .translated .loadCharProcs ) {
550
+ var charProcs = font .get ('CharProcs' ).getAll ();
551
+ var fontResources = font .get ('Resources' ) || resources ;
552
+ var opListPromises = [];
553
+ var charProcKeys = Object .keys (charProcs );
554
+ for (var i = 0 , n = charProcKeys .length ; i < n ; ++i ) {
555
+ var key = charProcKeys [i ];
556
+ var glyphStream = charProcs [key ];
557
+ opListPromises .push (
558
+ this .getOperatorList (glyphStream , fontResources ));
559
+ }
560
+ Promise .all (opListPromises ).then (function (datas ) {
561
+ var charProcOperatorList = {};
562
+ var dependencies = {};
549
563
for (var i = 0 , n = charProcKeys .length ; i < n ; ++i ) {
550
564
var key = charProcKeys [i ];
551
- var glyphStream = charProcs [ key ];
552
- opListPromises . push (
553
- this . getOperatorList ( glyphStream , fontResources ) );
565
+ var data = datas [ i ];
566
+ charProcOperatorList [ key ] = data . queue ;
567
+ Util . extendObj ( dependencies , data . dependencies );
554
568
}
555
- Promise .all (opListPromises ).then (function (datas ) {
556
- var charProcOperatorList = {};
557
- var dependencies = {};
558
- for (var i = 0 , n = charProcKeys .length ; i < n ; ++i ) {
559
- var key = charProcKeys [i ];
560
- var data = datas [i ];
561
- charProcOperatorList [key ] = data .queue ;
562
- Util .extendObj (dependencies , data .dependencies );
563
- }
564
- translated .charProcOperatorList = charProcOperatorList ;
565
- promise .resolve ({
566
- font : font ,
567
- dependencies : dependencies
568
- });
569
- });
570
- } else {
569
+ font .translated .charProcOperatorList = charProcOperatorList ;
570
+ font .loaded = true ;
571
+ ++this .idCounters .font ;
571
572
promise .resolve ({
572
573
font : font ,
573
- dependencies : {}
574
+ dependencies : dependencies
574
575
});
575
- }
576
-
577
- ++this .idCounters .font ;
576
+ }.bind (this ));
578
577
} else {
578
+ ++this .idCounters .font ;
579
+ font .loaded = true ;
579
580
promise .resolve ({
580
581
font : font ,
581
582
dependencies : {}
0 commit comments