This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/server/localeFont.js

28 lines
846 B
JavaScript
Raw Normal View History

import {registerFont} from "canvas";
import fs from 'fs';
const vars = {};
for (let [, name, value] of fs.readFileSync(__dirname + '/../data/variables.scss').toString('utf-8').matchAll(/^\$([^:]+): '([^']+)';$/gm)) {
vars[name] = value;
}
const fontSources = {
'Quicksand': 'quicksand-v21-latin-ext_latin-{weight}.ttf',
'Nunito': 'nunito-v16-latin-ext_latin_cyrillic-ext_cyrillic-{weight}.ttf',
'Zen Maru Gothic': 'zen-maru-gothic-v4-latin_japanese-{weight}.ttf',
}
const weightsValues = {
'bold': '700',
}
export const registerLocaleFont = (v, weights = ['regular']) => {
const family = vars[v];
const source = fontSources[family];
for (let weight of weights) {
registerFont('static/fonts/' + source.replace('{weight}', weightsValues[weight] || weight), {family, weight});
}
return family;
}