From 52f6016e6ca045a5675888ab1ced812d63b57d2e Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 2 Oct 2020 13:54:44 +0200 Subject: [PATCH] Fix the remaining ESLint `no-var` errors in the `src/display/` folder While most of necessary changes were fixed automatically, see the previous patch, there's a number of cases that needed to be fixed manually. --- src/display/canvas.js | 56 ++++++++++++++++------------------- src/display/pattern_helper.js | 10 +++---- src/display/text_layer.js | 12 ++++---- src/display/webgl.js | 26 +++++++--------- 4 files changed, 48 insertions(+), 56 deletions(-) diff --git a/src/display/canvas.js b/src/display/canvas.js index 2e4137eac..7a31fe075 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -210,11 +210,9 @@ function compileType3Glyph(imgData) { const POINT_TO_PROCESS_LIMIT = 1000; const width = imgData.width, - height = imgData.height; - let i, - j, - j0, + height = imgData.height, width1 = width + 1; + let i, ii, j, j0; const points = new Uint8Array(width1 * (height + 1)); // prettier-ignore const POINT_TYPES = @@ -223,12 +221,11 @@ function compileType3Glyph(imgData) { // decodes bit-packed mask data const lineSize = (width + 7) & ~7, data0 = imgData.data; - let data = new Uint8Array(lineSize * height), - pos = 0, - ii; + const data = new Uint8Array(lineSize * height); + let pos = 0; for (i = 0, ii = data0.length; i < ii; i++) { - let mask = 128, - elem = data0[i]; + const elem = data0[i]; + let mask = 128; while (mask > 0) { data[pos++] = elem & mask ? 0 : 255; mask >>= 1; @@ -328,16 +325,15 @@ function compileType3Glyph(imgData) { } const coords = [p % width1, i]; - var type = points[p], - p0 = p, - pp; + const p0 = p; + let type = points[p]; do { const step = steps[type]; do { p += step; } while (!points[p]); - pp = points[p]; + const pp = points[p]; if (pp !== 5 && pp !== 10) { // set new direction type = pp; @@ -705,10 +701,11 @@ const CanvasGraphics = (function CanvasGraphicsClosure() { // inversion has already been handled. let destPos = 3; // alpha component offset for (let j = 0; j < thisChunkHeight; j++) { - let mask = 0; + let elem, + mask = 0; for (let k = 0; k < width; k++) { if (!mask) { - var elem = src[srcPos++]; + elem = src[srcPos++]; mask = 128; } dest[destPos] = elem & mask ? 0 : 255; @@ -1276,16 +1273,16 @@ const CanvasGraphics = (function CanvasGraphicsClosure() { case OPS.rectangle: x = args[j++]; y = args[j++]; - var width = args[j++]; - var height = args[j++]; + let width = args[j++]; + let height = args[j++]; if (width === 0 && ctx.lineWidth < this.getSinglePixelWidth()) { width = this.getSinglePixelWidth(); } if (height === 0 && ctx.lineWidth < this.getSinglePixelWidth()) { height = this.getSinglePixelWidth(); } - var xw = x + width; - var yh = y + height; + const xw = x + width; + const yh = y + height; ctx.moveTo(x, y); ctx.lineTo(xw, y); ctx.lineTo(xw, yh); @@ -1756,14 +1753,13 @@ const CanvasGraphics = (function CanvasGraphicsClosure() { const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing; const character = glyph.fontChar; const accent = glyph.accent; - var scaledX, scaledY, scaledAccentX, scaledAccentY; + let scaledX, scaledY; let width = glyph.width; if (vertical) { - var vmetric, vx, vy; - vmetric = glyph.vmetric || defaultVMetrics; - vx = glyph.vmetric ? vmetric[1] : width * 0.5; - vx = -vx * widthAdvanceScale; - vy = vmetric[2] * widthAdvanceScale; + const vmetric = glyph.vmetric || defaultVMetrics; + const vx = + -(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale; + const vy = vmetric[2] * widthAdvanceScale; width = vmetric ? -vmetric[0] : width; scaledX = vx / fontSizeScale; @@ -1801,9 +1797,9 @@ const CanvasGraphics = (function CanvasGraphicsClosure() { } else { this.paintChar(character, scaledX, scaledY, patternTransform); if (accent) { - scaledAccentX = + const scaledAccentX = scaledX + (fontSize * accent.offset.x) / fontSizeScale; - scaledAccentY = + const scaledAccentY = scaledY - (fontSize * accent.offset.y) / fontSizeScale; this.paintChar( accent.fontChar, @@ -1815,7 +1811,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() { } } - var charWidth; + let charWidth; if (vertical) { charWidth = width * widthAdvanceScale - spacing * fontDirection; } else { @@ -2440,7 +2436,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() { d = currentTransform[3]; let heightScale = Math.max(Math.sqrt(c * c + d * d), 1); - let imgToPaint, tmpCanvas; + let imgToPaint, tmpCanvas, tmpCtx; // typeof check is needed due to node.js support, see issue #8489 if ( (typeof HTMLElement === "function" && imgData instanceof HTMLElement) || @@ -2449,7 +2445,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() { imgToPaint = imgData; } else { tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height); - var tmpCtx = tmpCanvas.context; + tmpCtx = tmpCanvas.context; putBinaryImageData(tmpCtx, imgData, this.current.transferMaps); imgToPaint = tmpCanvas.canvas; } diff --git a/src/display/pattern_helper.js b/src/display/pattern_helper.js index ce0f49555..4fe13a721 100644 --- a/src/display/pattern_helper.js +++ b/src/display/pattern_helper.js @@ -178,9 +178,9 @@ const createMeshCanvas = (function createMeshCanvasClosure() { let i, ii; switch (figure.type) { case "lattice": - var verticesPerRow = figure.verticesPerRow; - var rows = Math.floor(ps.length / verticesPerRow) - 1; - var cols = verticesPerRow - 1; + const verticesPerRow = figure.verticesPerRow; + const rows = Math.floor(ps.length / verticesPerRow) - 1; + const cols = verticesPerRow - 1; for (i = 0; i < rows; i++) { let q = i * verticesPerRow; for (let j = 0; j < cols; j++, q++) { @@ -564,14 +564,14 @@ const TilingPattern = (function TilingPatternClosure() { current = graphics.current; switch (paintType) { case PaintType.COLORED: - var ctx = this.ctx; + const ctx = this.ctx; context.fillStyle = ctx.fillStyle; context.strokeStyle = ctx.strokeStyle; current.fillColor = ctx.fillStyle; current.strokeColor = ctx.strokeStyle; break; case PaintType.UNCOLORED: - var cssColor = Util.makeCssRgb(color[0], color[1], color[2]); + const cssColor = Util.makeCssRgb(color[0], color[1], color[2]); context.fillStyle = cssColor; context.strokeStyle = cssColor; // Set color needed by image masks (fixes issues 3226 and 8741). diff --git a/src/display/text_layer.js b/src/display/text_layer.js index de6eb9954..fec6bb8f3 100644 --- a/src/display/text_layer.js +++ b/src/display/text_layer.js @@ -237,14 +237,14 @@ const renderTextLayer = (function renderTextLayerClosure() { } // Box is rotated -- trying to find padding so rotated div will not // exceed its expanded bounds. - var e = expanded[i], + const e = expanded[i], b = bounds[i]; - var m = b.m, + const m = b.m, c = m[0], s = m[1]; // Finding intersections with expanded box. const points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size]; - var ts = new Float64Array(64); + const ts = new Float64Array(64); points.forEach(function (p, j) { const t = Util.applyTransform(p, m); ts[j + 0] = c && (e.left - t[0]) / c; @@ -368,7 +368,7 @@ const renderTextLayer = (function renderTextLayerClosure() { for (q = i; q <= j; q++) { horizonPart = horizon[q]; affectedBoundary = horizonPart.boundary; - var xNew; + let xNew; if (affectedBoundary.x2 > boundary.x1) { // In the middle of the previous element, new x shall be at the // boundary start. Extending if further if the affected boundary @@ -415,8 +415,8 @@ const renderTextLayer = (function renderTextLayerClosure() { } // Fixing the horizon. - let changedHorizon = [], - lastBoundary = null; + const changedHorizon = []; + let lastBoundary = null; for (q = i; q <= j; q++) { horizonPart = horizon[q]; affectedBoundary = horizonPart.boundary; diff --git a/src/display/webgl.js b/src/display/webgl.js index 068291a17..e14ab28db 100644 --- a/src/display/webgl.js +++ b/src/display/webgl.js @@ -48,7 +48,7 @@ class WebGLContext { } } -var WebGLUtils = (function WebGLUtilsClosure() { +const WebGLUtils = (function WebGLUtilsClosure() { function loadShader(gl, code, shaderType) { const shader = gl.createShader(shaderType); gl.shaderSource(shader, code); @@ -157,12 +157,10 @@ var WebGLUtils = (function WebGLUtilsClosure() { let smaskCache = null; function initSmaskGL() { - let canvas, gl; - generateGL(); - canvas = currentCanvas; + const canvas = currentCanvas; currentCanvas = null; - gl = currentGL; + const gl = currentGL; currentGL = null; // setup a GLSL program @@ -302,12 +300,10 @@ var WebGLUtils = (function WebGLUtilsClosure() { let figuresCache = null; function initFiguresGL() { - let canvas, gl; - generateGL(); - canvas = currentCanvas; + const canvas = currentCanvas; currentCanvas = null; - gl = currentGL; + const gl = currentGL; currentGL = null; // setup a GLSL program @@ -343,11 +339,11 @@ var WebGLUtils = (function WebGLUtilsClosure() { // count triangle points let count = 0; - let i, ii, rows; - for (i = 0, ii = figures.length; i < ii; i++) { + for (let i = 0, ii = figures.length; i < ii; i++) { switch (figures[i].type) { case "lattice": - rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0; + const rows = + (figures[i].coords.length / figures[i].verticesPerRow) | 0; count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6; break; case "triangles": @@ -362,14 +358,14 @@ var WebGLUtils = (function WebGLUtilsClosure() { colorsMap = context.colors; let pIndex = 0, cIndex = 0; - for (i = 0, ii = figures.length; i < ii; i++) { + for (let i = 0, ii = figures.length; i < ii; i++) { const figure = figures[i], ps = figure.coords, cs = figure.colors; switch (figure.type) { case "lattice": - var cols = figure.verticesPerRow; - rows = (ps.length / cols) | 0; + const cols = figure.verticesPerRow; + const rows = (ps.length / cols) | 0; for (let row = 1; row < rows; row++) { let offset = row * cols + 1; for (let col = 1; col < cols; col++, offset++) {