Merge pull request #12503 from calixteman/no_quad
Invalidate an annotation with no quadPoints (when it's required)
This commit is contained in:
		
						commit
						8cf27494b3
					
				| @ -194,7 +194,11 @@ function getQuadPoints(dict, rect) { | |||||||
|   // The region is described as a number of quadrilaterals.
 |   // The region is described as a number of quadrilaterals.
 | ||||||
|   // Each quadrilateral must consist of eight coordinates.
 |   // Each quadrilateral must consist of eight coordinates.
 | ||||||
|   const quadPoints = dict.getArray("QuadPoints"); |   const quadPoints = dict.getArray("QuadPoints"); | ||||||
|   if (!Array.isArray(quadPoints) || quadPoints.length % 8 > 0) { |   if ( | ||||||
|  |     !Array.isArray(quadPoints) || | ||||||
|  |     quadPoints.length === 0 || | ||||||
|  |     quadPoints.length % 8 > 0 | ||||||
|  |   ) { | ||||||
|     return null; |     return null; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -312,6 +316,9 @@ class Annotation { | |||||||
|    * @type {boolean} |    * @type {boolean} | ||||||
|    */ |    */ | ||||||
|   get viewable() { |   get viewable() { | ||||||
|  |     if (this.data.quadPoints === null) { | ||||||
|  |       return false; | ||||||
|  |     } | ||||||
|     if (this.flags === 0) { |     if (this.flags === 0) { | ||||||
|       return true; |       return true; | ||||||
|     } |     } | ||||||
| @ -322,6 +329,9 @@ class Annotation { | |||||||
|    * @type {boolean} |    * @type {boolean} | ||||||
|    */ |    */ | ||||||
|   get printable() { |   get printable() { | ||||||
|  |     if (this.data.quadPoints === null) { | ||||||
|  |       return false; | ||||||
|  |     } | ||||||
|     if (this.flags === 0) { |     if (this.flags === 0) { | ||||||
|       return false; |       return false; | ||||||
|     } |     } | ||||||
| @ -2222,10 +2232,11 @@ class HighlightAnnotation extends MarkupAnnotation { | |||||||
|     super(parameters); |     super(parameters); | ||||||
| 
 | 
 | ||||||
|     this.data.annotationType = AnnotationType.HIGHLIGHT; |     this.data.annotationType = AnnotationType.HIGHLIGHT; | ||||||
| 
 |     const quadPoints = (this.data.quadPoints = getQuadPoints( | ||||||
|     const quadPoints = getQuadPoints(parameters.dict, null); |       parameters.dict, | ||||||
|  |       null | ||||||
|  |     )); | ||||||
|     if (quadPoints) { |     if (quadPoints) { | ||||||
|       this.data.quadPoints = quadPoints; |  | ||||||
|       if (!this.appearance) { |       if (!this.appearance) { | ||||||
|         // Default color is yellow in Acrobat Reader
 |         // Default color is yellow in Acrobat Reader
 | ||||||
|         const fillColor = this.color |         const fillColor = this.color | ||||||
| @ -2245,6 +2256,8 @@ class HighlightAnnotation extends MarkupAnnotation { | |||||||
|           }, |           }, | ||||||
|         }); |         }); | ||||||
|       } |       } | ||||||
|  |     } else { | ||||||
|  |       this.data.hasPopup = false; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @ -2254,10 +2267,11 @@ class UnderlineAnnotation extends MarkupAnnotation { | |||||||
|     super(parameters); |     super(parameters); | ||||||
| 
 | 
 | ||||||
|     this.data.annotationType = AnnotationType.UNDERLINE; |     this.data.annotationType = AnnotationType.UNDERLINE; | ||||||
| 
 |     const quadPoints = (this.data.quadPoints = getQuadPoints( | ||||||
|     const quadPoints = getQuadPoints(parameters.dict, null); |       parameters.dict, | ||||||
|  |       null | ||||||
|  |     )); | ||||||
|     if (quadPoints) { |     if (quadPoints) { | ||||||
|       this.data.quadPoints = quadPoints; |  | ||||||
|       if (!this.appearance) { |       if (!this.appearance) { | ||||||
|         // Default color is black
 |         // Default color is black
 | ||||||
|         const strokeColor = this.color |         const strokeColor = this.color | ||||||
| @ -2275,6 +2289,8 @@ class UnderlineAnnotation extends MarkupAnnotation { | |||||||
|           }, |           }, | ||||||
|         }); |         }); | ||||||
|       } |       } | ||||||
|  |     } else { | ||||||
|  |       this.data.hasPopup = false; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @ -2285,9 +2301,11 @@ class SquigglyAnnotation extends MarkupAnnotation { | |||||||
| 
 | 
 | ||||||
|     this.data.annotationType = AnnotationType.SQUIGGLY; |     this.data.annotationType = AnnotationType.SQUIGGLY; | ||||||
| 
 | 
 | ||||||
|     const quadPoints = getQuadPoints(parameters.dict, null); |     const quadPoints = (this.data.quadPoints = getQuadPoints( | ||||||
|  |       parameters.dict, | ||||||
|  |       null | ||||||
|  |     )); | ||||||
|     if (quadPoints) { |     if (quadPoints) { | ||||||
|       this.data.quadPoints = quadPoints; |  | ||||||
|       if (!this.appearance) { |       if (!this.appearance) { | ||||||
|         // Default color is black
 |         // Default color is black
 | ||||||
|         const strokeColor = this.color |         const strokeColor = this.color | ||||||
| @ -2314,6 +2332,8 @@ class SquigglyAnnotation extends MarkupAnnotation { | |||||||
|           }, |           }, | ||||||
|         }); |         }); | ||||||
|       } |       } | ||||||
|  |     } else { | ||||||
|  |       this.data.hasPopup = false; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @ -2324,9 +2344,11 @@ class StrikeOutAnnotation extends MarkupAnnotation { | |||||||
| 
 | 
 | ||||||
|     this.data.annotationType = AnnotationType.STRIKEOUT; |     this.data.annotationType = AnnotationType.STRIKEOUT; | ||||||
| 
 | 
 | ||||||
|     const quadPoints = getQuadPoints(parameters.dict, null); |     const quadPoints = (this.data.quadPoints = getQuadPoints( | ||||||
|  |       parameters.dict, | ||||||
|  |       null | ||||||
|  |     )); | ||||||
|     if (quadPoints) { |     if (quadPoints) { | ||||||
|       this.data.quadPoints = quadPoints; |  | ||||||
|       if (!this.appearance) { |       if (!this.appearance) { | ||||||
|         // Default color is black
 |         // Default color is black
 | ||||||
|         const strokeColor = this.color |         const strokeColor = this.color | ||||||
| @ -2350,6 +2372,8 @@ class StrikeOutAnnotation extends MarkupAnnotation { | |||||||
|           }, |           }, | ||||||
|         }); |         }); | ||||||
|       } |       } | ||||||
|  |     } else { | ||||||
|  |       this.data.hasPopup = false; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -3367,7 +3367,7 @@ describe("annotation", function () { | |||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   describe("HightlightAnnotation", function () { |   describe("HightlightAnnotation", function () { | ||||||
|     it("should not set quadpoints if not defined", function (done) { |     it("should set quadpoints to null if not defined", function (done) { | ||||||
|       const highlightDict = new Dict(); |       const highlightDict = new Dict(); | ||||||
|       highlightDict.set("Type", Name.get("Annot")); |       highlightDict.set("Type", Name.get("Annot")); | ||||||
|       highlightDict.set("Subtype", Name.get("Highlight")); |       highlightDict.set("Subtype", Name.get("Highlight")); | ||||||
| @ -3382,7 +3382,7 @@ describe("annotation", function () { | |||||||
|         idFactoryMock |         idFactoryMock | ||||||
|       ).then(({ data }) => { |       ).then(({ data }) => { | ||||||
|         expect(data.annotationType).toEqual(AnnotationType.HIGHLIGHT); |         expect(data.annotationType).toEqual(AnnotationType.HIGHLIGHT); | ||||||
|         expect(data.quadPoints).toBeUndefined(); |         expect(data.quadPoints).toEqual(null); | ||||||
|         done(); |         done(); | ||||||
|       }, done.fail); |       }, done.fail); | ||||||
|     }); |     }); | ||||||
| @ -3415,10 +3415,32 @@ describe("annotation", function () { | |||||||
|         done(); |         done(); | ||||||
|       }, done.fail); |       }, done.fail); | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|  |     it("should set quadpoints to null when empty", function (done) { | ||||||
|  |       const highlightDict = new Dict(); | ||||||
|  |       highlightDict.set("Type", Name.get("Annot")); | ||||||
|  |       highlightDict.set("Subtype", Name.get("Highlight")); | ||||||
|  |       highlightDict.set("Rect", [10, 10, 20, 20]); | ||||||
|  |       highlightDict.set("QuadPoints", []); | ||||||
|  | 
 | ||||||
|  |       const highlightRef = Ref.get(121, 0); | ||||||
|  |       const xref = new XRefMock([{ ref: highlightRef, data: highlightDict }]); | ||||||
|  | 
 | ||||||
|  |       AnnotationFactory.create( | ||||||
|  |         xref, | ||||||
|  |         highlightRef, | ||||||
|  |         pdfManagerMock, | ||||||
|  |         idFactoryMock | ||||||
|  |       ).then(({ data }) => { | ||||||
|  |         expect(data.annotationType).toEqual(AnnotationType.HIGHLIGHT); | ||||||
|  |         expect(data.quadPoints).toEqual(null); | ||||||
|  |         done(); | ||||||
|  |       }, done.fail); | ||||||
|  |     }); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   describe("UnderlineAnnotation", function () { |   describe("UnderlineAnnotation", function () { | ||||||
|     it("should not set quadpoints if not defined", function (done) { |     it("should set quadpoints to null if not defined", function (done) { | ||||||
|       const underlineDict = new Dict(); |       const underlineDict = new Dict(); | ||||||
|       underlineDict.set("Type", Name.get("Annot")); |       underlineDict.set("Type", Name.get("Annot")); | ||||||
|       underlineDict.set("Subtype", Name.get("Underline")); |       underlineDict.set("Subtype", Name.get("Underline")); | ||||||
| @ -3433,7 +3455,7 @@ describe("annotation", function () { | |||||||
|         idFactoryMock |         idFactoryMock | ||||||
|       ).then(({ data }) => { |       ).then(({ data }) => { | ||||||
|         expect(data.annotationType).toEqual(AnnotationType.UNDERLINE); |         expect(data.annotationType).toEqual(AnnotationType.UNDERLINE); | ||||||
|         expect(data.quadPoints).toBeUndefined(); |         expect(data.quadPoints).toEqual(null); | ||||||
|         done(); |         done(); | ||||||
|       }, done.fail); |       }, done.fail); | ||||||
|     }); |     }); | ||||||
| @ -3469,7 +3491,7 @@ describe("annotation", function () { | |||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   describe("SquigglyAnnotation", function () { |   describe("SquigglyAnnotation", function () { | ||||||
|     it("should not set quadpoints if not defined", function (done) { |     it("should set quadpoints to null if not defined", function (done) { | ||||||
|       const squigglyDict = new Dict(); |       const squigglyDict = new Dict(); | ||||||
|       squigglyDict.set("Type", Name.get("Annot")); |       squigglyDict.set("Type", Name.get("Annot")); | ||||||
|       squigglyDict.set("Subtype", Name.get("Squiggly")); |       squigglyDict.set("Subtype", Name.get("Squiggly")); | ||||||
| @ -3484,7 +3506,7 @@ describe("annotation", function () { | |||||||
|         idFactoryMock |         idFactoryMock | ||||||
|       ).then(({ data }) => { |       ).then(({ data }) => { | ||||||
|         expect(data.annotationType).toEqual(AnnotationType.SQUIGGLY); |         expect(data.annotationType).toEqual(AnnotationType.SQUIGGLY); | ||||||
|         expect(data.quadPoints).toBeUndefined(); |         expect(data.quadPoints).toEqual(null); | ||||||
|         done(); |         done(); | ||||||
|       }, done.fail); |       }, done.fail); | ||||||
|     }); |     }); | ||||||
| @ -3520,7 +3542,7 @@ describe("annotation", function () { | |||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   describe("StrikeOutAnnotation", function () { |   describe("StrikeOutAnnotation", function () { | ||||||
|     it("should not set quadpoints if not defined", function (done) { |     it("should set quadpoints to null if not defined", function (done) { | ||||||
|       const strikeOutDict = new Dict(); |       const strikeOutDict = new Dict(); | ||||||
|       strikeOutDict.set("Type", Name.get("Annot")); |       strikeOutDict.set("Type", Name.get("Annot")); | ||||||
|       strikeOutDict.set("Subtype", Name.get("StrikeOut")); |       strikeOutDict.set("Subtype", Name.get("StrikeOut")); | ||||||
| @ -3535,7 +3557,7 @@ describe("annotation", function () { | |||||||
|         idFactoryMock |         idFactoryMock | ||||||
|       ).then(({ data }) => { |       ).then(({ data }) => { | ||||||
|         expect(data.annotationType).toEqual(AnnotationType.STRIKEOUT); |         expect(data.annotationType).toEqual(AnnotationType.STRIKEOUT); | ||||||
|         expect(data.quadPoints).toBeUndefined(); |         expect(data.quadPoints).toEqual(null); | ||||||
|         done(); |         done(); | ||||||
|       }, done.fail); |       }, done.fail); | ||||||
|     }); |     }); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user