Annotations: move operator list addition logic to src/core/document.js
				
					
				
			Ideally, the `Annotation` class should not have anything to do with the page's operator list. How annotations are added to the page's operator list is logic that belongs in `src/core/document.js` instead where the operator list is constructed. Moreover, some comments have been added to clarify the intent of the code.
This commit is contained in:
		
							parent
							
								
									afc3cd2a81
								
							
						
					
					
						commit
						0739f90707
					
				| @ -467,25 +467,6 @@ var Annotation = (function AnnotationClosure() { | |||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   Annotation.appendToOperatorList = function Annotation_appendToOperatorList( |  | ||||||
|       annotations, opList, partialEvaluator, task, intent, renderForms) { |  | ||||||
|     var annotationPromises = []; |  | ||||||
|     for (var i = 0, n = annotations.length; i < n; ++i) { |  | ||||||
|       if ((intent === 'display' && annotations[i].viewable) || |  | ||||||
|           (intent === 'print' && annotations[i].printable)) { |  | ||||||
|         annotationPromises.push( |  | ||||||
|           annotations[i].getOperatorList(partialEvaluator, task, renderForms)); |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     return Promise.all(annotationPromises).then(function(operatorLists) { |  | ||||||
|       opList.addOp(OPS.beginAnnotations, []); |  | ||||||
|       for (var i = 0, n = operatorLists.length; i < n; ++i) { |  | ||||||
|         opList.addOpList(operatorLists[i]); |  | ||||||
|       } |  | ||||||
|       opList.addOp(OPS.endAnnotations, []); |  | ||||||
|     }); |  | ||||||
|   }; |  | ||||||
| 
 |  | ||||||
|   return Annotation; |   return Annotation; | ||||||
| })(); | })(); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -35,6 +35,7 @@ | |||||||
| }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj, | }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj, | ||||||
|                   coreParser, coreCrypto, coreEvaluator, coreAnnotation) { |                   coreParser, coreCrypto, coreEvaluator, coreAnnotation) { | ||||||
| 
 | 
 | ||||||
|  | var OPS = sharedUtil.OPS; | ||||||
| var MissingDataException = sharedUtil.MissingDataException; | var MissingDataException = sharedUtil.MissingDataException; | ||||||
| var Util = sharedUtil.Util; | var Util = sharedUtil.Util; | ||||||
| var assert = sharedUtil.assert; | var assert = sharedUtil.assert; | ||||||
| @ -63,7 +64,6 @@ var Linearization = coreParser.Linearization; | |||||||
| var calculateMD5 = coreCrypto.calculateMD5; | var calculateMD5 = coreCrypto.calculateMD5; | ||||||
| var OperatorList = coreEvaluator.OperatorList; | var OperatorList = coreEvaluator.OperatorList; | ||||||
| var PartialEvaluator = coreEvaluator.PartialEvaluator; | var PartialEvaluator = coreEvaluator.PartialEvaluator; | ||||||
| var Annotation = coreAnnotation.Annotation; |  | ||||||
| var AnnotationFactory = coreAnnotation.AnnotationFactory; | var AnnotationFactory = coreAnnotation.AnnotationFactory; | ||||||
| 
 | 
 | ||||||
| var Page = (function PageClosure() { | var Page = (function PageClosure() { | ||||||
| @ -71,6 +71,11 @@ var Page = (function PageClosure() { | |||||||
|   var DEFAULT_USER_UNIT = 1.0; |   var DEFAULT_USER_UNIT = 1.0; | ||||||
|   var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792]; |   var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792]; | ||||||
| 
 | 
 | ||||||
|  |   function isAnnotationRenderable(annotation, intent) { | ||||||
|  |     return (intent === 'display' && annotation.viewable) || | ||||||
|  |            (intent === 'print' && annotation.printable); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache, |   function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache, | ||||||
|                 builtInCMapCache) { |                 builtInCMapCache) { | ||||||
|     this.pdfManager = pdfManager; |     this.pdfManager = pdfManager; | ||||||
| @ -269,6 +274,8 @@ var Page = (function PageClosure() { | |||||||
|           }); |           }); | ||||||
|       }); |       }); | ||||||
| 
 | 
 | ||||||
|  |       // Fetch the page's annotations and add their operator lists to the
 | ||||||
|  |       // page's operator list to render them.
 | ||||||
|       var annotationsPromise = pdfManager.ensure(this, 'annotations'); |       var annotationsPromise = pdfManager.ensure(this, 'annotations'); | ||||||
|       return Promise.all([pageListPromise, annotationsPromise]).then( |       return Promise.all([pageListPromise, annotationsPromise]).then( | ||||||
|           function(datas) { |           function(datas) { | ||||||
| @ -280,10 +287,23 @@ var Page = (function PageClosure() { | |||||||
|           return pageOpList; |           return pageOpList; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         var annotationsReadyPromise = Annotation.appendToOperatorList( |         // Collect the operator list promises for the annotations. Each promise
 | ||||||
|           annotations, pageOpList, partialEvaluator, task, intent, |         // is resolved with the complete operator list for a single annotation.
 | ||||||
|           renderInteractiveForms); |         var i, ii, opListPromises = []; | ||||||
|         return annotationsReadyPromise.then(function () { |         for (i = 0, ii = annotations.length; i < ii; i++) { | ||||||
|  |           if (isAnnotationRenderable(annotations[i], intent)) { | ||||||
|  |             opListPromises.push(annotations[i].getOperatorList( | ||||||
|  |               partialEvaluator, task, renderInteractiveForms)); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return Promise.all(opListPromises).then(function(opLists) { | ||||||
|  |           pageOpList.addOp(OPS.beginAnnotations, []); | ||||||
|  |           for (i = 0, ii = opLists.length; i < ii; i++) { | ||||||
|  |             pageOpList.addOpList(opLists[i]); | ||||||
|  |           } | ||||||
|  |           pageOpList.addOp(OPS.endAnnotations, []); | ||||||
|  | 
 | ||||||
|           pageOpList.flush(true); |           pageOpList.flush(true); | ||||||
|           return pageOpList; |           return pageOpList; | ||||||
|         }); |         }); | ||||||
| @ -334,13 +354,9 @@ var Page = (function PageClosure() { | |||||||
|       var annotations = this.annotations; |       var annotations = this.annotations; | ||||||
|       var annotationsData = []; |       var annotationsData = []; | ||||||
|       for (var i = 0, n = annotations.length; i < n; ++i) { |       for (var i = 0, n = annotations.length; i < n; ++i) { | ||||||
|         if (intent) { |         if (!intent || isAnnotationRenderable(annotations[i], intent)) { | ||||||
|           if (!(intent === 'display' && annotations[i].viewable) && |           annotationsData.push(annotations[i].data); | ||||||
|               !(intent === 'print' && annotations[i].printable)) { |  | ||||||
|             continue; |  | ||||||
|           } |  | ||||||
|         } |         } | ||||||
|         annotationsData.push(annotations[i].data); |  | ||||||
|       } |       } | ||||||
|       return annotationsData; |       return annotationsData; | ||||||
|     }, |     }, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user