diff --git a/src/core.js b/src/core.js index 71c18f178..f78b4f7ec 100644 --- a/src/core.js +++ b/src/core.js @@ -323,10 +323,10 @@ var Page = (function PageClosure() { if (a) { switch (a.get('S').name) { case 'URI': - link.url = a.get('URI'); + item.url = a.get('URI'); break; case 'GoTo': - link.dest = a.get('D'); + item.dest = a.get('D'); break; default: TODO('other link types'); @@ -334,7 +334,7 @@ var Page = (function PageClosure() { } else if (annotation.has('Dest')) { // simple destination link var dest = annotation.get('Dest'); - link.dest = isName(dest) ? dest.name : dest; + item.dest = isName(dest) ? dest.name : dest; } break; case 'Widget': @@ -379,6 +379,18 @@ var Page = (function PageClosure() { item.textAlignment = getInheritableProperty(annotation, 'Q'); item.flags = getInheritableProperty(annotation, 'Ff') || 0; break; + + case 'Text': + var content = annotation.get('Contents'); + var title = annotation.get('T'); + item.content = (typeof content == 'string') ? stringToPDFString(content) : null; + item.title = (typeof title == 'string') ? stringToPDFString(title) : null; + item.name = annotation.get('Name').name; + break; + + default: + TODO('unimplemented annotation type: ' + subtype.name); + break; } items.push(item); } diff --git a/web/images/check.svg b/web/images/check.svg new file mode 100644 index 000000000..e0e1590a9 --- /dev/null +++ b/web/images/check.svg @@ -0,0 +1,3 @@ + + + diff --git a/web/images/comment.svg b/web/images/comment.svg new file mode 100644 index 000000000..84feef1c8 --- /dev/null +++ b/web/images/comment.svg @@ -0,0 +1,3 @@ + + + diff --git a/web/viewer.css b/web/viewer.css index a1ef92810..3cfb163b0 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -247,6 +247,39 @@ canvas { line-height:1.3; } +.annotComment > div { + position: absolute; +} + +.annotComment > .annotImageComment { + background: transparent url('./images/text.svg') no-repeat left top; + background-size: 75% 75%; +} + +.annotComment > .annotImageCheck { + background: transparent url('./images/check.svg') no-repeat left top; + background-size: 75% 75%; +} + +.annotComment > .annotImage:hover { + cursor: pointer; + opacity: 0.7; +} + +.annotComment > .annotDetails { + display: none; + padding: 0.2em; + max-width: 20em; + background-color: #F1E47B; +} + +.annotComment > .annotDetails > h1 { + font-weight: normal; + font-size: 1.2em; + border-bottom: 1px solid #000000; + margin: 0px; +} + /* TODO: file FF bug to support ::-moz-selection:window-inactive so we can override the opaque grey background when the window is inactive; see https://bugzilla.mozilla.org/show_bug.cgi?id=706209 */ diff --git a/web/viewer.js b/web/viewer.js index 32b3101c2..eba6d93e6 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -475,6 +475,41 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight, element.style.height = Math.ceil(item.height * scale) + 'px'; return element; } + function createCommentAnnotation(type, item) { + var annotContainer = document.createElement('section'); + annotContainer.className = 'annotComment'; + + var annotImage = createElementWithStyle('div', item); + annotImage.className = 'annotImage annotImage' + type; + var annotDetails = document.createElement('div'); + annotDetails.className = 'annotDetails'; + var annotTitle = document.createElement('h1'); + var annotContent = document.createElement('p'); + + annotDetails.style.left = (Math.floor(item.x - view.x + item.width) * scale) + 'px'; + annotDetails.style.top = (Math.floor(item.y - view.y) * scale) + 'px'; + annotTitle.textContent = item.title; + + if(!item.content) { + annotContent.style.display = 'none'; + } else { + annotContent.innerHTML = item.content.replace('\n', '
'); + annotImage.addEventListener('mouseover', function() { + this.nextSibling.style.display = 'block'; + }, true); + + annotImage.addEventListener('mouseout', function() { + this.nextSibling.style.display = 'none'; + }, true); + } + + annotDetails.appendChild(annotTitle); + annotDetails.appendChild(annotContent); + annotContainer.appendChild(annotImage); + annotContainer.appendChild(annotDetails); + + return annotContainer; + } var items = content.getAnnotations(); for (var i = 0; i < items.length; i++) { @@ -487,6 +522,13 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight, bindLink(link, ('dest' in item) ? item.dest : null); div.appendChild(link); break; + + case 'Text': + case 'Check': + var comment = createCommentAnnotation(item.name, item); + if(comment) + div.appendChild(comment); + break; } } }