read-font-cmap

1.0.0 • Public • Published

read-font-cmap

Build Status Build status Coverage Status Dependency Status devDependency Status

A Node module to parse CMap of a TrueType/OpenType font file

var readFontCmap = require('read-font-cmap');
 
readFontCmap('bower_components/font-awesome/fonts/FontAwesome.otf', function(err, map) {
  if (err) {
    throw err;
  }
 
  console.log(map); // yields: '{"32": 1, "168": 6, "169": 12, "174": 10, ... }'
});

Installation

NPM version

Use npm.

npm install read-font-cmap

API

var readFontCmap = require('read-font-cmap');

readFontCmap(filePath, callback)

filePath: String (font file path)
callback: Function

It reads and parses a TrueType/OpenType font file asynchronously, then runs callback function.

callback(error, cmap)

error: Object (an error if it fails to parse the font, otherwise null)
cmap: Object

The second argument represents CMap table in the form:

{
  "Unicode value (integer)": "Glyph ID (integer)"
}

Here is a real-life example, the result of parsing Font Awesome CMap table.

readFontCmap.sync(filePath)

filePath: String (font file path)
Return: Object (CMap table)

Synchronous version of readFontCmap.

var readFontCmap = require('read-font-cmap');
readFontCmap.sync('bower_components/font-awesome/fonts/FontAwesome.otf');
//=> {"32": 1, "168": 6, "169": 12, "174": 10, ... }

License

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT License.

Package Sidebar

Install

npm i read-font-cmap

Weekly Downloads

2

Version

1.0.0

License

none

Last publish

Collaborators

  • shinnn