Skip to content

Instantly share code, notes, and snippets.

@WoHal
Created May 26, 2020 07:34
Show Gist options
  • Select an option

  • Save WoHal/156880dada882f11ff422c4b0561b20e to your computer and use it in GitHub Desktop.

Select an option

Save WoHal/156880dada882f11ff422c4b0561b20e to your computer and use it in GitHub Desktop.
get sub font from ttf file
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