Enable the ESLint no-var
rule in the src/core/font_renderer.js
file
Note that the majority of these changes were done automatically, by using `gulp lint --fix`, and the manual changes were limited to the following diff: ```diff diff --git a/src/core/font_renderer.js b/src/core/font_renderer.js index e1538c481..00f5424cd 100644 --- a/src/core/font_renderer.js +++ b/src/core/font_renderer.js @@ -152,9 +152,9 @@ const FontRendererFactory = (function FontRendererFactoryClosure() { } function lookupCmap(ranges, unicode) { - let code = unicode.codePointAt(0), - gid = 0; - let l = 0, + const code = unicode.codePointAt(0); + let gid = 0, + l = 0, r = ranges.length - 1; while (l < r) { const c = (l + r + 1) >> 1; @@ -199,7 +199,7 @@ const FontRendererFactory = (function FontRendererFactoryClosure() { flags = (code[i] << 8) | code[i + 1]; const glyphIndex = (code[i + 2] << 8) | code[i + 3]; i += 4; - var arg1, arg2; + let arg1, arg2; if (flags & 0x01) { arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16; arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16; @@ -366,7 +366,7 @@ const FontRendererFactory = (function FontRendererFactoryClosure() { while (i < code.length) { let stackClean = false; let v = code[i++]; - var xa, xb, ya, yb, y1, y2, y3, n, subrCode; + let xa, xb, ya, yb, y1, y2, y3, n, subrCode; switch (v) { case 1: // hstem stems += stack.length >> 1; @@ -494,7 +494,7 @@ const FontRendererFactory = (function FontRendererFactoryClosure() { bezierCurveTo(xa, y2, xb, y3, x, y); break; case 37: // flex1 - var x0 = x, + const x0 = x, y0 = y; xa = x + stack.shift(); ya = y + stack.shift(); ```
This commit is contained in:
parent
56fd01bf8d
commit
f3948aeb90
@ -12,7 +12,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* eslint-disable no-var */
|
||||
|
||||
import {
|
||||
bytesToString,
|
||||
@ -26,7 +25,7 @@ import { getGlyphsUnicode } from "./glyphlist.js";
|
||||
import { StandardEncoding } from "./encodings.js";
|
||||
import { Stream } from "./stream.js";
|
||||
|
||||
var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
const FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
function getLong(data, offset) {
|
||||
return (
|
||||
(data[offset] << 24) |
|
||||
@ -52,15 +51,15 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
}
|
||||
|
||||
function parseCmap(data, start, end) {
|
||||
var offset =
|
||||
const offset =
|
||||
getUshort(data, start + 2) === 1
|
||||
? getLong(data, start + 8)
|
||||
: getLong(data, start + 16);
|
||||
var format = getUshort(data, start + offset);
|
||||
var ranges, p, i;
|
||||
const format = getUshort(data, start + offset);
|
||||
let ranges, p, i;
|
||||
if (format === 4) {
|
||||
getUshort(data, start + offset + 2); // length
|
||||
var segCount = getUshort(data, start + offset + 6) >> 1;
|
||||
const segCount = getUshort(data, start + offset + 6) >> 1;
|
||||
p = start + offset + 14;
|
||||
ranges = [];
|
||||
for (i = 0; i < segCount; i++, p += 2) {
|
||||
@ -74,12 +73,12 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
ranges[i].idDelta = getUshort(data, p);
|
||||
}
|
||||
for (i = 0; i < segCount; i++, p += 2) {
|
||||
var idOffset = getUshort(data, p);
|
||||
let idOffset = getUshort(data, p);
|
||||
if (idOffset === 0) {
|
||||
continue;
|
||||
}
|
||||
ranges[i].ids = [];
|
||||
for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
|
||||
for (let j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
|
||||
ranges[i].ids[j] = getUshort(data, p + idOffset);
|
||||
idOffset += 2;
|
||||
}
|
||||
@ -87,7 +86,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
return ranges;
|
||||
} else if (format === 12) {
|
||||
getLong(data, start + offset + 4); // length
|
||||
var groups = getLong(data, start + offset + 12);
|
||||
const groups = getLong(data, start + offset + 12);
|
||||
p = start + offset + 16;
|
||||
ranges = [];
|
||||
for (i = 0; i < groups; i++) {
|
||||
@ -104,13 +103,13 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
}
|
||||
|
||||
function parseCff(data, start, end, seacAnalysisEnabled) {
|
||||
var properties = {};
|
||||
var parser = new CFFParser(
|
||||
const properties = {};
|
||||
const parser = new CFFParser(
|
||||
new Stream(data, start, end - start),
|
||||
properties,
|
||||
seacAnalysisEnabled
|
||||
);
|
||||
var cff = parser.parse();
|
||||
const cff = parser.parse();
|
||||
return {
|
||||
glyphs: cff.charStrings.objects,
|
||||
subrs:
|
||||
@ -125,7 +124,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
}
|
||||
|
||||
function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
|
||||
var itemSize, itemDecode;
|
||||
let itemSize, itemDecode;
|
||||
if (isGlyphLocationsLong) {
|
||||
itemSize = 4;
|
||||
itemDecode = function fontItemDecodeLong(data, offset) {
|
||||
@ -142,10 +141,10 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
return (data[offset] << 9) | (data[offset + 1] << 1);
|
||||
};
|
||||
}
|
||||
var glyphs = [];
|
||||
var startOffset = itemDecode(loca, 0);
|
||||
for (var j = itemSize; j < loca.length; j += itemSize) {
|
||||
var endOffset = itemDecode(loca, j);
|
||||
const glyphs = [];
|
||||
let startOffset = itemDecode(loca, 0);
|
||||
for (let j = itemSize; j < loca.length; j += itemSize) {
|
||||
const endOffset = itemDecode(loca, j);
|
||||
glyphs.push(glyf.subarray(startOffset, endOffset));
|
||||
startOffset = endOffset;
|
||||
}
|
||||
@ -153,12 +152,12 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
}
|
||||
|
||||
function lookupCmap(ranges, unicode) {
|
||||
var code = unicode.codePointAt(0),
|
||||
gid = 0;
|
||||
var l = 0,
|
||||
const code = unicode.codePointAt(0);
|
||||
let gid = 0,
|
||||
l = 0,
|
||||
r = ranges.length - 1;
|
||||
while (l < r) {
|
||||
var c = (l + r + 1) >> 1;
|
||||
const c = (l + r + 1) >> 1;
|
||||
if (code < ranges[c].start) {
|
||||
r = c - 1;
|
||||
} else {
|
||||
@ -188,19 +187,19 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
cmds.push({ cmd: "quadraticCurveTo", args: [xa, ya, x, y] });
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
|
||||
var flags;
|
||||
var x = 0,
|
||||
let i = 0;
|
||||
const numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
|
||||
let flags;
|
||||
let x = 0,
|
||||
y = 0;
|
||||
i += 10;
|
||||
if (numberOfContours < 0) {
|
||||
// composite glyph
|
||||
do {
|
||||
flags = (code[i] << 8) | code[i + 1];
|
||||
var glyphIndex = (code[i + 2] << 8) | code[i + 3];
|
||||
const glyphIndex = (code[i + 2] << 8) | code[i + 3];
|
||||
i += 4;
|
||||
var arg1, arg2;
|
||||
let arg1, arg2;
|
||||
if (flags & 0x01) {
|
||||
arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
|
||||
arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
|
||||
@ -216,7 +215,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
x = 0;
|
||||
y = 0; // TODO "they are points" ?
|
||||
}
|
||||
var scaleX = 1,
|
||||
let scaleX = 1,
|
||||
scaleY = 1,
|
||||
scale01 = 0,
|
||||
scale10 = 0;
|
||||
@ -235,7 +234,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
|
||||
i += 8;
|
||||
}
|
||||
var subglyph = font.glyphs[glyphIndex];
|
||||
const subglyph = font.glyphs[glyphIndex];
|
||||
if (subglyph) {
|
||||
cmds.push({ cmd: "save" });
|
||||
cmds.push({
|
||||
@ -248,19 +247,19 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
} while (flags & 0x20);
|
||||
} else {
|
||||
// simple glyph
|
||||
var endPtsOfContours = [];
|
||||
var j, jj;
|
||||
const endPtsOfContours = [];
|
||||
let j, jj;
|
||||
for (j = 0; j < numberOfContours; j++) {
|
||||
endPtsOfContours.push((code[i] << 8) | code[i + 1]);
|
||||
i += 2;
|
||||
}
|
||||
var instructionLength = (code[i] << 8) | code[i + 1];
|
||||
const instructionLength = (code[i] << 8) | code[i + 1];
|
||||
i += 2 + instructionLength; // skipping the instructions
|
||||
var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
|
||||
var points = [];
|
||||
const numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
|
||||
const points = [];
|
||||
while (points.length < numberOfPoints) {
|
||||
flags = code[i++];
|
||||
var repeat = 1;
|
||||
let repeat = 1;
|
||||
if (flags & 0x08) {
|
||||
repeat += code[i++];
|
||||
}
|
||||
@ -299,12 +298,12 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
points[j].y = y;
|
||||
}
|
||||
|
||||
var startPoint = 0;
|
||||
let startPoint = 0;
|
||||
for (i = 0; i < numberOfContours; i++) {
|
||||
var endPoint = endPtsOfContours[i];
|
||||
const endPoint = endPtsOfContours[i];
|
||||
// contours might have implicit points, which is located in the middle
|
||||
// between two neighboring off-curve points
|
||||
var contour = points.slice(startPoint, endPoint + 1);
|
||||
const contour = points.slice(startPoint, endPoint + 1);
|
||||
if (contour[0].flags & 1) {
|
||||
contour.push(contour[0]); // using start point at the contour end
|
||||
} else if (contour[contour.length - 1].flags & 1) {
|
||||
@ -312,7 +311,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
contour.unshift(contour[contour.length - 1]);
|
||||
} else {
|
||||
// start and end are off-curve points, creating implicit one
|
||||
var p = {
|
||||
const p = {
|
||||
flags: 1,
|
||||
x: (contour[0].x + contour[contour.length - 1].x) / 2,
|
||||
y: (contour[0].y + contour[contour.length - 1].y) / 2,
|
||||
@ -357,17 +356,17 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
cmds.push({ cmd: "bezierCurveTo", args: [x1, y1, x2, y2, x, y] });
|
||||
}
|
||||
|
||||
var stack = [];
|
||||
var x = 0,
|
||||
const stack = [];
|
||||
let x = 0,
|
||||
y = 0;
|
||||
var stems = 0;
|
||||
let stems = 0;
|
||||
|
||||
function parse(code) {
|
||||
var i = 0;
|
||||
let i = 0;
|
||||
while (i < code.length) {
|
||||
var stackClean = false;
|
||||
var v = code[i++];
|
||||
var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
|
||||
let stackClean = false;
|
||||
let v = code[i++];
|
||||
let xa, xb, ya, yb, y1, y2, y3, n, subrCode;
|
||||
switch (v) {
|
||||
case 1: // hstem
|
||||
stems += stack.length >> 1;
|
||||
@ -495,7 +494,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
bezierCurveTo(xa, y2, xb, y3, x, y);
|
||||
break;
|
||||
case 37: // flex1
|
||||
var x0 = x,
|
||||
const x0 = x,
|
||||
y0 = y;
|
||||
xa = x + stack.shift();
|
||||
ya = y + stack.shift();
|
||||
@ -523,13 +522,13 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
break;
|
||||
case 14: // endchar
|
||||
if (stack.length >= 4) {
|
||||
var achar = stack.pop();
|
||||
var bchar = stack.pop();
|
||||
const achar = stack.pop();
|
||||
const bchar = stack.pop();
|
||||
y = stack.pop();
|
||||
x = stack.pop();
|
||||
cmds.push({ cmd: "save" });
|
||||
cmds.push({ cmd: "translate", args: [x, y] });
|
||||
var cmap = lookupCmap(
|
||||
let cmap = lookupCmap(
|
||||
font.cmap,
|
||||
String.fromCharCode(font.glyphNameMap[StandardEncoding[achar]])
|
||||
);
|
||||
@ -830,13 +829,13 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
|
||||
return {
|
||||
create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
|
||||
var data = new Uint8Array(font.data);
|
||||
var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
|
||||
var numTables = getUshort(data, 4);
|
||||
for (var i = 0, p = 12; i < numTables; i++, p += 16) {
|
||||
var tag = bytesToString(data.subarray(p, p + 4));
|
||||
var offset = getLong(data, p + 8);
|
||||
var length = getLong(data, p + 12);
|
||||
const data = new Uint8Array(font.data);
|
||||
let cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
|
||||
const numTables = getUshort(data, 4);
|
||||
for (let i = 0, p = 12; i < numTables; i++, p += 16) {
|
||||
const tag = bytesToString(data.subarray(p, p + 4));
|
||||
const offset = getLong(data, p + 8);
|
||||
const length = getLong(data, p + 12);
|
||||
switch (tag) {
|
||||
case "cmap":
|
||||
cmap = parseCmap(data, offset, offset + length);
|
||||
@ -858,7 +857,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
}
|
||||
|
||||
if (glyf) {
|
||||
var fontMatrix = !unitsPerEm
|
||||
const fontMatrix = !unitsPerEm
|
||||
? font.fontMatrix
|
||||
: [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0];
|
||||
return new TrueTypeCompiled(
|
||||
|
Loading…
Reference in New Issue
Block a user