1.0.0 • Published 11 years ago
read-font-cmap v1.0.0
read-font-cmap
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 install read-font-cmapAPI
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.
1.0.0
11 years ago