Implement caret annotations

The file `test/pdfs/annotation-caret-ink.pdf` is already available in
the repository as a reference test for this since I supplied it for
another patch that implemented ink annotations.
This commit is contained in:
Tim van der Meij 2019-04-09 23:35:32 +02:00
parent ce62373db3
commit 4055d0a302
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762
3 changed files with 40 additions and 0 deletions

View File

@ -107,6 +107,9 @@ class AnnotationFactory {
case 'Polygon': case 'Polygon':
return new PolygonAnnotation(parameters); return new PolygonAnnotation(parameters);
case 'Caret':
return new CaretAnnotation(parameters);
case 'Ink': case 'Ink':
return new InkAnnotation(parameters); return new InkAnnotation(parameters);
@ -1026,6 +1029,15 @@ class PolygonAnnotation extends PolylineAnnotation {
} }
} }
class CaretAnnotation extends Annotation {
constructor(parameters) {
super(parameters);
this.data.annotationType = AnnotationType.CARET;
this._preparePopup(parameters.dict);
}
}
class InkAnnotation extends Annotation { class InkAnnotation extends Annotation {
constructor(parameters) { constructor(parameters) {
super(parameters); super(parameters);

View File

@ -83,6 +83,9 @@ class AnnotationElementFactory {
case AnnotationType.POLYLINE: case AnnotationType.POLYLINE:
return new PolylineAnnotationElement(parameters); return new PolylineAnnotationElement(parameters);
case AnnotationType.CARET:
return new CaretAnnotationElement(parameters);
case AnnotationType.INK: case AnnotationType.INK:
return new InkAnnotationElement(parameters); return new InkAnnotationElement(parameters);
@ -1017,6 +1020,30 @@ class PolygonAnnotationElement extends PolylineAnnotationElement {
} }
} }
class CaretAnnotationElement extends AnnotationElement {
constructor(parameters) {
const isRenderable = !!(parameters.data.hasPopup ||
parameters.data.title || parameters.data.contents);
super(parameters, isRenderable, /* ignoreBorder = */ true);
}
/**
* Render the caret annotation's HTML element in the empty container.
*
* @public
* @memberof CaretAnnotationElement
* @returns {HTMLSectionElement}
*/
render() {
this.container.className = 'caretAnnotation';
if (!this.data.hasPopup) {
this._createPopup(this.container, null, this.data);
}
return this.container;
}
}
class InkAnnotationElement extends AnnotationElement { class InkAnnotationElement extends AnnotationElement {
constructor(parameters) { constructor(parameters) {
let isRenderable = !!(parameters.data.hasPopup || let isRenderable = !!(parameters.data.hasPopup ||

View File

@ -188,6 +188,7 @@
.annotationLayer .circleAnnotation svg ellipse, .annotationLayer .circleAnnotation svg ellipse,
.annotationLayer .polylineAnnotation svg polyline, .annotationLayer .polylineAnnotation svg polyline,
.annotationLayer .polygonAnnotation svg polygon, .annotationLayer .polygonAnnotation svg polygon,
.annotationLayer .caretAnnotation,
.annotationLayer .inkAnnotation svg polyline, .annotationLayer .inkAnnotation svg polyline,
.annotationLayer .stampAnnotation, .annotationLayer .stampAnnotation,
.annotationLayer .fileAttachmentAnnotation { .annotationLayer .fileAttachmentAnnotation {