From 3671118e1bde5ab82c365b0ad4448bf77d966a03 Mon Sep 17 00:00:00 2001 From: Artem Sapegin Date: Tue, 12 Nov 2013 19:02:07 +0400 Subject: [PATCH] Node engine: create SVG font. --- Gruntfile.js | 8 +++++++ package.json | 11 ++++++---- tasks/engines/node.js | 51 +++++++++++++++++++++++++++++++++++++++++++ tasks/webfont.js | 2 +- test/src/plusone.svg | 20 +++++++++++++++++ test/src/single.svg | 14 ++++++++++++ 6 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 tasks/engines/node.js create mode 100644 test/src/plusone.svg create mode 100644 test/src/single.svg diff --git a/Gruntfile.js b/Gruntfile.js index fe3524e..3fa52e8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -172,6 +172,14 @@ module.exports = function(grunt) { order: 'svg,woff', hashes: false } + }, + node: { + src: 'test/src/*.svg', + dest: 'test/tmp/node', + options: { + hashes: false, + engine: 'node' + } } }, nodeunit: { diff --git a/package.json b/package.json index c62de44..525ed6a 100644 --- a/package.json +++ b/package.json @@ -31,15 +31,18 @@ "node": "*" }, "dependencies": { - "temp": "~0.4.0" + "temp": "~0.4.0", + "svgicons2svgfont": "0.0.1", + "async": "~0.2.9", + "lodash": "~2.3.0" }, "devDependencies": { "grunt": "~0.4.1", - "grunt-contrib-jshint": "~0.6.4", + "grunt-contrib-jshint": "~0.7.1", "grunt-contrib-nodeunit": "~0.2.2", "grunt-contrib-clean": "~0.5.0", - "grunt-jscs-checker": "~0.2.2", - "stylus": "~0.38.0", + "grunt-jscs-checker": "~0.2.3", + "stylus": "~0.40.2", "matchdep": "~0.3.0" }, "peerDependencies": { diff --git a/tasks/engines/node.js b/tasks/engines/node.js new file mode 100644 index 0000000..ea56b77 --- /dev/null +++ b/tasks/engines/node.js @@ -0,0 +1,51 @@ +/** + * grunt-webfont: Node.js engine + * + * @requires ttfautohint + * @author Artem Sapegin (http://sapegin.me) + */ + +/*jshint node:true, laxbreak:true, latedef:false */ +module.exports = function(grunt, o, done) { + 'use strict'; + + var path = require('path'); + var async = require('async'); + var svgicons2svgfont = require('svgicons2svgfont'); + + // @todo Append hashes + + var result = { + fontName: o.fontName, + glyphs: [] + }; + + async.waterfall([ + svgFilesToSvgFont, + allDone + ]); + + + // Convert SVG files to SVG font + function svgFilesToSvgFont(done) { + console.log(o.files); + svgicons2svgfont(o.files, path.join(o.dest, o.fontName + '.svg'), { + fontName: o.fontName, + callback: function(glyphs) { + console.log('done', glyphs); + result.glyphs = glyphs; + done(); + } + }); + } + + // Create TTF font + // Autohint TTF + // Create WOFF font + // Create OTF font + + + function allDone() { + done(result); + } +}; diff --git a/tasks/webfont.js b/tasks/webfont.js index f4aeae9..b02c00d 100644 --- a/tasks/webfont.js +++ b/tasks/webfont.js @@ -12,7 +12,7 @@ module.exports = function(grunt) { var fs = require('fs'); var path = require('path'); var temp = require('temp'); - var async = grunt.util.async; + var async = require('async'); var _ = grunt.util._; var COMMAND_NOT_FOUND = 127; diff --git a/test/src/plusone.svg b/test/src/plusone.svg new file mode 100644 index 0000000..c811ef1 --- /dev/null +++ b/test/src/plusone.svg @@ -0,0 +1,20 @@ + + + plusone + Created with Sketch (http://www.bohemiancoding.com/sketch) + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/src/single.svg b/test/src/single.svg new file mode 100644 index 0000000..b9df5aa --- /dev/null +++ b/test/src/single.svg @@ -0,0 +1,14 @@ + + + single + Created with Sketch (http://www.bohemiancoding.com/sketch) + + + + + + + + + + \ No newline at end of file