-
Notifications
You must be signed in to change notification settings - Fork 134
/
generate-font.js
84 lines (73 loc) · 1.88 KB
/
generate-font.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import _ from "lodash";
import { writeFileSync } from "fs";
import { join } from "path";
import { createSVG, createTTF, createWOFF2 } from "svgtofont/lib/utils.js";
let infoData = {};
let lastUnicode = 0xf0000;
const options = {
src: "svg",
dist: "fonts",
emptyDist: true,
fontName: "paisa",
svg2ttf: {},
svgicons2svgfont: {
normalize: true,
fontWeight: 900,
fontHeight: 1000,
fontStyle: "normal",
fixedWidth: true,
centerHorizontally: true,
centerVertically: true
},
useNameAsUnicode: false,
symbolNameDelimiter: "-",
css: false,
getIconUnicode: (name, _unicode, startUnicode) => {
startUnicode++;
lastUnicode = startUnicode;
infoData[name] = startUnicode;
return [String.fromCodePoint(startUnicode), startUnicode];
},
startUnicode: 0xf0000,
outSVGReact: false,
generateInfoData: true
};
async function createFont(font) {
infoData = {};
options.src = join("svg", font);
options.fontName = font;
options.startUnicode = lastUnicode++;
await createSVG(options);
const ttf = await createTTF(options);
await createWOFF2(options, ttf);
if (options.generateInfoData) {
writeFileSync(`fonts/${font}-info.json`, JSON.stringify({ codepoints: infoData }), "utf8");
const min = _.min(Object.values(infoData));
const max = _.max(Object.values(infoData));
const scss = `
@font-face {
font-family: "${font}";
font-style: normal;
font-weight: 900;
src: url("../fonts/${font}.woff2") format("woff2");
unicode-range: U+${min.toString(16).toUpperCase()}-${max.toString(16).toUpperCase()};
font-display: block;
}
`;
writeFileSync(`fonts/${font}.scss`, scss, "utf8");
}
}
async function createFonts(fonts) {
for (const font of fonts) {
await createFont(font);
}
}
const fonts = [
"arcticons",
"fa6-solid",
"fa6-regular",
"fa6-brands",
"mdi",
"fluent-emoji-high-contrast"
];
createFonts(fonts);