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