Skip to content

Commit

Permalink
Bug 1772598 - Update PDF.js to 19539676813b5df6ca4726a1bfa6765193b106…
Browse files Browse the repository at this point in the history
…7c r=pdfjs-reviewers,Snuffleupagus

Differential Revision: https://phabricator.services.mozilla.com/D148307
  • Loading branch information
updatebot-ci committed Jun 5, 2022
1 parent d1fbd5e commit 1271c9a
Show file tree
Hide file tree
Showing 7 changed files with 457 additions and 328 deletions.
124 changes: 77 additions & 47 deletions toolkit/components/pdfjs/content/build/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
exports["pdfjs-dist/build/pdf"] = factory();
else
root["pdfjs-dist/build/pdf"] = root.pdfjsLib = factory();
})(this, () => {
})(globalThis, () => {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ([
Expand All @@ -42,7 +42,7 @@ return /******/ (() => { // webpackBootstrap
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports.VerbosityLevel = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.UNSUPPORTED_FEATURES = exports.TextRenderingMode = exports.StreamType = exports.RenderingIntentFlag = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FontType = exports.FeatureTest = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMode = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
exports.VerbosityLevel = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.UNSUPPORTED_FEATURES = exports.TextRenderingMode = exports.StreamType = exports.RenderingIntentFlag = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.LINE_FACTOR = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FontType = exports.FeatureTest = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMode = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
exports.arrayByteLength = arrayByteLength;
exports.arraysToBytes = arraysToBytes;
exports.assert = assert;
Expand Down Expand Up @@ -75,6 +75,8 @@ const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
const LINE_FACTOR = 1.35;
exports.LINE_FACTOR = LINE_FACTOR;
const RenderingIntentFlag = {
ANY: 0x01,
DISPLAY: 0x02,
Expand Down Expand Up @@ -1341,7 +1343,7 @@ async function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {

const workerId = await worker.messageHandler.sendWithPromise("GetDocRequest", {
docId,
apiVersion: '2.14.290',
apiVersion: '2.15.51',
source: {
data: source.data,
url: source.url,
Expand All @@ -1362,6 +1364,10 @@ async function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
standardFontDataUrl: source.useWorkerFetch ? source.standardFontDataUrl : null
});

if (source.data) {
source.data = null;
}

if (worker.destroyed) {
throw new Error("Worker was destroyed");
}
Expand Down Expand Up @@ -3365,9 +3371,9 @@ class InternalRenderTask {

}

const version = '2.14.290';
const version = '2.15.51';
exports.version = version;
const build = '38c82357b';
const build = '195396768';
exports.build = build;

/***/ }),
Expand Down Expand Up @@ -9270,6 +9276,7 @@ var _scripting_utils = __w_pdfjs_require__(20);
var _xfa_layer = __w_pdfjs_require__(21);

const DEFAULT_TAB_INDEX = 1000;
const DEFAULT_FONT_SIZE = 9;
const GetElementsByNameSet = new WeakSet();

function getRectDims(rect) {
Expand Down Expand Up @@ -9470,10 +9477,10 @@ class AnnotationElement {
break;
}

const borderColor = data.borderColor || data.color || null;
const borderColor = data.borderColor || null;

if (borderColor) {
container.style.borderColor = _util.Util.makeHexColor(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
container.style.borderColor = _util.Util.makeHexColor(borderColor[0] | 0, borderColor[1] | 0, borderColor[2] | 0);
} else {
container.style.borderWidth = 0;
}
Expand Down Expand Up @@ -9733,12 +9740,12 @@ class AnnotationElement {

class LinkAnnotationElement extends AnnotationElement {
constructor(parameters, options = null) {
const isRenderable = !!(parameters.data.url || parameters.data.dest || parameters.data.action || parameters.data.isTooltipOnly || parameters.data.resetForm || parameters.data.actions && (parameters.data.actions.Action || parameters.data.actions["Mouse Up"] || parameters.data.actions["Mouse Down"]));
super(parameters, {
isRenderable,
isRenderable: true,
ignoreBorder: !!options?.ignoreBorder,
createQuadrilaterals: true
});
this.isTooltipOnly = parameters.data.isTooltipOnly;
}

render() {
Expand All @@ -9747,26 +9754,34 @@ class LinkAnnotationElement extends AnnotationElement {
linkService
} = this;
const link = document.createElement("a");
let isBound = false;

if (data.url) {
linkService.addLinkAttributes(link, data.url, data.newWindow);
isBound = true;
} else if (data.action) {
this._bindNamedAction(link, data.action);

isBound = true;
} else if (data.dest) {
this._bindLink(link, data.dest);
} else {
let hasClickAction = false;

isBound = true;
} else {
if (data.actions && (data.actions.Action || data.actions["Mouse Up"] || data.actions["Mouse Down"]) && this.enableScripting && this.hasJSActions) {
hasClickAction = true;

this._bindJSAction(link, data);

isBound = true;
}

if (data.resetForm) {
this._bindResetFormAction(link, data.resetForm);
} else if (!hasClickAction) {

isBound = true;
} else if (this.isTooltipOnly && !isBound) {
this._bindLink(link, "");

isBound = true;
}
}

Expand All @@ -9779,7 +9794,11 @@ class LinkAnnotationElement extends AnnotationElement {
}

this.container.className = "linkAnnotation";
this.container.appendChild(link);

if (isBound) {
this.container.appendChild(link);
}

return this.container;
}

Expand Down Expand Up @@ -10054,6 +10073,31 @@ class WidgetAnnotationElement extends AnnotationElement {
element.style.backgroundColor = color === null ? "transparent" : _util.Util.makeHexColor(color[0], color[1], color[2]);
}

_setTextStyle(element) {
const TEXT_ALIGNMENT = ["left", "center", "right"];
const {
fontColor
} = this.data.defaultAppearanceData;
const fontSize = this.data.defaultAppearanceData.fontSize || DEFAULT_FONT_SIZE;
const style = element.style;

if (this.data.multiLine) {
const height = Math.abs(this.data.rect[3] - this.data.rect[1]);
const numberOfLines = Math.round(height / (_util.LINE_FACTOR * fontSize)) || 1;
const lineHeight = height / numberOfLines;
style.fontSize = `${Math.min(fontSize, Math.round(lineHeight / _util.LINE_FACTOR))}px`;
} else {
const height = Math.abs(this.data.rect[3] - this.data.rect[1]);
style.fontSize = `${Math.min(fontSize, Math.round(height / _util.LINE_FACTOR))}px`;
}

style.color = _util.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);

if (this.data.textAlignment !== null) {
style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
}
}

}

class TextWidgetAnnotationElement extends WidgetAnnotationElement {
Expand Down Expand Up @@ -10098,10 +10142,18 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
if (this.data.multiLine) {
element = document.createElement("textarea");
element.textContent = textContent;

if (this.data.doNotScroll) {
element.style.overflowY = "hidden";
}
} else {
element = document.createElement("input");
element.type = "text";
element.setAttribute("value", textContent);

if (this.data.doNotScroll) {
element.style.overflowX = "hidden";
}
}

GetElementsByNameSet.add(element);
Expand Down Expand Up @@ -10340,25 +10392,6 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
return this.container;
}

_setTextStyle(element) {
const TEXT_ALIGNMENT = ["left", "center", "right"];
const {
fontSize,
fontColor
} = this.data.defaultAppearanceData;
const style = element.style;

if (fontSize) {
style.fontSize = `${fontSize}px`;
}

style.color = _util.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);

if (this.data.textAlignment !== null) {
style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
}
}

}

class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
Expand Down Expand Up @@ -10581,22 +10614,14 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
const storedData = storage.getValue(id, {
value: this.data.fieldValue
});
let {
fontSize
} = this.data.defaultAppearanceData;

if (!fontSize) {
fontSize = 9;
}

const fontSize = this.data.defaultAppearanceData.fontSize || DEFAULT_FONT_SIZE;
const fontSizeStyle = `calc(${fontSize}px * var(--zoom-factor))`;
const selectElement = document.createElement("select");
GetElementsByNameSet.add(selectElement);
selectElement.disabled = this.data.readOnly;
selectElement.name = this.data.fieldName;
selectElement.setAttribute("id", id);
selectElement.tabIndex = DEFAULT_TAB_INDEX;
selectElement.style.fontSize = `${fontSize}px`;

if (!this.data.combo) {
selectElement.size = this.data.options.length;
Expand Down Expand Up @@ -10797,6 +10822,10 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
});
}

if (this.data.combo) {
this._setTextStyle(selectElement);
} else {}

this._setBackgroundColor(selectElement);

this._setDefaultPropertiesFromJS(selectElement);
Expand Down Expand Up @@ -11534,7 +11563,9 @@ class AnnotationLayer {
firstChild
} = element;

if (firstChild.nodeName === "CANVAS") {
if (!firstChild) {
element.appendChild(canvas);
} else if (firstChild.nodeName === "CANVAS") {
element.replaceChild(canvas, firstChild);
} else {
element.insertBefore(canvas, firstChild);
Expand Down Expand Up @@ -12509,7 +12540,6 @@ class TextLayerRenderTask {
const canvas = this._document.createElement("canvas");

canvas.height = canvas.width = DEFAULT_FONT_SIZE;
canvas.mozOpaque = true;
this._layoutTextCtx = canvas.getContext("2d", {
alpha: false
});
Expand Down Expand Up @@ -12926,8 +12956,8 @@ var _svg = __w_pdfjs_require__(23);

var _xfa_layer = __w_pdfjs_require__(21);

const pdfjsVersion = '2.14.290';
const pdfjsBuild = '38c82357b';
const pdfjsVersion = '2.15.51';
const pdfjsBuild = '195396768';
;
})();

Expand Down
25 changes: 22 additions & 3 deletions toolkit/components/pdfjs/content/build/pdf.scripting.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
exports["pdfjs-dist/build/pdf.scripting"] = factory();
else
root.pdfjsScripting = factory();
})(this, () => {
})(globalThis, () => {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ([
Expand Down Expand Up @@ -2638,6 +2638,10 @@ class EventDispatcher {
}

if (id === "doc") {
if (event.name === "Open") {
this.formatAll();
}

this._document.obj._dispatchDocEvent(event.name);
} else if (id === "page") {
this._document.obj._dispatchPageEvent(event.name, baseEvent.actions, baseEvent.pageNumber);
Expand Down Expand Up @@ -2740,6 +2744,21 @@ class EventDispatcher {
}
}

formatAll() {
const event = globalThis.event = new Event({});

for (const source of Object.values(this._objects)) {
event.value = source.obj.value;

if (this.runActions(source, source, event, "Format")) {
source.obj._send({
id: source.obj._id,
formattedValue: event.value?.toString?.()
});
}
}
}

runValidation(source, event) {
const didValidateRun = this.runActions(source, source, event, "Validate");

Expand Down Expand Up @@ -5020,8 +5039,8 @@ Object.defineProperty(exports, "initSandbox", ({

var _initialization = __w_pdfjs_require__(1);

const pdfjsVersion = '2.14.290';
const pdfjsBuild = '38c82357b';
const pdfjsVersion = '2.15.51';
const pdfjsBuild = '195396768';
})();

/******/ return __webpack_exports__;
Expand Down
Loading

0 comments on commit 1271c9a

Please sign in to comment.