Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

modern-font

qq15725202MIT0.4.1TypeScript support: included

JavaScript Font Codec.

modern-font, font-editor, font-minify, opentype, font

readme

modern-font

Minzip Version Downloads Issues License

Features

  • Encode, Decode

  • Get glyph path commands

  • Format conversion

  • Minify

  • TypeScript

📦 Install

npm i modern-font

🦄 Usage

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

🚀 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

changelog

0.4.1 (2025-03-31)

Features

  • add fonts.loadFallbackFont method (b2d9a05)

0.4.0 (2025-01-09)

Bug Fixes

Features

  • add SFNT.numGlyphs and SFNT.unicodes (ba1584a)
  • rename Woff to WOFFTtf to TTFOtf to OTFEot to EOT (8287680)
  • SFNT.unicodes (7a63e55)

0.3.5 (2024-12-31)

Bug Fixes

0.3.4 (2024-12-09)

0.3.3 (2024-12-09)

  • fix: defineColumn (dd066e2)
  • fix: Iterator.prototype.reduce (c42ca5a)
  • feat: export core dir (94a1652)
  • feat: rename Readable to FontDataObject (6cc00e6)

0.3.2 (2024-11-18)

Bug Fixes

  • getPathCommands text is not supported (660cbf8)

0.3.1 (2024-11-12)

Features

0.3.0 (2024-11-11)

Features

  • rename export util method, minifyFont and parseFont (e7c20b5)

0.2.1 (2024-10-23)

Bug Fixes

0.2.0 (2024-10-23)

Features

  • support get CFF table glyph (c40e030)

0.1.5 (2024-10-13)

Bug Fixes

0.1.4 (2024-10-12)

Features

0.1.3 (2024-10-12)

Features

  • rename FontLoader to Fonts, add fallbackFont prop to Fonts (697b9d4)

0.1.2 (2024-10-09)

0.1.1 (2024-10-09)

Features

  • glyph getPath method replace to getPathCommand, remove modern-path2d dep (8f31eb3)

0.1.0 (2024-10-08)

Features

0.0.4 (2024-03-12)

Bug Fixes

Features

  • minify support compound glyphs (41dc152)
  • minify support compound glyphs (926a6e1)

0.0.3 (2024-03-11)

Bug Fixes

Features

  • unprocessed tables are removed during minimization (14f12de)

0.0.2 (2024-03-11)

Bug Fixes

Features

0.0.1 (2024-03-08)

Features