├── .gitignore ├── LICENSE ├── README.md ├── bin └── ttf2svg.js ├── package.json └── src └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Deployed apps should consider commenting this line out: 24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 25 | node_modules 26 | 27 | 28 | 29 | test/fontello2.svg 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ttf2svg 2 | ======= 3 | 4 | Font convertor, TTF to SVG, for node.js 5 | 6 | 7 | Usage 8 | ----- 9 | 10 | Install: 11 | 12 | ``` bash 13 | npm install -g ttf2svg 14 | ``` 15 | 16 | Usage example: 17 | 18 | ``` bash 19 | ttf2svg fontello.ttf fontello.svg 20 | ``` 21 | 22 | Or: 23 | 24 | ``` javascript 25 | var ttf2svg = require('ttf2svg') 26 | , fs = require('fs') 27 | ; 28 | 29 | fs.readFile('./fontello.ttf', function (err, buffer) { 30 | if (!!err) throw err; 31 | 32 | var svgContent = ttf2svg(buffer); 33 | fs.writeFileSync('./fontello.svg', svgContent); 34 | 35 | }); 36 | 37 | ``` 38 | 39 | Stats 40 | ----- 41 | 42 | [![NPM](https://nodei.co/npm/ttf2svg.png?downloads=true&stars=true)](https://nodei.co/npm/ttf2svg/) 43 | [![NPM](https://nodei.co/npm-dl/ttf2svg.png)](https://nodei.co/npm/ttf2svg/) 44 | 45 | 46 | 47 | Reference 48 | ----- 49 | 50 | [gulp-ttf2svg](https://github.com/morlay/gulp-ttf2svg/) 51 | -------------------------------------------------------------------------------- /bin/ttf2svg.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | 3 | /* 4 | 5 | ttf2svg ./FZLTCXHJW.ttf ./ 6 | 7 | */ 8 | 9 | var ttf2svg = require('../src/index') 10 | , fs = require('fs') 11 | , path = require('path') 12 | ; 13 | 14 | var fontPath = process.argv[2]; 15 | var fontOutputPath = process.argv[3] || './'; 16 | 17 | if (!fontPath) { 18 | console.log(' eg: ttf2svg ./font.ttf ./font.svg'); 19 | process.exit(); 20 | } 21 | 22 | var fontOutputFilePath = fontOutputPath; 23 | if (path.extname(fontOutputFilePath) != '.svg') { 24 | var basename = path.basename(fontPath, path.extname(fontPath)); 25 | fontOutputFilePath = path.join(fontOutputPath, basename + '.svg'); 26 | } 27 | 28 | fs.readFile(fontPath, function (err, buffer) { 29 | if (!!err) throw err; 30 | 31 | // return string 32 | var svgContent = ttf2svg(buffer); 33 | fs.writeFileSync(fontOutputFilePath, svgContent); 34 | 35 | console.log('complete : '+fontOutputFilePath+'!'); 36 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ttf2svg", 3 | "version": "1.2.0", 4 | "description": "Font convertor, TTF to SVG, for node.js", 5 | "main": "./src/index.js", 6 | "scripts": {}, 7 | "bin": { 8 | "ttf2svg": "bin/ttf2svg.js" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git://github.com/qdsang/ttf2svg.git" 13 | }, 14 | "keywords": [ 15 | "SVG", 16 | "font", 17 | "fonts", 18 | "ttf", 19 | "ttf2svg", 20 | "webfont" 21 | ], 22 | "author": "qdsang", 23 | "license": "", 24 | "bugs": { 25 | "url": "https://github.com/qdsang/ttf2svg/issues" 26 | }, 27 | "homepage": "https://github.com/qdsang/ttf2svg", 28 | "dependencies": { 29 | "font-carrier": "0.3.0" 30 | }, 31 | "devDependencies": {} 32 | } 33 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 2 | var fontCarrier = require('font-carrier'); 3 | 4 | function ttf2svg(buffer) { 5 | 6 | var transFont = fontCarrier.transfer(buffer); 7 | 8 | var output = transFont.output({ 9 | types:['svg'] 10 | }); 11 | 12 | return output.svg.toString(); 13 | } 14 | 15 | module.exports = ttf2svg; 16 | --------------------------------------------------------------------------------