Skip to content

Commit

Permalink
Bug 1823360 - Update PDF.js to new version 3903391f3cbed25806adc4a987…
Browse files Browse the repository at this point in the history
…4979f7725ec883 r=pdfjs-reviewers,marco

Differential Revision: https://phabricator.services.mozilla.com/D172989
  • Loading branch information
calixteman committed Mar 20, 2023
1 parent 126bc64 commit b292300
Show file tree
Hide file tree
Showing 10 changed files with 347 additions and 279 deletions.
415 changes: 232 additions & 183 deletions toolkit/components/pdfjs/content/build/pdf.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions toolkit/components/pdfjs/content/build/pdf.scripting.js
Original file line number Diff line number Diff line change
Expand Up @@ -4258,8 +4258,8 @@ Object.defineProperty(exports, "initSandbox", ({
}
}));
var _initialization = __w_pdfjs_require__(1);
const pdfjsVersion = '3.5.34';
const pdfjsBuild = 'a0ef5a4ae';
const pdfjsVersion = '3.5.73';
const pdfjsBuild = '3903391f3';
})();

/******/ return __webpack_exports__;
Expand Down
24 changes: 15 additions & 9 deletions toolkit/components/pdfjs/content/build/pdf.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class WorkerMessageHandler {
docId,
apiVersion
} = docParams;
const workerVersion = '3.5.34';
const workerVersion = '3.5.73';
if (apiVersion !== workerVersion) {
throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`);
}
Expand Down Expand Up @@ -630,7 +630,7 @@ if (typeof window === "undefined" && !_is_node.isNodeJS && typeof self !== "unde
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports.VerbosityLevel = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.RenderingIntentFlag = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.LINE_FACTOR = exports.LINE_DESCENT_FACTOR = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FeatureTest = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.BASELINE_FACTOR = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMode = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationEditorType = exports.AnnotationEditorPrefix = exports.AnnotationEditorParamsType = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
exports.VerbosityLevel = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.RenderingIntentFlag = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.PageActionEventType = exports.OPS = exports.MissingPDFException = exports.MAX_IMAGE_SIZE_TO_CACHE = exports.LINE_FACTOR = exports.LINE_DESCENT_FACTOR = exports.InvalidPDFException = exports.ImageKind = exports.IDENTITY_MATRIX = exports.FormatError = exports.FeatureTest = exports.FONT_IDENTITY_MATRIX = exports.DocumentActionEventType = exports.CMapCompressionType = exports.BaseException = exports.BASELINE_FACTOR = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMode = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationEditorType = exports.AnnotationEditorPrefix = exports.AnnotationEditorParamsType = exports.AnnotationBorderStyleType = exports.AnnotationActionEventType = exports.AbortException = void 0;
exports.assert = assert;
exports.bytesToString = bytesToString;
exports.createPromiseCapability = createPromiseCapability;
Expand All @@ -656,6 +656,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 MAX_IMAGE_SIZE_TO_CACHE = 10e6;
exports.MAX_IMAGE_SIZE_TO_CACHE = MAX_IMAGE_SIZE_TO_CACHE;
const LINE_FACTOR = 1.35;
exports.LINE_FACTOR = LINE_FACTOR;
const LINE_DESCENT_FACTOR = 0.35;
Expand Down Expand Up @@ -3187,7 +3189,6 @@ class Page {
const opList = new _operator_list.OperatorList(intent, sink);
handler.send("StartRenderPage", {
transparency: partialEvaluator.hasBlendModes(this.resources, this.nonBlendModesSet),
isOffscreenCanvasSupported: this.evaluatorOptions.isOffscreenCanvasSupported,
pageIndex: this.pageIndex,
cacheKey
});
Expand Down Expand Up @@ -33536,8 +33537,13 @@ class PostScriptEvaluator {
}
break;
case "atan":
b = stack.pop();
a = stack.pop();
stack.push(Math.atan(a));
a = Math.atan2(a, b) / Math.PI * 180;
if (a < 0) {
a += 360;
}
stack.push(a);
break;
case "bitshift":
b = stack.pop();
Expand All @@ -33558,7 +33564,7 @@ class PostScriptEvaluator {
break;
case "cos":
a = stack.pop();
stack.push(Math.cos(a));
stack.push(Math.cos(a % 360 / 180 * Math.PI));
break;
case "cvi":
a = stack.pop() | 0;
Expand Down Expand Up @@ -33681,7 +33687,7 @@ class PostScriptEvaluator {
break;
case "sin":
a = stack.pop();
stack.push(Math.sin(a));
stack.push(Math.sin(a % 360 / 180 * Math.PI));
break;
case "sqrt":
a = stack.pop();
Expand Down Expand Up @@ -34392,7 +34398,7 @@ class GlobalImageCache {
return (0, _util.shadow)(this, "MIN_IMAGES_TO_CACHE", 10);
}
static get MAX_BYTE_SIZE() {
return (0, _util.shadow)(this, "MAX_BYTE_SIZE", 40e6);
return (0, _util.shadow)(this, "MAX_BYTE_SIZE", 5 * _util.MAX_IMAGE_SIZE_TO_CACHE);
}
constructor() {
this._refCache = new _primitives.RefSetCache();
Expand Down Expand Up @@ -53009,8 +53015,8 @@ Object.defineProperty(exports, "WorkerMessageHandler", ({
}
}));
var _worker = __w_pdfjs_require__(1);
const pdfjsVersion = '3.5.34';
const pdfjsBuild = 'a0ef5a4ae';
const pdfjsVersion = '3.5.73';
const pdfjsBuild = '3903391f3';
})();

/******/ return __webpack_exports__;
Expand Down
9 changes: 3 additions & 6 deletions toolkit/components/pdfjs/content/web/viewer-geckoview.css
Original file line number Diff line number Diff line change
Expand Up @@ -986,8 +986,7 @@
.pdfViewer.scrollHorizontal,
.pdfViewer.scrollWrapped,
.spread {
margin-left: 3.5px;
margin-right: 3.5px;
margin-inline: 3.5px;
text-align: center;
}

Expand All @@ -998,8 +997,7 @@

.pdfViewer.scrollHorizontal .spread,
.pdfViewer.scrollWrapped .spread {
margin-left: 0;
margin-right: 0;
margin-inline: 0;
}

.spread .page,
Expand All @@ -1015,8 +1013,7 @@
.spread .page,
.pdfViewer.scrollHorizontal .page,
.pdfViewer.scrollWrapped .page {
margin-left: var(--spreadHorizontalWrapped-margin-LR);
margin-right: var(--spreadHorizontalWrapped-margin-LR);
margin-inline: var(--spreadHorizontalWrapped-margin-LR);
}

.pdfViewer .page canvas {
Expand Down
7 changes: 3 additions & 4 deletions toolkit/components/pdfjs/content/web/viewer-geckoview.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
<title>PDF.js viewer</title>

<!-- This snippet is used in the Firefox extension (included from viewer.html) -->
<base href="resource://pdf.js/web/">
<script src="../build/pdf.js"></script>
<script src="resource://pdf.js/build/pdf.js"></script>

<link rel="stylesheet" href="viewer.css">
<link rel="stylesheet" href="resource://pdf.js/web/viewer.css">

<script src="viewer.js"></script>
<script src="resource://pdf.js/web/viewer.js"></script>

</head>

Expand Down
73 changes: 42 additions & 31 deletions toolkit/components/pdfjs/content/web/viewer-geckoview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3343,7 +3343,7 @@ const defaultOptions = {
kind: OptionKind.WORKER
},
workerSrc: {
value: "../build/pdf.worker.js",
value: "resource://pdf.js/build/pdf.worker.js",
kind: OptionKind.WORKER
}
};
Expand Down Expand Up @@ -4340,17 +4340,19 @@ function normalize(text) {
return p4;
}
if (p5) {
positions.push([i - shift + 1, 1 + shift]);
const len = p5.length - 2;
positions.push([i - shift + len, 1 + shift]);
shift += 1;
shiftOrigin += 1;
eol += 1;
return p5.charAt(0);
return p5.slice(0, -2);
}
if (p6) {
positions.push([i - shift + 1, shift]);
const len = p6.length - 1;
positions.push([i - shift + len, shift]);
shiftOrigin += 1;
eol += 1;
return p6.charAt(0);
return p6.slice(0, -1);
}
if (p7) {
positions.push([i - shift + 1, shift - 1]);
Expand Down Expand Up @@ -6028,7 +6030,7 @@ class PDFViewer {
#onVisibilityChange = null;
#scaleTimeoutId = null;
constructor(options) {
const viewerVersion = '3.5.34';
const viewerVersion = '3.5.73';
if (_pdfjsLib.version !== viewerVersion) {
throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
}
Expand Down Expand Up @@ -7260,43 +7262,51 @@ class PDFViewer {
this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
return true;
}
increaseScale(options = null) {
increaseScale({
drawingDelay,
scaleFactor,
steps
} = {}) {
if (!this.pdfDocument) {
return;
}
options ||= Object.create(null);
let newScale = this._currentScale;
if (options.scaleFactor > 1) {
newScale = Math.min(_ui_utils.MAX_SCALE, Math.round(newScale * options.scaleFactor * 100) / 100);
if (scaleFactor > 1) {
newScale = Math.min(_ui_utils.MAX_SCALE, Math.round(newScale * scaleFactor * 100) / 100);
} else {
let steps = options.steps ?? 1;
steps ??= 1;
do {
newScale = (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
newScale = Math.ceil(newScale * 10) / 10;
newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
newScale = Math.min(_ui_utils.MAX_SCALE, Math.ceil(newScale * 10) / 10);
} while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
}
options.noScroll = false;
this._setScale(newScale, options);
this._setScale(newScale, {
noScroll: false,
drawingDelay
});
}
decreaseScale(options = null) {
decreaseScale({
drawingDelay,
scaleFactor,
steps
} = {}) {
if (!this.pdfDocument) {
return;
}
options ||= Object.create(null);
let newScale = this._currentScale;
if (options.scaleFactor > 0 && options.scaleFactor < 1) {
newScale = Math.max(_ui_utils.MIN_SCALE, Math.round(newScale * options.scaleFactor * 100) / 100);
if (scaleFactor > 0 && scaleFactor < 1) {
newScale = Math.max(_ui_utils.MIN_SCALE, Math.round(newScale * scaleFactor * 100) / 100);
} else {
let steps = options.steps ?? 1;
steps ??= 1;
do {
newScale = (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2);
newScale = Math.floor(newScale * 10) / 10;
newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
newScale = Math.max(_ui_utils.MIN_SCALE, Math.floor(newScale * 10) / 10);
} while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
}
options.noScroll = false;
this._setScale(newScale, options);
this._setScale(newScale, {
noScroll: false,
drawingDelay
});
}
#updateContainerHeightCss(height = this.container.clientHeight) {
if (height !== this.#previousContainerHeight) {
Expand Down Expand Up @@ -8147,8 +8157,9 @@ class PDFPageView {
canvas.setAttribute("role", "presentation");
canvas.hidden = true;
let isCanvasHidden = true;
const showCanvas = function () {
if (isCanvasHidden) {
const hasHCM = !!(this.pageColors?.background && this.pageColors?.foreground);
const showCanvas = function (isLastShow) {
if (isCanvasHidden && (!hasHCM || isLastShow)) {
canvas.hidden = false;
isCanvasHidden = false;
}
Expand Down Expand Up @@ -8199,19 +8210,19 @@ class PDFPageView {
};
const renderTask = this.pdfPage.render(renderContext);
renderTask.onContinue = function (cont) {
showCanvas();
showCanvas(false);
if (result.onRenderContinue) {
result.onRenderContinue(cont);
} else {
cont();
}
};
renderTask.promise.then(function () {
showCanvas();
showCanvas(true);
renderCapability.resolve();
}, function (error) {
if (!(error instanceof _pdfjsLib.RenderingCancelledException)) {
showCanvas();
showCanvas(true);
}
renderCapability.reject(error);
});
Expand Down Expand Up @@ -9436,8 +9447,8 @@ var _ui_utils = __webpack_require__(4);
var _app_options = __webpack_require__(6);
var _pdf_link_service = __webpack_require__(8);
var _app = __webpack_require__(3);
const pdfjsVersion = '3.5.34';
const pdfjsBuild = 'a0ef5a4ae';
const pdfjsVersion = '3.5.73';
const pdfjsBuild = '3903391f3';
const AppConstants = null;
exports.PDFViewerApplicationConstants = AppConstants;
window.PDFViewerApplication = _app.PDFViewerApplication;
Expand Down
9 changes: 3 additions & 6 deletions toolkit/components/pdfjs/content/web/viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -986,8 +986,7 @@
.pdfViewer.scrollHorizontal,
.pdfViewer.scrollWrapped,
.spread {
margin-left: 3.5px;
margin-right: 3.5px;
margin-inline: 3.5px;
text-align: center;
}

Expand All @@ -998,8 +997,7 @@

.pdfViewer.scrollHorizontal .spread,
.pdfViewer.scrollWrapped .spread {
margin-left: 0;
margin-right: 0;
margin-inline: 0;
}

.spread .page,
Expand All @@ -1015,8 +1013,7 @@
.spread .page,
.pdfViewer.scrollHorizontal .page,
.pdfViewer.scrollWrapped .page {
margin-left: var(--spreadHorizontalWrapped-margin-LR);
margin-right: var(--spreadHorizontalWrapped-margin-LR);
margin-inline: var(--spreadHorizontalWrapped-margin-LR);
}

.pdfViewer .page canvas {
Expand Down
8 changes: 3 additions & 5 deletions toolkit/components/pdfjs/content/web/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
<title>PDF.js viewer</title>

<!-- This snippet is used in the Firefox extension (included from viewer.html) -->
<base href="resource://pdf.js/web/">
<script src="../build/pdf.js"></script>
<script src="resource://pdf.js/build/pdf.js"></script>

<link rel="stylesheet" href="viewer.css">

<script src="viewer.js"></script>
<link rel="stylesheet" href="resource://pdf.js/web/viewer.css">

<script src="resource://pdf.js/web/viewer.js"></script>
</head>

<body tabindex="1">
Expand Down
Loading

0 comments on commit b292300

Please sign in to comment.