https://github.com/shinnn/read-font-cmap
Parse CMap of a TrueType/OpenType font file
https://github.com/shinnn/read-font-cmap
Last synced: 3 months ago
JSON representation
Parse CMap of a TrueType/OpenType font file
- Host: GitHub
- URL: https://github.com/shinnn/read-font-cmap
- Owner: shinnn
- License: mit
- Created: 2014-10-14T01:30:35.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-07-24T09:58:57.000Z (almost 10 years ago)
- Last Synced: 2024-04-14T10:16:05.515Z (about 1 year ago)
- Language: JavaScript
- Size: 145 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# read-font-cmap
[](https://www.npmjs.com/package/read-font-cmap)
[](https://travis-ci.org/shinnn/read-font-cmap)
[](https://ci.appveyor.com/project/ShinnosukeWatanabe/read-font-cmap)
[](https://coveralls.io/r/shinnn/read-font-cmap)
[](https://david-dm.org/shinnn/read-font-cmap)
[](https://david-dm.org/shinnn/read-font-cmap#info=devDependencies)A [Node](http://nodejs.org/) module to parse [CMap](https://www.microsoft.com/typography/otspec/cmap.htm) of a TrueType/OpenType font file
```javascript
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.](https://docs.npmjs.com/cli/install)
```
npm install read-font-cmap
```## API
```javascript
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:
```json
{
"Unicode value (integer)": "Glyph ID (integer)"
}
```[Here](https://raw.githubusercontent.com/shinnn/read-font-cmap/master/test/fixture.json) is a real-life example, the result of parsing [Font Awesome](https://fortawesome.github.io/Font-Awesome/) CMap table.
### readFontCmap.sync(*filePath*)
*filePath*: `String` (font file path)
Return: `Object` (CMap table)Synchronous version of [`readFontCmap`](#readfontcmapfilepath-callback).
```javascript
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](https://github.com/shinnn)
Licensed under [the MIT License](./LICENSE).