|
|
@ -17,7 +17,7 @@ |
|
|
|
/* globals PDFJS, Util, isDict, isName, stringToPDFString, warn, Dict, Stream, |
|
|
|
/* globals PDFJS, Util, isDict, isName, stringToPDFString, warn, Dict, Stream, |
|
|
|
stringToBytes, Promise, isArray, ObjectLoader, OperatorList, |
|
|
|
stringToBytes, Promise, isArray, ObjectLoader, OperatorList, |
|
|
|
isValidUrl, OPS, createPromiseCapability, AnnotationType, |
|
|
|
isValidUrl, OPS, createPromiseCapability, AnnotationType, |
|
|
|
stringToUTF8String, AnnotationBorderStyleType */ |
|
|
|
stringToUTF8String, AnnotationBorderStyleType, ColorSpace */ |
|
|
|
|
|
|
|
|
|
|
|
'use strict'; |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
@ -79,28 +79,8 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
data.rect = Util.normalizeRect(rect); |
|
|
|
data.rect = Util.normalizeRect(rect); |
|
|
|
data.annotationFlags = dict.get('F'); |
|
|
|
data.annotationFlags = dict.get('F'); |
|
|
|
|
|
|
|
|
|
|
|
var color = dict.get('C'); |
|
|
|
this.setColor(dict.get('C')); |
|
|
|
if (!color) { |
|
|
|
data.color = this.color; |
|
|
|
// The PDF spec does not mention how a missing color array is interpreted.
|
|
|
|
|
|
|
|
// Adobe Reader seems to default to black in this case.
|
|
|
|
|
|
|
|
data.color = [0, 0, 0]; |
|
|
|
|
|
|
|
} else if (isArray(color)) { |
|
|
|
|
|
|
|
switch (color.length) { |
|
|
|
|
|
|
|
case 0: |
|
|
|
|
|
|
|
// Empty array denotes transparent border.
|
|
|
|
|
|
|
|
data.color = null; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
// TODO: implement DeviceGray
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 3: |
|
|
|
|
|
|
|
data.color = color; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 4: |
|
|
|
|
|
|
|
// TODO: implement DeviceCMYK
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.borderStyle = data.borderStyle = new AnnotationBorderStyle(); |
|
|
|
this.borderStyle = data.borderStyle = new AnnotationBorderStyle(); |
|
|
|
this.setBorderStyle(dict); |
|
|
|
this.setBorderStyle(dict); |
|
|
@ -111,6 +91,48 @@ var Annotation = (function AnnotationClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Annotation.prototype = { |
|
|
|
Annotation.prototype = { |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Set the color and take care of color space conversion. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @public |
|
|
|
|
|
|
|
* @memberof Annotation |
|
|
|
|
|
|
|
* @param {Array} color - The color array containing either 0 |
|
|
|
|
|
|
|
* (transparent), 1 (grayscale), 3 (RGB) or |
|
|
|
|
|
|
|
* 4 (CMYK) elements |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
setColor: function Annotation_setColor(color) { |
|
|
|
|
|
|
|
var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
|
|
|
|
|
|
|
|
if (!isArray(color)) { |
|
|
|
|
|
|
|
this.color = rgbColor; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (color.length) { |
|
|
|
|
|
|
|
case 0: // Transparent, which we indicate with a null value
|
|
|
|
|
|
|
|
this.color = null; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 1: // Convert grayscale to RGB
|
|
|
|
|
|
|
|
ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0); |
|
|
|
|
|
|
|
this.color = rgbColor; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 3: // Convert RGB percentages to RGB
|
|
|
|
|
|
|
|
ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0); |
|
|
|
|
|
|
|
this.color = rgbColor; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 4: // Convert CMYK to RGB
|
|
|
|
|
|
|
|
ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0); |
|
|
|
|
|
|
|
this.color = rgbColor; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
this.color = rgbColor; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the border style (as AnnotationBorderStyle object). |
|
|
|
* Set the border style (as AnnotationBorderStyle object). |
|
|
|
* |
|
|
|
* |
|
|
|