Browse Source

PDF.js version 1.5.477 - See mozilla/pdf.js@9e927ded937473c2a268fb549eeabd442bc40e55

master v1.5.477
Pdf Bot 9 years ago
parent
commit
4531f4dbcc
  1. 2
      bower.json
  2. 239
      build/pdf.combined.js
  3. 110
      build/pdf.js
  4. 156
      build/pdf.worker.js
  5. 2
      package.json
  6. 22
      web/pdf_viewer.css
  7. 26
      web/pdf_viewer.js

2
bower.json

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

239
build/pdf.combined.js

@ -28,8 +28,8 @@ factory((root.pdfjsDistBuildPdfCombined = {}));
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
'use strict'; 'use strict';
var pdfjsVersion = '1.5.458'; var pdfjsVersion = '1.5.477';
var pdfjsBuild = 'a7c3502'; var pdfjsBuild = '9e927de';
var pdfjsFilePath = var pdfjsFilePath =
typeof document !== 'undefined' && document.currentScript ? typeof document !== 'undefined' && document.currentScript ?
@ -1100,6 +1100,28 @@ var AnnotationFlag = {
LOCKEDCONTENTS: 0x200 LOCKEDCONTENTS: 0x200
}; };
var AnnotationFieldFlag = {
READONLY: 1,
REQUIRED: 2,
NOEXPORT: 3,
MULTILINE: 13,
PASSWORD: 14,
NOTOGGLETOOFF: 15,
RADIO: 16,
PUSHBUTTON: 17,
COMBO: 18,
EDIT: 19,
SORT: 20,
FILESELECT: 21,
MULTISELECT: 22,
DONOTSPELLCHECK: 23,
DONOTSCROLL: 24,
COMB: 25,
RICHTEXT: 26,
RADIOSINUNISON: 26,
COMMITONSELCHANGE: 27,
};
var AnnotationBorderStyleType = { var AnnotationBorderStyleType = {
SOLID: 1, SOLID: 1,
DASHED: 2, DASHED: 2,
@ -3361,6 +3383,7 @@ exports.OPS = OPS;
exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS; exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES; exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
exports.AnnotationBorderStyleType = AnnotationBorderStyleType; exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
exports.AnnotationFieldFlag = AnnotationFieldFlag;
exports.AnnotationFlag = AnnotationFlag; exports.AnnotationFlag = AnnotationFlag;
exports.AnnotationType = AnnotationType; exports.AnnotationType = AnnotationType;
exports.FontType = FontType; exports.FontType = FontType;
@ -24502,7 +24525,9 @@ var TextAnnotationElement = (function TextAnnotationElementClosure() {
*/ */
var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() { var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
function WidgetAnnotationElement(parameters) { function WidgetAnnotationElement(parameters) {
AnnotationElement.call(this, parameters, true); var isRenderable = parameters.renderInteractiveForms ||
(!parameters.data.hasAppearance && !!parameters.data.fieldValue);
AnnotationElement.call(this, parameters, isRenderable);
} }
Util.inherit(WidgetAnnotationElement, AnnotationElement, { Util.inherit(WidgetAnnotationElement, AnnotationElement, {
@ -24547,9 +24572,15 @@ var TextWidgetAnnotationElement = (
var element = null; var element = null;
if (this.renderInteractiveForms) { if (this.renderInteractiveForms) {
element = document.createElement('input'); if (this.data.multiLine) {
element.type = 'text'; element = document.createElement('textarea');
} else {
element = document.createElement('input');
element.type = 'text';
}
element.value = this.data.fieldValue; element.value = this.data.fieldValue;
element.disabled = this.data.readOnly;
if (this.data.maxLen !== null) { if (this.data.maxLen !== null) {
element.maxLength = this.data.maxLen; element.maxLength = this.data.maxLen;
@ -25105,14 +25136,20 @@ var renderTextLayer = (function renderTextLayerClosure() {
return !NonWhitespaceRegexp.test(str); return !NonWhitespaceRegexp.test(str);
} }
// Text layers may contain many thousand div's, and using `styleBuf` avoids
// creating many intermediate strings when building their 'style' properties.
var styleBuf = ['left: ', 0, 'px; top: ', 0, 'px; font-size: ', 0,
'px; font-family: ', '', ';'];
function appendText(task, geom, styles) { function appendText(task, geom, styles) {
// Initialize all used properties to keep the caches monomorphic. // Initialize all used properties to keep the caches monomorphic.
var textDiv = document.createElement('div'); var textDiv = document.createElement('div');
var textDivProperties = { var textDivProperties = {
style: null,
angle: 0, angle: 0,
canvasWidth: 0, canvasWidth: 0,
isWhitespace: false, isWhitespace: false,
originalTransform: '', originalTransform: null,
paddingBottom: 0, paddingBottom: 0,
paddingLeft: 0, paddingLeft: 0,
paddingRight: 0, paddingRight: 0,
@ -25150,10 +25187,12 @@ var renderTextLayer = (function renderTextLayerClosure() {
left = tx[4] + (fontAscent * Math.sin(angle)); left = tx[4] + (fontAscent * Math.sin(angle));
top = tx[5] - (fontAscent * Math.cos(angle)); top = tx[5] - (fontAscent * Math.cos(angle));
} }
textDiv.style.left = left + 'px'; styleBuf[1] = left;
textDiv.style.top = top + 'px'; styleBuf[3] = top;
textDiv.style.fontSize = fontHeight + 'px'; styleBuf[5] = fontHeight;
textDiv.style.fontFamily = style.fontFamily; styleBuf[7] = style.fontFamily;
textDivProperties.style = styleBuf.join('');
textDiv.setAttribute('style', textDivProperties.style);
textDiv.textContent = geom.str; textDiv.textContent = geom.str;
// |fontName| is only used by the Font Inspector. This test will succeed // |fontName| is only used by the Font Inspector. This test will succeed
@ -25560,7 +25599,6 @@ var renderTextLayer = (function renderTextLayerClosure() {
this._renderTimer = null; this._renderTimer = null;
this._bounds = []; this._bounds = [];
this._enhanceTextSelection = !!enhanceTextSelection; this._enhanceTextSelection = !!enhanceTextSelection;
this._expanded = false;
} }
TextLayerRenderTask.prototype = { TextLayerRenderTask.prototype = {
get promise() { get promise() {
@ -25598,18 +25636,20 @@ var renderTextLayer = (function renderTextLayerClosure() {
if (!this._enhanceTextSelection || !this._renderingDone) { if (!this._enhanceTextSelection || !this._renderingDone) {
return; return;
} }
if (!this._expanded) { if (this._bounds !== null) {
expand(this); expand(this);
this._expanded = true; this._bounds = null;
this._bounds.length = 0;
} }
for (var i = 0, ii = this._textDivs.length; i < ii; i++) { for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
var div = this._textDivs[i]; var div = this._textDivs[i];
var divProperties = this._textDivProperties.get(div); var divProperties = this._textDivProperties.get(div);
if (divProperties.isWhitespace) {
continue;
}
if (expandDivs) { if (expandDivs) {
var transform = ''; var transform = '', padding = '';
if (divProperties.scale !== 1) { if (divProperties.scale !== 1) {
transform = 'scaleX(' + divProperties.scale + ')'; transform = 'scaleX(' + divProperties.scale + ')';
@ -25618,21 +25658,26 @@ var renderTextLayer = (function renderTextLayerClosure() {
transform = 'rotate(' + divProperties.angle + 'deg) ' + transform; transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
} }
if (divProperties.paddingLeft !== 0) { if (divProperties.paddingLeft !== 0) {
div.style.paddingLeft = padding += ' padding-left: ' +
(divProperties.paddingLeft / divProperties.scale) + 'px'; (divProperties.paddingLeft / divProperties.scale) + 'px;';
transform += ' translateX(' + transform += ' translateX(' +
(-divProperties.paddingLeft / divProperties.scale) + 'px)'; (-divProperties.paddingLeft / divProperties.scale) + 'px)';
} }
if (divProperties.paddingTop !== 0) { if (divProperties.paddingTop !== 0) {
div.style.paddingTop = divProperties.paddingTop + 'px'; padding += ' padding-top: ' + divProperties.paddingTop + 'px;';
transform += ' translateY(' + (-divProperties.paddingTop) + 'px)'; transform += ' translateY(' + (-divProperties.paddingTop) + 'px)';
} }
if (divProperties.paddingRight !== 0) { if (divProperties.paddingRight !== 0) {
div.style.paddingRight = padding += ' padding-right: ' +
(divProperties.paddingRight / divProperties.scale) + 'px'; (divProperties.paddingRight / divProperties.scale) + 'px;';
} }
if (divProperties.paddingBottom !== 0) { if (divProperties.paddingBottom !== 0) {
div.style.paddingBottom = divProperties.paddingBottom + 'px'; padding += ' padding-bottom: ' +
divProperties.paddingBottom + 'px;';
}
if (padding !== '') {
div.setAttribute('style', divProperties.style + padding);
} }
if (transform !== '') { if (transform !== '') {
CustomStyle.setProp('transform', div, transform); CustomStyle.setProp('transform', div, transform);
@ -25640,7 +25685,7 @@ var renderTextLayer = (function renderTextLayerClosure() {
} else { } else {
div.style.padding = 0; div.style.padding = 0;
CustomStyle.setProp('transform', div, CustomStyle.setProp('transform', div,
divProperties.originalTransform); divProperties.originalTransform || '');
} }
} }
}, },
@ -32283,6 +32328,30 @@ function adjustWidths(properties) {
properties.defaultWidth *= scale; properties.defaultWidth *= scale;
} }
function adjustToUnicode(properties, builtInEncoding) {
if (properties.hasIncludedToUnicodeMap) {
return; // The font dictionary has a `ToUnicode` entry.
}
if (properties.hasEncoding) {
return; // The font dictionary has an `Encoding` entry.
}
if (builtInEncoding === properties.defaultEncoding) {
return; // No point in trying to adjust `toUnicode` if the encodings match.
}
if (properties.toUnicode instanceof IdentityToUnicodeMap) {
return;
}
var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
for (var charCode in builtInEncoding) {
var glyphName = builtInEncoding[charCode];
var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
if (unicode !== -1) {
toUnicode[charCode] = String.fromCharCode(unicode);
}
}
properties.toUnicode.amend(toUnicode);
}
function getFontType(type, subtype) { function getFontType(type, subtype) {
switch (type) { switch (type) {
case 'Type1': case 'Type1':
@ -32381,7 +32450,13 @@ var ToUnicodeMap = (function ToUnicodeMapClosure() {
charCodeOf: function(v) { charCodeOf: function(v) {
return this._map.indexOf(v); return this._map.indexOf(v);
} },
amend: function (map) {
for (var charCode in map) {
this._map[charCode] = map[charCode];
}
},
}; };
return ToUnicodeMap; return ToUnicodeMap;
@ -32417,7 +32492,11 @@ var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
charCodeOf: function (v) { charCodeOf: function (v) {
return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1; return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
} },
amend: function (map) {
error('Should not call amend()');
},
}; };
return IdentityToUnicodeMap; return IdentityToUnicodeMap;
@ -32818,6 +32897,7 @@ var Font = (function FontClosure() {
this.fontMatrix = properties.fontMatrix; this.fontMatrix = properties.fontMatrix;
this.widths = properties.widths; this.widths = properties.widths;
this.defaultWidth = properties.defaultWidth; this.defaultWidth = properties.defaultWidth;
this.toUnicode = properties.toUnicode;
this.encoding = properties.baseEncoding; this.encoding = properties.baseEncoding;
this.seacMap = properties.seacMap; this.seacMap = properties.seacMap;
@ -34439,10 +34519,8 @@ var Font = (function FontClosure() {
} else { } else {
// Most of the following logic in this code branch is based on the // Most of the following logic in this code branch is based on the
// 9.6.6.4 of the PDF spec. // 9.6.6.4 of the PDF spec.
var hasEncoding = var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont,
properties.differences.length > 0 || !!properties.baseEncodingName; properties.hasEncoding);
var cmapTable =
readCmapTable(tables['cmap'], font, this.isSymbolicFont, hasEncoding);
var cmapPlatformId = cmapTable.platformId; var cmapPlatformId = cmapTable.platformId;
var cmapEncodingId = cmapTable.encodingId; var cmapEncodingId = cmapTable.encodingId;
var cmapMappings = cmapTable.mappings; var cmapMappings = cmapTable.mappings;
@ -34451,7 +34529,7 @@ var Font = (function FontClosure() {
// The spec seems to imply that if the font is symbolic the encoding // The spec seems to imply that if the font is symbolic the encoding
// should be ignored, this doesn't appear to work for 'preistabelle.pdf' // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
// where the the font is symbolic and it has an encoding. // where the the font is symbolic and it has an encoding.
if (hasEncoding && if (properties.hasEncoding &&
(cmapPlatformId === 3 && cmapEncodingId === 1 || (cmapPlatformId === 3 && cmapEncodingId === 1 ||
cmapPlatformId === 1 && cmapEncodingId === 0) || cmapPlatformId === 1 && cmapEncodingId === 0) ||
(cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
@ -34615,6 +34693,12 @@ var Font = (function FontClosure() {
// TODO: Check the charstring widths to determine this. // TODO: Check the charstring widths to determine this.
properties.fixedPitch = false; properties.fixedPitch = false;
if (properties.builtInEncoding) {
// For Type1 fonts that do not include either `ToUnicode` or `Encoding`
// data, attempt to use the `builtInEncoding` to improve text selection.
adjustToUnicode(properties, properties.builtInEncoding);
}
var mapping = font.getGlyphMapping(properties); var mapping = font.getGlyphMapping(properties);
var newMapping = adjustMapping(mapping, properties); var newMapping = adjustMapping(mapping, properties);
this.toFontChar = newMapping.toFontChar; this.toFontChar = newMapping.toFontChar;
@ -36302,9 +36386,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
if (sourceCtx.setLineDash !== undefined) { if (sourceCtx.setLineDash !== undefined) {
destCtx.setLineDash(sourceCtx.getLineDash()); destCtx.setLineDash(sourceCtx.getLineDash());
destCtx.lineDashOffset = sourceCtx.lineDashOffset; destCtx.lineDashOffset = sourceCtx.lineDashOffset;
} else if (sourceCtx.mozDashOffset !== undefined) {
destCtx.mozDash = sourceCtx.mozDash;
destCtx.mozDashOffset = sourceCtx.mozDashOffset;
} }
} }
@ -36560,9 +36641,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
if (ctx.setLineDash !== undefined) { if (ctx.setLineDash !== undefined) {
ctx.setLineDash(dashArray); ctx.setLineDash(dashArray);
ctx.lineDashOffset = dashPhase; ctx.lineDashOffset = dashPhase;
} else {
ctx.mozDash = dashArray;
ctx.mozDashOffset = dashPhase;
} }
}, },
setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) { setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
@ -39742,6 +39820,9 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* calling of PDFPage.getViewport method. * calling of PDFPage.getViewport method.
* @property {string} intent - Rendering intent, can be 'display' or 'print' * @property {string} intent - Rendering intent, can be 'display' or 'print'
* (default value is 'display'). * (default value is 'display').
* @property {boolean} renderInteractiveForms - (optional) Whether or not
* interactive form elements are rendered in the display
* layer. If so, we do not render them on canvas as well.
* @property {Array} transform - (optional) Additional transform, applied * @property {Array} transform - (optional) Additional transform, applied
* just before viewport transform. * just before viewport transform.
* @property {Object} imageLayer - (optional) An object that has beginLayout, * @property {Object} imageLayer - (optional) An object that has beginLayout,
@ -39850,6 +39931,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
this.pendingCleanup = false; this.pendingCleanup = false;
var renderingIntent = (params.intent === 'print' ? 'print' : 'display'); var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
var renderInteractiveForms = (params.renderInteractiveForms === true ?
true : /* Default */ false);
if (!this.intentStates[renderingIntent]) { if (!this.intentStates[renderingIntent]) {
this.intentStates[renderingIntent] = Object.create(null); this.intentStates[renderingIntent] = Object.create(null);
@ -39870,7 +39953,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
this.stats.time('Page Request'); this.stats.time('Page Request');
this.transport.messageHandler.send('RenderPageRequest', { this.transport.messageHandler.send('RenderPageRequest', {
pageIndex: this.pageNumber - 1, pageIndex: this.pageNumber - 1,
intent: renderingIntent intent: renderingIntent,
renderInteractiveForms: renderInteractiveForms,
}); });
} }
@ -42603,13 +42687,6 @@ exports.ColorSpace = ColorSpace;
PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ? PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
true : PDFJS.isEvalSupported); true : PDFJS.isEvalSupported);
/**
* Renders interactive form elements.
* @var {boolean}
*/
PDFJS.renderInteractiveForms = (PDFJS.renderInteractiveForms === undefined ?
false : PDFJS.renderInteractiveForms);
var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow; var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow;
delete PDFJS.openExternalLinksInNewWindow; delete PDFJS.openExternalLinksInNewWindow;
Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', { Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', {
@ -47454,6 +47531,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
properties.differences = differences; properties.differences = differences;
properties.baseEncodingName = baseEncodingName; properties.baseEncodingName = baseEncodingName;
properties.hasEncoding = !!baseEncodingName || differences.length > 0;
properties.dict = dict; properties.dict = dict;
return toUnicodePromise.then(function(toUnicode) { return toUnicodePromise.then(function(toUnicode) {
properties.toUnicode = toUnicode; properties.toUnicode = toUnicode;
@ -47471,8 +47549,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
* {ToUnicodeMap|IdentityToUnicodeMap} object. * {ToUnicodeMap|IdentityToUnicodeMap} object.
*/ */
buildToUnicode: function PartialEvaluator_buildToUnicode(properties) { buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
properties.hasIncludedToUnicodeMap =
!!properties.toUnicode && properties.toUnicode.length > 0;
// Section 9.10.2 Mapping Character Codes to Unicode Values // Section 9.10.2 Mapping Character Codes to Unicode Values
if (properties.toUnicode && properties.toUnicode.length !== 0) { if (properties.hasIncludedToUnicodeMap) {
return Promise.resolve(properties.toUnicode); return Promise.resolve(properties.toUnicode);
} }
// According to the spec if the font is a simple font we should only map // According to the spec if the font is a simple font we should only map
@ -49017,6 +49097,7 @@ exports.PartialEvaluator = PartialEvaluator;
coreColorSpace, coreObj, coreEvaluator) { coreColorSpace, coreObj, coreEvaluator) {
var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType; var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
var AnnotationFlag = sharedUtil.AnnotationFlag; var AnnotationFlag = sharedUtil.AnnotationFlag;
var AnnotationType = sharedUtil.AnnotationType; var AnnotationType = sharedUtil.AnnotationType;
var OPS = sharedUtil.OPS; var OPS = sharedUtil.OPS;
@ -49049,10 +49130,14 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
/** /**
* @param {XRef} xref * @param {XRef} xref
* @param {Object} ref * @param {Object} ref
* @param {string} uniquePrefix
* @param {Object} idCounters
* @param {boolean} renderInteractiveForms
* @returns {Annotation} * @returns {Annotation}
*/ */
create: function AnnotationFactory_create(xref, ref, create: function AnnotationFactory_create(xref, ref,
uniquePrefix, idCounters) { uniquePrefix, idCounters,
renderInteractiveForms) {
var dict = xref.fetchIfRef(ref); var dict = xref.fetchIfRef(ref);
if (!isDict(dict)) { if (!isDict(dict)) {
return; return;
@ -49071,6 +49156,7 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
ref: isRef(ref) ? ref : null, ref: isRef(ref) ? ref : null,
subtype: subtype, subtype: subtype,
id: id, id: id,
renderInteractiveForms: renderInteractiveForms,
}; };
switch (subtype) { switch (subtype) {
@ -49605,9 +49691,13 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() {
data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || ''; data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
var fieldType = Util.getInheritableProperty(dict, 'FT'); var fieldType = Util.getInheritableProperty(dict, 'FT');
data.fieldType = isName(fieldType) ? fieldType.name : null; data.fieldType = isName(fieldType) ? fieldType.name : null;
data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty; this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
data.fieldFlags = 0;
}
// Hide signatures because we cannot validate them. // Hide signatures because we cannot validate them.
if (data.fieldType === 'Sig') { if (data.fieldType === 'Sig') {
this.setFlags(AnnotationFlag.HIDDEN); this.setFlags(AnnotationFlag.HIDDEN);
@ -49646,7 +49736,22 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() {
data.fullName = fieldName.join('.'); data.fullName = fieldName.join('.');
} }
Util.inherit(WidgetAnnotation, Annotation, {}); Util.inherit(WidgetAnnotation, Annotation, {
/**
* Check if a provided field flag is set.
*
* @public
* @memberof WidgetAnnotation
* @param {number} flag - Bit position, numbered from one instead of
* zero, to check
* @return {boolean}
* @see {@link shared/util.js}
*/
hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
var mask = 1 << (flag - 1);
return !!(this.data.fieldFlags & mask);
},
});
return WidgetAnnotation; return WidgetAnnotation;
})(); })();
@ -49655,6 +49760,8 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
function TextWidgetAnnotation(params) { function TextWidgetAnnotation(params) {
WidgetAnnotation.call(this, params); WidgetAnnotation.call(this, params);
this.renderInteractiveForms = params.renderInteractiveForms;
// Determine the alignment of text in the field. // Determine the alignment of text in the field.
var alignment = Util.getInheritableProperty(params.dict, 'Q'); var alignment = Util.getInheritableProperty(params.dict, 'Q');
if (!isInt(alignment) || alignment < 0 || alignment > 2) { if (!isInt(alignment) || alignment < 0 || alignment > 2) {
@ -49668,29 +49775,38 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
maximumLength = null; maximumLength = null;
} }
this.data.maxLen = maximumLength; this.data.maxLen = maximumLength;
// Process field flags for the display layer.
this.data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
} }
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, { Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator, getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
task) { task) {
var operatorList = new OperatorList();
// Do not render form elements on the canvas when interactive forms are
// enabled. The display layer is responsible for rendering them instead.
if (this.renderInteractiveForms) {
return Promise.resolve(operatorList);
}
if (this.appearance) { if (this.appearance) {
return Annotation.prototype.getOperatorList.call(this, evaluator, task); return Annotation.prototype.getOperatorList.call(this, evaluator, task);
} }
var opList = new OperatorList();
var data = this.data;
// Even if there is an appearance stream, ignore it. This is the // Even if there is an appearance stream, ignore it. This is the
// behaviour used by Adobe Reader. // behaviour used by Adobe Reader.
if (!data.defaultAppearance) { if (!this.data.defaultAppearance) {
return Promise.resolve(opList); return Promise.resolve(operatorList);
} }
var stream = new Stream(stringToBytes(data.defaultAppearance)); var stream = new Stream(stringToBytes(this.data.defaultAppearance));
return evaluator.getOperatorList(stream, task, return evaluator.getOperatorList(stream, task, this.fieldResources,
this.fieldResources, opList). operatorList).
then(function () { then(function () {
return opList; return operatorList;
}); });
} }
}); });
@ -50137,7 +50253,8 @@ var Page = (function PageClosure() {
}.bind(this)); }.bind(this));
}, },
getOperatorList: function Page_getOperatorList(handler, task, intent) { getOperatorList: function Page_getOperatorList(handler, task, intent,
renderInteractiveForms) {
var self = this; var self = this;
var pdfManager = this.pdfManager; var pdfManager = this.pdfManager;
@ -50177,6 +50294,8 @@ var Page = (function PageClosure() {
}); });
}); });
this.renderInteractiveForms = renderInteractiveForms;
var annotationsPromise = pdfManager.ensure(this, 'annotations'); var annotationsPromise = pdfManager.ensure(this, 'annotations');
return Promise.all([pageListPromise, annotationsPromise]).then( return Promise.all([pageListPromise, annotationsPromise]).then(
function(datas) { function(datas) {
@ -50260,7 +50379,8 @@ var Page = (function PageClosure() {
var annotationRef = annotationRefs[i]; var annotationRef = annotationRefs[i];
var annotation = annotationFactory.create(this.xref, annotationRef, var annotation = annotationFactory.create(this.xref, annotationRef,
this.uniquePrefix, this.uniquePrefix,
this.idCounters); this.idCounters,
this.renderInteractiveForms);
if (annotation) { if (annotation) {
annotations.push(annotation); annotations.push(annotation);
} }
@ -51447,7 +51567,8 @@ var WorkerMessageHandler = {
var pageNum = pageIndex + 1; var pageNum = pageIndex + 1;
var start = Date.now(); var start = Date.now();
// Pre compile the pdf page and fetch the fonts/images. // Pre compile the pdf page and fetch the fonts/images.
page.getOperatorList(handler, task, data.intent).then( page.getOperatorList(handler, task, data.intent,
data.renderInteractiveForms).then(
function(operatorList) { function(operatorList) {
finishWorkerTask(task); finishWorkerTask(task);

110
build/pdf.js

@ -28,8 +28,8 @@ factory((root.pdfjsDistBuildPdf = {}));
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
'use strict'; 'use strict';
var pdfjsVersion = '1.5.458'; var pdfjsVersion = '1.5.477';
var pdfjsBuild = 'a7c3502'; var pdfjsBuild = '9e927de';
var pdfjsFilePath = var pdfjsFilePath =
typeof document !== 'undefined' && document.currentScript ? typeof document !== 'undefined' && document.currentScript ?
@ -114,6 +114,28 @@ var AnnotationFlag = {
LOCKEDCONTENTS: 0x200 LOCKEDCONTENTS: 0x200
}; };
var AnnotationFieldFlag = {
READONLY: 1,
REQUIRED: 2,
NOEXPORT: 3,
MULTILINE: 13,
PASSWORD: 14,
NOTOGGLETOOFF: 15,
RADIO: 16,
PUSHBUTTON: 17,
COMBO: 18,
EDIT: 19,
SORT: 20,
FILESELECT: 21,
MULTISELECT: 22,
DONOTSPELLCHECK: 23,
DONOTSCROLL: 24,
COMB: 25,
RICHTEXT: 26,
RADIOSINUNISON: 26,
COMMITONSELCHANGE: 27,
};
var AnnotationBorderStyleType = { var AnnotationBorderStyleType = {
SOLID: 1, SOLID: 1,
DASHED: 2, DASHED: 2,
@ -2375,6 +2397,7 @@ exports.OPS = OPS;
exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS; exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES; exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
exports.AnnotationBorderStyleType = AnnotationBorderStyleType; exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
exports.AnnotationFieldFlag = AnnotationFieldFlag;
exports.AnnotationFlag = AnnotationFlag; exports.AnnotationFlag = AnnotationFlag;
exports.AnnotationType = AnnotationType; exports.AnnotationType = AnnotationType;
exports.FontType = FontType; exports.FontType = FontType;
@ -4697,7 +4720,9 @@ var TextAnnotationElement = (function TextAnnotationElementClosure() {
*/ */
var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() { var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
function WidgetAnnotationElement(parameters) { function WidgetAnnotationElement(parameters) {
AnnotationElement.call(this, parameters, true); var isRenderable = parameters.renderInteractiveForms ||
(!parameters.data.hasAppearance && !!parameters.data.fieldValue);
AnnotationElement.call(this, parameters, isRenderable);
} }
Util.inherit(WidgetAnnotationElement, AnnotationElement, { Util.inherit(WidgetAnnotationElement, AnnotationElement, {
@ -4742,9 +4767,15 @@ var TextWidgetAnnotationElement = (
var element = null; var element = null;
if (this.renderInteractiveForms) { if (this.renderInteractiveForms) {
element = document.createElement('input'); if (this.data.multiLine) {
element.type = 'text'; element = document.createElement('textarea');
} else {
element = document.createElement('input');
element.type = 'text';
}
element.value = this.data.fieldValue; element.value = this.data.fieldValue;
element.disabled = this.data.readOnly;
if (this.data.maxLen !== null) { if (this.data.maxLen !== null) {
element.maxLength = this.data.maxLen; element.maxLength = this.data.maxLen;
@ -5300,14 +5331,20 @@ var renderTextLayer = (function renderTextLayerClosure() {
return !NonWhitespaceRegexp.test(str); return !NonWhitespaceRegexp.test(str);
} }
// Text layers may contain many thousand div's, and using `styleBuf` avoids
// creating many intermediate strings when building their 'style' properties.
var styleBuf = ['left: ', 0, 'px; top: ', 0, 'px; font-size: ', 0,
'px; font-family: ', '', ';'];
function appendText(task, geom, styles) { function appendText(task, geom, styles) {
// Initialize all used properties to keep the caches monomorphic. // Initialize all used properties to keep the caches monomorphic.
var textDiv = document.createElement('div'); var textDiv = document.createElement('div');
var textDivProperties = { var textDivProperties = {
style: null,
angle: 0, angle: 0,
canvasWidth: 0, canvasWidth: 0,
isWhitespace: false, isWhitespace: false,
originalTransform: '', originalTransform: null,
paddingBottom: 0, paddingBottom: 0,
paddingLeft: 0, paddingLeft: 0,
paddingRight: 0, paddingRight: 0,
@ -5345,10 +5382,12 @@ var renderTextLayer = (function renderTextLayerClosure() {
left = tx[4] + (fontAscent * Math.sin(angle)); left = tx[4] + (fontAscent * Math.sin(angle));
top = tx[5] - (fontAscent * Math.cos(angle)); top = tx[5] - (fontAscent * Math.cos(angle));
} }
textDiv.style.left = left + 'px'; styleBuf[1] = left;
textDiv.style.top = top + 'px'; styleBuf[3] = top;
textDiv.style.fontSize = fontHeight + 'px'; styleBuf[5] = fontHeight;
textDiv.style.fontFamily = style.fontFamily; styleBuf[7] = style.fontFamily;
textDivProperties.style = styleBuf.join('');
textDiv.setAttribute('style', textDivProperties.style);
textDiv.textContent = geom.str; textDiv.textContent = geom.str;
// |fontName| is only used by the Font Inspector. This test will succeed // |fontName| is only used by the Font Inspector. This test will succeed
@ -5756,7 +5795,6 @@ var renderTextLayer = (function renderTextLayerClosure() {
this._renderTimer = null; this._renderTimer = null;
this._bounds = []; this._bounds = [];
this._enhanceTextSelection = !!enhanceTextSelection; this._enhanceTextSelection = !!enhanceTextSelection;
this._expanded = false;
} }
TextLayerRenderTask.prototype = { TextLayerRenderTask.prototype = {
get promise() { get promise() {
@ -5794,18 +5832,20 @@ var renderTextLayer = (function renderTextLayerClosure() {
if (!this._enhanceTextSelection || !this._renderingDone) { if (!this._enhanceTextSelection || !this._renderingDone) {
return; return;
} }
if (!this._expanded) { if (this._bounds !== null) {
expand(this); expand(this);
this._expanded = true; this._bounds = null;
this._bounds.length = 0;
} }
for (var i = 0, ii = this._textDivs.length; i < ii; i++) { for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
var div = this._textDivs[i]; var div = this._textDivs[i];
var divProperties = this._textDivProperties.get(div); var divProperties = this._textDivProperties.get(div);
if (divProperties.isWhitespace) {
continue;
}
if (expandDivs) { if (expandDivs) {
var transform = ''; var transform = '', padding = '';
if (divProperties.scale !== 1) { if (divProperties.scale !== 1) {
transform = 'scaleX(' + divProperties.scale + ')'; transform = 'scaleX(' + divProperties.scale + ')';
@ -5814,21 +5854,26 @@ var renderTextLayer = (function renderTextLayerClosure() {
transform = 'rotate(' + divProperties.angle + 'deg) ' + transform; transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
} }
if (divProperties.paddingLeft !== 0) { if (divProperties.paddingLeft !== 0) {
div.style.paddingLeft = padding += ' padding-left: ' +
(divProperties.paddingLeft / divProperties.scale) + 'px'; (divProperties.paddingLeft / divProperties.scale) + 'px;';
transform += ' translateX(' + transform += ' translateX(' +
(-divProperties.paddingLeft / divProperties.scale) + 'px)'; (-divProperties.paddingLeft / divProperties.scale) + 'px)';
} }
if (divProperties.paddingTop !== 0) { if (divProperties.paddingTop !== 0) {
div.style.paddingTop = divProperties.paddingTop + 'px'; padding += ' padding-top: ' + divProperties.paddingTop + 'px;';
transform += ' translateY(' + (-divProperties.paddingTop) + 'px)'; transform += ' translateY(' + (-divProperties.paddingTop) + 'px)';
} }
if (divProperties.paddingRight !== 0) { if (divProperties.paddingRight !== 0) {
div.style.paddingRight = padding += ' padding-right: ' +
(divProperties.paddingRight / divProperties.scale) + 'px'; (divProperties.paddingRight / divProperties.scale) + 'px;';
} }
if (divProperties.paddingBottom !== 0) { if (divProperties.paddingBottom !== 0) {
div.style.paddingBottom = divProperties.paddingBottom + 'px'; padding += ' padding-bottom: ' +
divProperties.paddingBottom + 'px;';
}
if (padding !== '') {
div.setAttribute('style', divProperties.style + padding);
} }
if (transform !== '') { if (transform !== '') {
CustomStyle.setProp('transform', div, transform); CustomStyle.setProp('transform', div, transform);
@ -5836,7 +5881,7 @@ var renderTextLayer = (function renderTextLayerClosure() {
} else { } else {
div.style.padding = 0; div.style.padding = 0;
CustomStyle.setProp('transform', div, CustomStyle.setProp('transform', div,
divProperties.originalTransform); divProperties.originalTransform || '');
} }
} }
}, },
@ -7361,9 +7406,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
if (sourceCtx.setLineDash !== undefined) { if (sourceCtx.setLineDash !== undefined) {
destCtx.setLineDash(sourceCtx.getLineDash()); destCtx.setLineDash(sourceCtx.getLineDash());
destCtx.lineDashOffset = sourceCtx.lineDashOffset; destCtx.lineDashOffset = sourceCtx.lineDashOffset;
} else if (sourceCtx.mozDashOffset !== undefined) {
destCtx.mozDash = sourceCtx.mozDash;
destCtx.mozDashOffset = sourceCtx.mozDashOffset;
} }
} }
@ -7619,9 +7661,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
if (ctx.setLineDash !== undefined) { if (ctx.setLineDash !== undefined) {
ctx.setLineDash(dashArray); ctx.setLineDash(dashArray);
ctx.lineDashOffset = dashPhase; ctx.lineDashOffset = dashPhase;
} else {
ctx.mozDash = dashArray;
ctx.mozDashOffset = dashPhase;
} }
}, },
setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) { setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
@ -9691,6 +9730,9 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* calling of PDFPage.getViewport method. * calling of PDFPage.getViewport method.
* @property {string} intent - Rendering intent, can be 'display' or 'print' * @property {string} intent - Rendering intent, can be 'display' or 'print'
* (default value is 'display'). * (default value is 'display').
* @property {boolean} renderInteractiveForms - (optional) Whether or not
* interactive form elements are rendered in the display
* layer. If so, we do not render them on canvas as well.
* @property {Array} transform - (optional) Additional transform, applied * @property {Array} transform - (optional) Additional transform, applied
* just before viewport transform. * just before viewport transform.
* @property {Object} imageLayer - (optional) An object that has beginLayout, * @property {Object} imageLayer - (optional) An object that has beginLayout,
@ -9799,6 +9841,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
this.pendingCleanup = false; this.pendingCleanup = false;
var renderingIntent = (params.intent === 'print' ? 'print' : 'display'); var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
var renderInteractiveForms = (params.renderInteractiveForms === true ?
true : /* Default */ false);
if (!this.intentStates[renderingIntent]) { if (!this.intentStates[renderingIntent]) {
this.intentStates[renderingIntent] = Object.create(null); this.intentStates[renderingIntent] = Object.create(null);
@ -9819,7 +9863,8 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
this.stats.time('Page Request'); this.stats.time('Page Request');
this.transport.messageHandler.send('RenderPageRequest', { this.transport.messageHandler.send('RenderPageRequest', {
pageIndex: this.pageNumber - 1, pageIndex: this.pageNumber - 1,
intent: renderingIntent intent: renderingIntent,
renderInteractiveForms: renderInteractiveForms,
}); });
} }
@ -11362,13 +11407,6 @@ exports._UnsupportedManager = _UnsupportedManager;
PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ? PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
true : PDFJS.isEvalSupported); true : PDFJS.isEvalSupported);
/**
* Renders interactive form elements.
* @var {boolean}
*/
PDFJS.renderInteractiveForms = (PDFJS.renderInteractiveForms === undefined ?
false : PDFJS.renderInteractiveForms);
var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow; var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow;
delete PDFJS.openExternalLinksInNewWindow; delete PDFJS.openExternalLinksInNewWindow;
Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', { Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', {

156
build/pdf.worker.js vendored

@ -28,8 +28,8 @@ factory((root.pdfjsDistBuildPdfWorker = {}));
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
'use strict'; 'use strict';
var pdfjsVersion = '1.5.458'; var pdfjsVersion = '1.5.477';
var pdfjsBuild = 'a7c3502'; var pdfjsBuild = '9e927de';
var pdfjsFilePath = var pdfjsFilePath =
typeof document !== 'undefined' && document.currentScript ? typeof document !== 'undefined' && document.currentScript ?
@ -1100,6 +1100,28 @@ var AnnotationFlag = {
LOCKEDCONTENTS: 0x200 LOCKEDCONTENTS: 0x200
}; };
var AnnotationFieldFlag = {
READONLY: 1,
REQUIRED: 2,
NOEXPORT: 3,
MULTILINE: 13,
PASSWORD: 14,
NOTOGGLETOOFF: 15,
RADIO: 16,
PUSHBUTTON: 17,
COMBO: 18,
EDIT: 19,
SORT: 20,
FILESELECT: 21,
MULTISELECT: 22,
DONOTSPELLCHECK: 23,
DONOTSCROLL: 24,
COMB: 25,
RICHTEXT: 26,
RADIOSINUNISON: 26,
COMMITONSELCHANGE: 27,
};
var AnnotationBorderStyleType = { var AnnotationBorderStyleType = {
SOLID: 1, SOLID: 1,
DASHED: 2, DASHED: 2,
@ -3361,6 +3383,7 @@ exports.OPS = OPS;
exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS; exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES; exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
exports.AnnotationBorderStyleType = AnnotationBorderStyleType; exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
exports.AnnotationFieldFlag = AnnotationFieldFlag;
exports.AnnotationFlag = AnnotationFlag; exports.AnnotationFlag = AnnotationFlag;
exports.AnnotationType = AnnotationType; exports.AnnotationType = AnnotationType;
exports.FontType = FontType; exports.FontType = FontType;
@ -27991,6 +28014,30 @@ function adjustWidths(properties) {
properties.defaultWidth *= scale; properties.defaultWidth *= scale;
} }
function adjustToUnicode(properties, builtInEncoding) {
if (properties.hasIncludedToUnicodeMap) {
return; // The font dictionary has a `ToUnicode` entry.
}
if (properties.hasEncoding) {
return; // The font dictionary has an `Encoding` entry.
}
if (builtInEncoding === properties.defaultEncoding) {
return; // No point in trying to adjust `toUnicode` if the encodings match.
}
if (properties.toUnicode instanceof IdentityToUnicodeMap) {
return;
}
var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
for (var charCode in builtInEncoding) {
var glyphName = builtInEncoding[charCode];
var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
if (unicode !== -1) {
toUnicode[charCode] = String.fromCharCode(unicode);
}
}
properties.toUnicode.amend(toUnicode);
}
function getFontType(type, subtype) { function getFontType(type, subtype) {
switch (type) { switch (type) {
case 'Type1': case 'Type1':
@ -28089,7 +28136,13 @@ var ToUnicodeMap = (function ToUnicodeMapClosure() {
charCodeOf: function(v) { charCodeOf: function(v) {
return this._map.indexOf(v); return this._map.indexOf(v);
} },
amend: function (map) {
for (var charCode in map) {
this._map[charCode] = map[charCode];
}
},
}; };
return ToUnicodeMap; return ToUnicodeMap;
@ -28125,7 +28178,11 @@ var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
charCodeOf: function (v) { charCodeOf: function (v) {
return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1; return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
} },
amend: function (map) {
error('Should not call amend()');
},
}; };
return IdentityToUnicodeMap; return IdentityToUnicodeMap;
@ -28526,6 +28583,7 @@ var Font = (function FontClosure() {
this.fontMatrix = properties.fontMatrix; this.fontMatrix = properties.fontMatrix;
this.widths = properties.widths; this.widths = properties.widths;
this.defaultWidth = properties.defaultWidth; this.defaultWidth = properties.defaultWidth;
this.toUnicode = properties.toUnicode;
this.encoding = properties.baseEncoding; this.encoding = properties.baseEncoding;
this.seacMap = properties.seacMap; this.seacMap = properties.seacMap;
@ -30147,10 +30205,8 @@ var Font = (function FontClosure() {
} else { } else {
// Most of the following logic in this code branch is based on the // Most of the following logic in this code branch is based on the
// 9.6.6.4 of the PDF spec. // 9.6.6.4 of the PDF spec.
var hasEncoding = var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont,
properties.differences.length > 0 || !!properties.baseEncodingName; properties.hasEncoding);
var cmapTable =
readCmapTable(tables['cmap'], font, this.isSymbolicFont, hasEncoding);
var cmapPlatformId = cmapTable.platformId; var cmapPlatformId = cmapTable.platformId;
var cmapEncodingId = cmapTable.encodingId; var cmapEncodingId = cmapTable.encodingId;
var cmapMappings = cmapTable.mappings; var cmapMappings = cmapTable.mappings;
@ -30159,7 +30215,7 @@ var Font = (function FontClosure() {
// The spec seems to imply that if the font is symbolic the encoding // The spec seems to imply that if the font is symbolic the encoding
// should be ignored, this doesn't appear to work for 'preistabelle.pdf' // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
// where the the font is symbolic and it has an encoding. // where the the font is symbolic and it has an encoding.
if (hasEncoding && if (properties.hasEncoding &&
(cmapPlatformId === 3 && cmapEncodingId === 1 || (cmapPlatformId === 3 && cmapEncodingId === 1 ||
cmapPlatformId === 1 && cmapEncodingId === 0) || cmapPlatformId === 1 && cmapEncodingId === 0) ||
(cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
@ -30323,6 +30379,12 @@ var Font = (function FontClosure() {
// TODO: Check the charstring widths to determine this. // TODO: Check the charstring widths to determine this.
properties.fixedPitch = false; properties.fixedPitch = false;
if (properties.builtInEncoding) {
// For Type1 fonts that do not include either `ToUnicode` or `Encoding`
// data, attempt to use the `builtInEncoding` to improve text selection.
adjustToUnicode(properties, properties.builtInEncoding);
}
var mapping = font.getGlyphMapping(properties); var mapping = font.getGlyphMapping(properties);
var newMapping = adjustMapping(mapping, properties); var newMapping = adjustMapping(mapping, properties);
this.toFontChar = newMapping.toFontChar; this.toFontChar = newMapping.toFontChar;
@ -38599,6 +38661,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
properties.differences = differences; properties.differences = differences;
properties.baseEncodingName = baseEncodingName; properties.baseEncodingName = baseEncodingName;
properties.hasEncoding = !!baseEncodingName || differences.length > 0;
properties.dict = dict; properties.dict = dict;
return toUnicodePromise.then(function(toUnicode) { return toUnicodePromise.then(function(toUnicode) {
properties.toUnicode = toUnicode; properties.toUnicode = toUnicode;
@ -38616,8 +38679,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
* {ToUnicodeMap|IdentityToUnicodeMap} object. * {ToUnicodeMap|IdentityToUnicodeMap} object.
*/ */
buildToUnicode: function PartialEvaluator_buildToUnicode(properties) { buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
properties.hasIncludedToUnicodeMap =
!!properties.toUnicode && properties.toUnicode.length > 0;
// Section 9.10.2 Mapping Character Codes to Unicode Values // Section 9.10.2 Mapping Character Codes to Unicode Values
if (properties.toUnicode && properties.toUnicode.length !== 0) { if (properties.hasIncludedToUnicodeMap) {
return Promise.resolve(properties.toUnicode); return Promise.resolve(properties.toUnicode);
} }
// According to the spec if the font is a simple font we should only map // According to the spec if the font is a simple font we should only map
@ -40162,6 +40227,7 @@ exports.PartialEvaluator = PartialEvaluator;
coreColorSpace, coreObj, coreEvaluator) { coreColorSpace, coreObj, coreEvaluator) {
var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType; var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
var AnnotationFlag = sharedUtil.AnnotationFlag; var AnnotationFlag = sharedUtil.AnnotationFlag;
var AnnotationType = sharedUtil.AnnotationType; var AnnotationType = sharedUtil.AnnotationType;
var OPS = sharedUtil.OPS; var OPS = sharedUtil.OPS;
@ -40194,10 +40260,14 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
/** /**
* @param {XRef} xref * @param {XRef} xref
* @param {Object} ref * @param {Object} ref
* @param {string} uniquePrefix
* @param {Object} idCounters
* @param {boolean} renderInteractiveForms
* @returns {Annotation} * @returns {Annotation}
*/ */
create: function AnnotationFactory_create(xref, ref, create: function AnnotationFactory_create(xref, ref,
uniquePrefix, idCounters) { uniquePrefix, idCounters,
renderInteractiveForms) {
var dict = xref.fetchIfRef(ref); var dict = xref.fetchIfRef(ref);
if (!isDict(dict)) { if (!isDict(dict)) {
return; return;
@ -40216,6 +40286,7 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
ref: isRef(ref) ? ref : null, ref: isRef(ref) ? ref : null,
subtype: subtype, subtype: subtype,
id: id, id: id,
renderInteractiveForms: renderInteractiveForms,
}; };
switch (subtype) { switch (subtype) {
@ -40750,9 +40821,13 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() {
data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || ''; data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
var fieldType = Util.getInheritableProperty(dict, 'FT'); var fieldType = Util.getInheritableProperty(dict, 'FT');
data.fieldType = isName(fieldType) ? fieldType.name : null; data.fieldType = isName(fieldType) ? fieldType.name : null;
data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty; this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
data.fieldFlags = 0;
}
// Hide signatures because we cannot validate them. // Hide signatures because we cannot validate them.
if (data.fieldType === 'Sig') { if (data.fieldType === 'Sig') {
this.setFlags(AnnotationFlag.HIDDEN); this.setFlags(AnnotationFlag.HIDDEN);
@ -40791,7 +40866,22 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() {
data.fullName = fieldName.join('.'); data.fullName = fieldName.join('.');
} }
Util.inherit(WidgetAnnotation, Annotation, {}); Util.inherit(WidgetAnnotation, Annotation, {
/**
* Check if a provided field flag is set.
*
* @public
* @memberof WidgetAnnotation
* @param {number} flag - Bit position, numbered from one instead of
* zero, to check
* @return {boolean}
* @see {@link shared/util.js}
*/
hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
var mask = 1 << (flag - 1);
return !!(this.data.fieldFlags & mask);
},
});
return WidgetAnnotation; return WidgetAnnotation;
})(); })();
@ -40800,6 +40890,8 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
function TextWidgetAnnotation(params) { function TextWidgetAnnotation(params) {
WidgetAnnotation.call(this, params); WidgetAnnotation.call(this, params);
this.renderInteractiveForms = params.renderInteractiveForms;
// Determine the alignment of text in the field. // Determine the alignment of text in the field.
var alignment = Util.getInheritableProperty(params.dict, 'Q'); var alignment = Util.getInheritableProperty(params.dict, 'Q');
if (!isInt(alignment) || alignment < 0 || alignment > 2) { if (!isInt(alignment) || alignment < 0 || alignment > 2) {
@ -40813,29 +40905,38 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
maximumLength = null; maximumLength = null;
} }
this.data.maxLen = maximumLength; this.data.maxLen = maximumLength;
// Process field flags for the display layer.
this.data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
} }
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, { Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator, getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
task) { task) {
var operatorList = new OperatorList();
// Do not render form elements on the canvas when interactive forms are
// enabled. The display layer is responsible for rendering them instead.
if (this.renderInteractiveForms) {
return Promise.resolve(operatorList);
}
if (this.appearance) { if (this.appearance) {
return Annotation.prototype.getOperatorList.call(this, evaluator, task); return Annotation.prototype.getOperatorList.call(this, evaluator, task);
} }
var opList = new OperatorList();
var data = this.data;
// Even if there is an appearance stream, ignore it. This is the // Even if there is an appearance stream, ignore it. This is the
// behaviour used by Adobe Reader. // behaviour used by Adobe Reader.
if (!data.defaultAppearance) { if (!this.data.defaultAppearance) {
return Promise.resolve(opList); return Promise.resolve(operatorList);
} }
var stream = new Stream(stringToBytes(data.defaultAppearance)); var stream = new Stream(stringToBytes(this.data.defaultAppearance));
return evaluator.getOperatorList(stream, task, return evaluator.getOperatorList(stream, task, this.fieldResources,
this.fieldResources, opList). operatorList).
then(function () { then(function () {
return opList; return operatorList;
}); });
} }
}); });
@ -41282,7 +41383,8 @@ var Page = (function PageClosure() {
}.bind(this)); }.bind(this));
}, },
getOperatorList: function Page_getOperatorList(handler, task, intent) { getOperatorList: function Page_getOperatorList(handler, task, intent,
renderInteractiveForms) {
var self = this; var self = this;
var pdfManager = this.pdfManager; var pdfManager = this.pdfManager;
@ -41322,6 +41424,8 @@ var Page = (function PageClosure() {
}); });
}); });
this.renderInteractiveForms = renderInteractiveForms;
var annotationsPromise = pdfManager.ensure(this, 'annotations'); var annotationsPromise = pdfManager.ensure(this, 'annotations');
return Promise.all([pageListPromise, annotationsPromise]).then( return Promise.all([pageListPromise, annotationsPromise]).then(
function(datas) { function(datas) {
@ -41405,7 +41509,8 @@ var Page = (function PageClosure() {
var annotationRef = annotationRefs[i]; var annotationRef = annotationRefs[i];
var annotation = annotationFactory.create(this.xref, annotationRef, var annotation = annotationFactory.create(this.xref, annotationRef,
this.uniquePrefix, this.uniquePrefix,
this.idCounters); this.idCounters,
this.renderInteractiveForms);
if (annotation) { if (annotation) {
annotations.push(annotation); annotations.push(annotation);
} }
@ -42592,7 +42697,8 @@ var WorkerMessageHandler = {
var pageNum = pageIndex + 1; var pageNum = pageIndex + 1;
var start = Date.now(); var start = Date.now();
// Pre compile the pdf page and fetch the fonts/images. // Pre compile the pdf page and fetch the fonts/images.
page.getOperatorList(handler, task, data.intent).then( page.getOperatorList(handler, task, data.intent,
data.renderInteractiveForms).then(
function(operatorList) { function(operatorList) {
finishWorkerTask(task); finishWorkerTask(task);

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.5.458", "version": "1.5.477",
"main": "build/pdf.js", "main": "build/pdf.js",
"description": "Generic build of Mozilla's PDF.js library.", "description": "Generic build of Mozilla's PDF.js library.",
"keywords": [ "keywords": [

22
web/pdf_viewer.css

@ -110,7 +110,8 @@
cursor: pointer; cursor: pointer;
} }
.annotationLayer .textWidgetAnnotation input { .annotationLayer .textWidgetAnnotation input,
.annotationLayer .textWidgetAnnotation textarea {
background-color: rgba(0, 54, 255, 0.13); background-color: rgba(0, 54, 255, 0.13);
border: 1px solid transparent; border: 1px solid transparent;
box-sizing: border-box; box-sizing: border-box;
@ -121,11 +122,26 @@
width: 100%; width: 100%;
} }
.annotationLayer .textWidgetAnnotation input:hover { .annotationLayer .textWidgetAnnotation textarea {
font: message-box;
font-size: 9px;
resize: none;
}
.annotationLayer .textWidgetAnnotation input[disabled],
.annotationLayer .textWidgetAnnotation textarea[disabled] {
background: none;
border: 1px solid transparent;
cursor: not-allowed;
}
.annotationLayer .textWidgetAnnotation input:hover,
.annotationLayer .textWidgetAnnotation textarea:hover {
border: 1px solid #000; border: 1px solid #000;
} }
.annotationLayer .textWidgetAnnotation input:focus { .annotationLayer .textWidgetAnnotation input:focus,
.annotationLayer .textWidgetAnnotation textarea:focus {
background: none; background: none;
border: 1px solid transparent; border: 1px solid transparent;
} }

26
web/pdf_viewer.js

@ -2285,6 +2285,8 @@ var TEXT_LAYER_RENDER_DELAY = 200; // ms
* @property {IPDFAnnotationLayerFactory} annotationLayerFactory * @property {IPDFAnnotationLayerFactory} annotationLayerFactory
* @property {boolean} enhanceTextSelection - Turns on the text selection * @property {boolean} enhanceTextSelection - Turns on the text selection
* enhancement. The default is `false`. * enhancement. The default is `false`.
* @property {boolean} renderInteractiveForms - Turns on rendering of
* interactive form elements. The default is `false`.
*/ */
/** /**
@ -2305,6 +2307,7 @@ var PDFPageView = (function PDFPageViewClosure() {
var textLayerFactory = options.textLayerFactory; var textLayerFactory = options.textLayerFactory;
var annotationLayerFactory = options.annotationLayerFactory; var annotationLayerFactory = options.annotationLayerFactory;
var enhanceTextSelection = options.enhanceTextSelection || false; var enhanceTextSelection = options.enhanceTextSelection || false;
var renderInteractiveForms = options.renderInteractiveForms || false;
this.id = id; this.id = id;
this.renderingId = 'page' + id; this.renderingId = 'page' + id;
@ -2315,6 +2318,7 @@ var PDFPageView = (function PDFPageViewClosure() {
this.pdfPageRotate = defaultViewport.rotation; this.pdfPageRotate = defaultViewport.rotation;
this.hasRestrictedScaling = false; this.hasRestrictedScaling = false;
this.enhanceTextSelection = enhanceTextSelection; this.enhanceTextSelection = enhanceTextSelection;
this.renderInteractiveForms = renderInteractiveForms;
this.eventBus = options.eventBus || domEvents.getGlobalEventBus(); this.eventBus = options.eventBus || domEvents.getGlobalEventBus();
this.renderingQueue = renderingQueue; this.renderingQueue = renderingQueue;
@ -2729,6 +2733,7 @@ var PDFPageView = (function PDFPageViewClosure() {
canvasContext: ctx, canvasContext: ctx,
transform: transform, transform: transform,
viewport: this.viewport, viewport: this.viewport,
renderInteractiveForms: this.renderInteractiveForms,
// intent: 'default', // === 'display' // intent: 'default', // === 'display'
}; };
var renderTask = this.renderTask = this.pdfPage.render(renderContext); var renderTask = this.renderTask = this.pdfPage.render(renderContext);
@ -2754,7 +2759,8 @@ var PDFPageView = (function PDFPageViewClosure() {
if (this.annotationLayerFactory) { if (this.annotationLayerFactory) {
if (!this.annotationLayer) { if (!this.annotationLayer) {
this.annotationLayer = this.annotationLayerFactory. this.annotationLayer = this.annotationLayerFactory.
createAnnotationLayerBuilder(div, this.pdfPage); createAnnotationLayerBuilder(div, this.pdfPage,
this.renderInteractiveForms);
} }
this.annotationLayer.render(this.viewport, 'display'); this.annotationLayer.render(this.viewport, 'display');
} }
@ -3217,6 +3223,7 @@ var SimpleLinkService = pdfLinkService.SimpleLinkService;
* @typedef {Object} AnnotationLayerBuilderOptions * @typedef {Object} AnnotationLayerBuilderOptions
* @property {HTMLDivElement} pageDiv * @property {HTMLDivElement} pageDiv
* @property {PDFPage} pdfPage * @property {PDFPage} pdfPage
* @property {boolean} renderInteractiveForms
* @property {IPDFLinkService} linkService * @property {IPDFLinkService} linkService
* @property {DownloadManager} downloadManager * @property {DownloadManager} downloadManager
*/ */
@ -3232,6 +3239,7 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
function AnnotationLayerBuilder(options) { function AnnotationLayerBuilder(options) {
this.pageDiv = options.pageDiv; this.pageDiv = options.pageDiv;
this.pdfPage = options.pdfPage; this.pdfPage = options.pdfPage;
this.renderInteractiveForms = options.renderInteractiveForms;
this.linkService = options.linkService; this.linkService = options.linkService;
this.downloadManager = options.downloadManager; this.downloadManager = options.downloadManager;
@ -3258,9 +3266,9 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
div: self.div, div: self.div,
annotations: annotations, annotations: annotations,
page: self.pdfPage, page: self.pdfPage,
renderInteractiveForms: self.renderInteractiveForms,
linkService: self.linkService, linkService: self.linkService,
downloadManager: self.downloadManager, downloadManager: self.downloadManager,
renderInteractiveForms: pdfjsLib.PDFJS.renderInteractiveForms,
}; };
if (self.div) { if (self.div) {
@ -3307,12 +3315,15 @@ DefaultAnnotationLayerFactory.prototype = {
/** /**
* @param {HTMLDivElement} pageDiv * @param {HTMLDivElement} pageDiv
* @param {PDFPage} pdfPage * @param {PDFPage} pdfPage
* @param {boolean} renderInteractiveForms
* @returns {AnnotationLayerBuilder} * @returns {AnnotationLayerBuilder}
*/ */
createAnnotationLayerBuilder: function (pageDiv, pdfPage) { createAnnotationLayerBuilder: function (pageDiv, pdfPage,
renderInteractiveForms) {
return new AnnotationLayerBuilder({ return new AnnotationLayerBuilder({
pageDiv: pageDiv, pageDiv: pageDiv,
pdfPage: pdfPage, pdfPage: pdfPage,
renderInteractiveForms: renderInteractiveForms,
linkService: new SimpleLinkService(), linkService: new SimpleLinkService(),
}); });
} }
@ -3374,6 +3385,8 @@ var DEFAULT_CACHE_SIZE = 10;
* around the pages. The default is false. * around the pages. The default is false.
* @property {boolean} enhanceTextSelection - (optional) Enables the improved * @property {boolean} enhanceTextSelection - (optional) Enables the improved
* text selection behaviour. The default is `false`. * text selection behaviour. The default is `false`.
* @property {boolean} renderInteractiveForms - (optional) Enables rendering of
* interactive form elements. The default is `false`.
*/ */
/** /**
@ -3426,6 +3439,7 @@ var PDFViewer = (function pdfViewer() {
this.downloadManager = options.downloadManager || null; this.downloadManager = options.downloadManager || null;
this.removePageBorders = options.removePageBorders || false; this.removePageBorders = options.removePageBorders || false;
this.enhanceTextSelection = options.enhanceTextSelection || false; this.enhanceTextSelection = options.enhanceTextSelection || false;
this.renderInteractiveForms = options.renderInteractiveForms || false;
this.defaultRenderingQueue = !options.renderingQueue; this.defaultRenderingQueue = !options.renderingQueue;
if (this.defaultRenderingQueue) { if (this.defaultRenderingQueue) {
@ -3653,6 +3667,7 @@ var PDFViewer = (function pdfViewer() {
textLayerFactory: textLayerFactory, textLayerFactory: textLayerFactory,
annotationLayerFactory: this, annotationLayerFactory: this,
enhanceTextSelection: this.enhanceTextSelection, enhanceTextSelection: this.enhanceTextSelection,
renderInteractiveForms: this.renderInteractiveForms,
}); });
bindOnAfterAndBeforeDraw(pageView); bindOnAfterAndBeforeDraw(pageView);
this._pages.push(pageView); this._pages.push(pageView);
@ -4150,12 +4165,15 @@ var PDFViewer = (function pdfViewer() {
/** /**
* @param {HTMLDivElement} pageDiv * @param {HTMLDivElement} pageDiv
* @param {PDFPage} pdfPage * @param {PDFPage} pdfPage
* @param {boolean} renderInteractiveForms
* @returns {AnnotationLayerBuilder} * @returns {AnnotationLayerBuilder}
*/ */
createAnnotationLayerBuilder: function (pageDiv, pdfPage) { createAnnotationLayerBuilder: function (pageDiv, pdfPage,
renderInteractiveForms) {
return new AnnotationLayerBuilder({ return new AnnotationLayerBuilder({
pageDiv: pageDiv, pageDiv: pageDiv,
pdfPage: pdfPage, pdfPage: pdfPage,
renderInteractiveForms: renderInteractiveForms,
linkService: this.linkService, linkService: this.linkService,
downloadManager: this.downloadManager downloadManager: this.downloadManager
}); });

Loading…
Cancel
Save