Support borders for link annotations

This commit is contained in:
Mack Duan 2013-03-26 02:41:56 -07:00 committed by Yury Delendik
parent 67eb3bbc68
commit a394c1bac6
2 changed files with 45 additions and 10 deletions

View File

@ -80,14 +80,23 @@ var Annotation = (function AnnotationClosure() {
data.rect = Util.normalizeRect(rect);
data.annotationFlags = dict.get('F');
var border = dict.get('BS');
if (isDict(border)) {
var borderWidth = border.has('W') ? border.get('W') : 1;
data.border = {
width: borderWidth,
type: border.get('S') || 'S',
rgb: dict.get('C') || [0, 0, 1]
};
var color = dict.get('C');
if (isArray(color) && color.length === 3) {
// TODO(mack): currently only supporting rgb; need support different
// colorspaces
data.color = color;
} else {
data.color = [0, 0, 0];
}
// Some types of annotations have border style dict which has more
// info than the border array
if (dict.has('BS')) {
var borderStyle = dict.get('BS');
data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
} else {
var borderArray = dict.get('Border') || [0, 0, 1];
data.borderWidth = borderArray[2];
}
this.appearance = getDefaultAppearance(dict);
@ -108,7 +117,8 @@ var Annotation = (function AnnotationClosure() {
'getHtmlElement() should be implemented in subclass');
},
getEmptyContainer: function Annotaiton_getEmptyContainer(tagName, rect) {
// TODO(mack): Remove this, it's not really that helpful.
getEmptyContainer: function Annotation_getEmptyContainer(tagName, rect) {
assert(!isWorker,
'getEmptyContainer() should be called from main thread');
@ -498,7 +508,24 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
},
getHtmlElement: function LinkAnnotation_getHtmlElement(commonObjs) {
var element = this.getEmptyContainer('a');
var rect = this.data.rect;
var element = document.createElement('a');
var borderWidth = this.data.borderWidth;
element.style.borderWidth = borderWidth + 'px';
var color = this.data.color;
var rgb = [];
for (var i = 0; i < 3; ++i) {
rgb[i] = Math.round(color[i] * 255);
}
element.style.borderColor = Util.makeCssRgb(rgb);
element.style.borderStyle = 'solid';
var width = rect[2] - rect[0] - 2 * borderWidth;
var height = rect[3] - rect[1] - 2 * borderWidth;
element.style.width = width + 'px';
element.style.height = height + 'px';
element.href = this.data.url || '';
return element;
}

View File

@ -729,6 +729,14 @@
"link": true,
"type": "eq"
},
{ "id": "link-annotation-border",
"file": "pdfs/link-annotation-border.pdf",
"md5": "a1d07bc17482e32111c27a57283e07b8",
"rounds": 1,
"lastPage": 1,
"link": true,
"type": "eq"
},
{ "id": "issue1002",
"file": "pdfs/issue1002.pdf",
"md5": "af62d6cd95079322d4af18edd960d15c",