From a394c1bac66719d992f50dd16fdd87ea7a127861 Mon Sep 17 00:00:00 2001 From: Mack Duan Date: Tue, 26 Mar 2013 02:41:56 -0700 Subject: [PATCH 1/2] Support borders for link annotations --- src/annotation.js | 47 ++++++++++++++++++++++++++++++++--------- test/test_manifest.json | 8 +++++++ 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/annotation.js b/src/annotation.js index 467cbf9f8..c4447944b 100644 --- a/src/annotation.js +++ b/src/annotation.js @@ -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; } diff --git a/test/test_manifest.json b/test/test_manifest.json index 7d6eb1cb5..8012474a4 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -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", From d8e3f1da72dc41d00db22edae6a1b6cabf23e36d Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Tue, 28 May 2013 17:31:54 -0500 Subject: [PATCH 2/2] Adds missing link-annotation-border file and lint error --- src/annotation.js | 2 +- test/pdfs/link-annotation-border.pdf.link | 1 + test/test_manifest.json | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 test/pdfs/link-annotation-border.pdf.link diff --git a/src/annotation.js b/src/annotation.js index c4447944b..3eb922da3 100644 --- a/src/annotation.js +++ b/src/annotation.js @@ -16,7 +16,7 @@ */ /* globals Util, isDict, isName, stringToPDFString, TODO, Dict, Stream, stringToBytes, PDFJS, isWorker, assert, NotImplementedException, - Promise */ + Promise, isArray */ 'use strict'; diff --git a/test/pdfs/link-annotation-border.pdf.link b/test/pdfs/link-annotation-border.pdf.link new file mode 100644 index 000000000..5db354d19 --- /dev/null +++ b/test/pdfs/link-annotation-border.pdf.link @@ -0,0 +1 @@ +https://bugzilla.mozilla.org/attachment.cgi?id=726621 diff --git a/test/test_manifest.json b/test/test_manifest.json index 8012474a4..0e5fcfcf3 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -731,7 +731,7 @@ }, { "id": "link-annotation-border", "file": "pdfs/link-annotation-border.pdf", - "md5": "a1d07bc17482e32111c27a57283e07b8", + "md5": "a0550889b010df9fabe4e2107662c8c4", "rounds": 1, "lastPage": 1, "link": true,