Skip to content
fonteditor core functions
JavaScript Other
Branch: master
Clone or download

Latest commit

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config add test cases Oct 17, 2019
demo support cmap format 14 Oct 29, 2019
src Fixed compound glyfs in otf Feb 27, 2020
test remove debug info of woff2 Mar 2, 2020
woff2 fix: reverse wasm build Mar 2, 2020
woff2src fix: reverse wasm build Mar 2, 2020
.babelrc add test cases Oct 17, 2019
.fecsignore add test cases Oct 17, 2019
.fecsrc add test cases Oct 17, 2019
.gitignore fix: reverse wasm build Mar 2, 2020
.travis.yml travis Jul 24, 2015
LICENSE init fonteditor-core Jul 19, 2015
README.md add support options to ttfwriter Nov 9, 2019
bower.json update Oct 26, 2016
package.json fix: reverse wasm build Mar 2, 2020

README.md

fonteditor-core

FontEditor core functions

NPM version Build Status Downloads

Feature

  • sfnt parse
  • read, write, transform fonts
    • ttf (read and write)
    • woff (read and write)
    • woff2 (read and write)
    • eot (read and write)
    • svg (read and write)
    • otf (only read)
  • ttf glyph adjust
  • svg to glyph

Usage

// read font file
const Font = require('fonteditor-core').Font;
const fs = require('fs');

let buffer = fs.readFileSync('font.ttf');
// read font data
let font = Font.create(buffer, {
  type: 'ttf', // support ttf, woff, woff2, eot, otf, svg
  subset: [65, 66], // only read `a`, `b` glyf
  hinting: true, // save font hinting
  compound2simple: true, // transform ttf compound glyf to simple
  inflate: null, // inflate function for woff
  combinePath: false, // for svg path
});
let fontObject = font.get();
console.log(Object.keys(fontObject));

/* => [ 'version',
  'numTables',
  'searchRenge',
  'entrySelector',
  'rengeShift',
  'head',
  'maxp',
  'glyf',
  'cmap',
  'name',
  'hhea',
  'post',
  'OS/2',
  'fpgm',
  'cvt',
  'prep'
]
*/

// write font file
let buffer = font.write({
  type: 'woff', // support ttf, woff, woff2, eot, svg
  hinting: true, // save font hinting
  deflate: null, // deflate function for woff
  support: {head: {}, hhea: {}} // for user to overwrite head.xMin, head.xMax, head.yMin, head.yMax, hhea etc.
});
// fs.writeFileSync('font.woff', buffer);

// to base64 str
font.toBase64({
  type: 'ttf' // support ttf, woff, woff2, eot, svg
});

// optimize glyf
font.optimize()

// compound2simple
font.compound2simple()

// sort glyf
font.sort()

// find glyf
let result = font.find({
  unicode: [65]
});
let result = font.find({
  filter: function (glyf) {
    return glyf.name == 'icon'
  }
});

// merge another font object
font.merge(font1, {
  scale: 1
});

woff2

Notice: woff2 use wasm build of google woff2, before read and write woff2, you should first call woff2.init().

const Font = require('fonteditor-core').Font;
const woff2 = require('fonteditor-core').woff2;

woff2.init().then(() => {
  // read
  let font = Font.create(buffer, {
    type: 'woff2'
  });
  // write
  font.write({type: 'woff2'});
});

Demo

npm run dev

build

npm run build

test

npm run test

support

Node.js:>= 8.0

Browser: Chrome, Safari

Related

License

MIT © Fonteditor

You can’t perform that action at this time.