Skip to content

shinnn/read-font-cmap

Repository files navigation

read-font-cmap

NPM version Build Status Build status Coverage Status Dependency Status devDependency Status

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

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

readFontCmap('bower_components/font-awesome/fonts/FontAwesome.otf', (err, map) => {
  if (err) {
    throw err;
  }

  console.log(map); // yields: '{"32": 1, "168": 6, "169": 12, "174": 10, ... }'
});

Installation

Use npm.

npm install read-font-cmap

API

const 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.

const 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 - 2015 Shinnosuke Watanabe

Licensed under the MIT License.

About

Parse CMap of a TrueType/OpenType font file

Resources

License

Stars

Watchers

Forks

Packages

No packages published