Merge pull request #13155 from Snuffleupagus/rotation-normalization

Move rotation normalization from `PDFViewerApplication` and into `BaseViewer`
This commit is contained in:
Tim van der Meij 2021-03-28 15:05:07 +02:00 committed by GitHub
commit 34542d814f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

View File

@ -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;

View File

@ -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.
},

View File

@ -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.
}