Skip to content

Commit

Permalink
Fixes Rush#1
Browse files Browse the repository at this point in the history
  • Loading branch information
Rush committed Feb 1, 2014
1 parent fe3529f commit 2c08546
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 14 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 CodeCharmLtd
Copyright (c) 2014 Code Charm Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
66 changes: 58 additions & 8 deletions font-awesome-svg-png.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env node
var fs = require('graceful-fs');


var template =
'<svg width="1792" height="1792" viewBox="{shiftX} -256 1792 1792">' +
'<svg width="{width}" height="{height}" viewBox="{shiftX} {shiftY} {width} {height}">' +
'<g transform="scale(1 -1) translate(0 -1280)">' +
'<path d="{path}" fill="{color}" />' +
'</g>' +
Expand All @@ -12,7 +13,7 @@ var spawn = require('child_process').spawn;
var http = require('http');
var request = require('request');
var yaml = require('js-yaml');

var extend = require('extend');

var pathModule = require('path');
var async = require('async');
Expand All @@ -38,24 +39,73 @@ sizes.forEach(function(siz) {
mkdir(pathModule.join(argv.color, 'png', siz.toString()));
});

var PIXEL = 128;

function generateIcon(name, path, params, cb) {
var out = template.substr(0);
out = out.replace("{path}", path);
out = out.replace("{shiftX}", -(1792 - params.advWidth)/2);
Object.keys(params).forEach(function(key) {
out = out.replace("{" + key + "}", params[key]);
});

function getTemplate(options) {
params = extend({}, params, {
shiftX: -(14*PIXEL - params.advWidth)/2 - options.paddingLeft,
shiftY: -2*PIXEL - options.paddingTop,
width: 14*PIXEL + options.paddingLeft + options.paddingRight,
height: 14*PIXEL + options.paddingBottom + options.paddingTop,
});
out = out.substr(0);
Object.keys(params).forEach(function(key) {
out = out.replace(new RegExp("{" + key + "}", 'g'), params[key]);
});
return out;
}

function optionsForSize(siz) {
var padding;

var ns = [1, 2, 4, 8, 16];
for(var i = 0;i < ns.length;++i) {
var n = ns[i];
if(siz > n*14 && siz <= n*16) {
padding = (siz - n*14)/2 * PIXEL;
}
else
continue;

if(padding - parseInt(padding) > 0) {
padding = 0;
}
return {
paddingTop: padding,
paddingBottom: padding,
paddingLeft: padding,
paddingRight: padding,
};
};
return {
paddingTop: 0,
paddingBottom: 0,
paddingLeft: 0,
paddingRight: 0
};
}


console.log("Generating icon", name);

async.eachSeries(sizes, function(siz, cb) {
var rsvgConvert;
rsvgConvert = spawn('rsvg-convert', ['-f', 'png', '-w', siz, '-o', pathModule.join(argv.color, 'png', siz.toString(), name+'.png')]);
rsvgConvert.stdin.end(out);
rsvgConvert.stdin.end(getTemplate(optionsForSize(siz)));
rsvgConvert.once('error', cb);
rsvgConvert.once('exit', cb);
}, cb);
var outSvg = fs.createWriteStream(pathModule.join(argv.color, 'svg', name + '.svg'));
outSvg.end(out);
outSvg.end(getTemplate({
paddingTop: 0,
paddingLeft: 0,
paddingBottom: 0,
paddingRight: 0
}));
}

console.log("Downloading latest icons.yml ...");
Expand Down
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
{
"name": "font-awesome-svg-png",
"version": "1.0.7",
"version": "1.0.8",
"description": "Font Awesome split to individual SVG and PNG files of different sizes along with Node.JS based generator",
"main": "font-awesome-svg-png",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Damian Kaczmarek <[email protected]>",
"repository": {"type": "git", "url": "https://github.com/CodeCharmLtd/Font-Awesome-SVG-PNG"},
"bin": {"font-awesome-svg-png":"./font-awesome-svg-png.js"},
"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/CodeCharmLtd/Font-Awesome-SVG-PNG"
},
"bin": {
"font-awesome-svg-png": "./font-awesome-svg-png.js"
},
"license": "MIT",
"dependencies": {
"request": "~2.33.0",
"js-yaml": "~3.0.1",
"async": "~0.2.10",
"graceful-fs": "~2.0.1",
"optimist": "~0.6.0"
"optimist": "~0.6.0",
"extend": "~1.2.1"
}
}

0 comments on commit 2c08546

Please sign in to comment.