Merge pull request #13094 from timvandermeij/no-var-src

Enable the `no-var` linting rule for `src/core/{operator_list, pattern}.js`
This commit is contained in:
Tim van der Meij 2021-03-14 11:59:09 +01:00 committed by GitHub
commit 7fef896a9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 240 additions and 245 deletions

View File

@ -12,15 +12,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable no-var */
import { assert, ImageKind, OPS, warn } from "../shared/util.js";
var QueueOptimizer = (function QueueOptimizerClosure() {
const QueueOptimizer = (function QueueOptimizerClosure() {
function addState(parentState, pattern, checkFn, iterateFn, processFn) {
var state = parentState;
for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
var item = pattern[i];
let state = parentState;
for (let i = 0, ii = pattern.length - 1; i < ii; i++) {
const item = pattern[i];
state = state[item] || (state[item] = []);
}
state[pattern[pattern.length - 1]] = {
@ -40,10 +39,11 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
// draw lines with the current fill style.
// 'count' groups of (save, transform, paintImageMaskXObject, restore)+
// have been found at iFirstSave.
var iFirstPIMXO = iFirstSave + 2;
for (var i = 0; i < count; i++) {
var arg = argsArray[iFirstPIMXO + 4 * i];
var imageMask = arg.length === 1 && arg[0];
const iFirstPIMXO = iFirstSave + 2;
let i;
for (i = 0; i < count; i++) {
const arg = argsArray[iFirstPIMXO + 4 * i];
const imageMask = arg.length === 1 && arg[0];
if (
imageMask &&
imageMask.width === 1 &&
@ -59,7 +59,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
return count - i;
}
var InitialState = [];
const InitialState = [];
// This replaces (save, transform, paintInlineImageXObject, restore)+
// sequences with one |paintInlineImageXObjectGroup| operation.
@ -68,9 +68,9 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
[OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
null,
function iterateInlineImageGroup(context, i) {
var fnArray = context.fnArray;
var iFirstSave = context.iCurr - 3;
var pos = (i - iFirstSave) % 4;
const fnArray = context.fnArray;
const iFirstSave = context.iCurr - 3;
const pos = (i - iFirstSave) % 4;
switch (pos) {
case 0:
return fnArray[i] === OPS.save;
@ -84,19 +84,19 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
throw new Error(`iterateInlineImageGroup - invalid pos: ${pos}`);
},
function foundInlineImageGroup(context, i) {
var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
var MAX_WIDTH = 1000;
var IMAGE_PADDING = 1;
const MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
const MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
const MAX_WIDTH = 1000;
const IMAGE_PADDING = 1;
var fnArray = context.fnArray,
const fnArray = context.fnArray,
argsArray = context.argsArray;
var curr = context.iCurr;
var iFirstSave = curr - 3;
var iFirstTransform = curr - 2;
var iFirstPIIXO = curr - 1;
const curr = context.iCurr;
const iFirstSave = curr - 3;
const iFirstTransform = curr - 2;
const iFirstPIIXO = curr - 1;
var count = Math.min(
const count = Math.min(
Math.floor((i - iFirstSave) / 4),
MAX_IMAGES_IN_INLINE_IMAGES_BLOCK
);
@ -106,15 +106,14 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
// assuming that heights of those image is too small (~1 pixel)
// packing as much as possible by lines
var maxX = 0;
var map = [],
maxLineHeight = 0;
var currentX = IMAGE_PADDING,
let maxX = 0;
const map = [];
let maxLineHeight = 0;
let currentX = IMAGE_PADDING,
currentY = IMAGE_PADDING;
var q;
for (q = 0; q < count; q++) {
var transform = argsArray[iFirstTransform + (q << 2)];
var img = argsArray[iFirstPIIXO + (q << 2)][0];
for (let q = 0; q < count; q++) {
const transform = argsArray[iFirstTransform + (q << 2)];
const img = argsArray[iFirstPIIXO + (q << 2)][0];
if (currentX + img.width > MAX_WIDTH) {
// starting new line
maxX = Math.max(maxX, currentX);
@ -132,18 +131,18 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
currentX += img.width + 2 * IMAGE_PADDING;
maxLineHeight = Math.max(maxLineHeight, img.height);
}
var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
var imgData = new Uint8ClampedArray(imgWidth * imgHeight * 4);
var imgRowSize = imgWidth << 2;
for (q = 0; q < count; q++) {
var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
const imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
const imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
const imgData = new Uint8ClampedArray(imgWidth * imgHeight * 4);
const imgRowSize = imgWidth << 2;
for (let q = 0; q < count; q++) {
const data = argsArray[iFirstPIIXO + (q << 2)][0].data;
// Copy image by lines and extends pixels into padding.
var rowSize = map[q].w << 2;
var dataOffset = 0;
var offset = (map[q].x + map[q].y * imgWidth) << 2;
const rowSize = map[q].w << 2;
let dataOffset = 0;
let offset = (map[q].x + map[q].y * imgWidth) << 2;
imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
for (var k = 0, kk = map[q].h; k < kk; k++) {
for (let k = 0, kk = map[q].h; k < kk; k++) {
imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
dataOffset += rowSize;
offset += imgRowSize;
@ -186,9 +185,9 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
[OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
null,
function iterateImageMaskGroup(context, i) {
var fnArray = context.fnArray;
var iFirstSave = context.iCurr - 3;
var pos = (i - iFirstSave) % 4;
const fnArray = context.fnArray;
const iFirstSave = context.iCurr - 3;
const pos = (i - iFirstSave) % 4;
switch (pos) {
case 0:
return fnArray[i] === OPS.save;
@ -202,20 +201,20 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
throw new Error(`iterateImageMaskGroup - invalid pos: ${pos}`);
},
function foundImageMaskGroup(context, i) {
var MIN_IMAGES_IN_MASKS_BLOCK = 10;
var MAX_IMAGES_IN_MASKS_BLOCK = 100;
var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
const MIN_IMAGES_IN_MASKS_BLOCK = 10;
const MAX_IMAGES_IN_MASKS_BLOCK = 100;
const MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
var fnArray = context.fnArray,
const fnArray = context.fnArray,
argsArray = context.argsArray;
var curr = context.iCurr;
var iFirstSave = curr - 3;
var iFirstTransform = curr - 2;
var iFirstPIMXO = curr - 1;
const curr = context.iCurr;
const iFirstSave = curr - 3;
const iFirstTransform = curr - 2;
const iFirstPIMXO = curr - 1;
// At this point, i is the index of the first op past the last valid
// quartet.
var count = Math.floor((i - iFirstSave) / 4);
let count = Math.floor((i - iFirstSave) / 4);
count = handlePaintSolidColorImageMask(
iFirstSave,
count,
@ -226,10 +225,9 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
return i - ((i - iFirstSave) % 4);
}
var q;
var isSameImage = false;
var iTransform, transformArgs;
var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
let isSameImage = false;
let iTransform, transformArgs;
const firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
const firstTransformArg0 = argsArray[iFirstTransform][0],
firstTransformArg1 = argsArray[iFirstTransform][1],
firstTransformArg2 = argsArray[iFirstTransform][2],
@ -238,8 +236,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
if (firstTransformArg1 === firstTransformArg2) {
isSameImage = true;
iTransform = iFirstTransform + 4;
var iPIMXO = iFirstPIMXO + 4;
for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
let iPIMXO = iFirstPIMXO + 4;
for (let q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
transformArgs = argsArray[iTransform];
if (
argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
@ -260,9 +258,9 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
if (isSameImage) {
count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
var positions = new Float32Array(count * 2);
const positions = new Float32Array(count * 2);
iTransform = iFirstTransform;
for (q = 0; q < count; q++, iTransform += 4) {
for (let q = 0; q < count; q++, iTransform += 4) {
transformArgs = argsArray[iTransform];
positions[q << 1] = transformArgs[4];
positions[(q << 1) + 1] = transformArgs[5];
@ -280,10 +278,10 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
]);
} else {
count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
var images = [];
for (q = 0; q < count; q++) {
const images = [];
for (let q = 0; q < count; q++) {
transformArgs = argsArray[iFirstTransform + (q << 2)];
var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
const maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
images.push({
data: maskParams.data,
width: maskParams.width,
@ -308,18 +306,18 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
InitialState,
[OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
function (context) {
var argsArray = context.argsArray;
var iFirstTransform = context.iCurr - 2;
const argsArray = context.argsArray;
const iFirstTransform = context.iCurr - 2;
return (
argsArray[iFirstTransform][1] === 0 &&
argsArray[iFirstTransform][2] === 0
);
},
function iterateImageGroup(context, i) {
var fnArray = context.fnArray,
const fnArray = context.fnArray,
argsArray = context.argsArray;
var iFirstSave = context.iCurr - 3;
var pos = (i - iFirstSave) % 4;
const iFirstSave = context.iCurr - 3;
const pos = (i - iFirstSave) % 4;
switch (pos) {
case 0:
return fnArray[i] === OPS.save;
@ -327,9 +325,9 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
if (fnArray[i] !== OPS.transform) {
return false;
}
var iFirstTransform = context.iCurr - 2;
var firstTransformArg0 = argsArray[iFirstTransform][0];
var firstTransformArg3 = argsArray[iFirstTransform][3];
const iFirstTransform = context.iCurr - 2;
const firstTransformArg0 = argsArray[iFirstTransform][0];
const firstTransformArg3 = argsArray[iFirstTransform][3];
if (
argsArray[i][0] !== firstTransformArg0 ||
argsArray[i][1] !== 0 ||
@ -343,8 +341,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
if (fnArray[i] !== OPS.paintImageXObject) {
return false;
}
var iFirstPIXO = context.iCurr - 1;
var firstPIXOArg0 = argsArray[iFirstPIXO][0];
const iFirstPIXO = context.iCurr - 1;
const firstPIXOArg0 = argsArray[iFirstPIXO][0];
if (argsArray[i][0] !== firstPIXOArg0) {
return false; // images don't match
}
@ -355,22 +353,22 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
throw new Error(`iterateImageGroup - invalid pos: ${pos}`);
},
function (context, i) {
var MIN_IMAGES_IN_BLOCK = 3;
var MAX_IMAGES_IN_BLOCK = 1000;
const MIN_IMAGES_IN_BLOCK = 3;
const MAX_IMAGES_IN_BLOCK = 1000;
var fnArray = context.fnArray,
const fnArray = context.fnArray,
argsArray = context.argsArray;
var curr = context.iCurr;
var iFirstSave = curr - 3;
var iFirstTransform = curr - 2;
var iFirstPIXO = curr - 1;
var firstPIXOArg0 = argsArray[iFirstPIXO][0];
var firstTransformArg0 = argsArray[iFirstTransform][0];
var firstTransformArg3 = argsArray[iFirstTransform][3];
const curr = context.iCurr;
const iFirstSave = curr - 3;
const iFirstTransform = curr - 2;
const iFirstPIXO = curr - 1;
const firstPIXOArg0 = argsArray[iFirstPIXO][0];
const firstTransformArg0 = argsArray[iFirstTransform][0];
const firstTransformArg3 = argsArray[iFirstTransform][3];
// At this point, i is the index of the first op past the last valid
// quartet.
var count = Math.min(
const count = Math.min(
Math.floor((i - iFirstSave) / 4),
MAX_IMAGES_IN_BLOCK
);
@ -379,16 +377,16 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
}
// Extract the (x,y) positions from all of the matching transforms.
var positions = new Float32Array(count * 2);
var iTransform = iFirstTransform;
for (var q = 0; q < count; q++, iTransform += 4) {
var transformArgs = argsArray[iTransform];
const positions = new Float32Array(count * 2);
let iTransform = iFirstTransform;
for (let q = 0; q < count; q++, iTransform += 4) {
const transformArgs = argsArray[iTransform];
positions[q << 1] = transformArgs[4];
positions[(q << 1) + 1] = transformArgs[5];
}
// Replace queue items.
var args = [
const args = [
firstPIXOArg0,
firstTransformArg0,
firstTransformArg3,
@ -409,10 +407,10 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
[OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
null,
function iterateShowTextGroup(context, i) {
var fnArray = context.fnArray,
const fnArray = context.fnArray,
argsArray = context.argsArray;
var iFirstSave = context.iCurr - 4;
var pos = (i - iFirstSave) % 5;
const iFirstSave = context.iCurr - 4;
const pos = (i - iFirstSave) % 5;
switch (pos) {
case 0:
return fnArray[i] === OPS.beginText;
@ -424,9 +422,9 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
if (fnArray[i] !== OPS.showText) {
return false;
}
var iFirstSetFont = context.iCurr - 3;
var firstSetFontArg0 = argsArray[iFirstSetFont][0];
var firstSetFontArg1 = argsArray[iFirstSetFont][1];
const iFirstSetFont = context.iCurr - 3;
const firstSetFontArg0 = argsArray[iFirstSetFont][0];
const firstSetFontArg1 = argsArray[iFirstSetFont][1];
if (
argsArray[i][0] !== firstSetFontArg0 ||
argsArray[i][1] !== firstSetFontArg1
@ -440,23 +438,23 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
throw new Error(`iterateShowTextGroup - invalid pos: ${pos}`);
},
function (context, i) {
var MIN_CHARS_IN_BLOCK = 3;
var MAX_CHARS_IN_BLOCK = 1000;
const MIN_CHARS_IN_BLOCK = 3;
const MAX_CHARS_IN_BLOCK = 1000;
var fnArray = context.fnArray,
const fnArray = context.fnArray,
argsArray = context.argsArray;
var curr = context.iCurr;
var iFirstBeginText = curr - 4;
var iFirstSetFont = curr - 3;
var iFirstSetTextMatrix = curr - 2;
var iFirstShowText = curr - 1;
var iFirstEndText = curr;
var firstSetFontArg0 = argsArray[iFirstSetFont][0];
var firstSetFontArg1 = argsArray[iFirstSetFont][1];
const curr = context.iCurr;
const iFirstBeginText = curr - 4;
const iFirstSetFont = curr - 3;
const iFirstSetTextMatrix = curr - 2;
const iFirstShowText = curr - 1;
const iFirstEndText = curr;
const firstSetFontArg0 = argsArray[iFirstSetFont][0];
const firstSetFontArg1 = argsArray[iFirstSetFont][1];
// At this point, i is the index of the first op past the last valid
// quintet.
var count = Math.min(
let count = Math.min(
Math.floor((i - iFirstBeginText) / 5),
MAX_CHARS_IN_BLOCK
);
@ -467,7 +465,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
// If the preceding quintet is (<something>, setFont, setTextMatrix,
// showText, endText), include that as well. (E.g. <something> might be
// |dependency|.)
var iFirst = iFirstBeginText;
let iFirst = iFirstBeginText;
if (
iFirstBeginText >= 4 &&
fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
@ -482,8 +480,8 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
}
// Remove (endText, beginText, setFont) trios.
var iEndText = iFirst + 4;
for (var q = 1; q < count; q++) {
let iEndText = iFirst + 4;
for (let q = 1; q < count; q++) {
fnArray.splice(iEndText, 3);
argsArray.splice(iEndText, 3);
iEndText += 2;
@ -587,7 +585,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() {
return QueueOptimizer;
})();
var NullOptimizer = (function NullOptimizerClosure() {
const NullOptimizer = (function NullOptimizerClosure() {
// eslint-disable-next-line no-shadow
function NullOptimizer(queue) {
this.queue = queue;
@ -607,9 +605,9 @@ var NullOptimizer = (function NullOptimizerClosure() {
return NullOptimizer;
})();
var OperatorList = (function OperatorListClosure() {
var CHUNK_SIZE = 1000;
var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
const OperatorList = (function OperatorListClosure() {
const CHUNK_SIZE = 1000;
const CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
// eslint-disable-next-line no-shadow
function OperatorList(intent, streamSink) {
@ -682,7 +680,7 @@ var OperatorList = (function OperatorListClosure() {
for (const dependency of opList.dependencies) {
this.dependencies.add(dependency);
}
for (var i = 0, ii = opList.length; i < ii; i++) {
for (let i = 0, ii = opList.length; i < ii; i++) {
this.addOp(opList.fnArray[i], opList.argsArray[i]);
}
},

View File

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