Update the signature of the PageViewport
constructor, and improve the JSDoc comments for the class
This changes the constructor to take a parameter object, rather than a string of parameters.
This commit is contained in:
parent
51673dbc5a
commit
69f2a77543
@ -885,7 +885,12 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
||||
* along with transforms required for rendering.
|
||||
*/
|
||||
getViewport(scale, rotate = this.rotate, dontFlip = false) {
|
||||
return new PageViewport(this.view, scale, rotate, 0, 0, dontFlip);
|
||||
return new PageViewport({
|
||||
viewBox: this.view,
|
||||
scale,
|
||||
rotation: rotate,
|
||||
dontFlip,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @param {GetAnnotationsParameters} params - Annotation parameters.
|
||||
|
@ -135,19 +135,38 @@ class DOMSVGFactory {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} PageViewportParameters
|
||||
* @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.
|
||||
* The default value is `0`.
|
||||
* @property {number} offsetY - (optional) The horizontal, i.e. y-axis, offset.
|
||||
* The default value is `0`.
|
||||
* @property {boolean} dontFlip - (optional) If true, the x-axis will not be
|
||||
* flipped. The default value is `false`.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} PageViewportCloneParameters
|
||||
* @property {number} scale - (optional) The scale, overriding the one in the
|
||||
* cloned viewport. The default value is `this.scale`.
|
||||
* @property {number} rotation - (optional) The rotation, in degrees, overriding
|
||||
* the one in the cloned viewport. The default value is `this.rotation`.
|
||||
* @property {boolean} dontFlip - (optional) If true, the x-axis will not be
|
||||
* flipped. The default value is `false`.
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDF page viewport created based on scale, rotation and offset.
|
||||
*/
|
||||
class PageViewport {
|
||||
/**
|
||||
* @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
|
||||
* @param scale {number} scale of the viewport.
|
||||
* @param rotation {number} rotations of the viewport in degrees.
|
||||
* @param offsetX {number} offset X
|
||||
* @param offsetY {number} offset Y
|
||||
* @param dontFlip {boolean} if true, axis Y will not be flipped.
|
||||
* @param {PageViewportParameters}
|
||||
*/
|
||||
constructor(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
|
||||
constructor({ viewBox, scale, rotation, offsetX = 0, offsetY = 0,
|
||||
dontFlip = false, }) {
|
||||
this.viewBox = viewBox;
|
||||
this.scale = scale;
|
||||
this.rotation = rotation;
|
||||
@ -211,27 +230,29 @@ class PageViewport {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones viewport with additional properties.
|
||||
* @param args {Object} (optional) If specified, may contain the 'scale' or
|
||||
* 'rotation' properties to override the corresponding properties in
|
||||
* the cloned viewport.
|
||||
* @returns {PageViewport} Cloned viewport.
|
||||
* Clones viewport, with optional additional properties.
|
||||
* @param {PageViewportCloneParameters} - (optional)
|
||||
* @return {PageViewport} Cloned viewport.
|
||||
*/
|
||||
clone(args) {
|
||||
args = args || {};
|
||||
let scale = 'scale' in args ? args.scale : this.scale;
|
||||
let rotation = 'rotation' in args ? args.rotation : this.rotation;
|
||||
return new PageViewport(this.viewBox.slice(), scale, rotation,
|
||||
this.offsetX, this.offsetY, args.dontFlip);
|
||||
clone({ scale = this.scale, rotation = this.rotation,
|
||||
dontFlip = false, } = {}) {
|
||||
return new PageViewport({
|
||||
viewBox: this.viewBox.slice(),
|
||||
scale,
|
||||
rotation,
|
||||
offsetX: this.offsetX,
|
||||
offsetY: this.offsetY,
|
||||
dontFlip,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts PDF point to the viewport coordinates. For examples, useful for
|
||||
* converting PDF location into canvas pixel coordinates.
|
||||
* @param x {number} X coordinate.
|
||||
* @param y {number} Y coordinate.
|
||||
* @returns {Object} Object that contains 'x' and 'y' properties of the
|
||||
* point in the viewport coordinate space.
|
||||
* @param {number} x - The x-coordinate.
|
||||
* @param {number} y - The y-coordinate.
|
||||
* @return {Object} Object containing `x` and `y` properties of the
|
||||
* point in the viewport coordinate space.
|
||||
* @see {@link convertToPdfPoint}
|
||||
* @see {@link convertToViewportRectangle}
|
||||
*/
|
||||
@ -241,9 +262,9 @@ class PageViewport {
|
||||
|
||||
/**
|
||||
* Converts PDF rectangle to the viewport coordinates.
|
||||
* @param rect {Array} xMin, yMin, xMax and yMax coordinates.
|
||||
* @returns {Array} Contains corresponding coordinates of the rectangle
|
||||
* in the viewport coordinate space.
|
||||
* @param {Array} rect - The xMin, yMin, xMax and yMax coordinates.
|
||||
* @return {Array} Array containing corresponding coordinates of the rectangle
|
||||
* in the viewport coordinate space.
|
||||
* @see {@link convertToViewportPoint}
|
||||
*/
|
||||
convertToViewportRectangle(rect) {
|
||||
@ -255,10 +276,10 @@ class PageViewport {
|
||||
/**
|
||||
* Converts viewport coordinates to the PDF location. For examples, useful
|
||||
* for converting canvas pixel location into PDF one.
|
||||
* @param x {number} X coordinate.
|
||||
* @param y {number} Y coordinate.
|
||||
* @returns {Object} Object that contains 'x' and 'y' properties of the
|
||||
* point in the PDF coordinate space.
|
||||
* @param {number} x - The x-coordinate.
|
||||
* @param {number} y - The y-coordinate.
|
||||
* @return {Object} Object containing `x` and `y` properties of the
|
||||
* point in the PDF coordinate space.
|
||||
* @see {@link convertToViewportPoint}
|
||||
*/
|
||||
convertToPdfPoint(x, y) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user