-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 989df6f
Showing
14 changed files
with
968 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 2 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
env: | ||
browser: false | ||
node: true | ||
rules: | ||
no-extra-parens: 2 | ||
eqeqeq: 2 | ||
block-scoped-var: 2 | ||
no-process-exit: 0 | ||
quotes: | ||
- 2 | ||
- single |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
coverage | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"preset": "google", | ||
"maximumLineLength": 98, | ||
"excludeFiles": [ | ||
"{coverage,node_modules}/**" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
language: node_js | ||
node_js: | ||
- '0.10' | ||
- '0.11' | ||
after_script: | ||
- npm run-script coveralls | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Shinnosuke Watanabe | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# font-cmap | ||
|
||
[![Build Status](https://travis-ci.org/shinnn/node-font-cmap.svg?branch=master)](https://travis-ci.org/shinnn/node-font-cmap) | ||
[![Build status](https://ci.appveyor.com/api/projects/status/71pgh750h4tnf30i?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/node-font-cmap) | ||
[![Coverage Status](https://img.shields.io/coveralls/shinnn/node-font-cmap.svg)](https://coveralls.io/r/shinnn/node-font-cmap) | ||
[![Dependency Status](https://david-dm.org/shinnn/node-font-cmap.svg)](https://david-dm.org/shinnn/node-font-cmap) | ||
[![devDependency Status](https://david-dm.org/shinnn/node-font-cmap/dev-status.svg)](https://david-dm.org/shinnn/node-font-cmap#info=devDependencies) | ||
|
||
Parse [CMap](http://www.microsoft.com/typography/otspec/cmap.htm) of a TrueType/OpenType font file [buffer][buffer] | ||
|
||
```javascript | ||
var fs = require('fs'); | ||
var fontCmap = require('font-cmap'); | ||
|
||
var buf = fs.readFIleSync('bower_components/font-awesome/fonts/FontAwesome.otf'); | ||
|
||
fontCmap(buf); //=> {"32": 1, "168": 6, "169": 12, "174": 10, ... } | ||
``` | ||
|
||
## Installation | ||
|
||
[![NPM version](https://badge.fury.io/js/font-cmap.svg)](https://www.npmjs.org/package/font-cmap) | ||
|
||
[Use npm](https://www.npmjs.org/doc/cli/npm-install.html). | ||
|
||
```sh | ||
npm install font-cmap | ||
``` | ||
|
||
## API | ||
|
||
```javascript | ||
var fontCmap = require('font-cmap'); | ||
``` | ||
|
||
### fontCmap(*buffer*) | ||
|
||
*buffer*: `Object` ([`Buffer`][buffer] of a TrueType/OpenType font file) | ||
Return: `Object` | ||
|
||
It returns an object of a CMap table in the form: | ||
|
||
```javascript | ||
{ | ||
"Unicode value (integer)": "Glyph ID (integer)" | ||
} | ||
``` | ||
|
||
[Here](https://raw.githubusercontent.com/shinnn/node-font-cmap/master/test/fixture.json) is the real-life example, the result of parsing [Font Awesome](http://fortawesome.github.io/Font-Awesome/) CMap table. | ||
|
||
## CLI | ||
|
||
You can use this module as a CLI tool by installing it [globally](https://www.npmjs.org/doc/files/npm-folders.html#global-installation). | ||
|
||
```sh | ||
npm install -g font-cmap | ||
``` | ||
|
||
### Usage | ||
|
||
``` | ||
Usage1: font-cmap <font file path> | ||
Usage2: cat <font file path> | font-cmap | ||
Options: | ||
--min, -m Minify output | ||
--help, -h Print usage information | ||
--version, -v Print version | ||
``` | ||
|
||
It prints a CMap table as a [JSON](http://www.json.org/) string. | ||
|
||
## License | ||
|
||
Copyright (c) 2014 [Shinnosuke Watanabe](https://github.com/shinnn) | ||
|
||
Licensed under [the MIT License](./LICENSE). | ||
|
||
[buffer]: http://nodejs.org/api/buffer.html#buffer_buffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
init: | ||
- git config --global core.autocrlf input | ||
|
||
version: '{build}' | ||
|
||
environment: | ||
matrix: | ||
- nodejs_version: '0.10' | ||
- nodejs_version: '0.11' | ||
|
||
install: | ||
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) | ||
- npm install | ||
|
||
build: off | ||
|
||
test_script: | ||
- ps: node test\test.js | ||
- cmd: node test\test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
|
||
var argv = require('minimist')(process.argv.slice(2), { | ||
alias: { | ||
m: 'min', | ||
h: 'help', | ||
v: 'version' | ||
} | ||
}); | ||
var pkg = require('./package.json'); | ||
|
||
function help() { | ||
var chalk = require('chalk'); | ||
|
||
console.log([ | ||
chalk.cyan(pkg.name) + chalk.gray(' v' + pkg.version), | ||
pkg.description, | ||
'', | ||
'Usage1: ' + pkg.name + ' <font file path>', | ||
'Usage2: cat <font file path> | ' + pkg.name, | ||
'', | ||
'Options:', | ||
chalk.yellow('--min, -m ') + ' Minify output', | ||
chalk.yellow('--help, -h ') + ' Print usage information', | ||
chalk.yellow('--version, -v ') + ' Print version', | ||
'' | ||
].join('\n')); | ||
} | ||
|
||
function run(buf) { | ||
var cmapData = require('./')(buf); | ||
var space; | ||
if (!argv.min) { | ||
space = ' '; | ||
} | ||
|
||
console.log(JSON.stringify(cmapData, null, space)); | ||
} | ||
|
||
function stderrWriteLn(msg) { | ||
process.stderr.write(msg + '\n', function() { | ||
process.exit(1); | ||
}); | ||
} | ||
|
||
if (argv.version) { | ||
console.log(pkg.version); | ||
} else if (argv.help) { | ||
help(); | ||
} else if (process.stdin.isTTY) { | ||
if (argv._.length === 0) { | ||
help(); | ||
} else if (!fs.existsSync(argv._[0])) { | ||
stderrWriteLn('Cannot read the file ' + argv._[0] + '.'); | ||
} else if (!fs.statSync(argv._[0]).isFile()) { | ||
stderrWriteLn(argv._[0] + ' is not a file.'); | ||
} else { | ||
run(fs.readFileSync(argv._[0])); | ||
} | ||
} else { | ||
require('get-stdin').buffer(run); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/*! | ||
* font-cmap | MIT (c) Shinnosuke Watanabe | ||
* https://github.com/shinnn/node-font-cmap | ||
*/ | ||
'use strict'; | ||
|
||
var opentype = require('opentype.js'); | ||
|
||
module.exports = function fontCmap(fontBuf) { | ||
if (arguments.length === 0) { | ||
throw new TypeError('One argument (buffer) required.'); | ||
} | ||
|
||
if (!Buffer.isBuffer(fontBuf)) { | ||
throw new TypeError(fontBuf + ' is not a buffer.'); | ||
} | ||
|
||
var arrayBuffer = new Uint8Array(fontBuf).buffer; | ||
return opentype.parse(arrayBuffer).tables.cmap.glyphIndexMap; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"name": "font-cmap", | ||
"version": "0.0.0", | ||
"description": "Parse CMap of a TrueType/OpenType font file buffer", | ||
"repository": "shinnn/node-font-cmap", | ||
"author": { | ||
"name": "Shinnosuke Watanabe", | ||
"url": "https://github.com/shinnn" | ||
}, | ||
"scripts": { | ||
"pretest": "eslint *.js test/test.js & jscs .", | ||
"test": "node test/test.js | tap-spec", | ||
"coverage": "istanbul cover test/test.js", | ||
"coveralls": "${npm_package_scripts_coverage} && istanbul-coveralls" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/shinnn/node-font-cmap/blob/master/LICENSE" | ||
} | ||
], | ||
"files": [ | ||
"cli.js", | ||
"index.js", | ||
"LICENSE" | ||
], | ||
"bin": "cli.js", | ||
"keywords": [ | ||
"buffer", | ||
"cmap", | ||
"table", | ||
"font", | ||
"glyph", | ||
"index", | ||
"id", | ||
"code-point", | ||
"json", | ||
"parse", | ||
"cli", | ||
"command-line" | ||
], | ||
"dependencies": { | ||
"chalk": "^0.5.1", | ||
"get-stdin": "^3.0.0", | ||
"minimist": "^1.1.0", | ||
"opentype.js": "git://github.com/nodebox/opentype.js#0a73d0fdf5a43dd12568636d9823dfde22a970d9" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^0.8.2", | ||
"font-awesome": "^4.2.0", | ||
"istanbul": "^0.3.2", | ||
"istanbul-coveralls": "^1.0.1", | ||
"jscs": "^1.6.2", | ||
"lodash": "^2.4.1", | ||
"tap-spec": "^1.0.0", | ||
"tape": "^3.0.0" | ||
} | ||
} |
Oops, something went wrong.