Skip to content

Commit

Permalink
DIGREPO-807: use FA icons for objects without thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
dunn committed Aug 15, 2017
1 parent f8b5d61 commit fb8265d
Show file tree
Hide file tree
Showing 29 changed files with 1,317 additions and 11 deletions.
36 changes: 36 additions & 0 deletions app/assets/images/fontawesome/.bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "Font-Awesome-SVG-PNG",
"main": "Font-Awesome-SVG-PNG.js",
"homepage": "https://github.com/encharm/Font-Awesome-SVG-PNG",
"authors": [
"Damian Kaczmarek <[email protected]>"
],
"description": "Font Awesome split to individual SVG and PNG files of different sizes along with Node.JS based generator",
"keywords": [
"svg",
"png",
"icons",
"design",
"ui",
"font"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"version": "1.1.5",
"_release": "1.1.5",
"_resolution": {
"type": "version",
"tag": "1.1.5",
"commit": "b7f74631d79e110ef972395fc408a59bea028319"
},
"_source": "https://github.com/encharm/Font-Awesome-SVG-PNG.git",
"_target": "^1.1.5",
"_originalSource": "font-awesome-svg-png",
"_direct": true
}
20 changes: 20 additions & 0 deletions app/assets/images/fontawesome/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

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
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56 changes: 56 additions & 0 deletions app/assets/images/fontawesome/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Font-Awesome-SVG-PNG
====================

This project provides a Font-Awesome build split to individual SVG and PNG files of different sizes along with Node.JS based generator to generate any other colors and sizes combinations.

