@@ -381,6 +381,16 @@ class PartialEvaluator {
381381 return false ;
382382 }
383383
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+
384394 async fetchBuiltInCMap ( name ) {
385395 const cachedData = this . builtInCMapCache . get ( name ) ;
386396 if ( cachedData ) {
@@ -390,17 +400,10 @@ class PartialEvaluator {
390400
391401 if ( this . options . cMapUrl !== null ) {
392402 // 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 } ;
404407 } else {
405408 // Get the data on the main-thread instead.
406409 data = await this . handler . sendWithPromise ( "FetchBuiltInCMap" , { name } ) ;
@@ -431,30 +434,19 @@ class PartialEvaluator {
431434 filename = standardFontNameToFileName [ name ] ;
432435 let data ;
433436
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 } `
440441 ) ;
441442 } 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.
447444 data = await this . handler . sendWithPromise ( "FetchStandardFontData" , {
448445 filename,
449446 } ) ;
450- } catch ( e ) {
451- warn (
452- `fetchStandardFontData: failed to fetch file "${ filename } " with "${ e } ".`
453- ) ;
454447 }
455- }
456-
457- if ( ! data ) {
448+ } catch ( ex ) {
449+ warn ( ex ) ;
458450 return null ;
459451 }
460452 // Cache the "raw" standard font data, to avoid fetching it repeatedly
0 commit comments