Merge pull request #11835 from Snuffleupagus/PageViewport-rotation-validation

[api-minor] Change `PageViewport` to throw when the `rotation` is not a multiple of 90 degrees
This commit is contained in:
Tim van der Meij 2020-04-22 23:49:13 +02:00 committed by GitHub
commit c8feea6990
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -245,13 +245,16 @@ class PageViewport {
rotateC = -1; rotateC = -1;
rotateD = 0; rotateD = 0;
break; break;
// case 0: case 0:
default:
rotateA = 1; rotateA = 1;
rotateB = 0; rotateB = 0;
rotateC = 0; rotateC = 0;
rotateD = -1; rotateD = -1;
break; break;
default:
throw new Error(
"PageViewport: Invalid rotation, must be a multiple of 90 degrees."
);
} }
if (dontFlip) { if (dontFlip) {

View File

@ -1427,6 +1427,16 @@ describe("api", function () {
expect(viewport.transform).toEqual([1, 0, 0, -1, 0, 841.89]); expect(viewport.transform).toEqual([1, 0, 0, -1, 0, 841.89]);
expect(dontFlipViewport.transform).toEqual([1, 0, -0, 1, 0, 0]); expect(dontFlipViewport.transform).toEqual([1, 0, -0, 1, 0, 0]);
}); });
it("gets viewport with invalid rotation", function () {
expect(function () {
page.getViewport({ scale: 1, rotation: 45 });
}).toThrow(
new Error(
"PageViewport: Invalid rotation, must be a multiple of 90 degrees."
)
);
});
it("gets annotations", function (done) { it("gets annotations", function (done) {
var defaultPromise = page.getAnnotations().then(function (data) { var defaultPromise = page.getAnnotations().then(function (data) {
expect(data.length).toEqual(4); expect(data.length).toEqual(4);