├── CONTRIBUTORS.md ├── LICENSE ├── README.md ├── index.js └── package.json /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | Contributors 2 | ------------- 3 | 4 | * Stefano Sabatini https://github.com/sabas 5 | * Tobin Bradley https://github.com/tobinbradley 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Stefano 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | genfontgl 2 | ----- 3 | A simple command line tool to generate fonts for Mapbox GL via fontnik without gzipping the result. 4 | 5 | Usage: ```genfontgl OpenSans-Regular.ttf [output location]``` 6 | 7 | Or if not installed globally: ```npm run genfontgl -- OpenSans-Regular.ttf [output location]``` 8 | 9 | Based on: 10 | * [Fontmachine](https://github.com/mapbox/fontmachine) 11 | * [build-glyphs](https://github.com/mapbox/node-fontnik/blob/master/bin/build-glyphs) 12 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | var fontnik = require('fontnik'); 6 | var d3 = require('d3-queue'); 7 | 8 | try { 9 | var fname = process.argv[2]; 10 | 11 | var fontstack = fs.readFileSync(fname); 12 | console.log('Process '+fname); 13 | 14 | var rex = /([A-Z])([A-Z])([a-z])|([a-z])([A-Z])/g; 15 | var folder = path.basename(fname).slice(0, -4).replace('-','').replace(rex, '$1$4 $2$3$5'); 16 | if (process.argv[3]) { 17 | if (fs.existsSync(process.argv[3])) { 18 | folder = path.join(process.argv[3], folder); 19 | } else { 20 | console.error('Path ' + process.argv[3] + ' does not exist. Using default.'); 21 | } 22 | } 23 | } catch (e) { 24 | console.error('error: could not read font '+e) 25 | return; 26 | } 27 | 28 | if(!fs.existsSync(folder)){ 29 | fs.mkdirSync(folder, 0766, function(err){ 30 | if(err){ 31 | console.log(err); 32 | response.send("ERROR! Can't make the directory! \n"); 33 | } 34 | }); 35 | } 36 | 37 | var q = d3.queue(Math.max(4, require('os').cpus().length)); 38 | var queue = []; 39 | for (var i = 0; i < 65536; (i = i + 256)) { 40 | q.defer(writeGlyphs, { 41 | font: fontstack, 42 | start: i, 43 | end: Math.min(i + 255, 65535) 44 | }); 45 | } 46 | 47 | 48 | function writeGlyphs(opts, done) { 49 | fontnik.range(opts, function(err, zdata) { 50 | if (err) { 51 | console.warn(err.toString()); 52 | process.exit(1); 53 | } 54 | fs.writeFileSync(folder + '/' + opts.start + '-' + opts.end + '.pbf', zdata); 55 | done(); 56 | }); 57 | } 58 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "genfontgl", 3 | "version": "0.3.1", 4 | "description": "Create a fontstack folder from a TTF font for Mapbox GL", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "genfontgl": "node index.js" 9 | }, 10 | "dependencies": { 11 | "d3-queue": "^2.0.2", 12 | "fontnik": "^0.4.4" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/sabas/genfontgl.git" 17 | }, 18 | "bin": { 19 | "genfontgl": "index.js" 20 | }, 21 | "keywords": [ 22 | "mapbox gl", 23 | "fontstack" 24 | ], 25 | "author": "Stefano Sabatini", 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/sabas/genfontgl/issues" 29 | }, 30 | "homepage": "https://github.com/sabas/genfontgl" 31 | } 32 | --------------------------------------------------------------------------------