-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathconfig.js
42 lines (34 loc) · 863 Bytes
/
config.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
import path from 'path'
import * as fontkit from 'fontkit'
const _config = { fontFamilyMappings: {} }
const fonts = {}
export const setFontDir = function (dir) {
_config.fontDir = dir
return this
}
export const setFontFamilyMappings = function (map) {
_config.fontFamilyMappings = map
return this
}
// TODO: make async
export const preloadFonts = () => {
const map = _config.fontFamilyMappings
for (const [ font, file ] of Object.entries(map)) {
const filename = path.join(_config.fontDir, file)
try {
fonts[font] = fontkit.openSync(filename)
} catch (e) {
console.warn(`Could not load font file for ${font}`, e)
}
}
return this
}
export const getConfig = () => _config
export const getFonts = () => fonts
export const config = {
setFontDir,
setFontFamilyMappings,
preloadFonts,
getConfig,
getFonts
}