Refactor: Create a separate class for glyph store
This commit is contained in:
parent
02e6d041be
commit
4d20f8e655
25 changed files with 482 additions and 360 deletions
|
@ -6,8 +6,7 @@ const Anchor = require("./anchor");
|
|||
|
||||
module.exports = class Glyph {
|
||||
constructor(name) {
|
||||
Object.defineProperty(this, "name", { value: name, writable: false });
|
||||
this.unicode = [];
|
||||
this._m_dependentName = name;
|
||||
this.contours = [];
|
||||
this.advanceWidth = 500;
|
||||
this.autoRefPriority = 0;
|
||||
|
@ -17,6 +16,15 @@ module.exports = class Glyph {
|
|||
this.dependencies = [];
|
||||
this.defaultTag = null;
|
||||
}
|
||||
get name() {
|
||||
throw new TypeError("Glyph::name has been deprecated");
|
||||
}
|
||||
get unicode() {
|
||||
throw new TypeError("Glyph::unicode has been deprecated");
|
||||
}
|
||||
set unicode(x) {
|
||||
throw new TypeError("Glyph::unicode has been deprecated");
|
||||
}
|
||||
// PTL pattern matching
|
||||
static unapply(obj, arity) {
|
||||
if (obj instanceof Glyph) return [obj];
|
||||
|
@ -26,14 +34,9 @@ module.exports = class Glyph {
|
|||
setWidth(w) {
|
||||
this.advanceWidth = w;
|
||||
}
|
||||
// Encoding
|
||||
assignUnicode(u) {
|
||||
if (typeof u === "string") this.unicode.push(u.codePointAt(0));
|
||||
else this.unicode.push(u);
|
||||
}
|
||||
// Dependency
|
||||
dependsOn(glyph) {
|
||||
if (glyph.name) this.dependencies.push(glyph.name);
|
||||
if (glyph._m_dependentName) this.dependencies.push(glyph._m_dependentName);
|
||||
if (glyph.dependencies) for (const dep of glyph.dependencies) this.dependencies.push(dep);
|
||||
}
|
||||
// Contour Tagging
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue