[Pkg-javascript-commits] [pdf.js] 03/157: Implement annotation border style class and constants
David Prévot
taffit at moszumanska.debian.org
Tue Aug 11 06:46:23 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit 88b2059ed9efec6e64f7b4c41b20d70028a2f541
Author: Tim van der Meij <timvandermeij at gmail.com>
Date: Thu Dec 25 20:11:23 2014 +0100
Implement annotation border style class and constants
---
src/core/annotation.js | 138 +++++++++++++++++++++++++++++++++++++++++++++++++
src/shared/util.js | 8 +++
2 files changed, 146 insertions(+)
diff --git a/src/core/annotation.js b/src/core/annotation.js
index 32974b5..41457cb 100644
--- a/src/core/annotation.js
+++ b/src/core/annotation.js
@@ -334,6 +334,144 @@ var Annotation = (function AnnotationClosure() {
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() {
function WidgetAnnotation(params) {
diff --git a/src/shared/util.js b/src/shared/util.js
index 382f643..bc36c56 100644
--- a/src/shared/util.js
+++ b/src/shared/util.js
@@ -50,6 +50,14 @@ var AnnotationType = {
LINK: 3
};
+var AnnotationBorderStyleType = {
+ SOLID: 1,
+ DASHED: 2,
+ BEVELED: 3,
+ INSET: 4,
+ UNDERLINE: 5
+};
+
var StreamType = {
UNKNOWN: 0,
FLATE: 1,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list