@@ -1237,15 +1237,15 @@ class PDFDocument {
12371237 return this . xfaFactory ? this . xfaFactory . getPages ( ) : null ;
12381238 }
12391239
1240- async loadXfaImages ( ) {
1240+ async # loadXfaImages( ) {
12411241 const xfaImages = await this . pdfManager . ensureCatalog ( "xfaImages" ) ;
12421242 if ( ! xfaImages ) {
12431243 return ;
12441244 }
12451245 this . xfaFactory . setImages ( xfaImages ) ;
12461246 }
12471247
1248- async loadXfaFonts ( handler , task ) {
1248+ async # loadXfaFonts( handler , task ) {
12491249 const acroForm = await this . pdfManager . ensureCatalog ( "acroForm" ) ;
12501250 if ( ! acroForm ) {
12511251 return ;
@@ -1264,18 +1264,19 @@ class PDFDocument {
12641264
12651265 const options = Object . assign (
12661266 Object . create ( null ) ,
1267- this . pdfManager . evaluatorOptions
1267+ this . pdfManager . evaluatorOptions ,
1268+ { useSystemFonts : false }
12681269 ) ;
1269- options . useSystemFonts = false ;
1270+ const { builtInCMapCache , fontCache , standardFontDataCache } = this . catalog ;
12701271
12711272 const partialEvaluator = new PartialEvaluator ( {
12721273 xref : this . xref ,
12731274 handler,
12741275 pageIndex : - 1 ,
12751276 idFactory : this . _globalIdFactory ,
1276- fontCache : this . catalog . fontCache ,
1277- builtInCMapCache : this . catalog . builtInCMapCache ,
1278- standardFontDataCache : this . catalog . standardFontDataCache ,
1277+ fontCache,
1278+ builtInCMapCache,
1279+ standardFontDataCache,
12791280 options,
12801281 } ) ;
12811282 const operatorList = new OperatorList ( ) ;
@@ -1292,6 +1293,23 @@ class PDFDocument {
12921293 } ,
12931294 } ;
12941295
1296+ const parseFont = ( fontName , fallbackFontDict , cssFontInfo ) =>
1297+ partialEvaluator
1298+ . handleSetFont (
1299+ resources ,
1300+ [ Name . get ( fontName ) , 1 ] ,
1301+ /* fontRef = */ null ,
1302+ operatorList ,
1303+ task ,
1304+ initialState ,
1305+ fallbackFontDict ,
1306+ cssFontInfo
1307+ )
1308+ . catch ( reason => {
1309+ warn ( `loadXfaFonts: "${ reason } ".` ) ;
1310+ return null ;
1311+ } ) ;
1312+
12951313 const promises = [ ] ;
12961314 for ( const [ fontName , font ] of fontRes ) {
12971315 const descriptor = font . get ( "FontDescriptor" ) ;
@@ -1313,21 +1331,7 @@ class PDFDocument {
13131331 continue ;
13141332 }
13151333 promises . push (
1316- partialEvaluator
1317- . handleSetFont (
1318- resources ,
1319- [ Name . get ( fontName ) , 1 ] ,
1320- /* fontRef = */ null ,
1321- operatorList ,
1322- task ,
1323- initialState ,
1324- /* fallbackFontDict = */ null ,
1325- /* cssFontInfo = */ cssFontInfo
1326- )
1327- . catch ( function ( reason ) {
1328- warn ( `loadXfaFonts: "${ reason } ".` ) ;
1329- return null ;
1330- } )
1334+ parseFont ( fontName , /* fallbackFontDict = */ null , cssFontInfo )
13311335 ) ;
13321336 }
13331337
@@ -1365,28 +1369,13 @@ class PDFDocument {
13651369 { name : "BoldItalic" , fontWeight : 700 , italicAngle : 12 } ,
13661370 ] ) {
13671371 const name = `${ missing } -${ fontInfo . name } ` ;
1368- const dict = getXfaFontDict ( name ) ;
13691372
13701373 promises . push (
1371- partialEvaluator
1372- . handleSetFont (
1373- resources ,
1374- [ Name . get ( name ) , 1 ] ,
1375- /* fontRef = */ null ,
1376- operatorList ,
1377- task ,
1378- initialState ,
1379- /* fallbackFontDict = */ dict ,
1380- /* cssFontInfo = */ {
1381- fontFamily : missing ,
1382- fontWeight : fontInfo . fontWeight ,
1383- italicAngle : fontInfo . italicAngle ,
1384- }
1385- )
1386- . catch ( function ( reason ) {
1387- warn ( `loadXfaFonts: "${ reason } ".` ) ;
1388- return null ;
1389- } )
1374+ parseFont ( name , getXfaFontDict ( name ) , {
1375+ fontFamily : missing ,
1376+ fontWeight : fontInfo . fontWeight ,
1377+ italicAngle : fontInfo . italicAngle ,
1378+ } )
13901379 ) ;
13911380 }
13921381 }
@@ -1395,6 +1384,15 @@ class PDFDocument {
13951384 this . xfaFactory . appendFonts ( pdfFonts , reallyMissingFonts ) ;
13961385 }
13971386
1387+ loadXfaResources ( handler , task ) {
1388+ return Promise . all ( [
1389+ this . #loadXfaFonts( handler , task ) . catch ( ( ) => {
1390+ // Ignore errors, to allow the document to load.
1391+ } ) ,
1392+ this . #loadXfaImages( ) ,
1393+ ] ) ;
1394+ }
1395+
13981396 serializeXfaData ( annotationStorage ) {
13991397 return this . xfaFactory
14001398 ? this . xfaFactory . serializeData ( annotationStorage )
0 commit comments