Move quadrilateral rendering logic into a method on the AnnotationElement class

Doing so avoids some code duplication.
This commit is contained in:
Tim van der Meij 2020-12-05 19:32:13 +01:00
parent 0273080031
commit cb422a80b0
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -23,6 +23,7 @@ import {
import { import {
AnnotationBorderStyleType, AnnotationBorderStyleType,
AnnotationType, AnnotationType,
assert,
stringToPDFString, stringToPDFString,
unreachable, unreachable,
Util, Util,
@ -324,6 +325,28 @@ class AnnotationElement {
container.appendChild(popup); container.appendChild(popup);
} }
/**
* Render the quadrilaterals of the annotation.
*
* @private
* @param {string} className
* @memberof AnnotationElement
* @returns {Array<HTMLSectionElement>}
*/
_renderQuadrilaterals(className) {
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING")
) {
assert(this.quadrilaterals, "Missing quadrilaterals during rendering");
}
this.quadrilaterals.forEach(quadrilateral => {
quadrilateral.className = className;
});
return this.quadrilaterals;
}
/** /**
* Render the annotation's HTML element in the empty container. * Render the annotation's HTML element in the empty container.
* *
@ -1463,10 +1486,7 @@ class HighlightAnnotationElement extends AnnotationElement {
} }
if (this.quadrilaterals) { if (this.quadrilaterals) {
this.quadrilaterals.forEach(quadrilateral => { return this._renderQuadrilaterals("highlightAnnotation");
quadrilateral.className = "highlightAnnotation";
});
return this.quadrilaterals;
} }
this.container.className = "highlightAnnotation"; this.container.className = "highlightAnnotation";
@ -1501,10 +1521,7 @@ class UnderlineAnnotationElement extends AnnotationElement {
} }
if (this.quadrilaterals) { if (this.quadrilaterals) {
this.quadrilaterals.forEach(quadrilateral => { return this._renderQuadrilaterals("underlineAnnotation");
quadrilateral.className = "underlineAnnotation";
});
return this.quadrilaterals;
} }
this.container.className = "underlineAnnotation"; this.container.className = "underlineAnnotation";
@ -1539,10 +1556,7 @@ class SquigglyAnnotationElement extends AnnotationElement {
} }
if (this.quadrilaterals) { if (this.quadrilaterals) {
this.quadrilaterals.forEach(quadrilateral => { return this._renderQuadrilaterals("squigglyAnnotation");
quadrilateral.className = "squigglyAnnotation";
});
return this.quadrilaterals;
} }
this.container.className = "squigglyAnnotation"; this.container.className = "squigglyAnnotation";
@ -1577,10 +1591,7 @@ class StrikeOutAnnotationElement extends AnnotationElement {
} }
if (this.quadrilaterals) { if (this.quadrilaterals) {
this.quadrilaterals.forEach(quadrilateral => { return this._renderQuadrilaterals("strikeoutAnnotation");
quadrilateral.className = "strikeoutAnnotation";
});
return this.quadrilaterals;
} }
this.container.className = "strikeoutAnnotation"; this.container.className = "strikeoutAnnotation";