Possibly Fix Some Fonts not working

This commit is contained in:
Dragon Fire
2021-02-20 11:01:19 -05:00
parent 20778d30a7
commit 7f448a7712
+7 -2
View File
@@ -20,6 +20,7 @@ module.exports = class Font {
constructor(path, filename, metadata) { constructor(path, filename, metadata) {
this.path = path; this.path = path;
this.name = variants[filename] || metadata.name || filename; this.name = variants[filename] || metadata.name || filename;
this.filename = filename;
this.style = metadata.style === 'regular' ? 'normal' : metadata.style || 'normal'; this.style = metadata.style === 'regular' ? 'normal' : metadata.style || 'normal';
this.weight = weights[metadata.weight] || metadata.weight || 'normal'; this.weight = weights[metadata.weight] || metadata.weight || 'normal';
this.type = metadata.type; this.type = metadata.type;
@@ -29,10 +30,14 @@ module.exports = class Font {
register() { register() {
if (this.registered) return null; if (this.registered) return null;
this.registered = true; this.registered = true;
return registerFont(this.path, { family: this.name, style: this.style, weight: this.weight }); return registerFont(this.path, { family: this.filenameNoExt, style: this.style, weight: this.weight });
} }
toCanvasString(size) { toCanvasString(size) {
return `${this.style} ${this.weight} ${size}px ${this.name}`; return `${this.style} ${this.weight} ${size}px ${this.filenameNoExt}`;
}
get filenameNoExt() {
return this.filename.replace(/(\.(otf|ttf))$/, '');
} }
}; };