Skip to content

Commit 400e4aa

Browse files
committed
Implement support for stamp annotations
1 parent 3be941d commit 400e4aa

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed

src/core/annotation.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class AnnotationFactory {
9999
case 'StrikeOut':
100100
return new StrikeOutAnnotation(parameters);
101101

102+
case 'Stamp':
103+
return new StampAnnotation(parameters);
104+
102105
case 'FileAttachment':
103106
return new FileAttachmentAnnotation(parameters);
104107

@@ -946,6 +949,15 @@ class StrikeOutAnnotation extends Annotation {
946949
}
947950
}
948951

952+
class StampAnnotation extends Annotation {
953+
constructor(parameters) {
954+
super(parameters);
955+
956+
this.data.annotationType = AnnotationType.STAMP;
957+
this._preparePopup(parameters.dict);
958+
}
959+
}
960+
949961
class FileAttachmentAnnotation extends Annotation {
950962
constructor(parameters) {
951963
super(parameters);

src/display/annotation_layer.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class AnnotationElementFactory {
9292
case AnnotationType.STRIKEOUT:
9393
return new StrikeOutAnnotationElement(parameters);
9494

95+
case AnnotationType.STAMP:
96+
return new StampAnnotationElement(parameters);
97+
9598
case AnnotationType.FILEATTACHMENT:
9699
return new FileAttachmentAnnotationElement(parameters);
97100

@@ -1004,6 +1007,30 @@ class StrikeOutAnnotationElement extends AnnotationElement {
10041007
}
10051008
}
10061009

1010+
class StampAnnotationElement extends AnnotationElement {
1011+
constructor(parameters) {
1012+
let isRenderable = !!(parameters.data.hasPopup ||
1013+
parameters.data.title || parameters.data.contents);
1014+
super(parameters, isRenderable, /* ignoreBorder = */ true);
1015+
}
1016+
1017+
/**
1018+
* Render the stamp annotation's HTML element in the empty container.
1019+
*
1020+
* @public
1021+
* @memberof StampAnnotationElement
1022+
* @returns {HTMLSectionElement}
1023+
*/
1024+
render() {
1025+
this.container.className = 'stampAnnotation';
1026+
1027+
if (!this.data.hasPopup) {
1028+
this._createPopup(this.container, null, this.data);
1029+
}
1030+
return this.container;
1031+
}
1032+
}
1033+
10071034
class FileAttachmentAnnotationElement extends AnnotationElement {
10081035
constructor(parameters) {
10091036
super(parameters, /* isRenderable = */ true);

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@
285285
!annotation-highlight.pdf
286286
!annotation-line.pdf
287287
!annotation-square-circle.pdf
288+
!annotation-stamp.pdf
288289
!annotation-fileattachment.pdf
289290
!annotation-text-widget.pdf
290291
!annotation-choice-widget.pdf

test/pdfs/annotation-stamp.pdf

86.8 KB
Binary file not shown.

test/test_manifest.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3583,6 +3583,13 @@
35833583
"type": "eq",
35843584
"annotations": true
35853585
},
3586+
{ "id": "annotation-stamp",
3587+
"file": "pdfs/annotation-stamp.pdf",
3588+
"md5": "0a04d7ce1ad103cb3c033d26855d6ec7",
3589+
"rounds": 1,
3590+
"type": "eq",
3591+
"annotations": true
3592+
},
35863593
{ "id": "annotation-fileattachment",
35873594
"file": "pdfs/annotation-fileattachment.pdf",
35883595
"md5": "d20ecee4b53c81b2dd44c8715a1b4a83",

web/annotation_layer_builder.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
.annotationLayer .lineAnnotation svg line,
192192
.annotationLayer .squareAnnotation svg rect,
193193
.annotationLayer .circleAnnotation svg ellipse,
194+
.annotationLayer .stampAnnotation,
194195
.annotationLayer .fileAttachmentAnnotation {
195196
cursor: pointer;
196197
}

0 commit comments

Comments
 (0)