1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 17:48:07 +02:00

Refactor annotation rectangle code and add unit tests

This patch refactors the code responsible for setting the annotation's rectangle. Its goal is to:

- Actually check that the input array is actually an array, and if so, that it contains exactly four elements.
- Only call `normalizeRect` if the input array is valid, i.e., we do not call it for the default rectangle anymore.

Unit tests are provided just like with the other patches in this series.
This commit is contained in:
Tim van der Meij 2015-07-20 22:01:47 +02:00
parent c42613b911
commit 980aa10e04
2 changed files with 36 additions and 2 deletions

View file

@ -75,10 +75,11 @@ var Annotation = (function AnnotationClosure() {
var data = this.data = {};
data.subtype = dict.get('Subtype').name;
var rect = dict.get('Rect') || [0, 0, 0, 0];
data.rect = Util.normalizeRect(rect);
data.annotationFlags = dict.get('F');
this.setRectangle(dict.get('Rect'));
data.rect = this.rectangle;
this.setColor(dict.get('C'));
data.color = this.color;
@ -91,6 +92,21 @@ var Annotation = (function AnnotationClosure() {
}
Annotation.prototype = {
/**
* Set the rectangle.
*
* @public
* @memberof Annotation
* @param {Array} rectangle - The rectangle array with exactly four entries
*/
setRectangle: function Annotation_setRectangle(rectangle) {
if (isArray(rectangle) && rectangle.length === 4) {
this.rectangle = Util.normalizeRect(rectangle);
} else {
this.rectangle = [0, 0, 0, 0];
}
},
/**
* Set the color and take care of color space conversion.
*