Created
May 26, 2020 07:34
-
-
Save WoHal/156880dada882f11ff422c4b0561b20e to your computer and use it in GitHub Desktop.
get sub font from ttf file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require('fs'); | |
| const util = require("util"); | |
| const fontKit = require("font-toolkit"); | |
| const readFile = util.promisify(fs.readFile); | |
| const writeFile = util.promisify(fs.writeFile); | |
| async function save() { | |
| // read font | |
| const buf = await readFile("20th_bold.ttf"); | |
| const srcFont = new fontKit.Font(buf); | |
| srcFont.satisfy(); | |
| // minify | |
| const mini = new fontKit.Minifier(srcFont); | |
| const newFont = mini.with("1234567890/"); | |
| // write to buf | |
| const wb = new fontKit.BufferWriter(); | |
| newFont.write2(wb); | |
| await writeFile("number.ttf", wb.buffer); | |
| } | |
| save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment