Bug 1301577 - Update pdf.js to version 1.5.437. r=bdahl

This commit is contained in:
Ryan VanderMeulen 2016-09-08 21:52:20 -04:00
Родитель d5acd544da
Коммит 00b6191463
7 изменённых файлов: 1303 добавлений и 1196 удалений

Просмотреть файл

@ -1,3 +1,3 @@
This is the pdf.js project output, https://github.com/mozilla/pdf.js
Current extension version is: 1.5.413
Current extension version is: 1.5.437

Просмотреть файл

@ -91,7 +91,8 @@ function initializeDefaultPreferences() {
"disableFontFace": false,
"disableTextLayer": false,
"useOnlyCssZoom": false,
"externalLinkTarget": 0
"externalLinkTarget": 0,
"renderInteractiveForms": false
}

Просмотреть файл

@ -49,7 +49,8 @@ var DEFAULT_PREFERENCES =
"disableFontFace": false,
"disableTextLayer": false,
"useOnlyCssZoom": false,
"externalLinkTarget": 0
"externalLinkTarget": 0,
"renderInteractiveForms": false
}

Просмотреть файл

@ -28,8 +28,8 @@ factory((root.pdfjsDistBuildPdf = {}));
// Use strict in our context only - users might not want it
'use strict';
var pdfjsVersion = '1.5.413';
var pdfjsBuild = '6bb95e3';
var pdfjsVersion = '1.5.437';
var pdfjsBuild = 'ca61ccc';
var pdfjsFilePath =
typeof document !== 'undefined' && document.currentScript ?
@ -1158,6 +1158,7 @@ function createPromiseCapability() {
throw new Error('DOM Promise is not present');
})();
var StatTimer = (function StatTimerClosure() {
function rpad(str, pad, length) {
while (str.length < length) {
@ -1938,6 +1939,8 @@ var getDefaultSetting = displayDOMUtils.getDefaultSetting;
* @property {PageViewport} viewport
* @property {IPDFLinkService} linkService
* @property {DownloadManager} downloadManager
* @property {string} imageResourcesPath
* @property {boolean} renderInteractiveForms
*/
/**
@ -1962,6 +1965,12 @@ AnnotationElementFactory.prototype =
return new TextAnnotationElement(parameters);
case AnnotationType.WIDGET:
var fieldType = parameters.data.fieldType;
switch (fieldType) {
case 'Tx':
return new TextWidgetAnnotationElement(parameters);
}
return new WidgetAnnotationElement(parameters);
case AnnotationType.POPUP:
@ -2002,6 +2011,7 @@ var AnnotationElement = (function AnnotationElementClosure() {
this.linkService = parameters.linkService;
this.downloadManager = parameters.downloadManager;
this.imageResourcesPath = parameters.imageResourcesPath;
this.renderInteractiveForms = parameters.renderInteractiveForms;
if (isRenderable) {
this.container = this._createContainer();
@ -2285,9 +2295,7 @@ var TextAnnotationElement = (function TextAnnotationElementClosure() {
*/
var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
function WidgetAnnotationElement(parameters) {
var isRenderable = !parameters.data.hasAppearance &&
!!parameters.data.fieldValue;
AnnotationElement.call(this, parameters, isRenderable);
AnnotationElement.call(this, parameters, true);
}
Util.inherit(WidgetAnnotationElement, AnnotationElement, {
@ -2299,18 +2307,55 @@ var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
* @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';
// Show only the container for unsupported field types.
return this.container;
}
});
var font = (this.data.fontRefName ?
this.page.commonObjs.getData(this.data.fontRefName) : null);
this._setTextStyle(content, font);
return WidgetAnnotationElement;
})();
this.container.appendChild(content);
/**
* @class
* @alias TextWidgetAnnotationElement
*/
var TextWidgetAnnotationElement = (
function TextWidgetAnnotationElementClosure() {
function TextWidgetAnnotationElement(parameters) {
WidgetAnnotationElement.call(this, parameters);
}
Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {
/**
* Render the text widget annotation's HTML element in the empty container.
*
* @public
* @memberof TextWidgetAnnotationElement
* @returns {HTMLSectionElement}
*/
render: function TextWidgetAnnotationElement_render() {
this.container.className = 'textWidgetAnnotation';
if (this.renderInteractiveForms) {
var input = document.createElement('input');
input.type = 'text';
input.value = this.data.fieldValue;
this.container.appendChild(input);
} else {
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);
this.container.appendChild(content);
}
return this.container;
},
@ -2320,10 +2365,10 @@ var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
* @private
* @param {HTMLDivElement} element
* @param {Object} font
* @memberof WidgetAnnotationElement
* @memberof TextWidgetAnnotationElement
*/
_setTextStyle:
function WidgetAnnotationElement_setTextStyle(element, font) {
function TextWidgetAnnotationElement_setTextStyle(element, font) {
// TODO: This duplicates some of the logic in CanvasGraphics.setFont().
var style = element.style;
style.fontSize = this.data.fontSize + 'px';
@ -2345,7 +2390,7 @@ var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
}
});
return WidgetAnnotationElement;
return TextWidgetAnnotationElement;
})();
/**
@ -2737,6 +2782,7 @@ var FileAttachmentAnnotationElement = (
* @property {PDFPage} page
* @property {IPDFLinkService} linkService
* @property {string} imageResourcesPath
* @property {boolean} renderInteractiveForms
*/
/**
@ -2769,7 +2815,8 @@ var AnnotationLayer = (function AnnotationLayerClosure() {
linkService: parameters.linkService,
downloadManager: parameters.downloadManager,
imageResourcesPath: parameters.imageResourcesPath ||
getDefaultSetting('imageResourcesPath')
getDefaultSetting('imageResourcesPath'),
renderInteractiveForms: parameters.renderInteractiveForms || false,
};
var element = annotationElementFactory.create(properties);
if (element.isRenderable) {
@ -2830,6 +2877,8 @@ var getDefaultSetting = displayDOMUtils.getDefaultSetting;
* initially be set to empty array.
* @property {number} timeout - (optional) Delay in milliseconds before
* rendering of the text runs occurs.
* @property {boolean} enhanceTextSelection - (optional) Whether to turn on the
* text selection enhancement.
*/
var renderTextLayer = (function renderTextLayerClosure() {
var MAX_TEXT_DIVS_TO_RENDER = 100000;
@ -2840,17 +2889,31 @@ var renderTextLayer = (function renderTextLayerClosure() {
return !NonWhitespaceRegexp.test(str);
}
function appendText(textDivs, viewport, geom, styles, bounds,
enhanceTextSelection) {
var style = styles[geom.fontName];
function appendText(task, geom, styles) {
// Initialize all used properties to keep the caches monomorphic.
var textDiv = document.createElement('div');
textDivs.push(textDiv);
var textDivProperties = {
angle: 0,
canvasWidth: 0,
isWhitespace: false,
originalTransform: '',
paddingBottom: 0,
paddingLeft: 0,
paddingRight: 0,
paddingTop: 0,
scale: 1,
};
task._textDivs.push(textDiv);
if (isAllWhitespace(geom.str)) {
textDiv.dataset.isWhitespace = true;
textDivProperties.isWhitespace = true;
task._textDivProperties.set(textDiv, textDivProperties);
return;
}
var tx = Util.transform(viewport.transform, geom.transform);
var tx = Util.transform(task._viewport.transform, geom.transform);
var angle = Math.atan2(tx[1], tx[0]);
var style = styles[geom.fontName];
if (style.vertical) {
angle += Math.PI / 2;
}
@ -2879,32 +2942,34 @@ var renderTextLayer = (function renderTextLayerClosure() {
textDiv.textContent = geom.str;
// |fontName| is only used by the Font Inspector. This test will succeed
// when e.g. the Font Inspector is off but the Stepper is on, but it's
// not worth the effort to do a more accurate test.
// not worth the effort to do a more accurate test. We only use `dataset`
// here to make the font name available for the debugger.
if (getDefaultSetting('pdfBug')) {
textDiv.dataset.fontName = geom.fontName;
}
// Storing into dataset will convert number into string.
if (angle !== 0) {
textDiv.dataset.angle = angle * (180 / Math.PI);
textDivProperties.angle = angle * (180 / Math.PI);
}
// We don't bother scaling single-char text divs, because it has very
// little effect on text highlighting. This makes scrolling on docs with
// lots of such divs a lot faster.
if (geom.str.length > 1) {
if (style.vertical) {
textDiv.dataset.canvasWidth = geom.height * viewport.scale;
textDivProperties.canvasWidth = geom.height * task._viewport.scale;
} else {
textDiv.dataset.canvasWidth = geom.width * viewport.scale;
textDivProperties.canvasWidth = geom.width * task._viewport.scale;
}
}
if (enhanceTextSelection) {
task._textDivProperties.set(textDiv, textDivProperties);
if (task._enhanceTextSelection) {
var angleCos = 1, angleSin = 0;
if (angle !== 0) {
angleCos = Math.cos(angle);
angleSin = Math.sin(angle);
}
var divWidth = (style.vertical ? geom.height : geom.width) *
viewport.scale;
task._viewport.scale;
var divHeight = fontHeight;
var m, b;
@ -2915,7 +2980,7 @@ var renderTextLayer = (function renderTextLayerClosure() {
b = [left, top, left + divWidth, top + divHeight];
}
bounds.push({
task._bounds.push({
left: b[0],
top: b[1],
right: b[2],
@ -2952,7 +3017,8 @@ var renderTextLayer = (function renderTextLayerClosure() {
var lastFontFamily;
for (var i = 0; i < textDivsLength; i++) {
var textDiv = textDivs[i];
if (textDiv.dataset.isWhitespace !== undefined) {
var textDivProperties = task._textDivProperties.get(textDiv);
if (textDivProperties.isWhitespace) {
continue;
}
@ -2967,38 +3033,40 @@ var renderTextLayer = (function renderTextLayerClosure() {
}
var width = ctx.measureText(textDiv.textContent).width;
textDiv.dataset.originalWidth = width;
textLayerFrag.appendChild(textDiv);
var transform;
if (textDiv.dataset.canvasWidth !== undefined && width > 0) {
// Dataset values come of type string.
var textScale = textDiv.dataset.canvasWidth / width;
transform = 'scaleX(' + textScale + ')';
} else {
transform = '';
}
var rotation = textDiv.dataset.angle;
if (rotation) {
transform = 'rotate(' + rotation + 'deg) ' + transform;
}
if (transform) {
textDiv.dataset.originalTransform = transform;
CustomStyle.setProp('transform' , textDiv, transform);
}
var transform = '';
if (textDivProperties.canvasWidth !== 0 && width > 0) {
textDivProperties.scale = textDivProperties.canvasWidth / width;
transform = 'scaleX(' + textDivProperties.scale + ')';
}
if (textDivProperties.angle !== 0) {
transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform;
}
if (transform !== '') {
textDivProperties.originalTransform = transform;
CustomStyle.setProp('transform', textDiv, transform);
}
task._textDivProperties.set(textDiv, textDivProperties);
}
task._renderingDone = true;
capability.resolve();
}
function expand(bounds, viewport) {
function expand(task) {
var bounds = task._bounds;
var viewport = task._viewport;
var expanded = expandBounds(viewport.width, viewport.height, bounds);
for (var i = 0; i < expanded.length; i++) {
var div = bounds[i].div;
if (!div.dataset.angle) {
div.dataset.paddingLeft = bounds[i].left - expanded[i].left;
div.dataset.paddingTop = bounds[i].top - expanded[i].top;
div.dataset.paddingRight = expanded[i].right - bounds[i].right;
div.dataset.paddingBottom = expanded[i].bottom - bounds[i].bottom;
var divProperties = task._textDivProperties.get(div);
if (divProperties.angle === 0) {
divProperties.paddingLeft = bounds[i].left - expanded[i].left;
divProperties.paddingTop = bounds[i].top - expanded[i].top;
divProperties.paddingRight = expanded[i].right - bounds[i].right;
divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
task._textDivProperties.set(div, divProperties);
continue;
}
// Box is rotated -- trying to find padding so rotated div will not
@ -3032,21 +3100,22 @@ var renderTextLayer = (function renderTextLayerClosure() {
});
var findPositiveMin = function (ts, offset, count) {
var result = 0;
for (var i = 0; i < count; i++) {
var t = ts[offset++];
if (t > 0) {
result = result ? Math.min(t, result) : t;
}
for (var i = 0; i < count; i++) {
var t = ts[offset++];
if (t > 0) {
result = result ? Math.min(t, result) : t;
}
return result;
}
return result;
};
// Not based on math, but to simplify calculations, using cos and sin
// absolute values to not exceed the box (it can but insignificantly).
var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
div.dataset.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
div.dataset.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
div.dataset.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
div.dataset.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
task._textDivProperties.set(div, divProperties);
}
}
@ -3268,8 +3337,8 @@ var renderTextLayer = (function renderTextLayerClosure() {
this._textContent = textContent;
this._container = container;
this._viewport = viewport;
textDivs = textDivs || [];
this._textDivs = textDivs;
this._textDivs = textDivs || [];
this._textDivProperties = new WeakMap();
this._renderingDone = false;
this._canceled = false;
this._capability = createPromiseCapability();
@ -3294,14 +3363,9 @@ var renderTextLayer = (function renderTextLayerClosure() {
_render: function TextLayer_render(timeout) {
var textItems = this._textContent.items;
var styles = this._textContent.styles;
var textDivs = this._textDivs;
var viewport = this._viewport;
var enhanceTextSelection = this._enhanceTextSelection;
var textStyles = this._textContent.styles;
for (var i = 0, len = textItems.length; i < len; i++) {
appendText(textDivs, viewport, textItems[i], styles, this._bounds,
enhanceTextSelection);
appendText(this, textItems[i], textStyles);
}
if (!timeout) { // Render right away
@ -3320,59 +3384,53 @@ var renderTextLayer = (function renderTextLayerClosure() {
return;
}
if (!this._expanded) {
expand(this._bounds, this._viewport);
expand(this);
this._expanded = true;
this._bounds.length = 0;
}
if (expandDivs) {
for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
var div = this._textDivs[i];
var transform;
var width = div.dataset.originalWidth;
if (div.dataset.canvasWidth !== undefined && width > 0) {
// Dataset values come of type string.
var textScale = div.dataset.canvasWidth / width;
transform = 'scaleX(' + textScale + ')';
} else {
transform = '';
for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
var div = this._textDivs[i];
var divProperties = this._textDivProperties.get(div);
if (expandDivs) {
var transform = '';
if (divProperties.scale !== 1) {
transform = 'scaleX(' + divProperties.scale + ')';
}
var rotation = div.dataset.angle;
if (rotation) {
transform = 'rotate(' + rotation + 'deg) ' + transform;
if (divProperties.angle !== 0) {
transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
}
if (div.dataset.paddingLeft) {
if (divProperties.paddingLeft !== 0) {
div.style.paddingLeft =
(div.dataset.paddingLeft / textScale) + 'px';
(divProperties.paddingLeft / divProperties.scale) + 'px';
transform += ' translateX(' +
(-div.dataset.paddingLeft / textScale) + 'px)';
(-divProperties.paddingLeft / divProperties.scale) + 'px)';
}
if (div.dataset.paddingTop) {
div.style.paddingTop = div.dataset.paddingTop + 'px';
transform += ' translateY(' + (-div.dataset.paddingTop) + 'px)';
if (divProperties.paddingTop !== 0) {
div.style.paddingTop = divProperties.paddingTop + 'px';
transform += ' translateY(' + (-divProperties.paddingTop) + 'px)';
}
if (div.dataset.paddingRight) {
if (divProperties.paddingRight !== 0) {
div.style.paddingRight =
div.dataset.paddingRight / textScale + 'px';
(divProperties.paddingRight / divProperties.scale) + 'px';
}
if (div.dataset.paddingBottom) {
div.style.paddingBottom = div.dataset.paddingBottom + 'px';
if (divProperties.paddingBottom !== 0) {
div.style.paddingBottom = divProperties.paddingBottom + 'px';
}
if (transform) {
CustomStyle.setProp('transform' , div, transform);
if (transform !== '') {
CustomStyle.setProp('transform', div, transform);
}
}
} else {
for (i = 0, ii = this._textDivs.length; i < ii; i++) {
div = this._textDivs[i];
} else {
div.style.padding = 0;
transform = div.dataset.originalTransform || '';
CustomStyle.setProp('transform', div, transform);
CustomStyle.setProp('transform', div,
divProperties.originalTransform);
}
}
},
};
/**
* Starts rendering of the text layer.
*
@ -6594,6 +6652,7 @@ var error = sharedUtil.error;
var deprecated = sharedUtil.deprecated;
var getVerbosityLevel = sharedUtil.getVerbosityLevel;
var info = sharedUtil.info;
var isInt = sharedUtil.isInt;
var isArrayBuffer = sharedUtil.isArrayBuffer;
var isSameOrigin = sharedUtil.isSameOrigin;
var loadJpegStream = sharedUtil.loadJpegStream;
@ -8115,7 +8174,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
messageHandler.on('JpegDecode', function(data) {
if (this.destroyed) {
return Promise.reject('Worker was terminated');
return Promise.reject(new Error('Worker was destroyed'));
}
var imageUrl = data[0];
@ -8165,8 +8224,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
},
getPage: function WorkerTransport_getPage(pageNumber, capability) {
if (pageNumber <= 0 || pageNumber > this.numPages ||
(pageNumber|0) !== pageNumber) {
if (!isInt(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) {
return Promise.reject(new Error('Invalid page request'));
}
@ -8189,12 +8247,11 @@ var WorkerTransport = (function WorkerTransportClosure() {
},
getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref }).
then(function (pageIndex) {
return pageIndex;
}, function (reason) {
return Promise.reject(new Error(reason));
});
return this.messageHandler.sendWithPromise('GetPageIndex', {
ref: ref,
}).catch(function (reason) {
return Promise.reject(new Error(reason));
});
},
getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
@ -8792,6 +8849,13 @@ exports._UnsupportedManager = _UnsupportedManager;
PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
true : PDFJS.isEvalSupported);
/**
* Renders interactive form elements.
* @var {boolean}
*/
PDFJS.renderInteractiveForms = (PDFJS.renderInteractiveForms === undefined ?
false : PDFJS.renderInteractiveForms);
PDFJS.getDocument = displayAPI.getDocument;
PDFJS.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -101,6 +101,26 @@
cursor: pointer;
}
.annotationLayer .textWidgetAnnotation input {
background-color: rgba(0, 54, 255, 0.13);
border: 1px solid transparent;
box-sizing: border-box;
font-size: 9px;
height: 100%;
padding: 0 3px;
vertical-align: top;
width: 100%;
}
.annotationLayer .textWidgetAnnotation input:hover {
border: 1px solid #000;
}
.annotationLayer .textWidgetAnnotation input:focus {
background: none;
border: 1px solid transparent;
}
.annotationLayer .popupWrapper {
position: absolute;
width: 20em;

Просмотреть файл

@ -951,7 +951,8 @@ exports.PDFRenderingQueue = PDFRenderingQueue;
"disableFontFace": false,
"disableTextLayer": false,
"useOnlyCssZoom": false,
"externalLinkTarget": 0
"externalLinkTarget": 0,
"renderInteractiveForms": false
}
);
@ -5037,7 +5038,7 @@ var TEXT_LAYER_RENDER_DELAY = 200; // ms
* @property {IPDFTextLayerFactory} textLayerFactory
* @property {IPDFAnnotationLayerFactory} annotationLayerFactory
* @property {boolean} enhanceTextSelection - Turns on the text selection
* enhancement. The default is `false`.
* enhancement. The default is `false`.
*/
/**
@ -5793,7 +5794,7 @@ exports.PDFThumbnailViewer = PDFThumbnailViewer;
* @property {PageViewport} viewport - The viewport of the text layer.
* @property {PDFFindController} findController
* @property {boolean} enhanceTextSelection - Option to turn on improved
* text selection.
* text selection.
*/
/**
@ -6190,7 +6191,8 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
annotations: annotations,
page: self.pdfPage,
linkService: self.linkService,
downloadManager: self.downloadManager
downloadManager: self.downloadManager,
renderInteractiveForms: pdfjsLib.PDFJS.renderInteractiveForms,
};
if (self.div) {
@ -7403,6 +7405,9 @@ var PDFViewerApplication = {
}
PDFJS.externalLinkTarget = value;
}),
Preferences.get('renderInteractiveForms').then(function resolved(value) {
PDFJS.renderInteractiveForms = value;
}),
// TODO move more preferences and other async stuff here
]).catch(function (reason) { });