From 237e1d941df640823a796228ce63333fe66f6c4d Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Tue, 17 Apr 2012 15:33:15 -0500 Subject: [PATCH] Fix annotations; add text annotation icon --- src/core.js | 3 ++- web/images/text.svg | 46 +++++++++++++++++++++++++++++++++++++++++++++ web/viewer.js | 15 +++++++++------ 3 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 web/images/text.svg diff --git a/src/core.js b/src/core.js index 2734d0eef..90a2c9733 100644 --- a/src/core.js +++ b/src/core.js @@ -283,7 +283,8 @@ var Page = (function PageClosure() { var title = annotation.get('T'); item.content = stringToPDFString(content || ''); item.title = stringToPDFString(title || ''); - item.name = annotation.get('Name').name; + item.name = !annotation.has('Name') ? 'Note' : + annotation.get('Name').name; break; default: TODO('unimplemented annotation type: ' + subtype.name); diff --git a/web/images/text.svg b/web/images/text.svg new file mode 100644 index 000000000..25df8f466 --- /dev/null +++ b/web/images/text.svg @@ -0,0 +1,46 @@ + + + + + + + + + diff --git a/web/viewer.js b/web/viewer.js index 3233371cc..f5bb9552f 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -805,17 +805,20 @@ var PageView = function pageView(container, pdfPage, id, scale, container.className = 'annotComment'; var image = createElementWithStyle('img', item); + var type = item.type; + var rect = viewport.convertToViewportRectangle(item.rect); + rect = PDFJS.Util.normalizeRect(rect); image.src = kImageDirectory + type.toLowerCase() + '.svg'; + image.alt = '[' + type + ' Annotation]'; var content = document.createElement('div'); content.setAttribute('hidden', true); var title = document.createElement('h1'); var text = document.createElement('p'); - var offsetPos = Math.floor(item.x - view.x + item.width); - content.style.left = (offsetPos * scale) + 'px'; - content.style.top = (Math.floor(item.y - view.y) * scale) + 'px'; + content.style.left = Math.floor(rect[2]) + 'px'; + content.style.top = Math.floor(rect[1]) + 'px'; title.textContent = item.title; - if (!item.content) { + if (!item.content && !item.title) { content.setAttribute('hidden', true); } else { var e = document.createElement('span'); @@ -828,11 +831,11 @@ var PageView = function pageView(container, pdfPage, id, scale, } text.appendChild(e); image.addEventListener('mouseover', function annotationImageOver() { - this.nextSibling.removeAttribute('hidden'); + content.removeAttribute('hidden'); }, false); image.addEventListener('mouseout', function annotationImageOut() { - this.nextSibling.setAttribute('hidden', true); + content.setAttribute('hidden', true); }, false); }