Skip to content

Instantly share code, notes, and snippets.

@developerdizzle
Created December 3, 2015 03:18
Show Gist options
  • Save developerdizzle/dfa871150fc6ab43142d to your computer and use it in GitHub Desktop.
Save developerdizzle/dfa871150fc6ab43142d to your computer and use it in GitHub Desktop.
WIP SVG to Ligature Font gulp task
var si2sf = require('svgicons2svgfont');
var svg2ttf = require('svg2ttf');
var fs = require('fs');
function toUnicode(theString) {
var unicodeString = '';
for (var i=0; i < theString.length; i++) {
var theUnicode = theString.charCodeAt(i).toString(16).toUpperCase();
while (theUnicode.length < 4) {
theUnicode = '0' + theUnicode;
}
theUnicode = '\\u' + theUnicode;
unicodeString += theUnicode;
}
return unicodeString;
}
function svg2font(options) {
var name = options.name;
var icons = options.icons;
var output= options.output;
var fontStream = si2sf({
fontName: name
});
// Setting the font destination
fontStream.pipe(fs.createWriteStream(output))
.on('finish',function() {
console.log('Font successfully created!');
})
.on('error',function(err) {
console.log(err);
});
icons.forEach(function(icon) {
var glyph = fs.createReadStream(icon.path);
glyph.metadata = {
unicode: [icon.ligature], //[ toUnicode(icon.ligature) ],
name: icon.ligature
};
console.log('glyph', glyph);
fontStream.write(glyph);
});
fontStream.end();
console.log('options', options);
var ttf = svg2ttf(fs.readFileSync(output), {});
var ttfOutput = options.output.replace('.svg', '.ttf');
fs.writeFileSync(ttfOutput, new Buffer(ttf.buffer));
}
module.exports = svg2font;
/*
gulp.task('svg2font', function(callback) {
var options = {
name: 'test',
output: './public/test-font.svg',
icons: icons.icons
};
svg2font(options);
callback();
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment