Skip to content

Commit 52f6016

Browse files
committed
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.
1 parent e557be5 commit 52f6016

File tree

4 files changed

+48
-56
lines changed

4 files changed

+48
-56
lines changed

src/display/canvas.js

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,9 @@ function compileType3Glyph(imgData) {
210210
const POINT_TO_PROCESS_LIMIT = 1000;
211211

212212
const width = imgData.width,
213-
height = imgData.height;
214-
let i,
215-
j,
216-
j0,
213+
height = imgData.height,
217214
width1 = width + 1;
215+
let i, ii, j, j0;
218216
const points = new Uint8Array(width1 * (height + 1));
219217
// prettier-ignore
220218
const POINT_TYPES =
@@ -223,12 +221,11 @@ function compileType3Glyph(imgData) {
223221
// decodes bit-packed mask data
224222
const lineSize = (width + 7) & ~7,
225223
data0 = imgData.data;
226-
let data = new Uint8Array(lineSize * height),
227-
pos = 0,
228-
ii;
224+
const data = new Uint8Array(lineSize * height);
225+
let pos = 0;
229226
for (i = 0, ii = data0.length; i < ii; i++) {
230-
let mask = 128,
231-
elem = data0[i];
227+
const elem = data0[i];
228+
let mask = 128;
232229
while (mask > 0) {
233230
data[pos++] = elem & mask ? 0 : 255;
234231
mask >>= 1;
@@ -328,16 +325,15 @@ function compileType3Glyph(imgData) {
328325
}
329326
const coords = [p % width1, i];
330327

331-
var type = points[p],
332-
p0 = p,
333-
pp;
328+
const p0 = p;
329+
let type = points[p];
334330
do {
335331
const step = steps[type];
336332
do {
337333
p += step;
338334
} while (!points[p]);
339335

340-
pp = points[p];
336+
const pp = points[p];
341337
if (pp !== 5 && pp !== 10) {
342338
// set new direction
343339
type = pp;
@@ -705,10 +701,11 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
705701
// inversion has already been handled.
706702
let destPos = 3; // alpha component offset
707703
for (let j = 0; j < thisChunkHeight; j++) {
708-
let mask = 0;
704+
let elem,
705+
mask = 0;
709706
for (let k = 0; k < width; k++) {
710707
if (!mask) {
711-
var elem = src[srcPos++];
708+
elem = src[srcPos++];
712709
mask = 128;
713710
}
714711
dest[destPos] = elem & mask ? 0 : 255;
@@ -1276,16 +1273,16 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
12761273
case OPS.rectangle:
12771274
x = args[j++];
12781275
y = args[j++];
1279-
var width = args[j++];
1280-
var height = args[j++];
1276+
let width = args[j++];
1277+
let height = args[j++];
12811278
if (width === 0 && ctx.lineWidth < this.getSinglePixelWidth()) {
12821279
width = this.getSinglePixelWidth();
12831280
}
12841281
if (height === 0 && ctx.lineWidth < this.getSinglePixelWidth()) {
12851282
height = this.getSinglePixelWidth();
12861283
}
1287-
var xw = x + width;
1288-
var yh = y + height;
1284+
const xw = x + width;
1285+
const yh = y + height;
12891286
ctx.moveTo(x, y);
12901287
ctx.lineTo(xw, y);
12911288
ctx.lineTo(xw, yh);
@@ -1756,14 +1753,13 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
17561753
const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
17571754
const character = glyph.fontChar;
17581755
const accent = glyph.accent;
1759-
var scaledX, scaledY, scaledAccentX, scaledAccentY;
1756+
let scaledX, scaledY;
17601757
let width = glyph.width;
17611758
if (vertical) {
1762-
var vmetric, vx, vy;
1763-
vmetric = glyph.vmetric || defaultVMetrics;
1764-
vx = glyph.vmetric ? vmetric[1] : width * 0.5;
1765-
vx = -vx * widthAdvanceScale;
1766-
vy = vmetric[2] * widthAdvanceScale;
1759+
const vmetric = glyph.vmetric || defaultVMetrics;
1760+
const vx =
1761+
-(glyph.vmetric ? vmetric[1] : width * 0.5) * widthAdvanceScale;
1762+
const vy = vmetric[2] * widthAdvanceScale;
17671763

17681764
width = vmetric ? -vmetric[0] : width;
17691765
scaledX = vx / fontSizeScale;
@@ -1801,9 +1797,9 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
18011797
} else {
18021798
this.paintChar(character, scaledX, scaledY, patternTransform);
18031799
if (accent) {
1804-
scaledAccentX =
1800+
const scaledAccentX =
18051801
scaledX + (fontSize * accent.offset.x) / fontSizeScale;
1806-
scaledAccentY =
1802+
const scaledAccentY =
18071803
scaledY - (fontSize * accent.offset.y) / fontSizeScale;
18081804
this.paintChar(
18091805
accent.fontChar,
@@ -1815,7 +1811,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
18151811
}
18161812
}
18171813

1818-
var charWidth;
1814+
let charWidth;
18191815
if (vertical) {
18201816
charWidth = width * widthAdvanceScale - spacing * fontDirection;
18211817
} else {
@@ -2440,7 +2436,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
24402436
d = currentTransform[3];
24412437
let heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
24422438

2443-
let imgToPaint, tmpCanvas;
2439+
let imgToPaint, tmpCanvas, tmpCtx;
24442440
// typeof check is needed due to node.js support, see issue #8489
24452441
if (
24462442
(typeof HTMLElement === "function" && imgData instanceof HTMLElement) ||
@@ -2449,7 +2445,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
24492445
imgToPaint = imgData;
24502446
} else {
24512447
tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
2452-
var tmpCtx = tmpCanvas.context;
2448+
tmpCtx = tmpCanvas.context;
24532449
putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
24542450
imgToPaint = tmpCanvas.canvas;
24552451
}

src/display/pattern_helper.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ const createMeshCanvas = (function createMeshCanvasClosure() {
178178
let i, ii;
179179
switch (figure.type) {
180180
case "lattice":
181-
var verticesPerRow = figure.verticesPerRow;
182-
var rows = Math.floor(ps.length / verticesPerRow) - 1;
183-
var cols = verticesPerRow - 1;
181+
const verticesPerRow = figure.verticesPerRow;
182+
const rows = Math.floor(ps.length / verticesPerRow) - 1;
183+
const cols = verticesPerRow - 1;
184184
for (i = 0; i < rows; i++) {
185185
let q = i * verticesPerRow;
186186
for (let j = 0; j < cols; j++, q++) {
@@ -564,14 +564,14 @@ const TilingPattern = (function TilingPatternClosure() {
564564
current = graphics.current;
565565
switch (paintType) {
566566
case PaintType.COLORED:
567-
var ctx = this.ctx;
567+
const ctx = this.ctx;
568568
context.fillStyle = ctx.fillStyle;
569569
context.strokeStyle = ctx.strokeStyle;
570570
current.fillColor = ctx.fillStyle;
571571
current.strokeColor = ctx.strokeStyle;
572572
break;
573573
case PaintType.UNCOLORED:
574-
var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
574+
const cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
575575
context.fillStyle = cssColor;
576576
context.strokeStyle = cssColor;
577577
// Set color needed by image masks (fixes issues 3226 and 8741).

src/display/text_layer.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ const renderTextLayer = (function renderTextLayerClosure() {
237237
}
238238
// Box is rotated -- trying to find padding so rotated div will not
239239
// exceed its expanded bounds.
240-
var e = expanded[i],
240+
const e = expanded[i],
241241
b = bounds[i];
242-
var m = b.m,
242+
const m = b.m,
243243
c = m[0],
244244
s = m[1];
245245
// Finding intersections with expanded box.
246246
const points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
247-
var ts = new Float64Array(64);
247+
const ts = new Float64Array(64);
248248
points.forEach(function (p, j) {
249249
const t = Util.applyTransform(p, m);
250250
ts[j + 0] = c && (e.left - t[0]) / c;
@@ -368,7 +368,7 @@ const renderTextLayer = (function renderTextLayerClosure() {
368368
for (q = i; q <= j; q++) {
369369
horizonPart = horizon[q];
370370
affectedBoundary = horizonPart.boundary;
371-
var xNew;
371+
let xNew;
372372
if (affectedBoundary.x2 > boundary.x1) {
373373
// In the middle of the previous element, new x shall be at the
374374
// boundary start. Extending if further if the affected boundary
@@ -415,8 +415,8 @@ const renderTextLayer = (function renderTextLayerClosure() {
415415
}
416416

417417
// Fixing the horizon.
418-
let changedHorizon = [],
419-
lastBoundary = null;
418+
const changedHorizon = [];
419+
let lastBoundary = null;
420420
for (q = i; q <= j; q++) {
421421
horizonPart = horizon[q];
422422
affectedBoundary = horizonPart.boundary;

src/display/webgl.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class WebGLContext {
4848
}
4949
}
5050

51-
var WebGLUtils = (function WebGLUtilsClosure() {
51+
const WebGLUtils = (function WebGLUtilsClosure() {
5252
function loadShader(gl, code, shaderType) {
5353
const shader = gl.createShader(shaderType);
5454
gl.shaderSource(shader, code);
@@ -157,12 +157,10 @@ var WebGLUtils = (function WebGLUtilsClosure() {
157157
let smaskCache = null;
158158

159159
function initSmaskGL() {
160-
let canvas, gl;
161-
162160
generateGL();
163-
canvas = currentCanvas;
161+
const canvas = currentCanvas;
164162
currentCanvas = null;
165-
gl = currentGL;
163+
const gl = currentGL;
166164
currentGL = null;
167165

168166
// setup a GLSL program
@@ -302,12 +300,10 @@ var WebGLUtils = (function WebGLUtilsClosure() {
302300
let figuresCache = null;
303301

304302
function initFiguresGL() {
305-
let canvas, gl;
306-
307303
generateGL();
308-
canvas = currentCanvas;
304+
const canvas = currentCanvas;
309305
currentCanvas = null;
310-
gl = currentGL;
306+
const gl = currentGL;
311307
currentGL = null;
312308

313309
// setup a GLSL program
@@ -343,11 +339,11 @@ var WebGLUtils = (function WebGLUtilsClosure() {
343339

344340
// count triangle points
345341
let count = 0;
346-
let i, ii, rows;
347-
for (i = 0, ii = figures.length; i < ii; i++) {
342+
for (let i = 0, ii = figures.length; i < ii; i++) {
348343
switch (figures[i].type) {
349344
case "lattice":
350-
rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
345+
const rows =
346+
(figures[i].coords.length / figures[i].verticesPerRow) | 0;
351347
count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
352348
break;
353349
case "triangles":
@@ -362,14 +358,14 @@ var WebGLUtils = (function WebGLUtilsClosure() {
362358
colorsMap = context.colors;
363359
let pIndex = 0,
364360
cIndex = 0;
365-
for (i = 0, ii = figures.length; i < ii; i++) {
361+
for (let i = 0, ii = figures.length; i < ii; i++) {
366362
const figure = figures[i],
367363
ps = figure.coords,
368364
cs = figure.colors;
369365
switch (figure.type) {
370366
case "lattice":
371-
var cols = figure.verticesPerRow;
372-
rows = (ps.length / cols) | 0;
367+
const cols = figure.verticesPerRow;
368+
const rows = (ps.length / cols) | 0;
373369
for (let row = 1; row < rows; row++) {
374370
let offset = row * cols + 1;
375371
for (let col = 1; col < cols; col++, offset++) {

0 commit comments

Comments
 (0)