Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-minor] Normalize the view-getter on the worker-thread #15773

Merged
merged 1 commit into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ class Page {
if (this.xfaData) {
return this.xfaData.bbox;
}

const box = this._getInheritableProperty(name, /* getArray = */ true);
let box = this._getInheritableProperty(name, /* getArray = */ true);

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;
}
warn(`Empty /${name} entry.`);
warn(`Empty, or invalid, /${name} entry.`);
}
return null;
}
Expand Down Expand Up @@ -190,18 +190,15 @@ class Page {
// extend beyond the boundaries of the media box. If they do, they are
// effectively reduced to their intersection with the media box."
const { cropBox, mediaBox } = this;
let view;
if (cropBox === mediaBox || isArrayEqual(cropBox, mediaBox)) {
view = mediaBox;
} else {

if (cropBox !== mediaBox && !isArrayEqual(cropBox, mediaBox)) {
const box = Util.intersect(cropBox, mediaBox);
if (box && box[2] - box[0] !== 0 && box[3] - box[1] !== 0) {
view = box;
} else {
warn("Empty /CropBox and /MediaBox intersection.");
if (box && box[2] - box[0] > 0 && box[3] - box[1] > 0) {
return shadow(this, "view", box);
}
warn("Empty /CropBox and /MediaBox intersection.");
}
return shadow(this, "view", view || mediaBox);
return shadow(this, "view", mediaBox);
}

get rotate() {
Expand Down
8 changes: 4 additions & 4 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ class PageViewport {
if (rotateA === 0) {
offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
width = Math.abs(viewBox[3] - viewBox[1]) * scale;
height = Math.abs(viewBox[2] - viewBox[0]) * scale;
width = (viewBox[3] - viewBox[1]) * scale;
height = (viewBox[2] - viewBox[0]) * scale;
} else {
offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
width = Math.abs(viewBox[2] - viewBox[0]) * scale;
height = Math.abs(viewBox[3] - viewBox[1]) * scale;
width = (viewBox[2] - viewBox[0]) * scale;
height = (viewBox[3] - viewBox[1]) * scale;
}
// creating transform for the following operations:
// translate(-centerX, -centerY), rotate and flip vertically,
Expand Down