## What is Font-Awesome?
Font Awesome is a full suite of 605 pictographic icons for easy scalable vector graphics on websites, created and
maintained by [Dave Gandy](http://twitter.com/davegandy). Stay up to date [@fontawesome](http://twitter.com/fontawesome).

Get started at http://fontawesome.io!

## License
- The Font Awesome font is licensed under the SIL OFL 1.1:
- http://scripts.sil.org/OFL
- Font-Awesome-SVG-PNG is licensed under the MIT license

## How to use?
You may use already generated icons in `white` and `black` directories. You can also generate your own set:

Note: you need to have a command `rsvg-convert` available.

Install via npm: `npm install -g font-awesome-svg-png`.

Install via Bower: `bower install font-awesome-svg-png`.

The following command will generate a red set of icons at sizes of 128 and 256 pixels in directory `red`:
`font-awesome-svg-png --color red --sizes 128,256`

## PNG creation

PNG creation depends on `rsvg-convert` command being in the path.

You can skip PNG creation with `--no-png`.

### Windows support
Everything should work once you have `rsvg-convert.exe`. You may get it from https://osspack32.googlecode.com/files/rsvg-convert.exe and move to `%PATH%`.

### Mac OS X support
```
sudo port install librsvg
... or ...
brew install librsvg
```
That should give the necessary `rsvg-convert` command.

WARNING: Starting from librsvg 2.40.11 and onwards `rsvg-convert` produces empty images due to a breaking change that was introduced. At moment there's no workaround but to revert to librsvg 2.40.10 and below.

### Linux support
For Debian `rsvg-convert` in located in the `librsvg2-bin` package.
```sh
sudo apt-get install librsvg2-bin
```

##Authors
- Damian Kaczmarek <[email protected]> [@Rush](https://github.com/Rush)
- Dominykas Blyžė <[email protected]> [@dominykas](https://github.com/dominykas)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions app/assets/images/fontawesome/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "Font-Awesome-SVG-PNG",
"main": "Font-Awesome-SVG-PNG.js",
"homepage": "https://github.com/encharm/Font-Awesome-SVG-PNG",
"authors": [
"Damian Kaczmarek <[email protected]>"
],
"description": "Font Awesome split to individual SVG and PNG files of different sizes along with Node.JS based generator",
"keywords": [
"svg",
"png",
"icons",
"design",
"ui",
"font"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
77 changes: 77 additions & 0 deletions app/assets/images/fontawesome/font-awesome-svg-png.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env node

var Promise = require("bluebird"),
optimist = require("optimist"),
getGlyphs = require("./lib/getGlyphs"),
libFontAwesome = require("./index");

var argv = optimist
.usage("Usage:\n $0 --sprites\n $0 --color white --no-png\n $0 --color black --no-svg\n $0 --sprites --color black,white --optipng\n $0 --list")
.describe('sizes', "Provide comma separated sizes to generate")
.describe('color', "Provide color or colors, e.g. --color black,white")
.describe('sprites', 'Generate sprites.svg to use SVG as icons (http://tympanus.net/codrops/2013/11/27/svg-icons-ftw/)')
.describe('nopadding', "Do not add padding for PNG pixel perfection")
.describe('png', "Generate PNG files")
.describe('optipng', "Run each file through optipng (need to be installed)")
.describe('svg', "Generate SVG files")
.describe('icons', "Optional list of icons to generate, e.g. --icons phone,star")
.describe('dest', "Output folder")
.describe('list', "List available icons")
.describe('help', "Show this help screen")
.default({
sizes: "16,22,24,32,48,64,128,256",
sprites: false,
nopadding: false,
optipng: false,
png: true,
svg: true,
dest: "./"
}).argv;

if (argv.help) {
console.log(optimist.help());
return;
}

if (argv.list) {
getGlyphs().then(function (glyphs) {
console.log(glyphs.map(function (glyphs) {
return glyphs.id;
}));
});
return;
}

if (!argv.sprites && !argv.color) {
console.log(optimist.help());
console.error("Error: either --sprites or --color param must be set.");
return;
}

if (argv.color && !argv.png && !argv.svg) {
console.log(optimist.help());
console.error("Error: at least one of --png or --svg must be set when --color is set.");
return;
}

var commandChecks = [];
// @todo: add optipng into command checks
if (argv.color && argv.png) {
commandChecks.push(new Promise(function (resolve, reject) {
// @todo: surely there's a module in npm that allows to do command checks automagically?
var convertTest = require('child_process').spawn('rsvg-convert', ['--help']);
convertTest.once('error', function () {
throw Error("Error: cannot start `rsvg-convert` command. Please install it or verify that it is in your PATH.");
});
convertTest.once('exit', function (code) {
if (code) return reject();
resolve();
});
}));
}

Promise.all(commandChecks).then(function () {
return libFontAwesome.generate(argv);
}).catch(function (err) {
console.error("Cought error", err);
});
1 change: 1 addition & 0 deletions app/assets/images/fontawesome/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports.generate = require("./lib/generate");
80 changes: 80 additions & 0 deletions app/assets/images/fontawesome/lib/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
var Promise = require("bluebird"),
extend = require('extend'),
getGlyphs = require("./getGlyphs"),
generateSprites = require("./generateSprites"),
generateIcon = require("./generateIcon");

function flatten(arr) {
return arr.reduce(function (a, b) {
return a.concat(b);
}, []);
}

function generate(argv, callback) {

var sizes = (argv.sizes || '').toString().split(',');

if (argv.color) {
var colors = argv.color.toString().split(',');
}

if (argv.icons) {
var icons = argv.icons.toString().split(',');
}

var createSprites = !!argv.sprites;
var addPadding = !argv.nopadding;
var png = !!argv.png;
var svg = !!argv.svg;
var optipng = !!argv.optipng;
var destFolder = argv.dest || "./";

return getGlyphs().then(function (glyphs) {

if (icons) {
glyphs = glyphs.filter(function (glyph) {
return icons.indexOf(glyph.id) >= 0;
});
}

var work = [];

if (colors) {
var iconConfigs = flatten(glyphs.map(function (glyph) {
return colors.map(function (color) {
return extend(true, {}, {
id: glyph.id,
advWidth: glyph.data['horiz-adv-x'] || 1536,
path: glyph.data.d,
color: color,
addPadding: addPadding,
generatePng: png,
sizes: sizes,
generateSvg: svg,
optipng: optipng,
destFolder: destFolder
});
})
}));

work.push(Promise.map(iconConfigs, generateIcon, {concurrency: 1}).then(function (done) {
console.log("Done",done.map(function (doneItem) {
return doneItem.color + " " + doneItem.id
}).join(", "));
}));
}

if (createSprites) {
work.push(generateSprites(glyphs, {
destFolder: destFolder
}));
}

return Promise.all(work).then(function () {
console.log('All done!');
}).nodeify(callback);

});
}

module.exports = generate;
75 changes: 75 additions & 0 deletions app/assets/images/fontawesome/lib/generateIcon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
var Promise = require("bluebird"),
fs = require('graceful-fs'),
mkdirp = require("mkdirp"),
SVGO = require('svgo'),
pathModule = require('path'),
spawn = require('child_process').spawn,
execFile = Promise.promisify(require('child_process').execFile),
getIconSvg = require("./getIconSvg");

var svgo = new SVGO({
removeViewBox: true
});

function generatePng(siz, name, params) {
return new Promise(function(resolve, reject) {
var rsvgConvert;
var color = params.color;
var svgCode = getIconSvg(params, siz);
var filename = pathModule.join(params.destFolder, color, 'png', siz.toString(), name + '.png');
rsvgConvert = spawn('rsvg-convert', ['-f', 'png', '-w', siz, '-o', filename]);
if (process.env.INTERMEDIATE_SVG) {
fs.writeFileSync(pathModule.join(params.destFolder, color, 'png', siz.toString(), name + '.svg'), svgCode);
}
rsvgConvert.stdin.end(svgCode);
rsvgConvert.once('error', reject);
rsvgConvert.once('exit', function (code) {
if (code) return reject(code);
resolve(filename);
});
}).then(function (filename) {
if (params.optipng) {
return execFile('optipng', [filename]).catch(function (err) {
throw Error("Cannot run 'optipng' - is it installed? " + err.code);
});
}
});
}


function generatePngs(name, params) {
return Promise.map(params.sizes, function (siz) {
mkdirp.sync(pathModule.join(params.destFolder, params.color, 'png', siz));
return generatePng(siz, name, params);
}, {concurrency: process.env['JOBS'] || 4});
}

function generateSvg(name, params) {
var svgFolder = pathModule.join(params.destFolder, params.color, 'svg');
mkdirp.sync(svgFolder);

return new Promise(function(resolve, reject) {
var outSvg = fs.createWriteStream(pathModule.join(svgFolder, name + '.svg'));
svgo.optimize(getIconSvg(params), function(result) {
outSvg.end(result.data);
resolve();
});
});
}

function generateIcon(params) {
var name = params.id;
console.log("Generating", params.color, name);
var workChain = [];
if(params.generatePng) {
workChain.push(generatePngs(name, params));
}
if(params.generateSvg) {
workChain.push(generateSvg(name, params));
}
return Promise.all(workChain).then(function () {
return { id: name, color: params.color };
});
}

module.exports = generateIcon;
Loading

0 comments on commit fb8265d

Please sign in to comment.