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

Move rotation normalization from PDFViewerApplication and into BaseViewer #13155

Merged
merged 1 commit into from
Mar 28, 2021
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
7 changes: 5 additions & 2 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,11 @@ class PageViewport {
const centerX = (viewBox[2] + viewBox[0]) / 2;
const centerY = (viewBox[3] + viewBox[1]) / 2;
let rotateA, rotateB, rotateC, rotateD;
rotation = rotation % 360;
rotation = rotation < 0 ? rotation + 360 : rotation;
// Normalize the rotation, by clamping it to the [0, 360) range.
rotation %= 360;
if (rotation < 0) {
rotation += 360;
}
switch (rotation) {
case 180:
rotateA = -1;
Expand Down
6 changes: 1 addition & 5 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1856,11 +1856,7 @@ const PDFViewerApplication = {
},

rotatePages(delta) {
if (!this.pdfDocument) {
return;
}
const newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
this.pdfViewer.pagesRotation = newRotation;
this.pdfViewer.pagesRotation += delta;
// Note that the thumbnail viewer is updated, and rendering is triggered,
// in the 'rotationchanging' event handler.
},
Expand Down
5 changes: 5 additions & 0 deletions web/base_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ class BaseViewer {
if (!this.pdfDocument) {
return;
}
// Normalize the rotation, by clamping it to the [0, 360) range.
rotation %= 360;
if (rotation < 0) {
rotation += 360;
}
if (this._pagesRotation === rotation) {
return; // The rotation didn't change.
}
Expand Down