Convert CompiledFont
, TrueTypeCompiled
, and Type2Compiled
to ES6 classes
Also changes `var` to `let`/`const` in code already touched in the patch.
This commit is contained in:
parent
775763a091
commit
ba1af46709
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
bytesToString, FONT_IDENTITY_MATRIX, FormatError, unreachable, Util, warn
|
bytesToString, FONT_IDENTITY_MATRIX, FormatError, unreachable, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { CFFParser } from './cff_parser';
|
import { CFFParser } from './cff_parser';
|
||||||
import { getGlyphsUnicode } from './glyphlist';
|
import { getGlyphsUnicode } from './glyphlist';
|
||||||
@ -618,15 +618,20 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
|
|
||||||
const NOOP = [];
|
const NOOP = [];
|
||||||
|
|
||||||
function CompiledFont(fontMatrix) {
|
class CompiledFont {
|
||||||
this.compiledGlyphs = Object.create(null);
|
constructor(fontMatrix) {
|
||||||
this.compiledCharCodeToGlyphId = Object.create(null);
|
if (this.constructor === CompiledFont) {
|
||||||
this.fontMatrix = fontMatrix;
|
unreachable('Cannot initialize CompiledFont.');
|
||||||
}
|
}
|
||||||
CompiledFont.prototype = {
|
this.fontMatrix = fontMatrix;
|
||||||
|
|
||||||
|
this.compiledGlyphs = Object.create(null);
|
||||||
|
this.compiledCharCodeToGlyphId = Object.create(null);
|
||||||
|
}
|
||||||
|
|
||||||
getPathJs(unicode) {
|
getPathJs(unicode) {
|
||||||
var cmap = lookupCmap(this.cmap, unicode);
|
const cmap = lookupCmap(this.cmap, unicode);
|
||||||
var fn = this.compiledGlyphs[cmap.glyphId];
|
let fn = this.compiledGlyphs[cmap.glyphId];
|
||||||
if (!fn) {
|
if (!fn) {
|
||||||
fn = this.compileGlyph(this.glyphs[cmap.glyphId], cmap.glyphId);
|
fn = this.compileGlyph(this.glyphs[cmap.glyphId], cmap.glyphId);
|
||||||
this.compiledGlyphs[cmap.glyphId] = fn;
|
this.compiledGlyphs[cmap.glyphId] = fn;
|
||||||
@ -635,7 +640,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
|
this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
|
||||||
}
|
}
|
||||||
return fn;
|
return fn;
|
||||||
},
|
}
|
||||||
|
|
||||||
compileGlyph(code, glyphId) {
|
compileGlyph(code, glyphId) {
|
||||||
if (!code || code.length === 0 || code[0] === 14) {
|
if (!code || code.length === 0 || code[0] === 14) {
|
||||||
@ -655,7 +660,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmds = [];
|
const cmds = [];
|
||||||
cmds.push({ cmd: 'save', });
|
cmds.push({ cmd: 'save', });
|
||||||
cmds.push({ cmd: 'transform', args: fontMatrix.slice(), });
|
cmds.push({ cmd: 'transform', args: fontMatrix.slice(), });
|
||||||
cmds.push({ cmd: 'scale', args: ['size', '-size'], });
|
cmds.push({ cmd: 'scale', args: ['size', '-size'], });
|
||||||
@ -665,58 +670,56 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
cmds.push({ cmd: 'restore', });
|
cmds.push({ cmd: 'restore', });
|
||||||
|
|
||||||
return cmds;
|
return cmds;
|
||||||
},
|
}
|
||||||
|
|
||||||
compileGlyphImpl() {
|
compileGlyphImpl() {
|
||||||
unreachable('Children classes should implement this.');
|
unreachable('Children classes should implement this.');
|
||||||
},
|
}
|
||||||
|
|
||||||
hasBuiltPath(unicode) {
|
hasBuiltPath(unicode) {
|
||||||
var cmap = lookupCmap(this.cmap, unicode);
|
const cmap = lookupCmap(this.cmap, unicode);
|
||||||
return (this.compiledGlyphs[cmap.glyphId] !== undefined &&
|
return (this.compiledGlyphs[cmap.glyphId] !== undefined &&
|
||||||
this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined);
|
this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined);
|
||||||
},
|
}
|
||||||
};
|
|
||||||
|
|
||||||
function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
|
|
||||||
fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
|
|
||||||
CompiledFont.call(this, fontMatrix);
|
|
||||||
|
|
||||||
this.glyphs = glyphs;
|
|
||||||
this.cmap = cmap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Util.inherit(TrueTypeCompiled, CompiledFont, {
|
class TrueTypeCompiled extends CompiledFont {
|
||||||
|
constructor(glyphs, cmap, fontMatrix) {
|
||||||
|
super(fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0]);
|
||||||
|
|
||||||
|
this.glyphs = glyphs;
|
||||||
|
this.cmap = cmap;
|
||||||
|
}
|
||||||
|
|
||||||
compileGlyphImpl(code, cmds) {
|
compileGlyphImpl(code, cmds) {
|
||||||
compileGlyf(code, cmds, this);
|
compileGlyf(code, cmds, this);
|
||||||
},
|
}
|
||||||
});
|
|
||||||
|
|
||||||
function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
|
|
||||||
fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
|
|
||||||
CompiledFont.call(this, fontMatrix);
|
|
||||||
|
|
||||||
this.glyphs = cffInfo.glyphs;
|
|
||||||
this.gsubrs = cffInfo.gsubrs || [];
|
|
||||||
this.subrs = cffInfo.subrs || [];
|
|
||||||
this.cmap = cmap;
|
|
||||||
this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
|
|
||||||
|
|
||||||
this.gsubrsBias = (this.gsubrs.length < 1240 ?
|
|
||||||
107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
|
|
||||||
this.subrsBias = (this.subrs.length < 1240 ?
|
|
||||||
107 : (this.subrs.length < 33900 ? 1131 : 32768));
|
|
||||||
|
|
||||||
this.isCFFCIDFont = cffInfo.isCFFCIDFont;
|
|
||||||
this.fdSelect = cffInfo.fdSelect;
|
|
||||||
this.fdArray = cffInfo.fdArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Util.inherit(Type2Compiled, CompiledFont, {
|
class Type2Compiled extends CompiledFont {
|
||||||
|
constructor(cffInfo, cmap, fontMatrix, glyphNameMap) {
|
||||||
|
super(fontMatrix || [0.001, 0, 0, 0.001, 0, 0]);
|
||||||
|
|
||||||
|
this.glyphs = cffInfo.glyphs;
|
||||||
|
this.gsubrs = cffInfo.gsubrs || [];
|
||||||
|
this.subrs = cffInfo.subrs || [];
|
||||||
|
this.cmap = cmap;
|
||||||
|
this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
|
||||||
|
|
||||||
|
this.gsubrsBias = (this.gsubrs.length < 1240 ?
|
||||||
|
107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
|
||||||
|
this.subrsBias = (this.subrs.length < 1240 ?
|
||||||
|
107 : (this.subrs.length < 33900 ? 1131 : 32768));
|
||||||
|
|
||||||
|
this.isCFFCIDFont = cffInfo.isCFFCIDFont;
|
||||||
|
this.fdSelect = cffInfo.fdSelect;
|
||||||
|
this.fdArray = cffInfo.fdArray;
|
||||||
|
}
|
||||||
|
|
||||||
compileGlyphImpl(code, cmds, glyphId) {
|
compileGlyphImpl(code, cmds, glyphId) {
|
||||||
compileCharString(code, cmds, this, glyphId);
|
compileCharString(code, cmds, this, glyphId);
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
|
create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user