Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qq15725/modern-font
✍🏻 Convert and minify font supports WOFF TTF EOT.
https://github.com/qq15725/modern-font
font font-editor font-minify modern-font
Last synced: 3 months ago
JSON representation
✍🏻 Convert and minify font supports WOFF TTF EOT.
- Host: GitHub
- URL: https://github.com/qq15725/modern-font
- Owner: qq15725
- License: mit
- Created: 2024-03-05T06:12:32.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-03-12T08:27:55.000Z (11 months ago)
- Last Synced: 2024-04-23T21:22:42.555Z (10 months ago)
- Topics: font, font-editor, font-minify, modern-font
- Language: TypeScript
- Homepage:
- Size: 3.23 MB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
modern-font
## Features
- Encode, Decode
- Get glyph path commands
- Format conversion
- Minify
- TypeScript
## 📦 Install
```shell
npm i modern-font
```## 🦄 Usage
```ts
import { Eot, minify, 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 = 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
```ts
import { Ttf, Woff } from 'modern-font'fetch('font.woff')
.then(rep => rep.arrayBuffer())
.then((buffer) => {
const ttf = Ttf.from(new Woff(buffer).sfnt)// ttf file
window.open(URL.createObjectURL(ttf.toBlob()))
})
```## 🚀 TTF to WOFF
```ts
import { Ttf, Woff } from 'modern-font'fetch('font.ttf')
.then(rep => rep.arrayBuffer())
.then((buffer) => {
const woff = Woff.from(new Ttf(buffer).sfnt)// woff file
window.open(URL.createObjectURL(woff.toBlob()))
})
```## 🚀 TTF to EOT
```ts
import { Eot, Ttf } from 'modern-font'fetch('font.ttf')
.then(rep => rep.arrayBuffer())
.then((buffer) => {
const eot = Eot.from(new Ttf(buffer))// eot file
window.open(URL.createObjectURL(eot.toBlob()))
})
```## 🚀 Minify
```ts
import { minify } from 'modern-font'fetch('font.woff')
.then(rep => rep.arrayBuffer())
.then((rawBuffer) => {
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
- [WOFF2](https://www.w3.org/TR/WOFF2)