Skip to content

Commit

Permalink
move hasHtml to AnnotationElement
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Jan 15, 2016
1 parent 52caad6 commit 1cfcaf8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
10 changes: 0 additions & 10 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,6 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
WidgetAnnotation.call(this, params);

this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
}

Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
Expand Down Expand Up @@ -658,7 +657,6 @@ var TextAnnotation = (function TextAnnotationClosure() {
Annotation.call(this, parameters);

this.data.annotationType = AnnotationType.TEXT;
this.data.hasHtml = true;

var dict = parameters.dict;
if (this.data.hasAppearance) {
Expand All @@ -680,7 +678,6 @@ var TextAnnotation = (function TextAnnotationClosure() {
// must create its own popup.
this.data.title = stringToPDFString(dict.get('T') || '');
this.data.contents = stringToPDFString(dict.get('Contents') || '');
this.data.hasHtml = (this.data.title || this.data.contents);
}
}

Expand All @@ -696,7 +693,6 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
var dict = params.dict;
var data = this.data;
data.annotationType = AnnotationType.LINK;
data.hasHtml = true;

var action = dict.get('A');
if (action && isDict(action)) {
Expand Down Expand Up @@ -789,8 +785,6 @@ var PopupAnnotation = (function PopupAnnotationClosure() {
this.setColor(parentItem.get('C'));
this.data.color = this.color;
}

this.data.hasHtml = (this.data.title || this.data.contents);
}

Util.inherit(PopupAnnotation, Annotation, {});
Expand All @@ -803,7 +797,6 @@ var HighlightAnnotation = (function HighlightAnnotationClosure() {
Annotation.call(this, parameters);

this.data.annotationType = AnnotationType.HIGHLIGHT;
this.data.hasHtml = true;

// PDF viewers completely ignore any border styles.
this.data.borderStyle.setWidth(0);
Expand All @@ -819,7 +812,6 @@ var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
Annotation.call(this, parameters);

this.data.annotationType = AnnotationType.UNDERLINE;
this.data.hasHtml = true;

// PDF viewers completely ignore any border styles.
this.data.borderStyle.setWidth(0);
Expand All @@ -835,7 +827,6 @@ var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
Annotation.call(this, parameters);

this.data.annotationType = AnnotationType.SQUIGGLY;
this.data.hasHtml = true;

// PDF viewers completely ignore any border styles.
this.data.borderStyle.setWidth(0);
Expand All @@ -851,7 +842,6 @@ var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
Annotation.call(this, parameters);

this.data.annotationType = AnnotationType.STRIKEOUT;
this.data.hasHtml = true;

// PDF viewers completely ignore any border styles.
this.data.borderStyle.setWidth(0);
Expand Down
35 changes: 22 additions & 13 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ AnnotationElementFactory.prototype =
return new StrikeOutAnnotationElement(parameters);

default:
throw new Error('Unimplemented annotation type "' + subtype + '"');
warn('Unimplemented annotation type "' + parameters.data.subtype + '"');
return null;
}
}
};
Expand All @@ -96,14 +97,17 @@ AnnotationElementFactory.prototype =
* @alias AnnotationElement
*/
var AnnotationElement = (function AnnotationElementClosure() {
function AnnotationElement(parameters) {
function AnnotationElement(parameters, isRenderable) {
this.isRenderable = isRenderable;
this.data = parameters.data;
this.layer = parameters.layer;
this.page = parameters.page;
this.viewport = parameters.viewport;
this.linkService = parameters.linkService;

this.container = this._createContainer();
if (isRenderable) {
this.container = this._createContainer();
}
}

AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
Expand Down Expand Up @@ -218,7 +222,7 @@ var AnnotationElement = (function AnnotationElementClosure() {
*/
var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
function LinkAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
AnnotationElement.call(this, parameters, true);
}

Util.inherit(LinkAnnotationElement, AnnotationElement, {
Expand Down Expand Up @@ -310,7 +314,9 @@ var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
*/
var TextAnnotationElement = (function TextAnnotationElementClosure() {
function TextAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
var isRenderable = !!(parameters.data.hasPopup||
parameters.data.title || parameters.data.contents);
AnnotationElement.call(this, parameters, isRenderable);
}

Util.inherit(TextAnnotationElement, AnnotationElement, {
Expand Down Expand Up @@ -364,7 +370,7 @@ var TextAnnotationElement = (function TextAnnotationElementClosure() {
*/
var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
function WidgetAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
AnnotationElement.call(this, parameters, true);
}

Util.inherit(WidgetAnnotationElement, AnnotationElement, {
Expand Down Expand Up @@ -431,7 +437,8 @@ var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
*/
var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
function PopupAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
var isRenderable = !!(parameters.data.title || parameters.data.contents);
AnnotationElement.call(this, parameters, isRenderable);
}

Util.inherit(PopupAnnotationElement, AnnotationElement, {
Expand Down Expand Up @@ -621,7 +628,7 @@ var PopupElement = (function PopupElementClosure() {
var HighlightAnnotationElement = (
function HighlightAnnotationElementClosure() {
function HighlightAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
AnnotationElement.call(this, parameters, true);
}

Util.inherit(HighlightAnnotationElement, AnnotationElement, {
Expand All @@ -648,7 +655,7 @@ var HighlightAnnotationElement = (
var UnderlineAnnotationElement = (
function UnderlineAnnotationElementClosure() {
function UnderlineAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
AnnotationElement.call(this, parameters, true);
}

Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
Expand All @@ -674,7 +681,7 @@ var UnderlineAnnotationElement = (
*/
var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {
function SquigglyAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
AnnotationElement.call(this, parameters, true);
}

Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
Expand All @@ -701,7 +708,7 @@ var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {
var StrikeOutAnnotationElement = (
function StrikeOutAnnotationElementClosure() {
function StrikeOutAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
AnnotationElement.call(this, parameters, true);
}

Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
Expand Down Expand Up @@ -748,7 +755,7 @@ var AnnotationLayer = (function AnnotationLayerClosure() {

for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
var data = parameters.annotations[i];
if (!data || !data.hasHtml) {
if (!data) {
continue;
}

Expand All @@ -760,7 +767,9 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
linkService: parameters.linkService
};
var element = annotationElementFactory.create(properties);
parameters.div.appendChild(element.render());
if (element && element.isRenderable) {
parameters.div.appendChild(element.render());
}
}
},

Expand Down

0 comments on commit 1cfcaf8

Please sign in to comment.