From e42da0f5e93f6b2cc2ae126995acb23a79fac532 Mon Sep 17 00:00:00 2001 From: Xiliang Chen Date: Tue, 12 Jan 2016 16:44:44 +1300 Subject: [PATCH] move hasHtml to AnnotationElement --- src/core/annotation.js | 10 --------- src/display/annotation_layer.js | 36 +++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/core/annotation.js b/src/core/annotation.js index 1efabe472..46a59c916 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -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, { @@ -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) { @@ -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); } } @@ -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)) { @@ -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, {}); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 2107012c1..722cf17ea 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -84,7 +84,7 @@ AnnotationElementFactory.prototype = return new StrikeOutAnnotationElement(parameters); default: - throw new Error('Unimplemented annotation type "' + subtype + '"'); + return new AnnotationElement(parameters); } } }; @@ -94,14 +94,17 @@ AnnotationElementFactory.prototype = * @alias AnnotationElement */ var AnnotationElement = (function AnnotationElementClosure() { - function AnnotationElement(parameters) { + function AnnotationElement(parameters, isRenderable) { + this.isRenderable = isRenderable || false; 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 */ { @@ -216,7 +219,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, { @@ -298,7 +301,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, { @@ -352,7 +357,9 @@ var TextAnnotationElement = (function TextAnnotationElementClosure() { */ var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() { function WidgetAnnotationElement(parameters) { - AnnotationElement.call(this, parameters); + var isRenderable = !parameters.data.hasAppearance && + !!parameters.data.fieldValue; + AnnotationElement.call(this, parameters, isRenderable); } Util.inherit(WidgetAnnotationElement, AnnotationElement, { @@ -419,7 +426,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, { @@ -609,7 +617,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, { @@ -636,7 +644,7 @@ var HighlightAnnotationElement = ( var UnderlineAnnotationElement = ( function UnderlineAnnotationElementClosure() { function UnderlineAnnotationElement(parameters) { - AnnotationElement.call(this, parameters); + AnnotationElement.call(this, parameters, true); } Util.inherit(UnderlineAnnotationElement, AnnotationElement, { @@ -662,7 +670,7 @@ var UnderlineAnnotationElement = ( */ var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() { function SquigglyAnnotationElement(parameters) { - AnnotationElement.call(this, parameters); + AnnotationElement.call(this, parameters, true); } Util.inherit(SquigglyAnnotationElement, AnnotationElement, { @@ -689,7 +697,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, { @@ -736,7 +744,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; } @@ -748,7 +756,9 @@ var AnnotationLayer = (function AnnotationLayerClosure() { linkService: parameters.linkService }; var element = annotationElementFactory.create(properties); - parameters.div.appendChild(element.render()); + if (element.isRenderable) { + parameters.div.appendChild(element.render()); + } } },