-
Encode, Decode
-
Get glyph path commands
-
Format conversion
-
Minify
-
TypeScript
npm i modern-font
import { parseSFNTFont } from 'modern-font'
fetch('font.woff')
.then(rep => rep.arrayBuffer())
.then((buffer) => {
const font = parseSFNTFont(buffer)
const sfnt = font.sfnt
// SFNT
console.log(sfnt)
// Char to SVG Path commands
console.log(sfnt.getPathCommands('A', 0, 0))
})
import { TTF, WOFF } from 'modern-font'
// buffer is WOFF file arrayBuffer
const ttf = TTF.from(new WOFF(buffer).sfnt)
// TTF file
window.open(URL.createObjectURL(ttf.toBlob()))
import { TTF, WOFF } from 'modern-font'
// buffer is TTF file arrayBuffer
const woff = WOFF.from(new TTF(buffer).sfnt)
// WOFF file
window.open(URL.createObjectURL(woff.toBlob()))
import { EOT, TTF } from 'modern-font'
// buffer is TTF file arrayBuffer
const eot = EOT.from(new TTF(buffer))
// EOT file
window.open(URL.createObjectURL(eot.toBlob()))
import { minifyFont } from 'modern-font'
fetch('font.woff')
.then(rep => rep.arrayBuffer())
.then((rawBuffer) => {
const buffer = minifyFont(rawBuffer, 'A set of text cropped from a font file')
console.log(
`raw size: ${rawBuffer.byteLength / 1024 / 1024}`,
`minimized size: ${buffer.byteLength / 1024 / 1024}`,
)
// minimized woff file
const woff = new Blob([buffer], { type: 'font/woff' })
window.open(URL.createObjectURL(woff))
})