Skip to content

Commit

Permalink
Implemented Comment and Check annotation. Correcting some typos in la…
Browse files Browse the repository at this point in the history
…st commit
  • Loading branch information
saebekassebil committed Dec 21, 2011
1 parent ca7d44c commit 4a661e1
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,18 +323,18 @@ 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');
}
} 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':
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions web/images/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions web/images/comment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions web/viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
42 changes: 42 additions & 0 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<br />');
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++) {
Expand All @@ -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;
}
}
}
Expand Down

0 comments on commit 4a661e1

Please sign in to comment.