@@ -47,12 +47,6 @@ import {
4747 RenderingCancelledException ,
4848 StatTimer ,
4949} from "./display_utils.js" ;
50- import { FontFaceObject , FontLoader } from "./font_loader.js" ;
51- import {
52- FontInfo ,
53- FontPathInfo ,
54- PatternInfo ,
55- } from "../shared/obj-bin-transform.js" ;
5650import {
5751 getDataProp ,
5852 getFactoryUrlProp ,
@@ -75,13 +69,15 @@ import { DOMCMapReaderFactory } from "display-cmap_reader_factory";
7569import { DOMFilterFactory } from "./filter_factory.js" ;
7670import { DOMStandardFontDataFactory } from "display-standard_fontdata_factory" ;
7771import { DOMWasmFactory } from "display-wasm_factory" ;
72+ import { FontLoader } from "./font_loader.js" ;
7873import { GlobalWorkerOptions } from "./worker_options.js" ;
7974import { Metadata } from "./metadata.js" ;
8075import { OptionalContentConfig } from "./optional_content_config.js" ;
8176import { PDFDataTransportStream } from "./transport_stream.js" ;
8277import { PDFFetchStream } from "display-fetch_stream" ;
8378import { PDFNetworkStream } from "display-network" ;
8479import { PDFNodeStream } from "display-node_stream" ;
80+ import { setupHandler } from "../shared/handle_objs.js" ;
8581import { TextLayer } from "./text_layer.js" ;
8682import { XfaText } from "./xfa_text.js" ;
8783
@@ -2873,110 +2869,13 @@ class WorkerTransport {
28732869 page . _startRenderPage ( data . transparency , data . cacheKey ) ;
28742870 } ) ;
28752871
2876- messageHandler . on ( "commonobj" , ( [ id , type , exportedData ] ) => {
2877- if ( this . destroyed ) {
2878- return null ; // Ignore any pending requests if the worker was terminated.
2879- }
2880-
2881- if ( this . commonObjs . has ( id ) ) {
2882- return null ;
2883- }
2884-
2885- switch ( type ) {
2886- case "Font" :
2887- if ( "error" in exportedData ) {
2888- const exportedError = exportedData . error ;
2889- warn ( `Error during font loading: ${ exportedError } ` ) ;
2890- this . commonObjs . resolve ( id , exportedError ) ;
2891- break ;
2892- }
2893-
2894- const fontData = new FontInfo ( exportedData ) ;
2895- const inspectFont =
2896- this . _params . pdfBug && globalThis . FontInspector ?. enabled
2897- ? ( font , url ) => globalThis . FontInspector . fontAdded ( font , url )
2898- : null ;
2899- const font = new FontFaceObject (
2900- fontData ,
2901- inspectFont ,
2902- exportedData . extra ,
2903- exportedData . charProcOperatorList
2904- ) ;
2905-
2906- this . fontLoader
2907- . bind ( font )
2908- . catch ( ( ) => messageHandler . sendWithPromise ( "FontFallback" , { id } ) )
2909- . finally ( ( ) => {
2910- if ( ! font . fontExtraProperties && font . data ) {
2911- // Immediately release the `font.data` property once the font
2912- // has been attached to the DOM, since it's no longer needed,
2913- // rather than waiting for a `PDFDocumentProxy.cleanup` call.
2914- // Since `font.data` could be very large, e.g. in some cases
2915- // multiple megabytes, this will help reduce memory usage.
2916- font . clearData ( ) ;
2917- }
2918- this . commonObjs . resolve ( id , font ) ;
2919- } ) ;
2920- break ;
2921- case "CopyLocalImage" :
2922- const { imageRef } = exportedData ;
2923- assert ( imageRef , "The imageRef must be defined." ) ;
2924-
2925- for ( const pageProxy of this . #pageCache. values ( ) ) {
2926- for ( const [ , data ] of pageProxy . objs ) {
2927- if ( data ?. ref !== imageRef ) {
2928- continue ;
2929- }
2930- if ( ! data . dataLen ) {
2931- return null ;
2932- }
2933- this . commonObjs . resolve ( id , structuredClone ( data ) ) ;
2934- return data . dataLen ;
2935- }
2936- }
2937- break ;
2938- case "FontPath" :
2939- this . commonObjs . resolve ( id , new FontPathInfo ( exportedData ) ) ;
2940- break ;
2941- case "Image" :
2942- this . commonObjs . resolve ( id , exportedData ) ;
2943- break ;
2944- case "Pattern" :
2945- const pattern = new PatternInfo ( exportedData ) ;
2946- this . commonObjs . resolve ( id , pattern . getIR ( ) ) ;
2947- break ;
2948- default :
2949- throw new Error ( `Got unknown common object type ${ type } ` ) ;
2950- }
2951-
2952- return null ;
2953- } ) ;
2954-
2955- messageHandler . on ( "obj" , ( [ id , pageIndex , type , imageData ] ) => {
2956- if ( this . destroyed ) {
2957- // Ignore any pending requests if the worker was terminated.
2958- return ;
2959- }
2960-
2961- const pageProxy = this . #pageCache. get ( pageIndex ) ;
2962- if ( pageProxy . objs . has ( id ) ) {
2963- return ;
2964- }
2965- // Don't store data *after* cleanup has successfully run, see bug 1854145.
2966- if ( pageProxy . _intentStates . size === 0 ) {
2967- imageData ?. bitmap ?. close ( ) ; // Release any `ImageBitmap` data.
2968- return ;
2969- }
2970-
2971- switch ( type ) {
2972- case "Image" :
2973- case "Pattern" :
2974- pageProxy . objs . resolve ( id , imageData ) ;
2975- break ;
2976- default :
2977- throw new Error ( `Got unknown object type ${ type } ` ) ;
2978- }
2979- } ) ;
2872+ setupHandler (
2873+ messageHandler ,
2874+ this . destroyed ,
2875+ this . commonObjs ,
2876+ this . #pageCache,
2877+ this . fontLoader
2878+ ) ;
29802879
29812880 messageHandler . on ( "DocProgress" , data => {
29822881 if ( this . destroyed ) {
0 commit comments