From 30d63b0c502e0b55590bc4bd4fb12c7fa5a7a5d9 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 2 Apr 2017 20:31:21 +0200 Subject: [PATCH] Annotations: move container border removal to the display layer The display layer is responsible for creating the HTML elements for the annotations from the core layer. If we need to ignore border styling for the containers of certain elements, the display layer should do so and not the core layer. I noticed this during the implementation of line annotations, for which we actually need the original border width in the display layer, even though we ignore it for the container. If we set the border style to zero in the core layer, this becomes impossible. To prevent this, this patch moves the container border removal code from the core layer to the display layer. This makes the core layer output the unchanged annotation data and lets the display layer remove any border styling if necessary. --- src/core/annotation.js | 12 ------------ src/display/annotation_layer.js | 26 ++++++++++++++------------ 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/core/annotation.js b/src/core/annotation.js index 20b7b7aa9..0ca76bf6a 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -989,9 +989,6 @@ var HighlightAnnotation = (function HighlightAnnotationClosure() { this.data.annotationType = AnnotationType.HIGHLIGHT; this._preparePopup(parameters.dict); - - // PDF viewers completely ignore any border styles. - this.data.borderStyle.setWidth(0); } Util.inherit(HighlightAnnotation, Annotation, {}); @@ -1005,9 +1002,6 @@ var UnderlineAnnotation = (function UnderlineAnnotationClosure() { this.data.annotationType = AnnotationType.UNDERLINE; this._preparePopup(parameters.dict); - - // PDF viewers completely ignore any border styles. - this.data.borderStyle.setWidth(0); } Util.inherit(UnderlineAnnotation, Annotation, {}); @@ -1021,9 +1015,6 @@ var SquigglyAnnotation = (function SquigglyAnnotationClosure() { this.data.annotationType = AnnotationType.SQUIGGLY; this._preparePopup(parameters.dict); - - // PDF viewers completely ignore any border styles. - this.data.borderStyle.setWidth(0); } Util.inherit(SquigglyAnnotation, Annotation, {}); @@ -1037,9 +1028,6 @@ var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() { this.data.annotationType = AnnotationType.STRIKEOUT; this._preparePopup(parameters.dict); - - // PDF viewers completely ignore any border styles. - this.data.borderStyle.setWidth(0); } Util.inherit(StrikeOutAnnotation, Annotation, {}); diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index fded967d5..65fd7cacd 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -119,7 +119,7 @@ AnnotationElementFactory.prototype = * @alias AnnotationElement */ var AnnotationElement = (function AnnotationElementClosure() { - function AnnotationElement(parameters, isRenderable) { + function AnnotationElement(parameters, isRenderable, ignoreBorder) { this.isRenderable = isRenderable || false; this.data = parameters.data; this.layer = parameters.layer; @@ -131,7 +131,7 @@ var AnnotationElement = (function AnnotationElementClosure() { this.renderInteractiveForms = parameters.renderInteractiveForms; if (isRenderable) { - this.container = this._createContainer(); + this.container = this._createContainer(ignoreBorder); } } @@ -140,10 +140,12 @@ var AnnotationElement = (function AnnotationElementClosure() { * Create an empty container for the annotation's HTML element. * * @private + * @param {boolean} ignoreBorder * @memberof AnnotationElement * @returns {HTMLSectionElement} */ - _createContainer: function AnnotationElement_createContainer() { + _createContainer: + function AnnotationElement_createContainer(ignoreBorder) { var data = this.data, page = this.page, viewport = this.viewport; var container = document.createElement('section'); var width = data.rect[2] - data.rect[0]; @@ -165,7 +167,7 @@ var AnnotationElement = (function AnnotationElementClosure() { CustomStyle.setProp('transformOrigin', container, -rect[0] + 'px ' + -rect[1] + 'px'); - if (data.borderStyle.width > 0) { + if (!ignoreBorder && data.borderStyle.width > 0) { container.style.borderWidth = data.borderStyle.width + 'px'; if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) { // Underline styles only have a bottom border, so we do not need @@ -873,7 +875,8 @@ var HighlightAnnotationElement = ( function HighlightAnnotationElement(parameters) { var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); - AnnotationElement.call(this, parameters, isRenderable); + AnnotationElement.call(this, parameters, isRenderable, + /* ignoreBorder = */ true); } Util.inherit(HighlightAnnotationElement, AnnotationElement, { @@ -890,7 +893,6 @@ var HighlightAnnotationElement = ( if (!this.data.hasPopup) { this._createPopup(this.container, null, this.data); } - return this.container; } }); @@ -907,7 +909,8 @@ var UnderlineAnnotationElement = ( function UnderlineAnnotationElement(parameters) { var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); - AnnotationElement.call(this, parameters, isRenderable); + AnnotationElement.call(this, parameters, isRenderable, + /* ignoreBorder = */ true); } Util.inherit(UnderlineAnnotationElement, AnnotationElement, { @@ -924,7 +927,6 @@ var UnderlineAnnotationElement = ( if (!this.data.hasPopup) { this._createPopup(this.container, null, this.data); } - return this.container; } }); @@ -940,7 +942,8 @@ var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() { function SquigglyAnnotationElement(parameters) { var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); - AnnotationElement.call(this, parameters, isRenderable); + AnnotationElement.call(this, parameters, isRenderable, + /* ignoreBorder = */ true); } Util.inherit(SquigglyAnnotationElement, AnnotationElement, { @@ -957,7 +960,6 @@ var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() { if (!this.data.hasPopup) { this._createPopup(this.container, null, this.data); } - return this.container; } }); @@ -974,7 +976,8 @@ var StrikeOutAnnotationElement = ( function StrikeOutAnnotationElement(parameters) { var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); - AnnotationElement.call(this, parameters, isRenderable); + AnnotationElement.call(this, parameters, isRenderable, + /* ignoreBorder = */ true); } Util.inherit(StrikeOutAnnotationElement, AnnotationElement, { @@ -991,7 +994,6 @@ var StrikeOutAnnotationElement = ( if (!this.data.hasPopup) { this._createPopup(this.container, null, this.data); } - return this.container; } });