Skip to content

Commit

Permalink
Merge pull request mozilla#10735 from timvandermeij/freetext-annotation
Browse files Browse the repository at this point in the history
Implement free text annotations
  • Loading branch information
timvandermeij authored Apr 13, 2019
2 parents 62dc431 + ae2a4dc commit 8bbae79
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class AnnotationFactory {
case 'Popup':
return new PopupAnnotation(parameters);

case 'FreeText':
return new FreeTextAnnotation(parameters);

case 'Line':
return new LineAnnotation(parameters);

Expand Down Expand Up @@ -964,6 +967,14 @@ class PopupAnnotation extends Annotation {
}
}

class FreeTextAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);

this.data.annotationType = AnnotationType.FREETEXT;
}
}

class LineAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);
Expand Down
27 changes: 27 additions & 0 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class AnnotationElementFactory {
case AnnotationType.POPUP:
return new PopupAnnotationElement(parameters);

case AnnotationType.FREETEXT:
return new FreeTextAnnotationElement(parameters);

case AnnotationType.LINE:
return new LineAnnotationElement(parameters);

Expand Down Expand Up @@ -807,6 +810,30 @@ class PopupElement {
}
}

class FreeTextAnnotationElement extends AnnotationElement {
constructor(parameters) {
const isRenderable = !!(parameters.data.hasPopup ||
parameters.data.title || parameters.data.contents);
super(parameters, isRenderable, /* ignoreBorder = */ true);
}

/**
* Render the free text annotation's HTML element in the empty container.
*
* @public
* @memberof FreeTextAnnotationElement
* @returns {HTMLSectionElement}
*/
render() {
this.container.className = 'freeTextAnnotation';

if (!this.data.hasPopup) {
this._createPopup(this.container, null, this.data);
}
return this.container;
}
}

class LineAnnotationElement extends AnnotationElement {
constructor(parameters) {
let isRenderable = !!(parameters.data.hasPopup ||
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
!annotation-strikeout.pdf
!annotation-squiggly.pdf
!annotation-highlight.pdf
!annotation-freetext.pdf
!annotation-line.pdf
!annotation-square-circle.pdf
!annotation-stamp.pdf
Expand Down
Binary file added test/pdfs/annotation-freetext.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4007,6 +4007,13 @@
"type": "eq",
"annotations": true
},
{ "id": "annotation-freetext",
"file": "pdfs/annotation-freetext.pdf",
"md5": "6ca19ce632ead3aed08f22e588510e2f",
"rounds": 1,
"type": "eq",
"annotations": true
},
{ "id": "annotation-line",
"file": "pdfs/annotation-line.pdf",
"md5": "fde60608be2748f10fb6522cba425ca1",
Expand Down
1 change: 1 addition & 0 deletions web/annotation_layer_builder.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
.annotationLayer .underlineAnnotation,
.annotationLayer .squigglyAnnotation,
.annotationLayer .strikeoutAnnotation,
.annotationLayer .freeTextAnnotation,
.annotationLayer .lineAnnotation svg line,
.annotationLayer .squareAnnotation svg rect,
.annotationLayer .circleAnnotation svg ellipse,
Expand Down

0 comments on commit 8bbae79

Please sign in to comment.