Browse Source

PDF.js version 1.3.116 - See mozilla/pdf.js@cfc0cc80eec8b61bd8ddb6abe0d8977b4ee39265

master v1.3.116
Pdf Bot 9 years ago
parent
commit
ebfe58704d
  1. 2
      bower.json
  2. 498
      build/pdf.combined.js
  3. 498
      build/pdf.js
  4. 4
      build/pdf.worker.js
  5. 2
      package.json
  6. 13
      web/pdf_viewer.js

2
bower.json

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

498
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.114'; PDFJS.version = '1.3.116';
PDFJS.build = '9228e1f'; PDFJS.build = 'cfc0cc8';
(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
@ -1811,30 +1811,68 @@ var CustomStyle = displayDOMUtils.CustomStyle;
var ANNOT_MIN_SIZE = 10; // px var ANNOT_MIN_SIZE = 10; // px
var AnnotationLayer = (function AnnotationLayerClosure() { /**
// TODO(mack): This dupes some of the logic in CanvasGraphics.setFont() * @typedef {Object} AnnotationElementParameters
function setTextStyles(element, item, fontObj) { * @property {Object} data
var style = element.style; * @property {PDFPage} page
style.fontSize = item.fontSize + 'px'; * @property {PageViewport} viewport
style.direction = item.fontDirection < 0 ? 'rtl': 'ltr'; * @property {IPDFLinkService} linkService
*/
if (!fontObj) { /**
return; * @class
* @alias AnnotationElementFactory
*/
function AnnotationElementFactory() {}
AnnotationElementFactory.prototype =
/** @lends AnnotationElementFactory.prototype */ {
/**
* @param {AnnotationElementParameters} parameters
* @returns {AnnotationElement}
*/
create: function AnnotationElementFactory_create(parameters) {
var subtype = parameters.data.annotationType;
switch (subtype) {
case AnnotationType.LINK:
return new LinkAnnotationElement(parameters);
case AnnotationType.TEXT:
return new TextAnnotationElement(parameters);
case AnnotationType.WIDGET:
return new WidgetAnnotationElement(parameters);
default:
throw new Error('Unimplemented annotation type "' + subtype + '"');
}
} }
};
style.fontWeight = fontObj.black ? /**
(fontObj.bold ? 'bolder' : 'bold') : * @class
(fontObj.bold ? 'bold' : 'normal'); * @alias AnnotationElement
style.fontStyle = fontObj.italic ? 'italic' : 'normal'; */
var AnnotationElement = (function AnnotationElementClosure() {
function AnnotationElement(parameters) {
this.data = parameters.data;
this.page = parameters.page;
this.viewport = parameters.viewport;
this.linkService = parameters.linkService;
var fontName = fontObj.loadedName; this.container = this._createContainer();
var fontFamily = fontName ? '"' + fontName + '", ' : '';
// Use a reasonable default font if the font doesn't specify a fallback
var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
style.fontFamily = fontFamily + fallbackName;
} }
function getContainer(data, page, viewport) { AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
/**
* Create an empty container for the annotation's HTML element.
*
* @private
* @memberof AnnotationElement
* @returns {HTMLSectionElement}
*/
_createContainer: function AnnotationElement_createContainer() {
var data = this.data, page = this.page, viewport = this.viewport;
var container = document.createElement('section'); var container = document.createElement('section');
var width = data.rect[2] - data.rect[0]; var width = data.rect[2] - data.rect[0];
var height = data.rect[3] - data.rect[1]; var height = data.rect[3] - data.rect[1];
@ -1913,31 +1951,136 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
container.style.height = height + 'px'; container.style.height = height + 'px';
return container; return container;
},
/**
* Render the annotation's HTML element in the empty container.
*
* @public
* @memberof AnnotationElement
*/
render: function AnnotationElement_render() {
throw new Error('Abstract method AnnotationElement.render called');
} }
};
function getHtmlElementForTextWidgetAnnotation(item, page, viewport) { return AnnotationElement;
var container = getContainer(item, page, viewport); })();
var content = document.createElement('div'); /**
content.textContent = item.fieldValue; * @class
var textAlignment = item.textAlignment; * @alias LinkAnnotationElement
content.style.textAlign = ['left', 'center', 'right'][textAlignment]; */
content.style.verticalAlign = 'middle'; var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
content.style.display = 'table-cell'; function LinkAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
}
var fontObj = item.fontRefName ? Util.inherit(LinkAnnotationElement, AnnotationElement, {
page.commonObjs.getData(item.fontRefName) : null; /**
setTextStyles(content, item, fontObj); * Render the link annotation's HTML element in the empty container.
*
* @public
* @memberof LinkAnnotationElement
* @returns {HTMLSectionElement}
*/
render: function LinkAnnotationElement_render() {
this.container.className = 'annotLink';
container.appendChild(content); var link = document.createElement('a');
link.href = link.title = this.data.url || '';
return container; if (this.data.url && isExternalLinkTargetSet()) {
link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
}
// Strip referrer from the URL.
if (this.data.url) {
link.rel = PDFJS.externalLinkRel;
}
if (!this.data.url) {
if (this.data.action) {
this._bindNamedAction(link, this.data.action);
} else {
this._bindLink(link, ('dest' in this.data) ? this.data.dest : null);
}
} }
function getHtmlElementForTextAnnotation(item, page, viewport) { this.container.appendChild(link);
var rect = item.rect; return this.container;
},
// sanity check because of OOo-generated PDFs /**
* Bind internal links to the link element.
*
* @private
* @param {Object} link
* @param {Object} destination
* @memberof LinkAnnotationElement
*/
_bindLink: function LinkAnnotationElement_bindLink(link, destination) {
var self = this;
link.href = this.linkService.getDestinationHash(destination);
link.onclick = function() {
if (destination) {
self.linkService.navigateTo(destination);
}
return false;
};
if (destination) {
link.className = 'internalLink';
}
},
/**
* Bind named actions to the link element.
*
* @private
* @param {Object} link
* @param {Object} action
* @memberof LinkAnnotationElement
*/
_bindNamedAction:
function LinkAnnotationElement_bindNamedAction(link, action) {
var self = this;
link.href = this.linkService.getAnchorUrl('');
link.onclick = function() {
self.linkService.executeNamedAction(action);
return false;
};
link.className = 'internalLink';
}
});
return LinkAnnotationElement;
})();
/**
* @class
* @alias TextAnnotationElement
*/
var TextAnnotationElement = (function TextAnnotationElementClosure() {
function TextAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
this.pinned = false;
}
Util.inherit(TextAnnotationElement, AnnotationElement, {
/**
* Render the text annotation's HTML element in the empty container.
*
* @public
* @memberof TextAnnotationElement
* @returns {HTMLSectionElement}
*/
render: function TextAnnotationElement_render() {
var rect = this.data.rect, container = this.container;
// Sanity check because of OOo-generated PDFs.
if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) { if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
rect[3] = rect[1] + ANNOT_MIN_SIZE; rect[3] = rect[1] + ANNOT_MIN_SIZE;
} }
@ -1945,13 +2088,12 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
rect[2] = rect[0] + (rect[3] - rect[1]); // make it square rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
} }
var container = getContainer(item, page, viewport);
container.className = 'annotText'; container.className = 'annotText';
var image = document.createElement('img'); var image = document.createElement('img');
image.style.height = container.style.height; image.style.height = container.style.height;
image.style.width = container.style.width; image.style.width = container.style.width;
var iconName = item.name; var iconName = this.data.name;
image.src = PDFJS.imageResourcesPath + 'annotation-' + image.src = PDFJS.imageResourcesPath + 'annotation-' +
iconName.toLowerCase() + '.svg'; iconName.toLowerCase() + '.svg';
image.alt = '[{{type}} Annotation]'; image.alt = '[{{type}} Annotation]';
@ -1963,15 +2105,15 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px'; contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
contentWrapper.style.top = '-10px'; contentWrapper.style.top = '-10px';
var content = document.createElement('div'); var content = this.content = document.createElement('div');
content.className = 'annotTextContent'; content.className = 'annotTextContent';
content.setAttribute('hidden', true); content.setAttribute('hidden', true);
var i, ii; var i, ii;
if (item.hasBgColor && item.color) { if (this.data.hasBgColor && this.data.color) {
var color = item.color; var color = this.data.color;
// Enlighten the color (70%) // Enlighten the color (70%).
var BACKGROUND_ENLIGHT = 0.7; var BACKGROUND_ENLIGHT = 0.7;
var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0]; var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1]; var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
@ -1981,13 +2123,13 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
var title = document.createElement('h1'); var title = document.createElement('h1');
var text = document.createElement('p'); var text = document.createElement('p');
title.textContent = item.title; title.textContent = this.data.title;
if (!item.content && !item.title) { if (!this.data.content && !this.data.title) {
content.setAttribute('hidden', true); content.setAttribute('hidden', true);
} else { } else {
var e = document.createElement('span'); var e = document.createElement('span');
var lines = item.content.split(/(?:\r\n?|\n)/); var lines = this.data.content.split(/(?:\r\n?|\n)/);
for (i = 0, ii = lines.length; i < ii; ++i) { for (i = 0, ii = lines.length; i < ii; ++i) {
var line = lines[i]; var line = lines[i];
e.appendChild(document.createTextNode(line)); e.appendChild(document.createTextNode(line));
@ -1997,49 +2139,10 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
} }
text.appendChild(e); text.appendChild(e);
var pinned = false; image.addEventListener('click', this._toggle.bind(this));
image.addEventListener('mouseover', this._show.bind(this, false));
var showAnnotation = function showAnnotation(pin) { image.addEventListener('mouseout', this._hide.bind(this, false));
if (pin) { content.addEventListener('click', this._hide.bind(this, true));
pinned = true;
}
if (content.hasAttribute('hidden')) {
container.style.zIndex += 1;
content.removeAttribute('hidden');
}
};
var hideAnnotation = function hideAnnotation(unpin) {
if (unpin) {
pinned = false;
}
if (!content.hasAttribute('hidden') && !pinned) {
container.style.zIndex -= 1;
content.setAttribute('hidden', true);
}
};
var toggleAnnotation = function toggleAnnotation() {
if (pinned) {
hideAnnotation(true);
} else {
showAnnotation(true);
}
};
image.addEventListener('click', function image_clickHandler() {
toggleAnnotation();
}, false);
image.addEventListener('mouseover', function image_mouseOverHandler() {
showAnnotation();
}, false);
image.addEventListener('mouseout', function image_mouseOutHandler() {
hideAnnotation();
}, false);
content.addEventListener('click', function content_clickHandler() {
hideAnnotation(true);
}, false);
} }
content.appendChild(title); content.appendChild(title);
@ -2047,105 +2150,192 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
contentWrapper.appendChild(content); contentWrapper.appendChild(content);
container.appendChild(image); container.appendChild(image);
container.appendChild(contentWrapper); container.appendChild(contentWrapper);
return container; return container;
},
/**
* Toggle the visibility of the content box.
*
* @private
* @memberof TextAnnotationElement
*/
_toggle: function TextAnnotationElement_toggle() {
if (this.pinned) {
this._hide(true);
} else {
this._show(true);
} }
},
function getHtmlElementForLinkAnnotation(item, page, viewport, linkService) { /**
function bindLink(link, dest) { * Show the content box.
link.href = linkService.getDestinationHash(dest); *
link.onclick = function annotationsLayerBuilderLinksOnclick() { * @private
if (dest) { * @param {boolean} pin
linkService.navigateTo(dest); * @memberof TextAnnotationElement
*/
_show: function TextAnnotationElement_show(pin) {
if (pin) {
this.pinned = true;
} }
return false; if (this.content.hasAttribute('hidden')) {
}; this.container.style.zIndex += 1;
if (dest) { this.content.removeAttribute('hidden');
link.className = 'internalLink'; }
},
/**
* Hide the content box.
*
* @private
* @param {boolean} unpin
* @memberof TextAnnotationElement
*/
_hide: function TextAnnotationElement_hide(unpin) {
if (unpin) {
this.pinned = false;
}
if (!this.content.hasAttribute('hidden') && !this.pinned) {
this.container.style.zIndex -= 1;
this.content.setAttribute('hidden', true);
} }
} }
});
function bindNamedAction(link, action) { return TextAnnotationElement;
link.href = linkService.getAnchorUrl(''); })();
link.onclick = function annotationsLayerBuilderNamedActionOnClick() {
linkService.executeNamedAction(action); /**
return false; * @class
}; * @alias WidgetAnnotationElement
link.className = 'internalLink'; */
var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
function WidgetAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
} }
var container = getContainer(item, page, viewport); Util.inherit(WidgetAnnotationElement, AnnotationElement, {
container.className = 'annotLink'; /**
* Render the widget annotation's HTML element in the empty container.
*
* @public
* @memberof WidgetAnnotationElement
* @returns {HTMLSectionElement}
*/
render: function WidgetAnnotationElement_render() {
var content = document.createElement('div');
content.textContent = this.data.fieldValue;
var textAlignment = this.data.textAlignment;
content.style.textAlign = ['left', 'center', 'right'][textAlignment];
content.style.verticalAlign = 'middle';
content.style.display = 'table-cell';
var font = (this.data.fontRefName ?
this.page.commonObjs.getData(this.data.fontRefName) : null);
this._setTextStyle(content, font);
var link = document.createElement('a'); this.container.appendChild(content);
link.href = link.title = item.url || ''; return this.container;
},
if (item.url && isExternalLinkTargetSet()) { /**
link.target = LinkTargetStringMap[PDFJS.externalLinkTarget]; * Apply text styles to the text in the element.
} *
* @private
* @param {HTMLDivElement} element
* @param {Object} font
* @memberof WidgetAnnotationElement
*/
_setTextStyle:
function WidgetAnnotationElement_setTextStyle(element, font) {
// TODO: This duplicates some of the logic in CanvasGraphics.setFont().
var style = element.style;
style.fontSize = this.data.fontSize + 'px';
style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
// Strip referrer if (!font) {
if (item.url) { return;
link.rel = PDFJS.externalLinkRel;
} }
if (!item.url) { style.fontWeight = (font.black ?
if (item.action) { (font.bold ? '900' : 'bold') :
bindNamedAction(link, item.action); (font.bold ? 'bold' : 'normal'));
} else { style.fontStyle = (font.italic ? 'italic' : 'normal');
bindLink(link, ('dest' in item) ? item.dest : null);
} // Use a reasonable default font if the font doesn't specify a fallback.
var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
style.fontFamily = fontFamily + fallbackName;
} }
});
container.appendChild(link); return WidgetAnnotationElement;
})();
return container; /**
} * @typedef {Object} AnnotationLayerParameters
* @property {PageViewport} viewport
* @property {HTMLDivElement} div
* @property {Array} annotations
* @property {PDFPage} page
* @property {IPDFLinkService} linkService
*/
function getHtmlElement(data, page, viewport, linkService) { /**
switch (data.annotationType) { * @class
case AnnotationType.WIDGET: * @alias AnnotationLayer
return getHtmlElementForTextWidgetAnnotation(data, page, viewport); */
case AnnotationType.TEXT: var AnnotationLayer = (function AnnotationLayerClosure() {
return getHtmlElementForTextAnnotation(data, page, viewport); return {
case AnnotationType.LINK: /**
return getHtmlElementForLinkAnnotation(data, page, viewport, * Render a new annotation layer with all annotation elements.
linkService); *
default: * @public
throw new Error('Unsupported annotationType: ' + data.annotationType); * @param {AnnotationLayerParameters} parameters
} * @memberof AnnotationLayer
} */
render: function AnnotationLayer_render(parameters) {
var annotationElementFactory = new AnnotationElementFactory();
function render(viewport, div, annotations, page, linkService) { for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
for (var i = 0, ii = annotations.length; i < ii; i++) { var data = parameters.annotations[i];
var data = annotations[i];
if (!data || !data.hasHtml) { if (!data || !data.hasHtml) {
continue; continue;
} }
var element = getHtmlElement(data, page, viewport, linkService); var properties = {
div.appendChild(element); data: data,
} page: parameters.page,
viewport: parameters.viewport,
linkService: parameters.linkService
};
var element = annotationElementFactory.create(properties);
parameters.div.appendChild(element.render());
} }
},
function update(viewport, div, annotations) { /**
for (var i = 0, ii = annotations.length; i < ii; i++) { * Update the annotation elements on existing annotation layer.
var data = annotations[i]; *
var element = div.querySelector( * @public
* @param {AnnotationLayerParameters} parameters
* @memberof AnnotationLayer
*/
update: function AnnotationLayer_update(parameters) {
for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
var data = parameters.annotations[i];
var element = parameters.div.querySelector(
'[data-annotation-id="' + data.id + '"]'); '[data-annotation-id="' + data.id + '"]');
if (element) { if (element) {
CustomStyle.setProp('transform', element, CustomStyle.setProp('transform', element,
'matrix(' + viewport.transform.join(',') + ')'); 'matrix(' + parameters.viewport.transform.join(',') + ')');
} }
} }
div.removeAttribute('hidden'); parameters.div.removeAttribute('hidden');
} }
return {
render: render,
update: update
}; };
})(); })();
PDFJS.AnnotationLayer = AnnotationLayer; PDFJS.AnnotationLayer = AnnotationLayer;
exports.AnnotationLayer = AnnotationLayer; exports.AnnotationLayer = AnnotationLayer;

