Skip to content

qq15725/modern-font

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

modern-font

Minzip Version Downloads Issues License

πŸ“¦ Install

npm i modern-font

πŸ¦„ Usage

import { Ttf, Woff, Eot, minify } from 'modern-font'

const buffer = await fetch('font.woff').then(rep => rep.arrayBuffer())

let woff, ttf, eot
if (Woff.is(buffer)) {
  woff = new Woff(buffer)
  ttf = Ttf.from(woff.sfnt)
  eot = Eot.from(ttf)
} else if (Ttf.is(buffer)) {
  ttf = new Ttf(buffer)
  woff = Woff.from(ttf.sfnt)
  eot = Eot.from(ttf)
}
const minifyWoff = minify(woff, 'minify')
document.fonts.add(woff.toFontFace('woff'))
document.fonts.add(ttf.toFontFace('ttf'))
document.fonts.add(eot.toFontFace('eot'))
document.fonts.add(minifyWoff.toFontFace('minifyWoff'))
console.log(woff, ttf, eot, minifyWoff)

πŸš€ WOFF to TTF

import { Ttf, Woff } from 'modern-font'

const buffer = await fetch('font.woff').then(rep => rep.arrayBuffer())
const ttf = Ttf.from(new Woff(buffer).sfnt)

// ttf file
window.open(URL.createObjectURL(ttf.toBlob()))

πŸš€ TTF to WOFF

import { Ttf, Woff } from 'modern-font'

const buffer = await fetch('font.ttf').then(rep => rep.arrayBuffer())
const woff = Woff.from(new Ttf(buffer).sfnt)

// woff file
window.open(URL.createObjectURL(woff.toBlob()))

πŸš€ TTF to EOT

import { Ttf, Eot } from 'modern-font'

const buffer = await fetch('font.ttf').then(rep => rep.arrayBuffer())
const eot = Eot.from(new Ttf(buffer))

// eot file
window.open(URL.createObjectURL(eot.toBlob()))

πŸš€ Minify

import { minify } from 'modern-font'

const rawBuffer = await fetch('font.woff').then(rep => rep.arrayBuffer())
const buffer = minify(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))

TODO