@@ -381,6 +381,16 @@ class PartialEvaluator {
381
381
return false ;
382
382
}
383
383
384
+ async #fetchData( url ) {
385
+ const response = await fetch ( url ) ;
386
+ if ( ! response . ok ) {
387
+ throw new Error (
388
+ `Failed to fetch file "${ url } " with "${ response . statusText } ".`
389
+ ) ;
390
+ }
391
+ return new Uint8Array ( await response . arrayBuffer ( ) ) ;
392
+ }
393
+
384
394
async fetchBuiltInCMap ( name ) {
385
395
const cachedData = this . builtInCMapCache . get ( name ) ;
386
396
if ( cachedData ) {
@@ -390,17 +400,10 @@ class PartialEvaluator {
390
400
391
401
if ( this . options . cMapUrl !== null ) {
392
402
// Only compressed CMaps are (currently) supported here.
393
- const url = `${ this . options . cMapUrl } ${ name } .bcmap` ;
394
- const response = await fetch ( url ) ;
395
- if ( ! response . ok ) {
396
- throw new Error (
397
- `fetchBuiltInCMap: failed to fetch file "${ url } " with "${ response . statusText } ".`
398
- ) ;
399
- }
400
- data = {
401
- cMapData : new Uint8Array ( await response . arrayBuffer ( ) ) ,
402
- isCompressed : true ,
403
- } ;
403
+ const cMapData = await this . #fetchData(
404
+ `${ this . options . cMapUrl } ${ name } .bcmap`
405
+ ) ;
406
+ data = { cMapData, isCompressed : true } ;
404
407
} else {
405
408
// Get the data on the main-thread instead.
406
409
data = await this . handler . sendWithPromise ( "FetchBuiltInCMap" , { name } ) ;
@@ -431,30 +434,19 @@ class PartialEvaluator {
431
434
filename = standardFontNameToFileName [ name ] ;
432
435
let data ;
433
436
434
- if ( this . options . standardFontDataUrl !== null ) {
435
- const url = `${ this . options . standardFontDataUrl } ${ filename } ` ;
436
- const response = await fetch ( url ) ;
437
- if ( ! response . ok ) {
438
- warn (
439
- `fetchStandardFontData: failed to fetch file "${ url } " with "${ response . statusText } ".`
437
+ try {
438
+ if ( this . options . standardFontDataUrl !== null ) {
439
+ data = await this . #fetchData(
440
+ `${ this . options . standardFontDataUrl } ${ filename } `
440
441
) ;
441
442
} else {
442
- data = new Uint8Array ( await response . arrayBuffer ( ) ) ;
443
- }
444
- } else {
445
- // Get the data on the main-thread instead.
446
- try {
443
+ // Get the data on the main-thread instead.
447
444
data = await this . handler . sendWithPromise ( "FetchStandardFontData" , {
448
445
filename,
449
446
} ) ;
450
- } catch ( e ) {
451
- warn (
452
- `fetchStandardFontData: failed to fetch file "${ filename } " with "${ e } ".`
453
- ) ;
454
447
}
455
- }
456
-
457
- if ( ! data ) {
448
+ } catch ( ex ) {
449
+ warn ( ex ) ;
458
450
return null ;
459
451
}
460
452
// Cache the "raw" standard font data, to avoid fetching it repeatedly
0 commit comments