498
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.114'; PDFJS.version = '1.3.116';
PDFJS.build = '9228e1f'; PDFJS.build = 'cfc0cc8';
(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
@ -1811,30 +1811,68 @@ var CustomStyle = displayDOMUtils.CustomStyle;
var ANNOT_MIN_SIZE = 10; // px var ANNOT_MIN_SIZE = 10; // px
var AnnotationLayer = (function AnnotationLayerClosure() { /**
// TODO(mack): This dupes some of the logic in CanvasGraphics.setFont() * @typedef {Object} AnnotationElementParameters
function setTextStyles(element, item, fontObj) { * @property {Object} data
var style = element.style; * @property {PDFPage} page
style.fontSize = item.fontSize + 'px'; * @property {PageViewport} viewport
style.direction = item.fontDirection < 0 ? 'rtl': 'ltr'; * @property {IPDFLinkService} linkService
*/
if (!fontObj) { /**
return; * @class
* @alias AnnotationElementFactory
*/
function AnnotationElementFactory() {}
AnnotationElementFactory.prototype =
/** @lends AnnotationElementFactory.prototype */ {
/**
* @param {AnnotationElementParameters} parameters
* @returns {AnnotationElement}
*/
create: function AnnotationElementFactory_create(parameters) {
var subtype = parameters.data.annotationType;
switch (subtype) {
case AnnotationType.LINK:
return new LinkAnnotationElement(parameters);
case AnnotationType.TEXT:
return new TextAnnotationElement(parameters);
case AnnotationType.WIDGET:
return new WidgetAnnotationElement(parameters);
default:
throw new Error('Unimplemented annotation type "' + subtype + '"');
}
} }
};
style.fontWeight = fontObj.black ? /**
(fontObj.bold ? 'bolder' : 'bold') : * @class
(fontObj.bold ? 'bold' : 'normal'); * @alias AnnotationElement
style.fontStyle = fontObj.italic ? 'italic' : 'normal'; */
var AnnotationElement = (function AnnotationElementClosure() {
function AnnotationElement(parameters) {
this.data = parameters.data;
this.page = parameters.page;
this.viewport = parameters.viewport;
this.linkService = parameters.linkService;
var fontName = fontObj.loadedName; this.container = this._createContainer();
var fontFamily = fontName ? '"' + fontName + '", ' : '';
// Use a reasonable default font if the font doesn't specify a fallback
var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
style.fontFamily = fontFamily + fallbackName;
} }
function getContainer(data, page, viewport) { AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
/**
* Create an empty container for the annotation's HTML element.
*
* @private
* @memberof AnnotationElement
* @returns {HTMLSectionElement}
*/
_createContainer: function AnnotationElement_createContainer() {
var data = this.data, page = this.page, viewport = this.viewport;
var container = document.createElement('section'); var container = document.createElement('section');
var width = data.rect[2] - data.rect[0]; var width = data.rect[2] - data.rect[0];
var height = data.rect[3] - data.rect[1]; var height = data.rect[3] - data.rect[1];
@ -1913,31 +1951,136 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
container.style.height = height + 'px'; container.style.height = height + 'px';
return container; return container;
},
/**
* Render the annotation's HTML element in the empty container.
*
* @public
* @memberof AnnotationElement
*/
render: function AnnotationElement_render() {
throw new Error('Abstract method AnnotationElement.render called');
} }
};
function getHtmlElementForTextWidgetAnnotation(item, page, viewport) { return AnnotationElement;
var container = getContainer(item, page, viewport); })();
var content = document.createElement('div'); /**
content.textContent = item.fieldValue; * @class
var textAlignment = item.textAlignment; * @alias LinkAnnotationElement
content.style.textAlign = ['left', 'center', 'right'][textAlignment]; */
content.style.verticalAlign = 'middle'; var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
content.style.display = 'table-cell'; function LinkAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
}
var fontObj = item.fontRefName ? Util.inherit(LinkAnnotationElement, AnnotationElement, {
page.commonObjs.getData(item.fontRefName) : null; /**
setTextStyles(content, item, fontObj); * Render the link annotation's HTML element in the empty container.
*
* @public
* @memberof LinkAnnotationElement
* @returns {HTMLSectionElement}
*/
render: function LinkAnnotationElement_render() {
this.container.className = 'annotLink';
container.appendChild(content); var link = document.createElement('a');
link.href = link.title = this.data.url || '';
return container; if (this.data.url && isExternalLinkTargetSet()) {
link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
} }
function getHtmlElementForTextAnnotation(item, page, viewport) { // Strip referrer from the URL.
var rect = item.rect; if (this.data.url) {
link.rel = PDFJS.externalLinkRel;
}
if (!this.data.url) {
if (this.data.action) {
this._bindNamedAction(link, this.data.action);
} else {
this._bindLink(link, ('dest' in this.data) ? this.data.dest : null);
}
}
this.container.appendChild(link);
return this.container;
},
/**
* Bind internal links to the link element.
*
* @private
* @param {Object} link
* @param {Object} destination
* @memberof LinkAnnotationElement
*/
_bindLink: function LinkAnnotationElement_bindLink(link, destination) {
var self = this;
// sanity check because of OOo-generated PDFs link.href = this.linkService.getDestinationHash(destination);
link.onclick = function() {
if (destination) {
self.linkService.navigateTo(destination);
}
return false;
};
if (destination) {
link.className = 'internalLink';
}
},
/**
* Bind named actions to the link element.
*
* @private
* @param {Object} link
* @param {Object} action
* @memberof LinkAnnotationElement
*/
_bindNamedAction:
function LinkAnnotationElement_bindNamedAction(link, action) {
var self = this;
link.href = this.linkService.getAnchorUrl('');
link.onclick = function() {
self.linkService.executeNamedAction(action);
return false;
};
link.className = 'internalLink';
}
});
return LinkAnnotationElement;
})();
/**
* @class
* @alias TextAnnotationElement
*/
var TextAnnotationElement = (function TextAnnotationElementClosure() {
function TextAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
this.pinned = false;
}
Util.inherit(TextAnnotationElement, AnnotationElement, {
/**
* Render the text annotation's HTML element in the empty container.
*
* @public
* @memberof TextAnnotationElement
* @returns {HTMLSectionElement}
*/
render: function TextAnnotationElement_render() {
var rect = this.data.rect, container = this.container;
// Sanity check because of OOo-generated PDFs.
if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) { if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
rect[3] = rect[1] + ANNOT_MIN_SIZE; rect[3] = rect[1] + ANNOT_MIN_SIZE;
} }
@ -1945,13 +2088,12 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
rect[2] = rect[0] + (rect[3] - rect[1]); // make it square rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
} }
var container = getContainer(item, page, viewport);
container.className = 'annotText'; container.className = 'annotText';
var image = document.createElement('img'); var image = document.createElement('img');
image.style.height = container.style.height; image.style.height = container.style.height;
image.style.width = container.style.width; image.style.width = container.style.width;
var iconName = item.name; var iconName = this.data.name;
image.src = PDFJS.imageResourcesPath + 'annotation-' + image.src = PDFJS.imageResourcesPath + 'annotation-' +
iconName.toLowerCase() + '.svg'; iconName.toLowerCase() + '.svg';
image.alt = '[{{type}} Annotation]'; image.alt = '[{{type}} Annotation]';
@ -1963,15 +2105,15 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px'; contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
contentWrapper.style.top = '-10px'; contentWrapper.style.top = '-10px';
var content = document.createElement('div'); var content = this.content = document.createElement('div');
content.className = 'annotTextContent'; content.className = 'annotTextContent';
content.setAttribute('hidden', true); content.setAttribute('hidden', true);
var i, ii; var i, ii;
if (item.hasBgColor && item.color) { if (this.data.hasBgColor && this.data.color) {
var color = item.color; var color = this.data.color;
// Enlighten the color (70%) // Enlighten the color (70%).
var BACKGROUND_ENLIGHT = 0.7; var BACKGROUND_ENLIGHT = 0.7;
var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0]; var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1]; var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
@ -1981,13 +2123,13 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
var title = document.createElement('h1'); var title = document.createElement('h1');
var text = document.createElement('p'); var text = document.createElement('p');
title.textContent = item.title; title.textContent = this.data.title;
if (!item.content && !item.title) { if (!this.data.content && !this.data.title) {
content.setAttribute('hidden', true); content.setAttribute('hidden', true);
} else { } else {
var e = document.createElement('span'); var e = document.createElement('span');
var lines = item.content.split(/(?:\r\n?|\n)/); var lines = this.data.content.split(/(?:\r\n?|\n)/);
for (i = 0, ii = lines.length; i < ii; ++i) { for (i = 0, ii = lines.length; i < ii; ++i) {
var line = lines[i]; var line = lines[i];
e.appendChild(document.createTextNode(line)); e.appendChild(document.createTextNode(line));
@ -1997,49 +2139,10 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
} }
text.appendChild(e); text.appendChild(e);
var pinned = false; image.addEventListener('click', this._toggle.bind(this));
image.addEventListener('mouseover', this._show.bind(this, false));
var showAnnotation = function showAnnotation(pin) { image.addEventListener('mouseout', this._hide.bind(this, false));
if (pin) { content.addEventListener('click', this._hide.bind(this, true));
pinned = true;
}
if (content.hasAttribute('hidden')) {
container.style.zIndex += 1;
content.removeAttribute('hidden');
}
};
var hideAnnotation = function hideAnnotation(unpin) {
if (unpin) {
pinned = false;
}
if (!content.hasAttribute('hidden') && !pinned) {
container.style.zIndex -= 1;
content.setAttribute('hidden', true);
}
};
var toggleAnnotation = function toggleAnnotation() {
if (pinned) {
hideAnnotation(true);
} else {
showAnnotation(true);
}
};
image.addEventListener('click', function image_clickHandler() {
toggleAnnotation();
}, false);
image.addEventListener('mouseover', function image_mouseOverHandler() {
showAnnotation();
}, false);
image.addEventListener('mouseout', function image_mouseOutHandler() {
hideAnnotation();
}, false);
content.addEventListener('click', function content_clickHandler() {
hideAnnotation(true);
}, false);
} }
content.appendChild(title); content.appendChild(title);
@ -2047,105 +2150,192 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
contentWrapper.appendChild(content); contentWrapper.appendChild(content);
container.appendChild(image); container.appendChild(image);
container.appendChild(contentWrapper); container.appendChild(contentWrapper);
return container; return container;
},
/**
* Toggle the visibility of the content box.
*
* @private
* @memberof TextAnnotationElement
*/
_toggle: function TextAnnotationElement_toggle() {
if (this.pinned) {
this._hide(true);
} else {
this._show(true);
} }
},
function getHtmlElementForLinkAnnotation(item, page, viewport, linkService) { /**
function bindLink(link, dest) { * Show the content box.
link.href = linkService.getDestinationHash(dest); *
link.onclick = function annotationsLayerBuilderLinksOnclick() { * @private
if (dest) { * @param {boolean} pin
linkService.navigateTo(dest); * @memberof TextAnnotationElement
*/
_show: function TextAnnotationElement_show(pin) {
if (pin) {
this.pinned = true;
} }
return false; if (this.content.hasAttribute('hidden')) {
}; this.container.style.zIndex += 1;
if (dest) { this.content.removeAttribute('hidden');
link.className = 'internalLink';
} }
},
/**
* Hide the content box.
*
* @private
* @param {boolean} unpin
* @memberof TextAnnotationElement
*/
_hide: function TextAnnotationElement_hide(unpin) {
if (unpin) {
this.pinned = false;
} }
if (!this.content.hasAttribute('hidden') && !this.pinned) {
this.container.style.zIndex -= 1;
this.content.setAttribute('hidden', true);
}
}
});
function bindNamedAction(link, action) { return TextAnnotationElement;
link.href = linkService.getAnchorUrl(''); })();
link.onclick = function annotationsLayerBuilderNamedActionOnClick() {
linkService.executeNamedAction(action); /**
return false; * @class
}; * @alias WidgetAnnotationElement
link.className = 'internalLink'; */
var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
function WidgetAnnotationElement(parameters) {
AnnotationElement.call(this, parameters);
} }
var container = getContainer(item, page, viewport); Util.inherit(WidgetAnnotationElement, AnnotationElement, {
container.className = 'annotLink'; /**
* Render the widget annotation's HTML element in the empty container.
*
* @public
* @memberof WidgetAnnotationElement
* @returns {HTMLSectionElement}
*/
render: function WidgetAnnotationElement_render() {
var content = document.createElement('div');
content.textContent = this.data.fieldValue;
var textAlignment = this.data.textAlignment;
content.style.textAlign = ['left', 'center', 'right'][textAlignment];
content.style.verticalAlign = 'middle';
content.style.display = 'table-cell';
var link = document.createElement('a'); var font = (this.data.fontRefName ?
link.href = link.title = item.url || ''; this.page.commonObjs.getData(this.data.fontRefName) : null);
this._setTextStyle(content, font);
if (item.url && isExternalLinkTargetSet()) { this.container.appendChild(content);
link.target = LinkTargetStringMap[PDFJS.externalLinkTarget]; return this.container;
} },
// Strip referrer /**
if (item.url) { * Apply text styles to the text in the element.
link.rel = PDFJS.externalLinkRel; *
} * @private
* @param {HTMLDivElement} element
* @param {Object} font
* @memberof WidgetAnnotationElement
*/
_setTextStyle:
function WidgetAnnotationElement_setTextStyle(element, font) {
// TODO: This duplicates some of the logic in CanvasGraphics.setFont().
var style = element.style;
style.fontSize = this.data.fontSize + 'px';
style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
if (!item.url) { if (!font) {
if (item.action) { return;
bindNamedAction(link, item.action);
} else {
bindLink(link, ('dest' in item) ? item.dest : null);
}
} }
container.appendChild(link); style.fontWeight = (font.black ?
(font.bold ? '900' : 'bold') :
(font.bold ? 'bold' : 'normal'));
style.fontStyle = (font.italic ? 'italic' : 'normal');
return container; // Use a reasonable default font if the font doesn't specify a fallback.
var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
style.fontFamily = fontFamily + fallbackName;
} }
});
function getHtmlElement(data, page, viewport, linkService) { return WidgetAnnotationElement;
switch (data.annotationType) { })();
case AnnotationType.WIDGET:
return getHtmlElementForTextWidgetAnnotation(data, page, viewport);
case AnnotationType.TEXT:
return getHtmlElementForTextAnnotation(data, page, viewport);
case AnnotationType.LINK:
return getHtmlElementForLinkAnnotation(data, page, viewport,
linkService);
default:
throw new Error('Unsupported annotationType: ' + data.annotationType);
}
}
function render(viewport, div, annotations, page, linkService) { /**
for (var i = 0, ii = annotations.length; i < ii; i++) { * @typedef {Object} AnnotationLayerParameters
var data = annotations[i]; * @property {PageViewport} viewport
* @property {HTMLDivElement} div
* @property {Array} annotations
* @property {PDFPage} page
* @property {IPDFLinkService} linkService
*/
/**
* @class
* @alias AnnotationLayer
*/
var AnnotationLayer = (function AnnotationLayerClosure() {
return {
/**
* Render a new annotation layer with all annotation elements.
*
* @public
* @param {AnnotationLayerParameters} parameters
* @memberof AnnotationLayer
*/
render: function AnnotationLayer_render(parameters) {
var annotationElementFactory = new AnnotationElementFactory();
for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
var data = parameters.annotations[i];
if (!data || !data.hasHtml) { if (!data || !data.hasHtml) {
continue; continue;
} }
var element = getHtmlElement(data, page, viewport, linkService); var properties = {
div.appendChild(element); data: data,
} page: parameters.page,
viewport: parameters.viewport,
linkService: parameters.linkService
};
var element = annotationElementFactory.create(properties);
parameters.div.appendChild(element.render());
} }
},
function update(viewport, div, annotations) { /**
for (var i = 0, ii = annotations.length; i < ii; i++) { * Update the annotation elements on existing annotation layer.
var data = annotations[i]; *
var element = div.querySelector( * @public
* @param {AnnotationLayerParameters} parameters
* @memberof AnnotationLayer
*/
update: function AnnotationLayer_update(parameters) {
for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
var data = parameters.annotations[i];
var element = parameters.div.querySelector(
'[data-annotation-id="' + data.id + '"]'); '[data-annotation-id="' + data.id + '"]');
if (element) { if (element) {
CustomStyle.setProp('transform', element, CustomStyle.setProp('transform', element,
'matrix(' + viewport.transform.join(',') + ')'); 'matrix(' + parameters.viewport.transform.join(',') + ')');
} }
} }
div.removeAttribute('hidden'); parameters.div.removeAttribute('hidden');
} }
return {
render: render,
update: update
}; };
})(); })();
PDFJS.AnnotationLayer = AnnotationLayer; PDFJS.AnnotationLayer = AnnotationLayer;
exports.AnnotationLayer = AnnotationLayer; exports.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.114'; PDFJS.version = '1.3.116';
PDFJS.build = '9228e1f'; PDFJS.build = 'cfc0cc8';
(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.114", "version": "1.3.116",
"description": "Generic build of Mozilla's PDF.js library.", "description": "Generic build of Mozilla's PDF.js library.",
"keywords": [ "keywords": [
"Mozilla", "Mozilla",

13
web/pdf_viewer.js

@ -1803,11 +1803,18 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
this.pdfPage.getAnnotations(parameters).then(function (annotations) { this.pdfPage.getAnnotations(parameters).then(function (annotations) {
viewport = viewport.clone({ dontFlip: true }); viewport = viewport.clone({ dontFlip: true });
parameters = {
viewport: viewport,
div: self.div,
annotations: annotations,
page: self.pdfPage,
linkService: self.linkService
};
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.
PDFJS.AnnotationLayer.update(viewport, self.div, annotations); PDFJS.AnnotationLayer.update(parameters);
} else { } else {
// Create an annotation layer div and render the annotations // Create an annotation layer div and render the annotations
// if there is at least one annotation. // if there is at least one annotation.
@ -1818,9 +1825,9 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
self.div = document.createElement('div'); self.div = document.createElement('div');
self.div.className = 'annotationLayer'; self.div.className = 'annotationLayer';
self.pageDiv.appendChild(self.div); self.pageDiv.appendChild(self.div);
parameters.div = self.div;
PDFJS.AnnotationLayer.render(viewport, self.div, annotations, PDFJS.AnnotationLayer.render(parameters);
self.pdfPage, self.linkService);
if (typeof mozL10n !== 'undefined') { if (typeof mozL10n !== 'undefined') {
mozL10n.translate(self.div); mozL10n.translate(self.div);
} }

Loading…
Cancel
Save