Skip to content

Commit

Permalink
Annotations - _preparePopup method replaced with MarkupAnnotation bas…
Browse files Browse the repository at this point in the history
…e class. This is just refactoring, so it shouldn't break anything. It should move annotation API closer to PDF spec and enable future expansion.
  • Loading branch information
vmacaGordic committed Apr 12, 2019
1 parent 74561f5 commit d96267c
Showing 1 changed file with 30 additions and 45 deletions.
75 changes: 30 additions & 45 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,24 +397,6 @@ class Annotation {
this.appearance = normalAppearanceState.get(as.name);
}

/**
* Prepare the annotation for working with a popup in the display layer.
*
* @private
* @memberof Annotation
* @param {Dict} dict - The annotation's data dictionary
*/
_preparePopup(dict) {
if (!dict.has('C')) {
// Fall back to the default background color.
this.data.color = null;
}

this.data.hasPopup = dict.has('Popup');
this.data.title = stringToPDFString(dict.get('T') || '');
this.data.contents = stringToPDFString(dict.get('Contents') || '');
}

loadResources(keys) {
return this.appearance.dict.getAsync('Resources').then((resources) => {
if (!resources) {
Expand Down Expand Up @@ -598,6 +580,22 @@ class AnnotationBorderStyle {
}
}

class MarkupAnnotation extends Annotation {
constructor(parameters) {
super(parameters);
const dict = parameters.dict;

if (!dict.has('C')) {
// Fall back to the default background color.
this.data.color = null;
}

this.data.hasPopup = dict.has('Popup');
this.data.title = stringToPDFString(dict.get('T') || '');
this.data.contents = stringToPDFString(dict.get('Contents') || '');
}
}

class WidgetAnnotation extends Annotation {
constructor(params) {
super(params);
Expand Down Expand Up @@ -893,7 +891,7 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
}
}

class TextAnnotation extends Annotation {
class TextAnnotation extends MarkupAnnotation {
constructor(parameters) {
const DEFAULT_ICON_SIZE = 22; // px

Expand All @@ -909,7 +907,7 @@ class TextAnnotation extends Annotation {
this.data.name = parameters.dict.has('Name') ?
parameters.dict.get('Name').name : 'Note';
}
this._preparePopup(parameters.dict);

}
}

Expand Down Expand Up @@ -966,37 +964,34 @@ class PopupAnnotation extends Annotation {
}
}

class LineAnnotation extends Annotation {
class LineAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);

this.data.annotationType = AnnotationType.LINE;

let dict = parameters.dict;
this.data.lineCoordinates = Util.normalizeRect(dict.getArray('L'));
this._preparePopup(dict);
}
}

class SquareAnnotation extends Annotation {
class SquareAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);

this.data.annotationType = AnnotationType.SQUARE;
this._preparePopup(parameters.dict);
}
}

class CircleAnnotation extends Annotation {
class CircleAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);

this.data.annotationType = AnnotationType.CIRCLE;
this._preparePopup(parameters.dict);
}
}

class PolylineAnnotation extends Annotation {
class PolylineAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);

Expand All @@ -1015,8 +1010,6 @@ class PolylineAnnotation extends Annotation {
y: rawVertices[i + 1],
});
}

this._preparePopup(dict);
}
}

Expand All @@ -1029,16 +1022,15 @@ class PolygonAnnotation extends PolylineAnnotation {
}
}

class CaretAnnotation extends Annotation {
class CaretAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);

this.data.annotationType = AnnotationType.CARET;
this._preparePopup(parameters.dict);
}
}

class InkAnnotation extends Annotation {
class InkAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);

Expand All @@ -1062,64 +1054,57 @@ class InkAnnotation extends Annotation {
});
}
}
this._preparePopup(dict);
}
}

class HighlightAnnotation extends Annotation {
class HighlightAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);

this.data.annotationType = AnnotationType.HIGHLIGHT;
this._preparePopup(parameters.dict);
}
}

class UnderlineAnnotation extends Annotation {
class UnderlineAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);

this.data.annotationType = AnnotationType.UNDERLINE;
this._preparePopup(parameters.dict);
}
}

class SquigglyAnnotation extends Annotation {
class SquigglyAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);

this.data.annotationType = AnnotationType.SQUIGGLY;
this._preparePopup(parameters.dict);
}
}

class StrikeOutAnnotation extends Annotation {
class StrikeOutAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);

this.data.annotationType = AnnotationType.STRIKEOUT;
this._preparePopup(parameters.dict);
}
}

class StampAnnotation extends Annotation {
class StampAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);

this.data.annotationType = AnnotationType.STAMP;
this._preparePopup(parameters.dict);
}
}

class FileAttachmentAnnotation extends Annotation {
class FileAttachmentAnnotation extends MarkupAnnotation {
constructor(parameters) {
super(parameters);

let file = new FileSpec(parameters.dict.get('FS'), parameters.xref);

this.data.annotationType = AnnotationType.FILEATTACHMENT;
this.data.file = file.serializable;
this._preparePopup(parameters.dict);
}
}

Expand Down

0 comments on commit d96267c

Please sign in to comment.