[
  {
    "path": ".gitignore",
    "content": "node_modules\n*.log\n*.\n"
  },
  {
    "path": "bin/fontpath",
    "content": "#!/usr/bin/env node\n\nvar fs = require('fs');\nvar argv = require('optimist')\n\t\t.usage('fontpath [options] path/to/FontFile.ttf')\n\t\t.demand(1)\n\t\t.alias('c', 'chars')\n\t\t.describe('c', 'the character set: all, ascii, ascii-extended')\n\t\t.default('c', 'ascii')\n\t\t.alias('s', 'size')\n\t\t.default('s', 64)\n\t\t.describe('s', 'the font size in points')\n\t\t.alias('r', 'resolution')\n\t\t.describe('r', 'the resolution in DPI')\n\t\t.default('r', 72)\n\t\t.alias('o', 'output')\n\t\t.describe('o', 'a file to save the data to')\n\t\t.describe('commonJS', 'wrap with module.exports for a JS file')\n\t\t.describe('ignoreKerning', 'ignore kerning')\n\t\t.describe('ignorePath', 'ignore font outlines')\n\t\t.describe('pretty', 'pretty-print the output')\n\t\t.argv;\n\nvar parse = require('../lib/index.js');\n\nfs.readFile(argv._[0], function(err, buffer) {\n\tif (err) \n\t\tthrow err;\n\n\tparse(buffer, {\n\t\toutput: argv.o,\n\t\tcommonJS: argv.commonJS,\n\t\tprettyPrint: argv.pretty,\n\t\tignoreKerning: argv.ignoreKerning,\n\t\tignorePath: argv.ignorePath,\n\t\tresolution: argv.resolution,\n\t\tsize: argv.size,\n\t\tcharcodes: argv.c,\n\t});\n});"
  },
  {
    "path": "lib/SimpleJson.js",
    "content": "//Exports to a minimal JSON format that is useful for web purposes\nvar fs = require('fs');\nvar pkg = require('../package.json');\n\nvar EXPORTER_NAME = \"SimpleJson\";\n\nfunction SimpleJson() {\n}\n\nSimpleJson.prototype.export = function(fontInfo, options) {\n\tvar writer = options.output ? fs.createWriteStream(options.output) : process.stdout;\n\n\tvar objOut = {};\n\tfor (var k in fontInfo) {\n\t\tif (k !== 'glyphs' && k !== 'kerning')\n\t\t\tobjOut[k] = fontInfo[k];\n\t}\t\n\n\t//For better minification, a list of arrays\n\t//Format: [leftChar, rightChar, kerning]\n\tobjOut.kerning = [];\n\n\tif (fontInfo.kerning) {\n\t\tfor (var i=0; i<fontInfo.kerning.length; i++) {\n\t\t\tvar kern = fontInfo.kerning[i];\n\t\t\tobjOut.kerning.push( \n\t\t\t\t[ String.fromCharCode(kern.left),\n\t\t\t\t  String.fromCharCode(kern.right),\n\t\t\t\t  kern.value ]);\n\t\t}\n\t}\n\t\t\n\tobjOut.glyphs = {};\n\tfor (var i=0; i<fontInfo.glyphs.length; i++) {\n\t\tvar g = fontInfo.glyphs[i];\n\t\tvar glyphOut = {\n\t\t\txoff: g.metrics.horiAdvance,\n\t\t\twidth: g.metrics.width,\n\t\t\theight: g.metrics.height,\n\t\t\thbx: g.metrics.horiBearingX,\n\t\t\thby: g.metrics.horiBearingY\n\t\t};\n\t\tif (g.outline)\n\t\t\tglyphOut.path = g.outline || [];\n\t\tobjOut.glyphs[ String.fromCharCode(g.code) ] = glyphOut;\n\t}\n\n\tobjOut.exporter = EXPORTER_NAME;\n\tobjOut.version = pkg.version;\n\n\tvar jsonOut = JSON.stringify(objOut, null, options.prettyPrint ? 2 : null);\n\n\tif (options.commonJS) {\n\t\tjsonOut = \"module.exports = \"+jsonOut+\";\";\n\t}\n\n\twriter.write(jsonOut);\n}\n\nSimpleJson.prototype.getGlyphOutline = function(ft, face, code) {\n\tif (face.glyph.format !== ft.GLYPH_FORMAT_OUTLINE) {\n\t\t// console.warn(\"Charcode\", code, \"(\"+String.fromCharCode(code)+\") has no outline\");\n\t\treturn [];\n\t}\n\tvar data = [];\n\tft.Outline_Decompose(face, {\n\t\tmove_to: function(x, y) {\n\t\t\tdata.push([\"m\", x, y]);\n\t\t},\n\t\tline_to: function(x, y) {\n\t\t\tdata.push([\"l\", x, y]);\n\t\t},\n\t\tquad_to: function(cx, cy, x, y) {\n\t\t\tdata.push([\"q\", cx, cy, x, y]);\n\t\t},\n\t\tcubic_to: function(cx1, cy1, cx2, cy2, x, y) {\n\t\t\tdata.push([\"c\", cx1, cy1, cx2, cy2, x, y]);\n\t\t},\n\t});\n\treturn data;\n}\n\n//small decrease in filesize, worse to parse though.. worth it?\nSimpleJson.prototype.getGlyphOutlineStr = function(ft, face, code) {\n\tif (face.glyph.format !== ft.GLYPH_FORMAT_OUTLINE) {\n\t\t// console.warn(\"Charcode\", code, \"(\"+String.fromCharCode(code)+\") has no outline\");\n\t\treturn [];\n\t}\n\tvar data = \"\";\n\tft.Outline_Decompose(face, {\n\t\tmove_to: function(x, y) {\n\t\t\tdata += \"m \"+(Math.floor(x))+\" \"+(Math.floor(y))+\" \";\n\t\t},\n\t\tline_to: function(x, y) {\n\t\t\tdata += \"l \"+(Math.floor(x))+\" \"+(Math.floor(y))+\" \";\n\t\t},\n\t\tquad_to: function(cx, cy, x, y) {\n\t\t\tdata += \"q \"+(Math.floor(cx))+\" \"+(Math.floor(cy))+\" \"+(Math.floor(x))+\" \"+(Math.floor(y))+\" \";\n\t\t},\n\t\tcubic_to: function(cx1, cy1, cx2, cy2, x, y) {\n\t\t\tdata += \"c \"+(Math.floor(cx1))+\" \"+(Math.floor(cy1))+\" \"+(Math.floor(cx2))+\" \"+(Math.floor(cy2))+\" \"+(Math.floor(x))+\" \"+(Math.floor(y))+\" \";\n\t\t},\n\t});\n\treturn data.trim();\n}\n\nmodule.exports = SimpleJson;"
  },
  {
    "path": "lib/defaultFields.js",
    "content": "module.exports = [\n\t'style_name', 'family_name', 'ascender',\n\t'descender', 'height', 'underline_thickness',\n\t'underline_position', 'units_per_EM', \n\t'max_advance_width'\n];"
  },
  {
    "path": "lib/index.js",
    "content": "var fs = require('fs');\nvar ft = require('freetype2');\nvar SimpleJson = require('./SimpleJson');\n\nvar defaultFields = require('./defaultFields');\n\nfunction getAvailableCharacters(ft, face) {\n\tvar gindex = {},\n\t\tcharcode,\n\t\tchars = [];\n\n\tcharcode = ft.Get_First_Char(face, gindex);\n\twhile (gindex.gindex !== 0) {\n\t  chars.push(charcode);\n\t  charcode = ft.Get_Next_Char(face, charcode, gindex);\n\t}\n\n\treturn chars;\n}\n\nfunction basicASCII(extended) {\n\tvar codes = [];\n\tfor (var i=32; i<=126; i++)\n\t\tcodes.push( i );\n\tif (extended) {\n\t\tfor (i=161; i<255; i++)\n\t\t\tcodes.push( i );\n\t}\n\treturn codes;\n}\n\nfunction getKerning(ft, face, chars, available, kernMode) {\n\tvar kernings = [];\t\n\tkernMode = kernMode || ft.KERNING_DEFAULT;\n\n\tfor (var i=0; i<chars.length; i++) {\n\t\tvar leftCode = chars[i];\n\t\tvar left = ft.Get_Char_Index(face, leftCode);\n\n\t\tfor (var j=0; j<chars.length; j++) {\n\t\t\tvar rightCode = chars[j];\n\t\t\tvar right = ft.Get_Char_Index(face, rightCode);\n\t\t\tvar kern = { x:0, y:0 };\n\t\t\tvar err = ft.Get_Kerning(face, left, right, kernMode, kern);\n\t\t\tif (!err && kern.x !== 0) {\n\t\t\t\tkernings.push({\n\t\t\t\t\tleft: leftCode,\n\t\t\t\t\tright: rightCode,\n\t\t\t\t\tvalue: kern.x\n\t\t\t\t});\n\t\t\t} \n\t\t}\n\t}\n\t// console.log(\"Found\", kernings.length, \"kerning pairs\");\n\treturn kernings;\n}\n\n//this tool is a bit of a mess. gotta clean 'er up..\n\nfunction parse(buffer, options) {\n\toptions = options||{};\n\t\n\t// Create a font face\n\tvar face = ft.New_Memory_Face(buffer, 0);\n\tvar available = getAvailableCharacters(ft, face);\n\n\t// if ((face.face_flags & ft.FACE_FLAG_SCALABLE) !== ft.FACE_FLAG_SCALABLE)\n\t// \tconsole.warn(\"Font is not scalable\");\n\n\tvar codesToUse = options.charcodes;\n\tif (options.charcodes === \"all\")\n\t\tcodesToUse = available;\n\telse if (!codesToUse || codesToUse === \"ascii\")\n\t\tcodesToUse = basicASCII();\n\telse if (codesToUse === \"ascii-extended\")\n\t\tcodesToUse = basicASCII(true);\n\n\n\tvar exporter = options.exporter || new SimpleJson();\n\tvar fontPtSize = options.size || 12;\n\tvar fontResolution = options.resolution || 72;\n\tvar ignoreKerning = options.ignoreKerning;\n\tvar ignorePath = options.ignorePath;\n\tvar exportFields = options.fields || defaultFields;\n\n\t//if 'all' is specified, run the tool on the entire set\n\tvar charcodes = options.charcodes === \"all\" \n\t\t\t? available \n\t\t\t: codesToUse.filter(function(c) {\n\t\t\t\treturn available.indexOf(c) !== -1;\n\t\t\t});\n\n\t//Set the point size\n\tft.Set_Char_Size(face, fontPtSize * 64, fontPtSize * 64, fontResolution, fontResolution);\n\n\tvar dataObj = {};\n\tdataObj.size = fontPtSize;\n\tdataObj.resolution = fontResolution;\n\n\t//copy contents..\n\tfor (var k in face) {\n\t\tif (defaultFields.indexOf(k) !== -1)\n\t\t\tdataObj[k] = face[k];\n\t}\n\n\tif (!ignoreKerning) {\n\t\t//check if we have kerning in the font file\n\t\tif ( (face.face_flags & ft.FACE_FLAG_KERNING) === ft.FACE_FLAG_KERNING ) {\n\t\t\tdataObj.kerning = getKerning(ft, face, charcodes, available);\n\t\t} else {\n\t\t\t// console.warn(\"No kerning information in font file.\");\n\t\t\tdataObj.kerning = [];\n\t\t}\n\t}\n\n\tdataObj.glyphs = [];\n\tfor (var i=0; i<charcodes.length; i++) {\n\t\tvar code = charcodes[i];\n\t\tvar gindex = ft.Get_Char_Index(face, code);\n\t\tft.Load_Glyph(face, gindex, ft.LOAD_NO_BITMAP);\n\n\t\tvar metrics = {};\n\n\t\tfor (var k in face.glyph.metrics) {\n\t\t\tmetrics[k] = face.glyph.metrics[k];\n\t\t}\n\n\t\tvar glyph = {\n\t\t\tcode: charcodes[i],\n\t\t\tmetrics: metrics\n\t\t};\n\n\t\tif (!ignorePath) {\n\t\t\tglyph.outline = exporter.getGlyphOutline(ft, face, code);\n\t\t}\n\n\t\tdataObj.glyphs.push(glyph);\n\t}\n\texporter.export(dataObj, options);\n}\n\nmodule.exports = parse;"
  },
  {
    "path": "lib/parser.js",
    "content": "function Parser(buffer, options) {\n\n}\n\nParser.Font = function() {\n\n};\n\n\n\n\nmodule.exports = parser\n\n\n\n\n/*\nParser: parses TTF/OTF/WOFF/etc files into objects:\n\nData\n    type\n    version\n    scaled\n    family_name\n    style_name\n    size\n    style_flags\n    face_flags\n    \n    ascender\n    descender\n    underline_thickness\n    underline_position\n    \n    max_advance_width\n    width\n    height\n\n    glyphs\n    kerning\n    paths\n\n    bitmap //only if we have fontpath-bmfont\n */"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"fontpath\",\n  \"version\": \"0.0.6\",\n  \"description\": \"Generates path and kerning info from a font\",\n  \"main\": \"index.js\",\n  \"bin\": {\n    \"fontpath\": \"./bin/fontpath\"\n  },\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"author\": \"Matt DesLauriers\",\n  \"license\": \"MIT\",\n  \"dependencies\": {\n    \"freetype2\": \"mattdesl/node-freetype2#shapes\",\n    \"optimist\": \"^0.6.1\"\n  },\n  \"devDependencies\": {},\n  \"directories\": {\n    \"example\": \"examples\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"https://github.com/mattdesl/fontpath.git\"\n  },\n  \"keywords\": [\n    \"font\",\n    \"fonts\",\n    \"ttf\",\n    \"otf\",\n    \"woff\",\n    \"freetype\",\n    \"freetype2\",\n    \"vector\",\n    \"outline\",\n    \"decompose\"\n  ],\n  \"bugs\": {\n    \"url\": \"https://github.com/mattdesl/fontpath/issues\"\n  },\n  \"homepage\": \"https://github.com/mattdesl/fontpath\"\n}\n"
  },
  {
    "path": "readme.md",
    "content": "# fontpath\n\n[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)\n\nA tool which generates paths and kerning data from a TTF/OTF/WOFF/etc font. The paths can then be decomposed into points, or rendered to a canvas, or triangulated.\n\nThe project is similar to [typeface.js](http://typeface.neocracy.org/) and [cufon](http://cufon.shoqolate.com/generate/). Both of those tools are very old, and were made before @font-face gained widespread support. This project has a few different goals in mind:\n\n- Stronger focus on WebGL/animations/effects rather than trying to replace DOM text rendering\n- NPM/node tooling, eventual integration with build tools\n- decoupled modules, e.g. outline generator doesn't depend on rendering utils, glyph layout doesn't depend on canvas rendering\n- rendering engine isn't tied to Canvas (or even the browser; e.g. you could use node-canvas)\n- eventually, these tools could be used by a server to generate paths or hinted bitmap data for the client\n- TTF, OTF, WOFF, and most other formats supported (FreeType2)\n- font converter is an offline tool and fairly easy to modify (i.e. for a custom JSON/binary exporter)\n- you can specify any charsets with the API (e.g. foreign and icon fonts)\n- other stuff: hit detection on paths, advanced glyph/face metrics\n\n# example\n\n```fontpath myfont.ttf -o mfont.json --size 128```\n\nThe default size is 12 pt, but exporting with a higher font size will give you better resolution when rendering the path at large sizes. It's best to match the exported size to the final rendered size, as it will produce better rounding when scaled down.\n\n# roadmap\n\nThis project is a heavy WIP. Some things I want to explore:\n\n- Bitmap font rendering and atlas packing for Canvas/WebGL\n- Basic support for styled/attributed text (italics, bold, color, etc)\n- Maybe some tools for SDF rendering\n- Better Node/CLI integration\n\nNew modules will be added to [text-modules](https://github.com/mattdesl/text-modules).\n\n# demos\n\n- [Triangulated text effect](http://mattdesl.github.io/fontpath-renderer/demo/tris.html) - a custom renderer using triangles \n- [Custom steiner points](http://mattdesl.github.io/shape2d-triangulate/demo/glyph.html) - finer control over triangulation for creative effects\n- [WebGL Path Rendering](http://mattdesl.github.io/fontpath-gl/demo/)\n- [WebGL Triangulated Rendering](http://mattdesl.github.io/fontpath-gl/demo/wireframe.html)\n- [Bitmap Fonts](http://mattdesl.github.io/gl-sprite-text/demo/demo.html)\n- [Signed-Distance Field Bitmap Fonts](http://mattdesl.github.io/gl-sprite-text/demo/demo-sdf.html) \n\n# modules\n\n*Note:* New modules will be more generic and not specifically tied to \"fontpath.\" See [text-modules](https://github.com/mattdesl/text-modules).\n\nThe framework is split into many small modules. Some of them aren't specific to fontpath, but are useful alongside it. You generally won't need to use all of them together; but instead, you'll pick and choose based on your particular application.\n\nMost commonly, you might want to use a \"renderer\" which gives you a basic word-wrapper and glyph layout tools. \n\n- [fontpath-canvas](https://github.com/mattdesl/fontpath-canvas) - a renderer using 2D Canvas and paths for fill/stroke\n- [fontpath-gl](https://github.com/mattdesl/fontpath-gl) - a WebGL renderer using stackgl modules\n- [gl-sprite-text](https://github.com/mattdesl/gl-sprite-text) - a WebGL renderer for [BMFont](http://www.angelcode.com/products/bmfont/) files that can also be used for signed-distance field text\n\nSome other utilities that make up the ecosystem:\n\n- [fontpath-simple-renderer](https://github.com/mattdesl/fontpath-simple-renderer) a generic renderer, useful if you need something more optimized\n- [fontpath-wordwrap](https://github.com/mattdesl/fontpath-wordwrap) a basic word wrapper that supports `pre` and `nowrap` (for parity with CSS)\n- [fontpath-util](https://github.com/mattdesl/fontpath-util) - point to pixel utilities\n- [shape2d](https://github.com/mattdesl/shape2d) - Converts bezier/quadratic curves into points, with HTML5CanvasContext-like API\n- [shape2d-triangulate](https://github.com/mattdesl/shape2d-triangulate) - triangulates a list of Shapes from shape2d, ideal for triangulating fontpath glyphs. uses poly2tri\n- [fontpath-shape2d](https://github.com/mattdesl/fontpath-shape2d) - decomposes a fontpath JSON/JS glyph into points with shape2d\n- [fontpath-test-fonts](https://github.com/mattdesl/fontpath-test-fonts) - some fonts that have already been exported to JSON, so you can easily pull them in with NPM\n- [fontpath-vecmath](https://github.com/mattdesl/fontpath-vecmath) - vector/matrix utilities for font and glyph faces, built on [vecmath](https://github.com/mattdesl/vecmath)\n- [point-util](https://github.com/mattdesl/point-util) - used by shape2d-triangulate, but includes a couple of handy features like `pointInPoly`\n\n\n# license\n\nMIT\n"
  }
]