1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 08:38:06 +02:00

[api-minor] Change the getViewport method, on PDFPageProxy, to take a parameter object rather than a bunch of (randomly) ordered parameters

If, as PR 10368 suggests, more parameters should be added to `getViewport` I think that it would be a mistake to not change the signature *first* to avoid needlessly unwieldy call-sites.

To not break any existing code and third-party use-cases, this is obviously implemented with a deprecation warning *and* with a working fallback[1] for the old method signature.

---
[1] This is limited to `GENERIC` builds, which should be sufficient.
This commit is contained in:
Jonas Jenwald 2018-12-21 11:47:37 +01:00
parent ba2edeae18
commit f0719ed565
19 changed files with 54 additions and 38 deletions

View file

@ -755,6 +755,17 @@ class PDFDocumentProxy {
}
}
/**
* Page getViewport parameters.
*
* @typedef {Object} GetViewportParameters
* @property {number} scale - The desired scale of the viewport.
* @property {number} rotation - (optional) The desired rotation, in degrees, of
* the viewport. If omitted it defaults to the page rotation.
* @property {boolean} dontFlip - (optional) If true, the y-axis will not be
* flipped. The default value is `false`.
*/
/**
* Page getTextContent parameters.
*
@ -811,7 +822,7 @@ class PDFDocumentProxy {
* @typedef {Object} RenderParameters
* @property {Object} canvasContext - A 2D context of a DOM Canvas object.
* @property {PageViewport} viewport - Rendering viewport obtained by
* calling of PDFPage.getViewport method.
* calling the `PDFPageProxy.getViewport` method.
* @property {string} intent - Rendering intent, can be 'display' or 'print'
* (default value is 'display').
* @property {boolean} enableWebGL - (optional) Enables WebGL accelerated
@ -900,18 +911,22 @@ class PDFPageProxy {
}
/**
* @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.
* @param {GetViewportParameters} params - Viewport parameters.
* @return {PageViewport} Contains 'width' and 'height' properties
* along with transforms required for rendering.
* along with transforms required for rendering.
*/
getViewport(scale, rotate = this.rotate, dontFlip = false) {
getViewport({ scale, rotation = this.rotate, dontFlip = false, } = {}) {
if ((typeof PDFJSDev !== 'undefined' && PDFJSDev.test('GENERIC')) &&
(arguments.length > 1 || typeof arguments[0] === 'number')) {
deprecated('getViewport is called with obsolete arguments.');
scale = arguments[0];
rotation = typeof arguments[1] === 'number' ? arguments[1] : this.rotate;
dontFlip = typeof arguments[2] === 'boolean' ? arguments[2] : false;
}
return new PageViewport({
viewBox: this.view,
scale,
rotation: rotate,
rotation,
dontFlip,
});
}

View file

@ -140,11 +140,11 @@ class DOMSVGFactory {
* @property {Array} viewBox - The xMin, yMin, xMax and yMax coordinates.
* @property {number} scale - The scale of the viewport.
* @property {number} rotation - The rotation, in degrees, of the viewport.
* @property {number} offsetX - (optional) The vertical, i.e. x-axis, offset.
* @property {number} offsetX - (optional) The horizontal, i.e. x-axis, offset.
* The default value is `0`.
* @property {number} offsetY - (optional) The horizontal, i.e. y-axis, offset.
* @property {number} offsetY - (optional) The vertical, i.e. y-axis, offset.
* The default value is `0`.
* @property {boolean} dontFlip - (optional) If true, the x-axis will not be
* @property {boolean} dontFlip - (optional) If true, the y-axis will not be
* flipped. The default value is `false`.
*/