Merge pull request #15773 from Snuffleupagus/view-worker-normalize

[api-minor] Normalize the `view`-getter on the worker-thread
This commit is contained in:
Tim van der Meij 2022-12-02 19:52:44 +01:00 committed by GitHub
commit 67e1c37e0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 17 deletions

View File

@ -146,14 +146,14 @@ class Page {
if (this.xfaData) { if (this.xfaData) {
return this.xfaData.bbox; return this.xfaData.bbox;
} }
let box = this._getInheritableProperty(name, /* getArray = */ true);
const box = this._getInheritableProperty(name, /* getArray = */ true);
if (Array.isArray(box) && box.length === 4) { if (Array.isArray(box) && box.length === 4) {
if (box[2] - box[0] !== 0 && box[3] - box[1] !== 0) { box = Util.normalizeRect(box);
if (box[2] - box[0] > 0 && box[3] - box[1] > 0) {
return box; return box;
} }
warn(`Empty /${name} entry.`); warn(`Empty, or invalid, /${name} entry.`);
} }
return null; return null;
} }
@ -190,18 +190,15 @@ class Page {
// extend beyond the boundaries of the media box. If they do, they are // extend beyond the boundaries of the media box. If they do, they are
// effectively reduced to their intersection with the media box." // effectively reduced to their intersection with the media box."
const { cropBox, mediaBox } = this; const { cropBox, mediaBox } = this;
let view;
if (cropBox === mediaBox || isArrayEqual(cropBox, mediaBox)) { if (cropBox !== mediaBox && !isArrayEqual(cropBox, mediaBox)) {
view = mediaBox;
} else {
const box = Util.intersect(cropBox, mediaBox); const box = Util.intersect(cropBox, mediaBox);
if (box && box[2] - box[0] !== 0 && box[3] - box[1] !== 0) { if (box && box[2] - box[0] > 0 && box[3] - box[1] > 0) {
view = box; return shadow(this, "view", box);
} else {
warn("Empty /CropBox and /MediaBox intersection.");
} }
warn("Empty /CropBox and /MediaBox intersection.");
} }
return shadow(this, "view", view || mediaBox); return shadow(this, "view", mediaBox);
} }
get rotate() { get rotate() {

View File

@ -224,13 +224,13 @@ class PageViewport {
if (rotateA === 0) { if (rotateA === 0) {
offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX; offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY; offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
width = Math.abs(viewBox[3] - viewBox[1]) * scale; width = (viewBox[3] - viewBox[1]) * scale;
height = Math.abs(viewBox[2] - viewBox[0]) * scale; height = (viewBox[2] - viewBox[0]) * scale;
} else { } else {
offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX; offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY; offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
width = Math.abs(viewBox[2] - viewBox[0]) * scale; width = (viewBox[2] - viewBox[0]) * scale;
height = Math.abs(viewBox[3] - viewBox[1]) * scale; height = (viewBox[3] - viewBox[1]) * scale;
} }
// creating transform for the following operations: // creating transform for the following operations:
// translate(-centerX, -centerY), rotate and flip vertically, // translate(-centerX, -centerY), rotate and flip vertically,