Merge pull request #13341 from Snuffleupagus/FontRendererFactory-rm-closure
Remove unnecessary closure in the `src/core/font_renderer.js` file
This commit is contained in:
commit
f66829e5ea
@ -25,21 +25,20 @@ 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";
|
||||||
|
|
||||||
const FontRendererFactory = (function FontRendererFactoryClosure() {
|
function getLong(data, offset) {
|
||||||
function getLong(data, offset) {
|
|
||||||
return (
|
return (
|
||||||
(data[offset] << 24) |
|
(data[offset] << 24) |
|
||||||
(data[offset + 1] << 16) |
|
(data[offset + 1] << 16) |
|
||||||
(data[offset + 2] << 8) |
|
(data[offset + 2] << 8) |
|
||||||
data[offset + 3]
|
data[offset + 3]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUshort(data, offset) {
|
function getUshort(data, offset) {
|
||||||
return (data[offset] << 8) | data[offset + 1];
|
return (data[offset] << 8) | data[offset + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSubroutineBias(subrs) {
|
function getSubroutineBias(subrs) {
|
||||||
const numSubrs = subrs.length;
|
const numSubrs = subrs.length;
|
||||||
let bias = 32768;
|
let bias = 32768;
|
||||||
if (numSubrs < 1240) {
|
if (numSubrs < 1240) {
|
||||||
@ -48,9 +47,9 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
bias = 1131;
|
bias = 1131;
|
||||||
}
|
}
|
||||||
return bias;
|
return bias;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCmap(data, start, end) {
|
function parseCmap(data, start, end) {
|
||||||
const offset =
|
const offset =
|
||||||
getUshort(data, start + 2) === 1
|
getUshort(data, start + 2) === 1
|
||||||
? getLong(data, start + 8)
|
? getLong(data, start + 8)
|
||||||
@ -100,9 +99,9 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
return ranges;
|
return ranges;
|
||||||
}
|
}
|
||||||
throw new FormatError(`unsupported cmap: ${format}`);
|
throw new FormatError(`unsupported cmap: ${format}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCff(data, start, end, seacAnalysisEnabled) {
|
function parseCff(data, start, end, seacAnalysisEnabled) {
|
||||||
const properties = {};
|
const properties = {};
|
||||||
const parser = new CFFParser(
|
const parser = new CFFParser(
|
||||||
new Stream(data, start, end - start),
|
new Stream(data, start, end - start),
|
||||||
@ -121,9 +120,9 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
fdSelect: cff.fdSelect,
|
fdSelect: cff.fdSelect,
|
||||||
fdArray: cff.fdArray,
|
fdArray: cff.fdArray,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
|
function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
|
||||||
let itemSize, itemDecode;
|
let itemSize, itemDecode;
|
||||||
if (isGlyphLocationsLong) {
|
if (isGlyphLocationsLong) {
|
||||||
itemSize = 4;
|
itemSize = 4;
|
||||||
@ -149,9 +148,9 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
startOffset = endOffset;
|
startOffset = endOffset;
|
||||||
}
|
}
|
||||||
return glyphs;
|
return glyphs;
|
||||||
}
|
}
|
||||||
|
|
||||||
function lookupCmap(ranges, unicode) {
|
function lookupCmap(ranges, unicode) {
|
||||||
const code = unicode.codePointAt(0);
|
const code = unicode.codePointAt(0);
|
||||||
let gid = 0,
|
let gid = 0,
|
||||||
l = 0,
|
l = 0,
|
||||||
@ -174,9 +173,9 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
charCode: code,
|
charCode: code,
|
||||||
glyphId: gid,
|
glyphId: gid,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function compileGlyf(code, cmds, font) {
|
function compileGlyf(code, cmds, font) {
|
||||||
function moveTo(x, y) {
|
function moveTo(x, y) {
|
||||||
cmds.push({ cmd: "moveTo", args: [x, y] });
|
cmds.push({ cmd: "moveTo", args: [x, y] });
|
||||||
}
|
}
|
||||||
@ -220,8 +219,7 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
scale01 = 0,
|
scale01 = 0,
|
||||||
scale10 = 0;
|
scale10 = 0;
|
||||||
if (flags & 0x08) {
|
if (flags & 0x08) {
|
||||||
scaleX = scaleY =
|
scaleX = scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
|
||||||
((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
|
|
||||||
i += 2;
|
i += 2;
|
||||||
} else if (flags & 0x40) {
|
} else if (flags & 0x40) {
|
||||||
scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
|
scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
|
||||||
@ -343,9 +341,9 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
startPoint = endPoint + 1;
|
startPoint = endPoint + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function compileCharString(charStringCode, cmds, font, glyphId) {
|
function compileCharString(charStringCode, cmds, font, glyphId) {
|
||||||
function moveTo(x, y) {
|
function moveTo(x, y) {
|
||||||
cmds.push({ cmd: "moveTo", args: [x, y] });
|
cmds.push({ cmd: "moveTo", args: [x, y] });
|
||||||
}
|
}
|
||||||
@ -720,11 +718,11 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
parse(charStringCode);
|
parse(charStringCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
const NOOP = [];
|
const NOOP = [];
|
||||||
|
|
||||||
class CompiledFont {
|
class CompiledFont {
|
||||||
constructor(fontMatrix) {
|
constructor(fontMatrix) {
|
||||||
if (this.constructor === CompiledFont) {
|
if (this.constructor === CompiledFont) {
|
||||||
unreachable("Cannot initialize CompiledFont.");
|
unreachable("Cannot initialize CompiledFont.");
|
||||||
@ -789,9 +787,9 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined
|
this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TrueTypeCompiled extends CompiledFont {
|
class TrueTypeCompiled extends CompiledFont {
|
||||||
constructor(glyphs, cmap, fontMatrix) {
|
constructor(glyphs, cmap, fontMatrix) {
|
||||||
super(fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0]);
|
super(fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0]);
|
||||||
|
|
||||||
@ -802,9 +800,9 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
compileGlyphImpl(code, cmds) {
|
compileGlyphImpl(code, cmds) {
|
||||||
compileGlyf(code, cmds, this);
|
compileGlyf(code, cmds, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Type2Compiled extends CompiledFont {
|
class Type2Compiled extends CompiledFont {
|
||||||
constructor(cffInfo, cmap, fontMatrix, glyphNameMap) {
|
constructor(cffInfo, cmap, fontMatrix, glyphNameMap) {
|
||||||
super(fontMatrix || [0.001, 0, 0, 0.001, 0, 0]);
|
super(fontMatrix || [0.001, 0, 0, 0.001, 0, 0]);
|
||||||
|
|
||||||
@ -825,10 +823,10 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
compileGlyphImpl(code, cmds, glyphId) {
|
compileGlyphImpl(code, cmds, glyphId) {
|
||||||
compileCharString(code, cmds, this, glyphId);
|
compileCharString(code, cmds, this, glyphId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
class FontRendererFactory {
|
||||||
create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
|
static create(font, seacAnalysisEnabled) {
|
||||||
const data = new Uint8Array(font.data);
|
const data = new Uint8Array(font.data);
|
||||||
let cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
|
let cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
|
||||||
const numTables = getUshort(data, 4);
|
const numTables = getUshort(data, 4);
|
||||||
@ -867,8 +865,7 @@ const FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
|
return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
})();
|
|
||||||
|
|
||||||
export { FontRendererFactory };
|
export { FontRendererFactory };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user