Enable the no-var linting rule for src/core/pattern.js

This is mostly done using `gulp lint --fix` with a few manual changes in
the following diff:

```diff
diff --git a/src/core/pattern.js b/src/core/pattern.js
index 365491ed3..eedd8b686 100644
--- a/src/core/pattern.js
+++ b/src/core/pattern.js
@@ -105,7 +105,7 @@ const Pattern = (function PatternClosure() {
   return Pattern;
 })();

-var Shadings = {};
+const Shadings = {};

 // A small number to offset the first/last color stops so we can insert ones to
 // support extend. Number.MIN_VALUE is too small and breaks the extend.
@@ -597,16 +597,15 @@ Shadings.Mesh = (function MeshClosure() {
       if (!(0 <= f && f <= 3)) {
         throw new FormatError("Unknown type6 flag");
       }
-      var i, ii;
       const pi = coords.length;
-      for (i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
+      for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
         coords.push(reader.readCoordinate());
       }
       const ci = colors.length;
-      for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
+      for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
         colors.push(reader.readComponents());
       }
-      var tmp1, tmp2, tmp3, tmp4;
+      let tmp1, tmp2, tmp3, tmp4;
       switch (f) {
         // prettier-ignore
         case 0:
@@ -729,16 +728,15 @@ Shadings.Mesh = (function MeshClosure() {
       if (!(0 <= f && f <= 3)) {
         throw new FormatError("Unknown type7 flag");
       }
-      var i, ii;
       const pi = coords.length;
-      for (i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
+      for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
         coords.push(reader.readCoordinate());
       }
       const ci = colors.length;
-      for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
+      for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
         colors.push(reader.readComponents());
       }
-      var tmp1, tmp2, tmp3, tmp4;
+      let tmp1, tmp2, tmp3, tmp4;
       switch (f) {
         // prettier-ignore
         case 0:
@@ -897,7 +895,7 @@ Shadings.Mesh = (function MeshClosure() {
         decodeType4Shading(this, reader);
         break;
       case ShadingType.LATTICE_FORM_MESH:
-        var verticesPerRow = dict.get("VerticesPerRow") | 0;
+        const verticesPerRow = dict.get("VerticesPerRow") | 0;
         if (verticesPerRow < 2) {
           throw new FormatError("Invalid VerticesPerRow");
         }
```
This commit is contained in:
Tim van der Meij 2021-03-13 17:54:52 +01:00
parent 67b866b9ed
commit 24ff738e7b
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint-disable no-var */
import { import {
assert, assert,
@ -27,7 +26,7 @@ import { ColorSpace } from "./colorspace.js";
import { isStream } from "./primitives.js"; import { isStream } from "./primitives.js";
import { MissingDataException } from "./core_utils.js"; import { MissingDataException } from "./core_utils.js";
var ShadingType = { const ShadingType = {
FUNCTION_BASED: 1, FUNCTION_BASED: 1,
AXIAL: 2, AXIAL: 2,
RADIAL: 3, RADIAL: 3,
@ -37,7 +36,7 @@ var ShadingType = {
TENSOR_PATCH_MESH: 7, TENSOR_PATCH_MESH: 7,
}; };
var Pattern = (function PatternClosure() { const Pattern = (function PatternClosure() {
// Constructor should define this.getPattern // Constructor should define this.getPattern
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
function Pattern() { function Pattern() {
@ -61,8 +60,8 @@ var Pattern = (function PatternClosure() {
pdfFunctionFactory, pdfFunctionFactory,
localColorSpaceCache localColorSpaceCache
) { ) {
var dict = isStream(shading) ? shading.dict : shading; const dict = isStream(shading) ? shading.dict : shading;
var type = dict.get("ShadingType"); const type = dict.get("ShadingType");
try { try {
switch (type) { switch (type) {
@ -106,7 +105,7 @@ var Pattern = (function PatternClosure() {
return Pattern; return Pattern;
})(); })();
var Shadings = {}; const Shadings = {};
// A small number to offset the first/last color stops so we can insert ones to // A small number to offset the first/last color stops so we can insert ones to
// support extend. Number.MIN_VALUE is too small and breaks the extend. // support extend. Number.MIN_VALUE is too small and breaks the extend.
@ -142,18 +141,18 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
this.bbox = null; this.bbox = null;
} }
var t0 = 0.0, let t0 = 0.0,
t1 = 1.0; t1 = 1.0;
if (dict.has("Domain")) { if (dict.has("Domain")) {
var domainArr = dict.getArray("Domain"); const domainArr = dict.getArray("Domain");
t0 = domainArr[0]; t0 = domainArr[0];
t1 = domainArr[1]; t1 = domainArr[1];
} }
var extendStart = false, let extendStart = false,
extendEnd = false; extendEnd = false;
if (dict.has("Extend")) { if (dict.has("Extend")) {
var extendArr = dict.getArray("Extend"); const extendArr = dict.getArray("Extend");
extendStart = extendArr[0]; extendStart = extendArr[0];
extendEnd = extendArr[1]; extendEnd = extendArr[1];
} }
@ -174,8 +173,8 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
this.extendStart = extendStart; this.extendStart = extendStart;
this.extendEnd = extendEnd; this.extendEnd = extendEnd;
var fnObj = dict.getRaw("Function"); const fnObj = dict.getRaw("Function");
var fn = pdfFunctionFactory.createFromArray(fnObj); const fn = pdfFunctionFactory.createFromArray(fnObj);
// 10 samples seems good enough for now, but probably won't work // 10 samples seems good enough for now, but probably won't work
// if there are sharp color changes. Ideally, we would implement // if there are sharp color changes. Ideally, we would implement
@ -183,7 +182,7 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
const NUMBER_OF_SAMPLES = 10; const NUMBER_OF_SAMPLES = 10;
const step = (t1 - t0) / NUMBER_OF_SAMPLES; const step = (t1 - t0) / NUMBER_OF_SAMPLES;
var colorStops = (this.colorStops = []); const colorStops = (this.colorStops = []);
// Protect against bad domains. // Protect against bad domains.
if (t0 >= t1 || step <= 0) { if (t0 >= t1 || step <= 0) {
@ -193,18 +192,18 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
return; return;
} }
var color = new Float32Array(cs.numComps), const color = new Float32Array(cs.numComps),
ratio = new Float32Array(1); ratio = new Float32Array(1);
var rgbColor; let rgbColor;
for (let i = 0; i <= NUMBER_OF_SAMPLES; i++) { for (let i = 0; i <= NUMBER_OF_SAMPLES; i++) {
ratio[0] = t0 + i * step; ratio[0] = t0 + i * step;
fn(ratio, 0, color, 0); fn(ratio, 0, color, 0);
rgbColor = cs.getRgb(color, 0); rgbColor = cs.getRgb(color, 0);
var cssColor = Util.makeHexColor(rgbColor[0], rgbColor[1], rgbColor[2]); const cssColor = Util.makeHexColor(rgbColor[0], rgbColor[1], rgbColor[2]);
colorStops.push([i / NUMBER_OF_SAMPLES, cssColor]); colorStops.push([i / NUMBER_OF_SAMPLES, cssColor]);
} }
var background = "transparent"; let background = "transparent";
if (dict.has("Background")) { if (dict.has("Background")) {
rgbColor = cs.getRgb(dict.get("Background"), 0); rgbColor = cs.getRgb(dict.get("Background"), 0);
background = Util.makeHexColor(rgbColor[0], rgbColor[1], rgbColor[2]); background = Util.makeHexColor(rgbColor[0], rgbColor[1], rgbColor[2]);
@ -227,9 +226,9 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
RadialAxial.prototype = { RadialAxial.prototype = {
getIR: function RadialAxial_getIR() { getIR: function RadialAxial_getIR() {
var coordsArr = this.coordsArr; const coordsArr = this.coordsArr;
var shadingType = this.shadingType; const shadingType = this.shadingType;
var type, p0, p1, r0, r1; let type, p0, p1, r0, r1;
if (shadingType === ShadingType.AXIAL) { if (shadingType === ShadingType.AXIAL) {
p0 = [coordsArr[0], coordsArr[1]]; p0 = [coordsArr[0], coordsArr[1]];
p1 = [coordsArr[2], coordsArr[3]]; p1 = [coordsArr[2], coordsArr[3]];
@ -246,12 +245,12 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
unreachable(`getPattern type unknown: ${shadingType}`); unreachable(`getPattern type unknown: ${shadingType}`);
} }
var matrix = this.matrix; const matrix = this.matrix;
if (matrix) { if (matrix) {
p0 = Util.applyTransform(p0, matrix); p0 = Util.applyTransform(p0, matrix);
p1 = Util.applyTransform(p1, matrix); p1 = Util.applyTransform(p1, matrix);
if (shadingType === ShadingType.RADIAL) { if (shadingType === ShadingType.RADIAL) {
var scale = Util.singularValueDecompose2dScale(matrix); const scale = Util.singularValueDecompose2dScale(matrix);
r0 *= scale[0]; r0 *= scale[0];
r1 *= scale[1]; r1 *= scale[1];
} }
@ -273,9 +272,9 @@ Shadings.Mesh = (function MeshClosure() {
this.buffer = 0; this.buffer = 0;
this.bufferLength = 0; this.bufferLength = 0;
var numComps = context.numComps; const numComps = context.numComps;
this.tmpCompsBuf = new Float32Array(numComps); this.tmpCompsBuf = new Float32Array(numComps);
var csNumComps = context.colorSpace.numComps; const csNumComps = context.colorSpace.numComps;
this.tmpCsCompsBuf = context.colorFn this.tmpCsCompsBuf = context.colorFn
? new Float32Array(csNumComps) ? new Float32Array(csNumComps)
: this.tmpCompsBuf; : this.tmpCompsBuf;
@ -288,7 +287,7 @@ Shadings.Mesh = (function MeshClosure() {
if (this.bufferLength > 0) { if (this.bufferLength > 0) {
return true; return true;
} }
var nextByte = this.stream.getByte(); const nextByte = this.stream.getByte();
if (nextByte < 0) { if (nextByte < 0) {
return false; return false;
} }
@ -297,8 +296,8 @@ Shadings.Mesh = (function MeshClosure() {
return true; return true;
}, },
readBits: function MeshStreamReader_readBits(n) { readBits: function MeshStreamReader_readBits(n) {
var buffer = this.buffer; let buffer = this.buffer;
var bufferLength = this.bufferLength; let bufferLength = this.bufferLength;
if (n === 32) { if (n === 32) {
if (bufferLength === 0) { if (bufferLength === 0) {
return ( return (
@ -314,7 +313,7 @@ Shadings.Mesh = (function MeshClosure() {
(this.stream.getByte() << 16) | (this.stream.getByte() << 16) |
(this.stream.getByte() << 8) | (this.stream.getByte() << 8) |
this.stream.getByte(); this.stream.getByte();
var nextByte = this.stream.getByte(); const nextByte = this.stream.getByte();
this.buffer = nextByte & ((1 << bufferLength) - 1); this.buffer = nextByte & ((1 << bufferLength) - 1);
return ( return (
((buffer << (8 - bufferLength)) | ((buffer << (8 - bufferLength)) |
@ -342,11 +341,11 @@ Shadings.Mesh = (function MeshClosure() {
return this.readBits(this.context.bitsPerFlag); return this.readBits(this.context.bitsPerFlag);
}, },
readCoordinate: function MeshStreamReader_readCoordinate() { readCoordinate: function MeshStreamReader_readCoordinate() {
var bitsPerCoordinate = this.context.bitsPerCoordinate; const bitsPerCoordinate = this.context.bitsPerCoordinate;
var xi = this.readBits(bitsPerCoordinate); const xi = this.readBits(bitsPerCoordinate);
var yi = this.readBits(bitsPerCoordinate); const yi = this.readBits(bitsPerCoordinate);
var decode = this.context.decode; const decode = this.context.decode;
var scale = const scale =
bitsPerCoordinate < 32 bitsPerCoordinate < 32
? 1 / ((1 << bitsPerCoordinate) - 1) ? 1 / ((1 << bitsPerCoordinate) - 1)
: 2.3283064365386963e-10; // 2 ^ -32 : 2.3283064365386963e-10; // 2 ^ -32
@ -356,19 +355,19 @@ Shadings.Mesh = (function MeshClosure() {
]; ];
}, },
readComponents: function MeshStreamReader_readComponents() { readComponents: function MeshStreamReader_readComponents() {
var numComps = this.context.numComps; const numComps = this.context.numComps;
var bitsPerComponent = this.context.bitsPerComponent; const bitsPerComponent = this.context.bitsPerComponent;
var scale = const scale =
bitsPerComponent < 32 bitsPerComponent < 32
? 1 / ((1 << bitsPerComponent) - 1) ? 1 / ((1 << bitsPerComponent) - 1)
: 2.3283064365386963e-10; // 2 ^ -32 : 2.3283064365386963e-10; // 2 ^ -32
var decode = this.context.decode; const decode = this.context.decode;
var components = this.tmpCompsBuf; const components = this.tmpCompsBuf;
for (var i = 0, j = 4; i < numComps; i++, j += 2) { for (let i = 0, j = 4; i < numComps; i++, j += 2) {
var ci = this.readBits(bitsPerComponent); const ci = this.readBits(bitsPerComponent);
components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j]; components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
} }
var color = this.tmpCsCompsBuf; const color = this.tmpCsCompsBuf;
if (this.context.colorFn) { if (this.context.colorFn) {
this.context.colorFn(components, 0, color, 0); this.context.colorFn(components, 0, color, 0);
} }
@ -377,15 +376,15 @@ Shadings.Mesh = (function MeshClosure() {
}; };
function decodeType4Shading(mesh, reader) { function decodeType4Shading(mesh, reader) {
var coords = mesh.coords; const coords = mesh.coords;
var colors = mesh.colors; const colors = mesh.colors;
var operators = []; const operators = [];
var ps = []; // not maintaining cs since that will match ps const ps = []; // not maintaining cs since that will match ps
var verticesLeft = 0; // assuming we have all data to start a new triangle let verticesLeft = 0; // assuming we have all data to start a new triangle
while (reader.hasData) { while (reader.hasData) {
var f = reader.readFlag(); const f = reader.readFlag();
var coord = reader.readCoordinate(); const coord = reader.readCoordinate();
var color = reader.readComponents(); const color = reader.readComponents();
if (verticesLeft === 0) { if (verticesLeft === 0) {
// ignoring flags if we started a triangle // ignoring flags if we started a triangle
if (!(0 <= f && f <= 2)) { if (!(0 <= f && f <= 2)) {
@ -421,12 +420,12 @@ Shadings.Mesh = (function MeshClosure() {
} }
function decodeType5Shading(mesh, reader, verticesPerRow) { function decodeType5Shading(mesh, reader, verticesPerRow) {
var coords = mesh.coords; const coords = mesh.coords;
var colors = mesh.colors; const colors = mesh.colors;
var ps = []; // not maintaining cs since that will match ps const ps = []; // not maintaining cs since that will match ps
while (reader.hasData) { while (reader.hasData) {
var coord = reader.readCoordinate(); const coord = reader.readCoordinate();
var color = reader.readComponents(); const color = reader.readComponents();
ps.push(coords.length); ps.push(coords.length);
coords.push(coord); coords.push(coord);
colors.push(color); colors.push(color);
@ -439,16 +438,16 @@ Shadings.Mesh = (function MeshClosure() {
}); });
} }
var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3; const MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20; const MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds const TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
var getB = (function getBClosure() { const getB = (function getBClosure() {
function buildB(count) { function buildB(count) {
var lut = []; const lut = [];
for (var i = 0; i <= count; i++) { for (let i = 0; i <= count; i++) {
var t = i / count, const t = i / count,
t_ = 1 - t; t_ = 1 - t;
lut.push( lut.push(
new Float32Array([ new Float32Array([
@ -461,7 +460,7 @@ Shadings.Mesh = (function MeshClosure() {
} }
return lut; return lut;
} }
var cache = []; const cache = [];
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
return function getB(count) { return function getB(count) {
@ -473,39 +472,39 @@ Shadings.Mesh = (function MeshClosure() {
})(); })();
function buildFigureFromPatch(mesh, index) { function buildFigureFromPatch(mesh, index) {
var figure = mesh.figures[index]; const figure = mesh.figures[index];
assert(figure.type === "patch", "Unexpected patch mesh figure"); assert(figure.type === "patch", "Unexpected patch mesh figure");
var coords = mesh.coords, const coords = mesh.coords,
colors = mesh.colors; colors = mesh.colors;
var pi = figure.coords; const pi = figure.coords;
var ci = figure.colors; const ci = figure.colors;
var figureMinX = Math.min( const figureMinX = Math.min(
coords[pi[0]][0], coords[pi[0]][0],
coords[pi[3]][0], coords[pi[3]][0],
coords[pi[12]][0], coords[pi[12]][0],
coords[pi[15]][0] coords[pi[15]][0]
); );
var figureMinY = Math.min( const figureMinY = Math.min(
coords[pi[0]][1], coords[pi[0]][1],
coords[pi[3]][1], coords[pi[3]][1],
coords[pi[12]][1], coords[pi[12]][1],
coords[pi[15]][1] coords[pi[15]][1]
); );
var figureMaxX = Math.max( const figureMaxX = Math.max(
coords[pi[0]][0], coords[pi[0]][0],
coords[pi[3]][0], coords[pi[3]][0],
coords[pi[12]][0], coords[pi[12]][0],
coords[pi[15]][0] coords[pi[15]][0]
); );
var figureMaxY = Math.max( const figureMaxY = Math.max(
coords[pi[0]][1], coords[pi[0]][1],
coords[pi[3]][1], coords[pi[3]][1],
coords[pi[12]][1], coords[pi[12]][1],
coords[pi[15]][1] coords[pi[15]][1]
); );
var splitXBy = Math.ceil( let splitXBy = Math.ceil(
((figureMaxX - figureMinX) * TRIANGLE_DENSITY) / ((figureMaxX - figureMinX) * TRIANGLE_DENSITY) /
(mesh.bounds[2] - mesh.bounds[0]) (mesh.bounds[2] - mesh.bounds[0])
); );
@ -513,7 +512,7 @@ Shadings.Mesh = (function MeshClosure() {
MIN_SPLIT_PATCH_CHUNKS_AMOUNT, MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy) Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy)
); );
var splitYBy = Math.ceil( let splitYBy = Math.ceil(
((figureMaxY - figureMinY) * TRIANGLE_DENSITY) / ((figureMaxY - figureMinY) * TRIANGLE_DENSITY) /
(mesh.bounds[3] - mesh.bounds[1]) (mesh.bounds[3] - mesh.bounds[1])
); );
@ -522,19 +521,19 @@ Shadings.Mesh = (function MeshClosure() {
Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy) Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy)
); );
var verticesPerRow = splitXBy + 1; const verticesPerRow = splitXBy + 1;
var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow); const figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow); const figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
var k = 0; let k = 0;
var cl = new Uint8Array(3), const cl = new Uint8Array(3),
cr = new Uint8Array(3); cr = new Uint8Array(3);
var c0 = colors[ci[0]], const c0 = colors[ci[0]],
c1 = colors[ci[1]], c1 = colors[ci[1]],
c2 = colors[ci[2]], c2 = colors[ci[2]],
c3 = colors[ci[3]]; c3 = colors[ci[3]];
var bRow = getB(splitYBy), const bRow = getB(splitYBy),
bCol = getB(splitXBy); bCol = getB(splitXBy);
for (var row = 0; row <= splitYBy; row++) { for (let row = 0; row <= splitYBy; row++) {
cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0; cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0; cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0; cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
@ -543,19 +542,19 @@ Shadings.Mesh = (function MeshClosure() {
cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0; cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0; cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
for (var col = 0; col <= splitXBy; col++, k++) { for (let col = 0; col <= splitXBy; col++, k++) {
if ( if (
(row === 0 || row === splitYBy) && (row === 0 || row === splitYBy) &&
(col === 0 || col === splitXBy) (col === 0 || col === splitXBy)
) { ) {
continue; continue;
} }
var x = 0, let x = 0,
y = 0; y = 0;
var q = 0; let q = 0;
for (var i = 0; i <= 3; i++) { for (let i = 0; i <= 3; i++) {
for (var j = 0; j <= 3; j++, q++) { for (let j = 0; j <= 3; j++, q++) {
var m = bRow[row][i] * bCol[col][j]; const m = bRow[row][i] * bCol[col][j];
x += coords[pi[q]][0] * m; x += coords[pi[q]][0] * m;
y += coords[pi[q]][1] * m; y += coords[pi[q]][1] * m;
} }
@ -563,7 +562,7 @@ Shadings.Mesh = (function MeshClosure() {
figureCoords[k] = coords.length; figureCoords[k] = coords.length;
coords.push([x, y]); coords.push([x, y]);
figureColors[k] = colors.length; figureColors[k] = colors.length;
var newColor = new Uint8Array(3); const newColor = new Uint8Array(3);
newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0; newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0; newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0; newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
@ -589,25 +588,24 @@ Shadings.Mesh = (function MeshClosure() {
function decodeType6Shading(mesh, reader) { function decodeType6Shading(mesh, reader) {
// A special case of Type 7. The p11, p12, p21, p22 automatically filled // A special case of Type 7. The p11, p12, p21, p22 automatically filled
var coords = mesh.coords; const coords = mesh.coords;
var colors = mesh.colors; const colors = mesh.colors;
var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33 const ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
var cs = new Int32Array(4); // c00, c30, c03, c33 const cs = new Int32Array(4); // c00, c30, c03, c33
while (reader.hasData) { while (reader.hasData) {
var f = reader.readFlag(); const f = reader.readFlag();
if (!(0 <= f && f <= 3)) { if (!(0 <= f && f <= 3)) {
throw new FormatError("Unknown type6 flag"); throw new FormatError("Unknown type6 flag");
} }
var i, ii; const pi = coords.length;
var pi = coords.length; for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
for (i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
coords.push(reader.readCoordinate()); coords.push(reader.readCoordinate());
} }
var ci = colors.length; const ci = colors.length;
for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) { for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
colors.push(reader.readComponents()); colors.push(reader.readComponents());
} }
var tmp1, tmp2, tmp3, tmp4; let tmp1, tmp2, tmp3, tmp4;
switch (f) { switch (f) {
// prettier-ignore // prettier-ignore
case 0: case 0:
@ -721,25 +719,24 @@ Shadings.Mesh = (function MeshClosure() {
} }
function decodeType7Shading(mesh, reader) { function decodeType7Shading(mesh, reader) {
var coords = mesh.coords; const coords = mesh.coords;
var colors = mesh.colors; const colors = mesh.colors;
var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33 const ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
var cs = new Int32Array(4); // c00, c30, c03, c33 const cs = new Int32Array(4); // c00, c30, c03, c33
while (reader.hasData) { while (reader.hasData) {
var f = reader.readFlag(); const f = reader.readFlag();
if (!(0 <= f && f <= 3)) { if (!(0 <= f && f <= 3)) {
throw new FormatError("Unknown type7 flag"); throw new FormatError("Unknown type7 flag");
} }
var i, ii; const pi = coords.length;
var pi = coords.length; for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
for (i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
coords.push(reader.readCoordinate()); coords.push(reader.readCoordinate());
} }
var ci = colors.length; const ci = colors.length;
for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) { for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
colors.push(reader.readComponents()); colors.push(reader.readComponents());
} }
var tmp1, tmp2, tmp3, tmp4; let tmp1, tmp2, tmp3, tmp4;
switch (f) { switch (f) {
// prettier-ignore // prettier-ignore
case 0: case 0:
@ -792,12 +789,12 @@ Shadings.Mesh = (function MeshClosure() {
} }
function updateBounds(mesh) { function updateBounds(mesh) {
var minX = mesh.coords[0][0], let minX = mesh.coords[0][0],
minY = mesh.coords[0][1], minY = mesh.coords[0][1],
maxX = minX, maxX = minX,
maxY = minY; maxY = minY;
for (var i = 1, ii = mesh.coords.length; i < ii; i++) { for (let i = 1, ii = mesh.coords.length; i < ii; i++) {
var x = mesh.coords[i][0], const x = mesh.coords[i][0],
y = mesh.coords[i][1]; y = mesh.coords[i][1];
minX = minX > x ? x : minX; minX = minX > x ? x : minX;
minY = minY > y ? y : minY; minY = minY > y ? y : minY;
@ -808,30 +805,30 @@ Shadings.Mesh = (function MeshClosure() {
} }
function packData(mesh) { function packData(mesh) {
var i, ii, j, jj; let i, ii, j, jj;
var coords = mesh.coords; const coords = mesh.coords;
var coordsPacked = new Float32Array(coords.length * 2); const coordsPacked = new Float32Array(coords.length * 2);
for (i = 0, j = 0, ii = coords.length; i < ii; i++) { for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
var xy = coords[i]; const xy = coords[i];
coordsPacked[j++] = xy[0]; coordsPacked[j++] = xy[0];
coordsPacked[j++] = xy[1]; coordsPacked[j++] = xy[1];
} }
mesh.coords = coordsPacked; mesh.coords = coordsPacked;
var colors = mesh.colors; const colors = mesh.colors;
var colorsPacked = new Uint8Array(colors.length * 3); const colorsPacked = new Uint8Array(colors.length * 3);
for (i = 0, j = 0, ii = colors.length; i < ii; i++) { for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
var c = colors[i]; const c = colors[i];
colorsPacked[j++] = c[0]; colorsPacked[j++] = c[0];
colorsPacked[j++] = c[1]; colorsPacked[j++] = c[1];
colorsPacked[j++] = c[2]; colorsPacked[j++] = c[2];
} }
mesh.colors = colorsPacked; mesh.colors = colorsPacked;
var figures = mesh.figures; const figures = mesh.figures;
for (i = 0, ii = figures.length; i < ii; i++) { for (i = 0, ii = figures.length; i < ii; i++) {
var figure = figures[i], const figure = figures[i],
ps = figure.coords, ps = figure.coords,
cs = figure.colors; cs = figure.colors;
for (j = 0, jj = ps.length; j < jj; j++) { for (j = 0, jj = ps.length; j < jj; j++) {
@ -852,7 +849,7 @@ Shadings.Mesh = (function MeshClosure() {
if (!isStream(stream)) { if (!isStream(stream)) {
throw new FormatError("Mesh data is not a stream"); throw new FormatError("Mesh data is not a stream");
} }
var dict = stream.dict; const dict = stream.dict;
this.matrix = matrix; this.matrix = matrix;
this.shadingType = dict.get("ShadingType"); this.shadingType = dict.get("ShadingType");
this.type = "Pattern"; this.type = "Pattern";
@ -874,14 +871,14 @@ Shadings.Mesh = (function MeshClosure() {
? cs.getRgb(dict.get("Background"), 0) ? cs.getRgb(dict.get("Background"), 0)
: null; : null;
var fnObj = dict.getRaw("Function"); const fnObj = dict.getRaw("Function");
var fn = fnObj ? pdfFunctionFactory.createFromArray(fnObj) : null; const fn = fnObj ? pdfFunctionFactory.createFromArray(fnObj) : null;
this.coords = []; this.coords = [];
this.colors = []; this.colors = [];
this.figures = []; this.figures = [];
var decodeContext = { const decodeContext = {
bitsPerCoordinate: dict.get("BitsPerCoordinate"), bitsPerCoordinate: dict.get("BitsPerCoordinate"),
bitsPerComponent: dict.get("BitsPerComponent"), bitsPerComponent: dict.get("BitsPerComponent"),
bitsPerFlag: dict.get("BitsPerFlag"), bitsPerFlag: dict.get("BitsPerFlag"),
@ -890,15 +887,15 @@ Shadings.Mesh = (function MeshClosure() {
colorSpace: cs, colorSpace: cs,
numComps: fn ? 1 : cs.numComps, numComps: fn ? 1 : cs.numComps,
}; };
var reader = new MeshStreamReader(stream, decodeContext); const reader = new MeshStreamReader(stream, decodeContext);
var patchMesh = false; let patchMesh = false;
switch (this.shadingType) { switch (this.shadingType) {
case ShadingType.FREE_FORM_MESH: case ShadingType.FREE_FORM_MESH:
decodeType4Shading(this, reader); decodeType4Shading(this, reader);
break; break;
case ShadingType.LATTICE_FORM_MESH: case ShadingType.LATTICE_FORM_MESH:
var verticesPerRow = dict.get("VerticesPerRow") | 0; const verticesPerRow = dict.get("VerticesPerRow") | 0;
if (verticesPerRow < 2) { if (verticesPerRow < 2) {
throw new FormatError("Invalid VerticesPerRow"); throw new FormatError("Invalid VerticesPerRow");
} }
@ -920,7 +917,7 @@ Shadings.Mesh = (function MeshClosure() {
if (patchMesh) { if (patchMesh) {
// dirty bounds calculation for determining, how dense shall be triangles // dirty bounds calculation for determining, how dense shall be triangles
updateBounds(this); updateBounds(this);
for (var i = 0, ii = this.figures.length; i < ii; i++) { for (let i = 0, ii = this.figures.length; i < ii; i++) {
buildFigureFromPatch(this, i); buildFigureFromPatch(this, i);
} }
} }