Remove the remaining closure in the src/display/canvas.js
file
For e.g. the `gulp mozcentral` command, the *built* `pdf.js` file decreases from `304 607` to `301 295` bytes with this patch. The improvement comes mostly from having less overall indentation in the code.
This commit is contained in:
parent
156762c482
commit
fbaafdc4e8
@ -37,6 +37,12 @@ const MIN_FONT_SIZE = 16;
|
|||||||
const MAX_FONT_SIZE = 100;
|
const MAX_FONT_SIZE = 100;
|
||||||
const MAX_GROUP_SIZE = 4096;
|
const MAX_GROUP_SIZE = 4096;
|
||||||
|
|
||||||
|
// Defines the time the `executeOperatorList`-method is going to be executing
|
||||||
|
// before it stops and shedules a continue of execution.
|
||||||
|
const EXECUTION_TIME = 15; // ms
|
||||||
|
// Defines the number of steps before checking the execution time.
|
||||||
|
const EXECUTION_STEPS = 10;
|
||||||
|
|
||||||
const COMPILE_TYPE3_GLYPHS = true;
|
const COMPILE_TYPE3_GLYPHS = true;
|
||||||
const MAX_SIZE_TO_COMPILE = 1000;
|
const MAX_SIZE_TO_COMPILE = 1000;
|
||||||
|
|
||||||
@ -442,16 +448,6 @@ class CanvasExtraState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {any}
|
|
||||||
*/
|
|
||||||
const CanvasGraphics = (function CanvasGraphicsClosure() {
|
|
||||||
// Defines the time the executeOperatorList is going to be executing
|
|
||||||
// before it stops and shedules a continue of execution.
|
|
||||||
const EXECUTION_TIME = 15;
|
|
||||||
// Defines the number of steps before checking the execution time
|
|
||||||
const EXECUTION_STEPS = 10;
|
|
||||||
|
|
||||||
function putBinaryImageData(ctx, imgData, transferMaps = null) {
|
function putBinaryImageData(ctx, imgData, transferMaps = null) {
|
||||||
if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
|
if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
|
||||||
ctx.putImageData(imgData, 0, 0);
|
ctx.putImageData(imgData, 0, 0);
|
||||||
@ -518,8 +514,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < totalChunks; i++) {
|
for (i = 0; i < totalChunks; i++) {
|
||||||
thisChunkHeight =
|
thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
|
||||||
i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
|
|
||||||
destPos = 0;
|
destPos = 0;
|
||||||
for (j = 0; j < thisChunkHeight; j++) {
|
for (j = 0; j < thisChunkHeight; j++) {
|
||||||
const srcDiff = srcLength - srcPos;
|
const srcDiff = srcLength - srcPos;
|
||||||
@ -837,7 +832,6 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
const NORMAL_CLIP = {};
|
const NORMAL_CLIP = {};
|
||||||
const EO_CLIP = {};
|
const EO_CLIP = {};
|
||||||
|
|
||||||
// eslint-disable-next-line no-shadow
|
|
||||||
class CanvasGraphics {
|
class CanvasGraphics {
|
||||||
constructor(
|
constructor(
|
||||||
canvasCtx,
|
canvasCtx,
|
||||||
@ -913,10 +907,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.ctx.save();
|
this.ctx.save();
|
||||||
// The transform can be applied before rendering, transferring it to
|
// The transform can be applied before rendering, transferring it to
|
||||||
// the new canvas.
|
// the new canvas.
|
||||||
this.ctx.transform.apply(
|
this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
|
||||||
this.ctx,
|
|
||||||
this.compositeCtx.mozCurrentTransform
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ctx.save();
|
this.ctx.save();
|
||||||
@ -2617,10 +2608,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
imgToPaint = tmpCanvas.canvas;
|
imgToPaint = tmpCanvas.canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
const scaled = this._scaleImage(
|
const scaled = this._scaleImage(imgToPaint, ctx.mozCurrentTransformInverse);
|
||||||
imgToPaint,
|
|
||||||
ctx.mozCurrentTransformInverse
|
|
||||||
);
|
|
||||||
ctx.drawImage(
|
ctx.drawImage(
|
||||||
scaled.img,
|
scaled.img,
|
||||||
0,
|
0,
|
||||||
@ -2773,10 +2761,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
const sqNorm1 = m[0] ** 2 + m[2] ** 2;
|
const sqNorm1 = m[0] ** 2 + m[2] ** 2;
|
||||||
const sqNorm2 = m[1] ** 2 + m[3] ** 2;
|
const sqNorm2 = m[1] ** 2 + m[3] ** 2;
|
||||||
const pixelHeight = Math.sqrt(Math.max(sqNorm1, sqNorm2)) / absDet;
|
const pixelHeight = Math.sqrt(Math.max(sqNorm1, sqNorm2)) / absDet;
|
||||||
if (
|
if (sqNorm1 !== sqNorm2 && this._combinedScaleFactor * pixelHeight > 1) {
|
||||||
sqNorm1 !== sqNorm2 &&
|
|
||||||
this._combinedScaleFactor * pixelHeight > 1
|
|
||||||
) {
|
|
||||||
// The parallelogram isn't a square and at least one height
|
// The parallelogram isn't a square and at least one height
|
||||||
// is lower than 1 so the resulting line width must be 1
|
// is lower than 1 so the resulting line width must be 1
|
||||||
// but it cannot be achieved with one scale: when scaling a pixel
|
// but it cannot be achieved with one scale: when scaling a pixel
|
||||||
@ -2822,7 +2807,4 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
|
CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
|
||||||
}
|
}
|
||||||
|
|
||||||
return CanvasGraphics;
|
|
||||||
})();
|
|
||||||
|
|
||||||
export { CanvasGraphics };
|
export { CanvasGraphics };
|
||||||
|
Loading…
Reference in New Issue
Block a user