fonteditor core functions
Clone or download
Latest commit e6b82f9 Jun 1, 2018
Permalink
Failed to load latest commit information.
demo fecs lint Mar 30, 2017
src add ttf modified set Jun 1, 2018
test add ttf head modified option Jun 1, 2018
tool add font store Apr 17, 2016
.fecsignore build node Jul 24, 2015
.fecsrc fecs lint Mar 30, 2017
.gitignore ignore node Jul 24, 2015
.travis.yml travis Jul 24, 2015
LICENSE init fonteditor-core Jul 19, 2015
README.md update readme Feb 21, 2017
bower.json update Oct 26, 2016
edp-build-config-node.js build node Jul 24, 2015
edp-webserver-config.js init fonteditor-core Jul 19, 2015
package.json add ttf modified set Jun 1, 2018

README.md

fonteditor-core

FontEditor core functions

NPM version Build Status Downloads

Feature

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

Usage

// read font file
var Font = require('fonteditor-core').Font;
var fs = require('fs');
var buffer = fs.readFileSync('font.ttf');

// read font data
var font = Font.create(buffer, {
  type: 'ttf', // support ttf,woff,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
});
var 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
var buffer = font.write({
  type: 'woff', // support ttf,woff,eot,otf,svg
  hinting: true, // save font hinting
  deflate: null, // deflate function for woff
});
// fs.writeFileSync('font.woff', buffer);

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

// optimize glyf
font.optimize()

// compound2simple
font.compound2simple()

// sort glyf
font.sort()

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

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

Demo

edp webserver

open http://127.0.0.1:9999/demo

Related

License

MIT © Fonteditor