Implement annotation border style class and constants
This commit is contained in:
parent
bf20334bea
commit
88b2059ed9
@ -334,6 +334,144 @@ var Annotation = (function AnnotationClosure() {
|
|||||||
return Annotation;
|
return Annotation;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains all data regarding an annotation's border style.
|
||||||
|
*
|
||||||
|
* @class
|
||||||
|
*/
|
||||||
|
var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
function AnnotationBorderStyle() {
|
||||||
|
this.width = 1;
|
||||||
|
this.style = AnnotationBorderStyleType.SOLID;
|
||||||
|
this.dashArray = [3];
|
||||||
|
this.horizontalCornerRadius = 0;
|
||||||
|
this.verticalCornerRadius = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
AnnotationBorderStyle.prototype = {
|
||||||
|
/**
|
||||||
|
* Set the width.
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
* @memberof AnnotationBorderStyle
|
||||||
|
* @param {integer} width - The width
|
||||||
|
*/
|
||||||
|
setWidth: function AnnotationBorderStyle_setWidth(width) {
|
||||||
|
if (width === (width | 0)) {
|
||||||
|
this.width = width;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the style.
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
* @memberof AnnotationBorderStyle
|
||||||
|
* @param {Object} style - The style object
|
||||||
|
* @see {@link shared/util.js}
|
||||||
|
*/
|
||||||
|
setStyle: function AnnotationBorderStyle_setStyle(style) {
|
||||||
|
if (!style) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (style.name) {
|
||||||
|
case 'S':
|
||||||
|
this.style = AnnotationBorderStyleType.SOLID;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'D':
|
||||||
|
this.style = AnnotationBorderStyleType.DASHED;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'B':
|
||||||
|
this.style = AnnotationBorderStyleType.BEVELED;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'I':
|
||||||
|
this.style = AnnotationBorderStyleType.INSET;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'U':
|
||||||
|
this.style = AnnotationBorderStyleType.UNDERLINE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dash array.
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
* @memberof AnnotationBorderStyle
|
||||||
|
* @param {Array} dashArray - The dash array with at least one element
|
||||||
|
*/
|
||||||
|
setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
|
||||||
|
// We validate the dash array, but we do not use it because CSS does not
|
||||||
|
// allow us to change spacing of dashes. For more information, visit
|
||||||
|
// http://www.w3.org/TR/css3-background/#the-border-style.
|
||||||
|
if (isArray(dashArray) && dashArray.length > 0) {
|
||||||
|
// According to the PDF specification: the elements in a dashArray
|
||||||
|
// shall be numbers that are nonnegative and not all equal to zero.
|
||||||
|
var isValid = true;
|
||||||
|
var allZeros = true;
|
||||||
|
for (var i = 0, len = dashArray.length; i < len; i++) {
|
||||||
|
var element = dashArray[i];
|
||||||
|
var validNumber = (+element >= 0);
|
||||||
|
if (!validNumber) {
|
||||||
|
isValid = false;
|
||||||
|
break;
|
||||||
|
} else if (element > 0) {
|
||||||
|
allZeros = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isValid && !allZeros) {
|
||||||
|
this.dashArray = dashArray;
|
||||||
|
} else {
|
||||||
|
this.width = 0; // Adobe behavior when the array is invalid.
|
||||||
|
}
|
||||||
|
} else if (dashArray) {
|
||||||
|
this.width = 0; // Adobe behavior when the array is invalid.
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the horizontal corner radius (from a Border dictionary).
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
* @memberof AnnotationBorderStyle
|
||||||
|
* @param {integer} radius - The horizontal corner radius
|
||||||
|
*/
|
||||||
|
setHorizontalCornerRadius:
|
||||||
|
function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
|
||||||
|
if (radius === (radius | 0)) {
|
||||||
|
this.horizontalCornerRadius = radius;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the vertical corner radius (from a Border dictionary).
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
* @memberof AnnotationBorderStyle
|
||||||
|
* @param {integer} radius - The vertical corner radius
|
||||||
|
*/
|
||||||
|
setVerticalCornerRadius:
|
||||||
|
function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
|
||||||
|
if (radius === (radius | 0)) {
|
||||||
|
this.verticalCornerRadius = radius;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return AnnotationBorderStyle;
|
||||||
|
})();
|
||||||
|
|
||||||
var WidgetAnnotation = (function WidgetAnnotationClosure() {
|
var WidgetAnnotation = (function WidgetAnnotationClosure() {
|
||||||
|
|
||||||
function WidgetAnnotation(params) {
|
function WidgetAnnotation(params) {
|
||||||
|
@ -50,6 +50,14 @@ var AnnotationType = {
|
|||||||
LINK: 3
|
LINK: 3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var AnnotationBorderStyleType = {
|
||||||
|
SOLID: 1,
|
||||||
|
DASHED: 2,
|
||||||
|
BEVELED: 3,
|
||||||
|
INSET: 4,
|
||||||
|
UNDERLINE: 5
|
||||||
|
};
|
||||||
|
|
||||||
var StreamType = {
|
var StreamType = {
|
||||||
UNKNOWN: 0,
|
UNKNOWN: 0,
|
||||||
FLATE: 1,
|
FLATE: 1,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user