Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/read-font-cmap
Parse CMap of a TrueType/OpenType font file
https://github.com/shinnn/read-font-cmap
Last synced: 26 days 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 (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-07-24T09:58:57.000Z (over 9 years ago)
- Last Synced: 2024-04-14T10:16:05.515Z (7 months 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
[![NPM version](https://img.shields.io/npm/v/read-font-cmap.svg)](https://www.npmjs.com/package/read-font-cmap)
[![Build Status](https://travis-ci.org/shinnn/read-font-cmap.svg?branch=master)](https://travis-ci.org/shinnn/read-font-cmap)
[![Build status](https://ci.appveyor.com/api/projects/status/507uq9x81gspk8wb?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/read-font-cmap)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/read-font-cmap.svg)](https://coveralls.io/r/shinnn/read-font-cmap)
[![Dependency Status](https://img.shields.io/david/shinnn/read-font-cmap.svg?label=deps)](https://david-dm.org/shinnn/read-font-cmap)
[![devDependency Status](https://img.shields.io/david/dev/shinnn/read-font-cmap.svg?label=devDeps)](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).