{"size": 1297, "ext": "js", "max_stars_repo_path": "structures/Font.js", "max_stars_repo_name": "Shindva/celestia", "max_stars_repo_stars_event_min_datetime": "2020-12-01T19:31:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-19T18:24:50.000Z", "max_issues_repo_path": "structures/Font.js", "max_issues_repo_name": "Shindva/celestia", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "structures/Font.js", "max_forks_repo_name": "Shindva/celestia", "max_forks_repo_forks_event_min_datetime": "2020-12-02T23:20:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-04T06:29:53.000Z"}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 27.5957446809, "max_line_length": 105, "alphanum_fraction": 0.6646106399}
const { registerFont } = require('canvas');
const weights = {
	100: 'thin',
	200: 'extraLight',
	300: 'light',
	400: 'normal',
	500: 'medium',
	600: 'semiBold',
	700: 'bold',
	800: 'extraBold',
	900: 'heavy',
	950: 'extraBlack'
};
const fallbacks = ['Symbola', 'Noto-CJK'];

module.exports = class Font {
	constructor(path, filename, metadata) {
		this.path = path;
		this.name = metadata.name || filename;
		this.filename = filename;
		this.style = metadata.style === 'regular' ? 'normal' : metadata.style || 'normal';
		this.weight = weights[metadata.weight] || metadata.weight || 'normal';
		this.type = metadata.type;
		this.registered = false;
		this.fallbacks = fallbacks.filter(fallback => fallback !== this.filenameNoExt);
	}

	register() {
		if (this.registered) return null;
		this.registered = true;
		return registerFont(this.path, { family: this.filenameNoExt, style: this.style, weight: this.weight });
	}

	toCanvasString(size, shouldDoFallbacks = true) {
		const shouldFall = shouldDoFallbacks ? `, ${this.fallbacks.join(', ')}` : '';
		return `${this.style} ${this.weight} ${size}px ${this.filenameNoExt}${shouldFall}`;
	}

	get filenameNoExt() {
		return this.filename.replace(/(\.(otf|ttf))$/, '');
	}

	get isFallback() {
		return fallbacks.includes(this.filenameNoExt);
	}
};
