0.4.0 • Published 6 months ago

modern-font v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Features

  • Encode, Decode

  • Get glyph path commands

  • Format conversion

  • Minify

  • TypeScript

📦 Install

npm i modern-font

🦄 Usage

import { EOT, minifyFont, TTF, WOFF } from 'modern-font'

fetch('font.woff')
  .then(rep => rep.arrayBuffer())
  .then((buffer) => {
    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 = minifyFont(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'

// buffer is WOFF file 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'

// buffer is TTF file arrayBuffer
const woff = WOFF.from(new TTF(buffer).sfnt)

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

🚀 TTF to EOT

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()))

🚀 Minify

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))
  })

TODO

0.3.0

8 months ago

0.3.5

6 months ago

0.3.2

8 months ago

0.4.0

6 months ago

0.3.1

8 months ago

0.3.4

7 months ago

0.2.1

9 months ago

0.2.0

9 months ago

0.1.0

9 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.4

9 months ago

0.1.3

9 months ago

0.1.5

9 months ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.4

1 year ago

0.0.1

1 year ago