diff --git a/src/display/api.js b/src/display/api.js index 35e5b584c..2c5b339cb 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -781,14 +781,12 @@ var PDFPageProxy = (function PDFPageProxyClosure() { * @param {number} scale The desired scale of the viewport. * @param {number} rotate Degrees to rotate the viewport. If omitted this * defaults to the page rotation. + * @param {boolean} dontFlip (optional) If true, axis Y will not be flipped. * @return {PageViewport} Contains 'width' and 'height' properties * along with transforms required for rendering. */ - getViewport: function PDFPageProxy_getViewport(scale, rotate) { - if (arguments.length < 2) { - rotate = this.rotate; - } - return new PageViewport(this.view, scale, rotate, 0, 0); + getViewport(scale, rotate = this.rotate, dontFlip = false) { + return new PageViewport(this.view, scale, rotate, 0, 0, dontFlip); }, /** * @param {GetAnnotationsParameters} params - Annotation parameters. diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 7a50792c9..30fcc7b18 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -979,6 +979,18 @@ describe('api', function() { expect(viewport.width).toEqual(1262.835); expect(viewport.height).toEqual(892.92); }); + it('gets viewport respecting "dontFlip" argument', function () { + const scale = 1; + const rotation = 135; + let viewport = page.getViewport(scale, rotation); + let dontFlipViewport = page.getViewport(scale, rotation, true); + + expect(dontFlipViewport).not.toEqual(viewport); + expect(dontFlipViewport).toEqual(viewport.clone({ dontFlip: true, })); + + expect(viewport.transform).toEqual([1, 0, 0, -1, 0, 841.89]); + expect(dontFlipViewport.transform).toEqual([1, 0, -0, 1, 0, 0]); + }); it('gets annotations', function (done) { var defaultPromise = page.getAnnotations().then(function (data) { expect(data.length).toEqual(4);