Browse Source

PDF.js version 1.3.88 - See mozilla/pdf.js@1b5940edd2f167f026d1ba209a4c68204a777b9f

master v1.3.88
Pdf Bot 9 years ago
parent
commit
5e604bfeab
  1. 2
      bower.json
  2. 147
      build/pdf.combined.js
  3. 147
      build/pdf.js
  4. 4
      build/pdf.worker.js
  5. 2
      package.json
  6. 4
      web/pdf_viewer.css
  7. 114
      web/pdf_viewer.js

2
bower.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.3.81", "version": "1.3.88",
"main": [ "main": [
"build/pdf.js", "build/pdf.js",
"build/pdf.worker.js" "build/pdf.worker.js"

147
build/pdf.combined.js

@ -20,8 +20,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.3.81'; PDFJS.version = '1.3.88';
PDFJS.build = '7f34d40'; PDFJS.build = '1b5940e';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
@ -7135,10 +7135,9 @@ PDFJS.CustomStyle = CustomStyle;
var ANNOT_MIN_SIZE = 10; // px var ANNOT_MIN_SIZE = 10; // px
var AnnotationUtils = (function AnnotationUtilsClosure() { var AnnotationLayer = (function AnnotationLayerClosure() {
// TODO(mack): This dupes some of the logic in CanvasGraphics.setFont() // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
function setTextStyles(element, item, fontObj) { function setTextStyles(element, item, fontObj) {
var style = element.style; var style = element.style;
style.fontSize = item.fontSize + 'px'; style.fontSize = item.fontSize + 'px';
style.direction = item.fontDirection < 0 ? 'rtl': 'ltr'; style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
@ -7159,34 +7158,43 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
style.fontFamily = fontFamily + fallbackName; style.fontFamily = fontFamily + fallbackName;
} }
function initContainer(item) { function getContainer(data, page, viewport) {
var container = document.createElement('section'); var container = document.createElement('section');
var cstyle = container.style; var width = data.rect[2] - data.rect[0];
var width = item.rect[2] - item.rect[0]; var height = data.rect[3] - data.rect[1];
var height = item.rect[3] - item.rect[1];
// Border container.setAttribute('data-annotation-id', data.id);
if (item.borderStyle.width > 0) {
// Border width data.rect = Util.normalizeRect([
container.style.borderWidth = item.borderStyle.width + 'px'; data.rect[0],
if (item.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) { page.view[3] - data.rect[1] + page.view[1],
data.rect[2],
page.view[3] - data.rect[3] + page.view[1]
]);
CustomStyle.setProp('transform', container,
'matrix(' + viewport.transform.join(',') + ')');
CustomStyle.setProp('transformOrigin', container,
-data.rect[0] + 'px ' + -data.rect[1] + 'px');
if (data.borderStyle.width > 0) {
container.style.borderWidth = data.borderStyle.width + 'px';
if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
// Underline styles only have a bottom border, so we do not need // Underline styles only have a bottom border, so we do not need
// to adjust for all borders. This yields a similar result as // to adjust for all borders. This yields a similar result as
// Adobe Acrobat/Reader. // Adobe Acrobat/Reader.
width = width - 2 * item.borderStyle.width; width = width - 2 * data.borderStyle.width;
height = height - 2 * item.borderStyle.width; height = height - 2 * data.borderStyle.width;
} }
// Horizontal and vertical border radius var horizontalRadius = data.borderStyle.horizontalCornerRadius;
var horizontalRadius = item.borderStyle.horizontalCornerRadius; var verticalRadius = data.borderStyle.verticalCornerRadius;
var verticalRadius = item.borderStyle.verticalCornerRadius;
if (horizontalRadius > 0 || verticalRadius > 0) { if (horizontalRadius > 0 || verticalRadius > 0) {
var radius = horizontalRadius + 'px / ' + verticalRadius + 'px'; var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
CustomStyle.setProp('borderRadius', container, radius); CustomStyle.setProp('borderRadius', container, radius);
} }
// Border style switch (data.borderStyle.style) {
switch (item.borderStyle.style) {
case AnnotationBorderStyleType.SOLID: case AnnotationBorderStyleType.SOLID:
container.style.borderStyle = 'solid'; container.style.borderStyle = 'solid';
break; break;
@ -7211,24 +7219,27 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
break; break;
} }
// Border color if (data.color) {
if (item.color) {
container.style.borderColor = container.style.borderColor =
Util.makeCssRgb(item.color[0] | 0, Util.makeCssRgb(data.color[0] | 0,
item.color[1] | 0, data.color[1] | 0,
item.color[2] | 0); data.color[2] | 0);
} else { } else {
// Transparent (invisible) border, so do not draw it at all. // Transparent (invisible) border, so do not draw it at all.
container.style.borderWidth = 0; container.style.borderWidth = 0;
} }
} }
cstyle.width = width + 'px'; container.style.left = data.rect[0] + 'px';
cstyle.height = height + 'px'; container.style.top = data.rect[1] + 'px';
container.style.width = width + 'px';
container.style.height = height + 'px';
return container; return container;
} }
function getHtmlElementForTextWidgetAnnotation(item, commonObjs) { function getHtmlElementForTextWidgetAnnotation(item, page) {
var element = document.createElement('div'); var element = document.createElement('div');
var width = item.rect[2] - item.rect[0]; var width = item.rect[2] - item.rect[0];
var height = item.rect[3] - item.rect[1]; var height = item.rect[3] - item.rect[1];
@ -7244,7 +7255,7 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
content.style.display = 'table-cell'; content.style.display = 'table-cell';
var fontObj = item.fontRefName ? var fontObj = item.fontRefName ?
commonObjs.getData(item.fontRefName) : null; page.commonObjs.getData(item.fontRefName) : null;
setTextStyles(content, item, fontObj); setTextStyles(content, item, fontObj);
element.appendChild(content); element.appendChild(content);
@ -7252,7 +7263,7 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
return element; return element;
} }
function getHtmlElementForTextAnnotation(item) { function getHtmlElementForTextAnnotation(item, page, viewport) {
var rect = item.rect; var rect = item.rect;
// sanity check because of OOo-generated PDFs // sanity check because of OOo-generated PDFs
@ -7263,7 +7274,7 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
rect[2] = rect[0] + (rect[3] - rect[1]); // make it square rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
} }
var container = initContainer(item); var container = getContainer(item, page, viewport);
container.className = 'annotText'; container.className = 'annotText';
var image = document.createElement('img'); var image = document.createElement('img');
@ -7369,8 +7380,30 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
return container; return container;
} }
function getHtmlElementForLinkAnnotation(item) { function getHtmlElementForLinkAnnotation(item, page, viewport, linkService) {
var container = initContainer(item); function bindLink(link, dest) {
link.href = linkService.getDestinationHash(dest);
link.onclick = function annotationsLayerBuilderLinksOnclick() {
if (dest) {
linkService.navigateTo(dest);
}
return false;
};
if (dest) {
link.className = 'internalLink';
}
}
function bindNamedAction(link, action) {
link.href = linkService.getAnchorUrl('');
link.onclick = function annotationsLayerBuilderNamedActionOnClick() {
linkService.executeNamedAction(action);
return false;
};
link.className = 'internalLink';
}
var container = getContainer(item, page, viewport);
container.className = 'annotLink'; container.className = 'annotLink';
var link = document.createElement('a'); var link = document.createElement('a');
@ -7380,29 +7413,65 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
link.target = LinkTargetStringMap[PDFJS.externalLinkTarget]; link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
} }
if (!item.url) {
if (item.action) {
bindNamedAction(link, item.action);
} else {
bindLink(link, ('dest' in item) ? item.dest : null);
}
}
container.appendChild(link); container.appendChild(link);
return container; return container;
} }
function getHtmlElement(data, objs) { function getHtmlElement(data, page, viewport, linkService) {
switch (data.annotationType) { switch (data.annotationType) {
case AnnotationType.WIDGET: case AnnotationType.WIDGET:
return getHtmlElementForTextWidgetAnnotation(data, objs); return getHtmlElementForTextWidgetAnnotation(data, page);
case AnnotationType.TEXT: case AnnotationType.TEXT:
return getHtmlElementForTextAnnotation(data); return getHtmlElementForTextAnnotation(data, page, viewport);
case AnnotationType.LINK: case AnnotationType.LINK:
return getHtmlElementForLinkAnnotation(data); return getHtmlElementForLinkAnnotation(data, page, viewport,
linkService);
default: default:
throw new Error('Unsupported annotationType: ' + data.annotationType); throw new Error('Unsupported annotationType: ' + data.annotationType);
} }
} }
function render(viewport, div, annotations, page, linkService) {
for (var i = 0, ii = annotations.length; i < ii; i++) {
var data = annotations[i];
if (!data || !data.hasHtml) {
continue;
}
var element = getHtmlElement(data, page, viewport, linkService);
div.appendChild(element);
}
}
function update(viewport, div, annotations) {
for (var i = 0, ii = annotations.length; i < ii; i++) {
var data = annotations[i];
var element = div.querySelector(
'[data-annotation-id="' + data.id + '"]');
if (element) {
CustomStyle.setProp('transform', element,
'matrix(' + viewport.transform.join(',') + ')');
}
}
div.removeAttribute('hidden');
}
return { return {
getHtmlElement: getHtmlElement render: render,
update: update
}; };
})(); })();
PDFJS.AnnotationUtils = AnnotationUtils;
PDFJS.AnnotationLayer = AnnotationLayer;
/** /**

147
build/pdf.js

@ -20,8 +20,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.3.81'; PDFJS.version = '1.3.88';
PDFJS.build = '7f34d40'; PDFJS.build = '1b5940e';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
@ -7194,10 +7194,9 @@ PDFJS.CustomStyle = CustomStyle;
var ANNOT_MIN_SIZE = 10; // px var ANNOT_MIN_SIZE = 10; // px
var AnnotationUtils = (function AnnotationUtilsClosure() { var AnnotationLayer = (function AnnotationLayerClosure() {
// TODO(mack): This dupes some of the logic in CanvasGraphics.setFont() // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
function setTextStyles(element, item, fontObj) { function setTextStyles(element, item, fontObj) {
var style = element.style; var style = element.style;
style.fontSize = item.fontSize + 'px'; style.fontSize = item.fontSize + 'px';
style.direction = item.fontDirection < 0 ? 'rtl': 'ltr'; style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
@ -7218,34 +7217,43 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
style.fontFamily = fontFamily + fallbackName; style.fontFamily = fontFamily + fallbackName;
} }
function initContainer(item) { function getContainer(data, page, viewport) {
var container = document.createElement('section'); var container = document.createElement('section');
var cstyle = container.style; var width = data.rect[2] - data.rect[0];
var width = item.rect[2] - item.rect[0]; var height = data.rect[3] - data.rect[1];
var height = item.rect[3] - item.rect[1];
// Border container.setAttribute('data-annotation-id', data.id);
if (item.borderStyle.width > 0) {
// Border width data.rect = Util.normalizeRect([
container.style.borderWidth = item.borderStyle.width + 'px'; data.rect[0],
if (item.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) { page.view[3] - data.rect[1] + page.view[1],
data.rect[2],
page.view[3] - data.rect[3] + page.view[1]
]);
CustomStyle.setProp('transform', container,
'matrix(' + viewport.transform.join(',') + ')');
CustomStyle.setProp('transformOrigin', container,
-data.rect[0] + 'px ' + -data.rect[1] + 'px');
if (data.borderStyle.width > 0) {
container.style.borderWidth = data.borderStyle.width + 'px';
if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
// Underline styles only have a bottom border, so we do not need // Underline styles only have a bottom border, so we do not need
// to adjust for all borders. This yields a similar result as // to adjust for all borders. This yields a similar result as
// Adobe Acrobat/Reader. // Adobe Acrobat/Reader.
width = width - 2 * item.borderStyle.width; width = width - 2 * data.borderStyle.width;
height = height - 2 * item.borderStyle.width; height = height - 2 * data.borderStyle.width;
} }
// Horizontal and vertical border radius var horizontalRadius = data.borderStyle.horizontalCornerRadius;
var horizontalRadius = item.borderStyle.horizontalCornerRadius; var verticalRadius = data.borderStyle.verticalCornerRadius;
var verticalRadius = item.borderStyle.verticalCornerRadius;
if (horizontalRadius > 0 || verticalRadius > 0) { if (horizontalRadius > 0 || verticalRadius > 0) {
var radius = horizontalRadius + 'px / ' + verticalRadius + 'px'; var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
CustomStyle.setProp('borderRadius', container, radius); CustomStyle.setProp('borderRadius', container, radius);
} }
// Border style switch (data.borderStyle.style) {
switch (item.borderStyle.style) {
case AnnotationBorderStyleType.SOLID: case AnnotationBorderStyleType.SOLID:
container.style.borderStyle = 'solid'; container.style.borderStyle = 'solid';
break; break;
@ -7270,24 +7278,27 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
break; break;
} }
// Border color if (data.color) {
if (item.color) {
container.style.borderColor = container.style.borderColor =
Util.makeCssRgb(item.color[0] | 0, Util.makeCssRgb(data.color[0] | 0,
item.color[1] | 0, data.color[1] | 0,
item.color[2] | 0); data.color[2] | 0);
} else { } else {
// Transparent (invisible) border, so do not draw it at all. // Transparent (invisible) border, so do not draw it at all.
container.style.borderWidth = 0; container.style.borderWidth = 0;
} }
} }
cstyle.width = width + 'px'; container.style.left = data.rect[0] + 'px';
cstyle.height = height + 'px'; container.style.top = data.rect[1] + 'px';
container.style.width = width + 'px';
container.style.height = height + 'px';
return container; return container;
} }
function getHtmlElementForTextWidgetAnnotation(item, commonObjs) { function getHtmlElementForTextWidgetAnnotation(item, page) {
var element = document.createElement('div'); var element = document.createElement('div');
var width = item.rect[2] - item.rect[0]; var width = item.rect[2] - item.rect[0];
var height = item.rect[3] - item.rect[1]; var height = item.rect[3] - item.rect[1];
@ -7303,7 +7314,7 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
content.style.display = 'table-cell'; content.style.display = 'table-cell';
var fontObj = item.fontRefName ? var fontObj = item.fontRefName ?
commonObjs.getData(item.fontRefName) : null; page.commonObjs.getData(item.fontRefName) : null;
setTextStyles(content, item, fontObj); setTextStyles(content, item, fontObj);
element.appendChild(content); element.appendChild(content);
@ -7311,7 +7322,7 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
return element; return element;
} }
function getHtmlElementForTextAnnotation(item) { function getHtmlElementForTextAnnotation(item, page, viewport) {
var rect = item.rect; var rect = item.rect;
// sanity check because of OOo-generated PDFs // sanity check because of OOo-generated PDFs
@ -7322,7 +7333,7 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
rect[2] = rect[0] + (rect[3] - rect[1]); // make it square rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
} }
var container = initContainer(item); var container = getContainer(item, page, viewport);
container.className = 'annotText'; container.className = 'annotText';
var image = document.createElement('img'); var image = document.createElement('img');
@ -7428,8 +7439,30 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
return container; return container;
} }
function getHtmlElementForLinkAnnotation(item) { function getHtmlElementForLinkAnnotation(item, page, viewport, linkService) {
var container = initContainer(item); function bindLink(link, dest) {
link.href = linkService.getDestinationHash(dest);
link.onclick = function annotationsLayerBuilderLinksOnclick() {
if (dest) {
linkService.navigateTo(dest);
}
return false;
};
if (dest) {
link.className = 'internalLink';
}
}
function bindNamedAction(link, action) {
link.href = linkService.getAnchorUrl('');
link.onclick = function annotationsLayerBuilderNamedActionOnClick() {
linkService.executeNamedAction(action);
return false;
};
link.className = 'internalLink';
}
var container = getContainer(item, page, viewport);
container.className = 'annotLink'; container.className = 'annotLink';
var link = document.createElement('a'); var link = document.createElement('a');
@ -7439,29 +7472,65 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
link.target = LinkTargetStringMap[PDFJS.externalLinkTarget]; link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
} }
if (!item.url) {
if (item.action) {
bindNamedAction(link, item.action);
} else {
bindLink(link, ('dest' in item) ? item.dest : null);
}
}
container.appendChild(link); container.appendChild(link);
return container; return container;
} }
function getHtmlElement(data, objs) { function getHtmlElement(data, page, viewport, linkService) {
switch (data.annotationType) { switch (data.annotationType) {
case AnnotationType.WIDGET: case AnnotationType.WIDGET:
return getHtmlElementForTextWidgetAnnotation(data, objs); return getHtmlElementForTextWidgetAnnotation(data, page);
case AnnotationType.TEXT: case AnnotationType.TEXT:
return getHtmlElementForTextAnnotation(data); return getHtmlElementForTextAnnotation(data, page, viewport);
case AnnotationType.LINK: case AnnotationType.LINK:
return getHtmlElementForLinkAnnotation(data); return getHtmlElementForLinkAnnotation(data, page, viewport,
linkService);
default: default:
throw new Error('Unsupported annotationType: ' + data.annotationType); throw new Error('Unsupported annotationType: ' + data.annotationType);
} }
} }
function render(viewport, div, annotations, page, linkService) {
for (var i = 0, ii = annotations.length; i < ii; i++) {
var data = annotations[i];
if (!data || !data.hasHtml) {
continue;
}
var element = getHtmlElement(data, page, viewport, linkService);
div.appendChild(element);
}
}
function update(viewport, div, annotations) {
for (var i = 0, ii = annotations.length; i < ii; i++) {
var data = annotations[i];
var element = div.querySelector(
'[data-annotation-id="' + data.id + '"]');
if (element) {
CustomStyle.setProp('transform', element,
'matrix(' + viewport.transform.join(',') + ')');
}
}
div.removeAttribute('hidden');
}
return { return {
getHtmlElement: getHtmlElement render: render,
update: update
}; };
})(); })();
PDFJS.AnnotationUtils = AnnotationUtils;
PDFJS.AnnotationLayer = AnnotationLayer;
/** /**

4
build/pdf.worker.js vendored

@ -20,8 +20,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.3.81'; PDFJS.version = '1.3.88';
PDFJS.build = '7f34d40'; PDFJS.build = '1b5940e';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.3.81", "version": "1.3.88",
"description": "Generic build of Mozilla's PDF.js library.", "description": "Generic build of Mozilla's PDF.js library.",
"keywords": [ "keywords": [
"Mozilla", "Mozilla",

4
web/pdf_viewer.css

@ -82,6 +82,10 @@
} }
.annotationLayer section {
position: absolute;
}
.annotationLayer .annotLink > a:hover { .annotationLayer .annotLink > a:hover {
opacity: 0.2; opacity: 0.2;
background: #ff0; background: #ff0;

114
web/pdf_viewer.js

@ -1143,7 +1143,7 @@ var PDFPageView = (function PDFPageViewClosure() {
} }
if (redrawAnnotations && this.annotationLayer) { if (redrawAnnotations && this.annotationLayer) {
this.annotationLayer.setupAnnotations(this.viewport, 'display'); this.annotationLayer.render(this.viewport, 'display');
} }
}, },
@ -1363,7 +1363,7 @@ var PDFPageView = (function PDFPageViewClosure() {
this.annotationLayer = this.annotationsLayerFactory. this.annotationLayer = this.annotationsLayerFactory.
createAnnotationsLayerBuilder(div, this.pdfPage); createAnnotationsLayerBuilder(div, this.pdfPage);
} }
this.annotationLayer.setupAnnotations(this.viewport, 'display'); this.annotationLayer.render(this.viewport, 'display');
} }
div.setAttribute('data-loaded', true); div.setAttribute('data-loaded', true);
@ -1776,8 +1776,6 @@ DefaultTextLayerFactory.prototype = {
* @class * @class
*/ */
var AnnotationsLayerBuilder = (function AnnotationsLayerBuilderClosure() { var AnnotationsLayerBuilder = (function AnnotationsLayerBuilderClosure() {
var CustomStyle = PDFJS.CustomStyle;
/** /**
* @param {AnnotationsLayerBuilderOptions} options * @param {AnnotationsLayerBuilderOptions} options
* @constructs AnnotationsLayerBuilder * @constructs AnnotationsLayerBuilder
@ -1789,6 +1787,7 @@ var AnnotationsLayerBuilder = (function AnnotationsLayerBuilderClosure() {
this.div = null; this.div = null;
} }
AnnotationsLayerBuilder.prototype = AnnotationsLayerBuilder.prototype =
/** @lends AnnotationsLayerBuilder.prototype */ { /** @lends AnnotationsLayerBuilder.prototype */ {
@ -1796,118 +1795,47 @@ var AnnotationsLayerBuilder = (function AnnotationsLayerBuilderClosure() {
* @param {PageViewport} viewport * @param {PageViewport} viewport
* @param {string} intent (default value is 'display') * @param {string} intent (default value is 'display')
*/ */
setupAnnotations: render: function AnnotationsLayerBuilder_render(viewport, intent) {
function AnnotationsLayerBuilder_setupAnnotations(viewport, intent) {
function bindLink(link, dest) {
link.href = linkService.getDestinationHash(dest);
link.onclick = function annotationsLayerBuilderLinksOnclick() {
if (dest) {
linkService.navigateTo(dest);
}
return false;
};
if (dest) {
link.className = 'internalLink';
}
}
function bindNamedAction(link, action) {
link.href = linkService.getAnchorUrl('');
link.onclick = function annotationsLayerBuilderNamedActionOnClick() {
linkService.executeNamedAction(action);
return false;
};
link.className = 'internalLink';
}
var linkService = this.linkService;
var pdfPage = this.pdfPage;
var self = this; var self = this;
var getAnnotationsParams = { var parameters = {
intent: (intent === undefined ? 'display' : intent), intent: (intent === undefined ? 'display' : intent),
}; };
pdfPage.getAnnotations(getAnnotationsParams).then( this.pdfPage.getAnnotations(parameters).then(function (annotations) {
function (annotationsData) {
viewport = viewport.clone({ dontFlip: true }); viewport = viewport.clone({ dontFlip: true });
var transform = viewport.transform;
var transformStr = 'matrix(' + transform.join(',') + ')';
var data, element, i, ii;
if (self.div) { if (self.div) {
// If an annotationLayer already exists, refresh its children's // If an annotationLayer already exists, refresh its children's
// transformation matrices // transformation matrices.
for (i = 0, ii = annotationsData.length; i < ii; i++) { PDFJS.AnnotationLayer.update(viewport, self.div, annotations);
data = annotationsData[i];
element = self.div.querySelector(
'[data-annotation-id="' + data.id + '"]');
if (element) {
CustomStyle.setProp('transform', element, transformStr);
}
}
// See PDFPageView.reset()
self.div.removeAttribute('hidden');
} else { } else {
for (i = 0, ii = annotationsData.length; i < ii; i++) { // Create an annotation layer div and render the annotations
data = annotationsData[i]; // if there is at least one annotation.
if (!data || !data.hasHtml) { if (annotations.length === 0) {
continue; return;
}
element = PDFJS.AnnotationUtils.getHtmlElement(data,
pdfPage.commonObjs);
element.setAttribute('data-annotation-id', data.id);
if (typeof mozL10n !== 'undefined') {
mozL10n.translate(element);
}
var rect = data.rect;
var view = pdfPage.view;
rect = PDFJS.Util.normalizeRect([
rect[0],
view[3] - rect[1] + view[1],
rect[2],
view[3] - rect[3] + view[1]
]);
element.style.left = rect[0] + 'px';
element.style.top = rect[1] + 'px';
element.style.position = 'absolute';
CustomStyle.setProp('transform', element, transformStr);
var transformOriginStr = -rect[0] + 'px ' + -rect[1] + 'px';
CustomStyle.setProp('transformOrigin', element, transformOriginStr);
if (data.subtype === 'Link' && !data.url) {
var link = element.getElementsByTagName('a')[0];
if (link) {
if (data.action) {
bindNamedAction(link, data.action);
} else {
bindLink(link, ('dest' in data) ? data.dest : null);
}
}
} }
if (!self.div) { self.div = document.createElement('div');
var annotationLayerDiv = document.createElement('div'); self.div.className = 'annotationLayer';
annotationLayerDiv.className = 'annotationLayer'; self.pageDiv.appendChild(self.div);
self.pageDiv.appendChild(annotationLayerDiv);
self.div = annotationLayerDiv;
}
self.div.appendChild(element); PDFJS.AnnotationLayer.render(viewport, self.div, annotations,
self.pdfPage, self.linkService);
if (typeof mozL10n !== 'undefined') {
mozL10n.translate(self.div);
} }
} }
}); });
}, },
hide: function () { hide: function AnnotationsLayerBuilder_hide() {
if (!this.div) { if (!this.div) {
return; return;
} }
this.div.setAttribute('hidden', 'true'); this.div.setAttribute('hidden', 'true');
} }
}; };
return AnnotationsLayerBuilder; return AnnotationsLayerBuilder;
})(); })();

Loading…
Cancel
Save