mirror of
https://github.com/daniel-j/fimfic2epub.git
synced 2024-06-17 18:04:47 +12:00
font subset function
This commit is contained in:
parent
dfd6e9897e
commit
5836ecb136
29
src/subsetFont.js
Normal file
29
src/subsetFont.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
|
||||||
|
import isNode from 'detect-node'
|
||||||
|
import { Font } from 'fonteditor-core'
|
||||||
|
import fs from 'fs'
|
||||||
|
import fetch from './fetch'
|
||||||
|
|
||||||
|
async function subsetFont (fontPath, glyphs, options = {}) {
|
||||||
|
let data
|
||||||
|
if (!isNode || !options.local) {
|
||||||
|
data = await fetch(fontPath, 'arraybuffer')
|
||||||
|
} else {
|
||||||
|
data = await new Promise((resolve, reject) => {
|
||||||
|
fs.readFile(fontPath, (err, data) => {
|
||||||
|
if (err) reject(err)
|
||||||
|
else resolve(data)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return Font.create(data, {
|
||||||
|
type: 'ttf',
|
||||||
|
subset: glyphs,
|
||||||
|
hinting: true
|
||||||
|
}).write({
|
||||||
|
type: 'ttf',
|
||||||
|
hinting: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default subsetFont
|
Loading…
Reference in a new issue