@@ -2362,6 +2362,7 @@ class PartialEvaluator {
23622362 disableNormalization = false ,
23632363 keepWhiteSpace = false ,
23642364 prevRefs = null ,
2365+ intersector = null ,
23652366 } ) {
23662367 const objId = stream . dict ?. objId ;
23672368 const seenRefs = new RefSet ( prevRefs ) ;
@@ -2506,6 +2507,7 @@ class PartialEvaluator {
25062507 transform = textContentItem . prevTransform ,
25072508 fontName = textContentItem . fontName ,
25082509 } ) {
2510+ intersector ?. addExtraChar ( " " ) ;
25092511 textContent . items . push ( {
25102512 str : " " ,
25112513 dir : "ltr" ,
@@ -2964,9 +2966,21 @@ class PartialEvaluator {
29642966
29652967 if ( ! font . vertical ) {
29662968 scaledDim *= textState . textHScale ;
2969+ intersector ?. addGlyph (
2970+ getCurrentTextTransform ( ) ,
2971+ scaledDim ,
2972+ 0 ,
2973+ glyph . unicode
2974+ ) ;
29672975 textState . translateTextMatrix ( scaledDim , 0 ) ;
29682976 textChunk . width += scaledDim ;
29692977 } else {
2978+ intersector ?. addGlyph (
2979+ getCurrentTextTransform ( ) ,
2980+ 0 ,
2981+ scaledDim ,
2982+ glyph . unicode
2983+ ) ;
29702984 textState . translateTextMatrix ( 0 , scaledDim ) ;
29712985 scaledDim = Math . abs ( scaledDim ) ;
29722986 textChunk . height += scaledDim ;
@@ -2985,8 +2999,12 @@ class PartialEvaluator {
29852999 // alignment issues between the textLayer and the canvas if the text
29863000 // contains e.g. tabs (fixes issue6612.pdf).
29873001 textChunk . str . push ( " " ) ;
3002+ intersector ?. addExtraChar ( " " ) ;
3003+ }
3004+
3005+ if ( ! intersector ) {
3006+ textChunk . str . push ( glyphUnicode ) ;
29883007 }
2989- textChunk . str . push ( glyphUnicode ) ;
29903008
29913009 if ( charSpacing ) {
29923010 if ( ! font . vertical ) {
@@ -3002,6 +3020,7 @@ class PartialEvaluator {
30023020 }
30033021
30043022 function appendEOL ( ) {
3023+ intersector ?. addExtraChar ( "\n" ) ;
30053024 resetLastChars ( ) ;
30063025 if ( textContentItem . initialized ) {
30073026 textContentItem . hasEOL = true ;
@@ -3027,6 +3046,7 @@ class PartialEvaluator {
30273046 if ( textContentItem . initialized ) {
30283047 resetLastChars ( ) ;
30293048 textContentItem . str . push ( " " ) ;
3049+ intersector ?. addExtraChar ( " " ) ;
30303050 }
30313051 return false ;
30323052 }
@@ -3078,7 +3098,7 @@ class PartialEvaluator {
30783098 if ( batch && length < TEXT_CHUNK_BATCH_SIZE ) {
30793099 return ;
30803100 }
3081- sink . enqueue ( textContent , length ) ;
3101+ sink ? .enqueue ( textContent , length ) ;
30823102 textContent . items = [ ] ;
30833103 textContent . styles = Object . create ( null ) ;
30843104 }
@@ -3088,7 +3108,7 @@ class PartialEvaluator {
30883108 return new Promise ( function promiseBody ( resolve , reject ) {
30893109 const next = function ( promise ) {
30903110 enqueueChunk ( /* batch = */ true ) ;
3091- Promise . all ( [ promise , sink . ready ] ) . then ( function ( ) {
3111+ Promise . all ( [ promise , sink ? .ready ] ) . then ( function ( ) {
30923112 try {
30933113 promiseBody ( resolve , reject ) ;
30943114 } catch ( ex ) {
@@ -3341,7 +3361,7 @@ class PartialEvaluator {
33413361 } ,
33423362
33433363 get desiredSize ( ) {
3344- return sink . desiredSize ;
3364+ return sink . desiredSize ?? 0 ;
33453365 } ,
33463366
33473367 get ready ( ) {
@@ -3359,7 +3379,7 @@ class PartialEvaluator {
33593379 : resources ,
33603380 stateManager : xObjStateManager ,
33613381 includeMarkedContent,
3362- sink : sinkWrapper ,
3382+ sink : sink && sinkWrapper ,
33633383 seenStyles,
33643384 viewBox,
33653385 lang,
@@ -3499,7 +3519,7 @@ class PartialEvaluator {
34993519 }
35003520 break ;
35013521 } // switch
3502- if ( textContent . items . length >= sink . desiredSize ) {
3522+ if ( textContent . items . length >= ( sink ? .desiredSize ?? 1 ) ) {
35033523 // Wait for ready, if we reach highWaterMark.
35043524 stop = true ;
35053525 break ;
0 commit comments