Merge pull request #6239 from timvandermeij/annotation-rectangle
Refactor annotation rectangle code and add unit tests
This commit is contained in:
commit
862342189f
@ -75,10 +75,11 @@ var Annotation = (function AnnotationClosure() {
|
|||||||
var data = this.data = {};
|
var data = this.data = {};
|
||||||
|
|
||||||
data.subtype = dict.get('Subtype').name;
|
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');
|
data.annotationFlags = dict.get('F');
|
||||||
|
|
||||||
|
this.setRectangle(dict.get('Rect'));
|
||||||
|
data.rect = this.rectangle;
|
||||||
|
|
||||||
this.setColor(dict.get('C'));
|
this.setColor(dict.get('C'));
|
||||||
data.color = this.color;
|
data.color = this.color;
|
||||||
|
|
||||||
@ -91,6 +92,21 @@ var Annotation = (function AnnotationClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Annotation.prototype = {
|
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.
|
* Set the color and take care of color space conversion.
|
||||||
*
|
*
|
||||||
|
@ -7,6 +7,24 @@
|
|||||||
|
|
||||||
describe('Annotation layer', function() {
|
describe('Annotation layer', function() {
|
||||||
describe('Annotation', function() {
|
describe('Annotation', function() {
|
||||||
|
it('should set and get a valid rectangle', function() {
|
||||||
|
var dict = new Dict();
|
||||||
|
dict.set('Subtype', '');
|
||||||
|
var annotation = new Annotation({ dict: dict, ref: 0 });
|
||||||
|
annotation.setRectangle([117, 694, 164.298, 720]);
|
||||||
|
|
||||||
|
expect(annotation.rectangle).toEqual([117, 694, 164.298, 720]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not set and get an invalid rectangle', function() {
|
||||||
|
var dict = new Dict();
|
||||||
|
dict.set('Subtype', '');
|
||||||
|
var annotation = new Annotation({ dict: dict, ref: 0 });
|
||||||
|
annotation.setRectangle([117, 694, 164.298]);
|
||||||
|
|
||||||
|
expect(annotation.rectangle).toEqual([0, 0, 0, 0]);
|
||||||
|
});
|
||||||
|
|
||||||
it('should reject a color if it is not an array', function() {
|
it('should reject a color if it is not an array', function() {
|
||||||
var dict = new Dict();
|
var dict = new Dict();
|
||||||
dict.set('Subtype', '');
|
dict.set('Subtype', '');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user