@@ -1046,27 +1046,19 @@ class PartialEvaluator {
1046
1046
) {
1047
1047
const fontName = fontArgs ?. [ 0 ] instanceof Name ? fontArgs [ 0 ] . name : null ;
1048
1048
1049
- let translated = await this . loadFont (
1049
+ const translated = await this . loadFont (
1050
1050
fontName ,
1051
1051
fontRef ,
1052
1052
resources ,
1053
+ task ,
1053
1054
fallbackFontDict ,
1054
1055
cssFontInfo
1055
1056
) ;
1056
1057
1057
1058
if ( translated . font . isType3Font ) {
1058
- try {
1059
- await translated . loadType3Data ( this , resources , task ) ;
1060
- // Add the dependencies to the parent operatorList so they are
1061
- // resolved before Type3 operatorLists are executed synchronously.
1062
- operatorList . addDependencies ( translated . type3Dependencies ) ;
1063
- } catch ( reason ) {
1064
- translated = new TranslatedFont ( {
1065
- loadedName : "g_font_error" ,
1066
- font : new ErrorFont ( `Type3 font load error: ${ reason } ` ) ,
1067
- dict : translated . font ,
1068
- } ) ;
1069
- }
1059
+ // Add the dependencies to the parent operatorList so they are
1060
+ // resolved before Type3 operatorLists are executed synchronously.
1061
+ operatorList . addDependencies ( translated . type3Dependencies ) ;
1070
1062
}
1071
1063
1072
1064
state . font = translated . font ;
@@ -1228,6 +1220,7 @@ class PartialEvaluator {
1228
1220
fontName ,
1229
1221
font ,
1230
1222
resources ,
1223
+ task ,
1231
1224
fallbackFontDict = null ,
1232
1225
cssFontInfo = null
1233
1226
) {
@@ -1356,14 +1349,21 @@ class PartialEvaluator {
1356
1349
font . loadedName = `${ this . idFactory . getDocId ( ) } _${ fontID } ` ;
1357
1350
1358
1351
this . translateFont ( preEvaluatedFont )
1359
- . then ( translatedFont => {
1360
- resolve (
1361
- new TranslatedFont ( {
1362
- loadedName : font . loadedName ,
1363
- font : translatedFont ,
1364
- dict : font ,
1365
- } )
1366
- ) ;
1352
+ . then ( async translatedFont => {
1353
+ const translated = new TranslatedFont ( {
1354
+ loadedName : font . loadedName ,
1355
+ font : translatedFont ,
1356
+ dict : font ,
1357
+ } ) ;
1358
+
1359
+ if ( translatedFont . isType3Font ) {
1360
+ try {
1361
+ await translated . loadType3Data ( this , resources , task ) ;
1362
+ } catch ( reason ) {
1363
+ throw new Error ( `Type3 font load error: ${ reason } ` ) ;
1364
+ }
1365
+ }
1366
+ resolve ( translated ) ;
1367
1367
} )
1368
1368
. catch ( reason => {
1369
1369
// TODO reject?
@@ -1372,9 +1372,7 @@ class PartialEvaluator {
1372
1372
resolve (
1373
1373
new TranslatedFont ( {
1374
1374
loadedName : font . loadedName ,
1375
- font : new ErrorFont (
1376
- reason instanceof Error ? reason . message : reason
1377
- ) ,
1375
+ font : new ErrorFont ( reason ?. message ) ,
1378
1376
dict : font ,
1379
1377
} )
1380
1378
) ;
@@ -2616,16 +2614,12 @@ class PartialEvaluator {
2616
2614
}
2617
2615
2618
2616
async function handleSetFont ( fontName , fontRef ) {
2619
- const translated = await self . loadFont ( fontName , fontRef , resources ) ;
2620
-
2621
- if ( translated . font . isType3Font ) {
2622
- try {
2623
- await translated . loadType3Data ( self , resources , task ) ;
2624
- } catch {
2625
- // Ignore Type3-parsing errors, since we only use `loadType3Data`
2626
- // here to ensure that we'll always obtain a useful /FontBBox.
2627
- }
2628
- }
2617
+ const translated = await self . loadFont (
2618
+ fontName ,
2619
+ fontRef ,
2620
+ resources ,
2621
+ task
2622
+ ) ;
2629
2623
2630
2624
textState . loadedName = translated . loadedName ;
2631
2625
textState . font = translated . font ;
@@ -4602,20 +4596,22 @@ class PartialEvaluator {
4602
4596
}
4603
4597
4604
4598
class TranslatedFont {
4599
+ #sent = false ;
4600
+
4601
+ #type3Loaded = null ;
4602
+
4605
4603
constructor ( { loadedName, font, dict } ) {
4606
4604
this . loadedName = loadedName ;
4607
4605
this . font = font ;
4608
4606
this . dict = dict ;
4609
- this . type3Loaded = null ;
4610
4607
this . type3Dependencies = font . isType3Font ? new Set ( ) : null ;
4611
- this . sent = false ;
4612
4608
}
4613
4609
4614
4610
send ( handler ) {
4615
- if ( this . sent ) {
4611
+ if ( this . # sent) {
4616
4612
return ;
4617
4613
}
4618
- this . sent = true ;
4614
+ this . # sent = true ;
4619
4615
4620
4616
handler . send ( "commonobj" , [
4621
4617
this . loadedName ,
@@ -4645,12 +4641,12 @@ class TranslatedFont {
4645
4641
}
4646
4642
4647
4643
loadType3Data ( evaluator , resources , task ) {
4648
- if ( this . type3Loaded ) {
4649
- return this . type3Loaded ;
4650
- }
4651
- if ( ! this . font . isType3Font ) {
4652
- throw new Error ( "Must be a Type3 font." ) ;
4644
+ if ( this . #type3Loaded) {
4645
+ return this . #type3Loaded;
4653
4646
}
4647
+ const { font, type3Dependencies } = this ;
4648
+ assert ( font . isType3Font , "Must be a Type3 font." ) ;
4649
+
4654
4650
// When parsing Type3 glyphs, always ignore them if there are errors.
4655
4651
// Compared to the parsing of e.g. an entire page, it doesn't really
4656
4652
// make sense to only be able to render a Type3 glyph partially.
@@ -4662,14 +4658,12 @@ class TranslatedFont {
4662
4658
}
4663
4659
type3Evaluator . type3FontRefs = type3FontRefs ;
4664
4660
4665
- const translatedFont = this . font ,
4666
- type3Dependencies = this . type3Dependencies ;
4667
4661
let loadCharProcsPromise = Promise . resolve ( ) ;
4668
4662
const charProcs = this . dict . get ( "CharProcs" ) ;
4669
4663
const fontResources = this . dict . get ( "Resources" ) || resources ;
4670
4664
const charProcOperatorList = Object . create ( null ) ;
4671
4665
4672
- const fontBBox = Util . normalizeRect ( translatedFont . bbox || [ 0 , 0 , 0 , 0 ] ) ,
4666
+ const fontBBox = Util . normalizeRect ( font . bbox || [ 0 , 0 , 0 , 0 ] ) ,
4673
4667
width = fontBBox [ 2 ] - fontBBox [ 0 ] ,
4674
4668
height = fontBBox [ 3 ] - fontBBox [ 1 ] ;
4675
4669
const fontBBoxSize = Math . hypot ( width , height ) ;
@@ -4693,7 +4687,7 @@ class TranslatedFont {
4693
4687
// colour-related parameters) in the graphics state;
4694
4688
// any use of such operators shall be ignored."
4695
4689
if ( operatorList . fnArray [ 0 ] === OPS . setCharWidthAndBounds ) {
4696
- this . _removeType3ColorOperators ( operatorList , fontBBoxSize ) ;
4690
+ this . #removeType3ColorOperators ( operatorList , fontBBoxSize ) ;
4697
4691
}
4698
4692
charProcOperatorList [ key ] = operatorList . getIR ( ) ;
4699
4693
@@ -4708,20 +4702,17 @@ class TranslatedFont {
4708
4702
} ) ;
4709
4703
} ) ;
4710
4704
}
4711
- this . type3Loaded = loadCharProcsPromise . then ( ( ) => {
4712
- translatedFont . charProcOperatorList = charProcOperatorList ;
4705
+ this . # type3Loaded = loadCharProcsPromise . then ( ( ) => {
4706
+ font . charProcOperatorList = charProcOperatorList ;
4713
4707
if ( this . _bbox ) {
4714
- translatedFont . isCharBBox = true ;
4715
- translatedFont . bbox = this . _bbox ;
4708
+ font . isCharBBox = true ;
4709
+ font . bbox = this . _bbox ;
4716
4710
}
4717
4711
} ) ;
4718
- return this . type3Loaded ;
4712
+ return this . # type3Loaded;
4719
4713
}
4720
4714
4721
- /**
4722
- * @private
4723
- */
4724
- _removeType3ColorOperators ( operatorList , fontBBoxSize = NaN ) {
4715
+ #removeType3ColorOperators( operatorList , fontBBoxSize = NaN ) {
4725
4716
if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "TESTING" ) ) {
4726
4717
assert (
4727
4718
operatorList . fnArray [ 0 ] === OPS . setCharWidthAndBounds ,
0 commit comments