Merge pull request #15632 from Snuffleupagus/issue-15629-2
[api-minor] Move the handling of unbalanced markedContent to the worker-thread (PR 15630 follow-up)
This commit is contained in:
		
						commit
						8b970109ea
					
				| @ -2283,12 +2283,16 @@ class PartialEvaluator { | |||||||
|     sink, |     sink, | ||||||
|     seenStyles = new Set(), |     seenStyles = new Set(), | ||||||
|     viewBox, |     viewBox, | ||||||
|  |     markedContentData = null, | ||||||
|   }) { |   }) { | ||||||
|     // Ensure that `resources`/`stateManager` is correctly initialized,
 |     // Ensure that `resources`/`stateManager` is correctly initialized,
 | ||||||
|     // even if the provided parameter is e.g. `null`.
 |     // even if the provided parameter is e.g. `null`.
 | ||||||
|     resources = resources || Dict.empty; |     resources = resources || Dict.empty; | ||||||
|     stateManager = stateManager || new StateManager(new TextState()); |     stateManager = stateManager || new StateManager(new TextState()); | ||||||
| 
 | 
 | ||||||
|  |     if (includeMarkedContent) { | ||||||
|  |       markedContentData = markedContentData || { level: 0 }; | ||||||
|  |     } | ||||||
|     const NormalizedUnicodes = getNormalizedUnicodes(); |     const NormalizedUnicodes = getNormalizedUnicodes(); | ||||||
| 
 | 
 | ||||||
|     const textContent = { |     const textContent = { | ||||||
| @ -3225,6 +3229,7 @@ class PartialEvaluator { | |||||||
|                     sink: sinkWrapper, |                     sink: sinkWrapper, | ||||||
|                     seenStyles, |                     seenStyles, | ||||||
|                     viewBox, |                     viewBox, | ||||||
|  |                     markedContentData, | ||||||
|                   }) |                   }) | ||||||
|                   .then(function () { |                   .then(function () { | ||||||
|                     if (!sinkWrapper.enqueueInvoked) { |                     if (!sinkWrapper.enqueueInvoked) { | ||||||
| @ -3305,6 +3310,8 @@ class PartialEvaluator { | |||||||
|           case OPS.beginMarkedContent: |           case OPS.beginMarkedContent: | ||||||
|             flushTextContentItem(); |             flushTextContentItem(); | ||||||
|             if (includeMarkedContent) { |             if (includeMarkedContent) { | ||||||
|  |               markedContentData.level++; | ||||||
|  | 
 | ||||||
|               textContent.items.push({ |               textContent.items.push({ | ||||||
|                 type: "beginMarkedContent", |                 type: "beginMarkedContent", | ||||||
|                 tag: args[0] instanceof Name ? args[0].name : null, |                 tag: args[0] instanceof Name ? args[0].name : null, | ||||||
| @ -3314,6 +3321,8 @@ class PartialEvaluator { | |||||||
|           case OPS.beginMarkedContentProps: |           case OPS.beginMarkedContentProps: | ||||||
|             flushTextContentItem(); |             flushTextContentItem(); | ||||||
|             if (includeMarkedContent) { |             if (includeMarkedContent) { | ||||||
|  |               markedContentData.level++; | ||||||
|  | 
 | ||||||
|               let mcid = null; |               let mcid = null; | ||||||
|               if (args[1] instanceof Dict) { |               if (args[1] instanceof Dict) { | ||||||
|                 mcid = args[1].get("MCID"); |                 mcid = args[1].get("MCID"); | ||||||
| @ -3330,6 +3339,13 @@ class PartialEvaluator { | |||||||
|           case OPS.endMarkedContent: |           case OPS.endMarkedContent: | ||||||
|             flushTextContentItem(); |             flushTextContentItem(); | ||||||
|             if (includeMarkedContent) { |             if (includeMarkedContent) { | ||||||
|  |               if (markedContentData.level === 0) { | ||||||
|  |                 // Handle unbalanced beginMarkedContent/endMarkedContent
 | ||||||
|  |                 // operators (fixes issue15629.pdf).
 | ||||||
|  |                 break; | ||||||
|  |               } | ||||||
|  |               markedContentData.level--; | ||||||
|  | 
 | ||||||
|               textContent.items.push({ |               textContent.items.push({ | ||||||
|                 type: "endMarkedContent", |                 type: "endMarkedContent", | ||||||
|               }); |               }); | ||||||
|  | |||||||
| @ -224,8 +224,6 @@ function render(task) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| class TextLayerRenderTask { | class TextLayerRenderTask { | ||||||
|   #initialContainer = null; |  | ||||||
| 
 |  | ||||||
|   constructor({ |   constructor({ | ||||||
|     textContent, |     textContent, | ||||||
|     textContentStream, |     textContentStream, | ||||||
| @ -237,7 +235,6 @@ class TextLayerRenderTask { | |||||||
|     this._textContent = textContent; |     this._textContent = textContent; | ||||||
|     this._textContentStream = textContentStream; |     this._textContentStream = textContentStream; | ||||||
|     this._container = container; |     this._container = container; | ||||||
|     this.#initialContainer = container; |  | ||||||
|     this._document = container.ownerDocument; |     this._document = container.ownerDocument; | ||||||
|     this._viewport = viewport; |     this._viewport = viewport; | ||||||
|     this._textDivs = textDivs || []; |     this._textDivs = textDivs || []; | ||||||
| @ -321,13 +318,7 @@ class TextLayerRenderTask { | |||||||
|           } |           } | ||||||
|           parent.append(this._container); |           parent.append(this._container); | ||||||
|         } else if (item.type === "endMarkedContent") { |         } else if (item.type === "endMarkedContent") { | ||||||
|           const parent = this._container.parentNode; |           this._container = this._container.parentNode; | ||||||
|           if (!parent || this._container === this.#initialContainer) { |  | ||||||
|             // Handle unbalanced beginMarkedContent/endMarkedContent operators
 |  | ||||||
|             // (fixes issue15629.pdf).
 |  | ||||||
|             continue; |  | ||||||
|           } |  | ||||||
|           this._container = parent; |  | ||||||
|         } |         } | ||||||
|         continue; |         continue; | ||||||
|       } |       } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user