Convert the PageViewport to a proper ES6 class

Also converts all `var` to `let` for good measure.
This commit is contained in:
Jonas Jenwald 2018-06-04 12:36:53 +02:00
parent 5917b21702
commit 51673dbc5a

View File

@ -137,13 +137,9 @@ class DOMSVGFactory {
/**
* PDF page viewport created based on scale, rotation and offset.
* @class
* @alias PageViewport
*/
var PageViewport = (function PageViewportClosure() {
class PageViewport {
/**
* @constructor
* @private
* @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.
@ -151,7 +147,7 @@ var PageViewport = (function PageViewportClosure() {
* @param offsetY {number} offset Y
* @param dontFlip {boolean} if true, axis Y will not be flipped.
*/
function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
constructor(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
this.viewBox = viewBox;
this.scale = scale;
this.rotation = rotation;
@ -160,9 +156,9 @@ var PageViewport = (function PageViewportClosure() {
// creating transform to convert pdf coordinate system to the normal
// canvas like coordinates taking in account scale and rotation
var centerX = (viewBox[2] + viewBox[0]) / 2;
var centerY = (viewBox[3] + viewBox[1]) / 2;
var rotateA, rotateB, rotateC, rotateD;
let centerX = (viewBox[2] + viewBox[0]) / 2;
let centerY = (viewBox[3] + viewBox[1]) / 2;
let rotateA, rotateB, rotateC, rotateD;
rotation = rotation % 360;
rotation = rotation < 0 ? rotation + 360 : rotation;
switch (rotation) {
@ -185,8 +181,8 @@ var PageViewport = (function PageViewportClosure() {
rotateC = -rotateC; rotateD = -rotateD;
}
var offsetCanvasX, offsetCanvasY;
var width, height;
let offsetCanvasX, offsetCanvasY;
let width, height;
if (rotateA === 0) {
offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
@ -213,7 +209,7 @@ var PageViewport = (function PageViewportClosure() {
this.width = width;
this.height = height;
}
PageViewport.prototype = /** @lends PageViewport.prototype */ {
/**
* Clones viewport with additional properties.
* @param args {Object} (optional) If specified, may contain the 'scale' or
@ -221,13 +217,14 @@ var PageViewport = (function PageViewportClosure() {
* the cloned viewport.
* @returns {PageViewport} Cloned viewport.
*/
clone: function PageViewPort_clone(args) {
clone(args) {
args = args || {};
var scale = 'scale' in args ? args.scale : this.scale;
var rotation = 'rotation' in args ? args.rotation : this.rotation;
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);
},
}
/**
* Converts PDF point to the viewport coordinates. For examples, useful for
* converting PDF location into canvas pixel coordinates.
@ -238,9 +235,10 @@ var PageViewport = (function PageViewportClosure() {
* @see {@link convertToPdfPoint}
* @see {@link convertToViewportRectangle}
*/
convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
convertToViewportPoint(x, y) {
return Util.applyTransform([x, y], this.transform);
},
}
/**
* Converts PDF rectangle to the viewport coordinates.
* @param rect {Array} xMin, yMin, xMax and yMax coordinates.
@ -248,12 +246,12 @@ var PageViewport = (function PageViewportClosure() {
* in the viewport coordinate space.
* @see {@link convertToViewportPoint}
*/
convertToViewportRectangle:
function PageViewport_convertToViewportRectangle(rect) {
var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
var br = Util.applyTransform([rect[2], rect[3]], this.transform);
convertToViewportRectangle(rect) {
let tl = Util.applyTransform([rect[0], rect[1]], this.transform);
let br = Util.applyTransform([rect[2], rect[3]], this.transform);
return [tl[0], tl[1], br[0], br[1]];
},
}
/**
* Converts viewport coordinates to the PDF location. For examples, useful
* for converting canvas pixel location into PDF one.
@ -263,12 +261,10 @@ var PageViewport = (function PageViewportClosure() {
* point in the PDF coordinate space.
* @see {@link convertToViewportPoint}
*/
convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
convertToPdfPoint(x, y) {
return Util.applyInverseTransform([x, y], this.transform);
},
};
return PageViewport;
})();
}
}
var RenderingCancelledException = (function RenderingCancelledException() {
function RenderingCancelledException(msg, type) {