svgicons2svgfont
Advanced tools
Comparing version 6.1.0 to 7.0.0
@@ -16,9 +16,9 @@ svgicons2svgfont is a simple tool to merge | ||
## Usage | ||
## Usage | ||
### In your scripts | ||
### In your scripts | ||
```js | ||
var svgicons2svgfont = require('svgicons2svgfont'); | ||
var fs = require('fs'); | ||
var fontStream = svgicons2svgfont({ | ||
const SVGIcons2SVGFontStream = require('svgicons2svgfont'); | ||
const fs = require('fs'); | ||
const fontStream = new SVGIcons2SVGFontStream({ | ||
fontName: 'hello' | ||
@@ -37,3 +37,3 @@ }); | ||
// Writing glyphs | ||
var glyph1 = fs.createReadStream('icons/icon1.svg'); | ||
const glyph1 = fs.createReadStream('icons/icon1.svg'); | ||
glyph1.metadata = { | ||
@@ -45,3 +45,3 @@ unicode: ['\uE001\uE002'], | ||
// Multiple unicode values are possible | ||
var glyph2 = fs.createReadStream('icons/icon1.svg'); | ||
const glyph2 = fs.createReadStream('icons/icon1.svg'); | ||
glyph2.metadata = { | ||
@@ -53,3 +53,3 @@ unicode: ['\uE002', '\uEA02'], | ||
// Either ligatures are available | ||
var glyph3 = fs.createReadStream('icons/icon1.svg'); | ||
const glyph3 = fs.createReadStream('icons/icon1.svg'); | ||
glyph3.metadata = { | ||
@@ -78,3 +78,3 @@ unicode: ['\uE001\uE002'], | ||
There is a few more options for the CLI interface, you can list all of them: | ||
```js | ||
```txt | ||
svgicons2svgfont --help | ||
@@ -107,3 +107,3 @@ # Usage: svgicons2svgfont [options] <icons ...> | ||
### svgicons2svgfont(options) | ||
### new SVGIcons2SVGFontStream(options) | ||
@@ -209,11 +209,11 @@ #### options.fontName | ||
### Stylus plugin | ||
### Stylus plugin | ||
Use [stylus-iconfont](https://www.npmjs.org/package/stylus-iconfont). | ||
### Mimosa plugin | ||
### Mimosa plugin | ||
Use [mimosa-svgs-to-iconfonts](https://www.npmjs.org/package/mimosa-svgs-to-iconfonts). | ||
## CLI alternatives | ||
## CLI alternatives | ||
@@ -220,0 +220,0 @@ You can combine this plugin's CLI interface with |
#! /usr/bin/env node | ||
/* eslint-disable prefer-reflect */ | ||
@@ -9,4 +10,4 @@ 'use strict'; | ||
const svgicons2svgfont = require('../src/index.js'); | ||
const svgiconsdir = require('../src/iconsdir.js'); | ||
const SVGIcons2SVGFont = require('../src/index.js'); | ||
const SVGIconsDirStream = require('../src/iconsdir.js'); | ||
@@ -26,3 +27,3 @@ program | ||
.option('-h, --height [value]', 'the outputted font height [MAX(icons.height)].', parseInt) | ||
.option('-r, --round [value]', 'setup the SVG path rounding [10e12].', parseInt) | ||
.option('-r, --round [value]', 'setup the SVG path rounding [10e12].', parseFloat) | ||
.option('-d, --descent [value]', 'the font descent [0].', parseInt) | ||
@@ -42,5 +43,5 @@ .option('-a, --ascent [value]', 'the font ascent [height - ascent].', parseInt) | ||
const files = [].concat.apply([], program.args.map(file => glob.sync(file))); | ||
const files = [].concat(...program.args.map(file => glob.sync(file))); | ||
svgiconsdir(files, { | ||
new SVGIconsDirStream(files, { | ||
startUnicode: program.startunicode, | ||
@@ -50,3 +51,3 @@ prependUnicode: program.prependUnicode, | ||
}) | ||
.pipe(svgicons2svgfont({ | ||
.pipe(new SVGIcons2SVGFont({ | ||
fontName: program.fontname, | ||
@@ -53,0 +54,0 @@ fontId: program.fontId, |
@@ -0,1 +1,6 @@ | ||
<a name="7.0.0"></a> | ||
# [7.0.0](https://github.com/nfroidure/svgicons2svgfont/compare/v6.0.0...v7.0.0) (2017-08-24) | ||
<a name="6.1.0"></a> | ||
@@ -2,0 +7,0 @@ # [6.1.0](https://github.com/nfroidure/svgicons2svgfont/compare/v6.0.0...v6.1.0) (2017-08-22) |
{ | ||
"name": "svgicons2svgfont", | ||
"version": "6.1.0", | ||
"version": "7.0.0", | ||
"description": "Read a set of SVG icons and ouput a SVG font", | ||
@@ -46,2 +46,3 @@ "homepage": "https://github.com/nfroidure/svgicons2svgfont", | ||
"debug": "2.6.1", | ||
"glob": "^7.1.2", | ||
"neatequal": "^1.0.0", | ||
@@ -53,3 +54,3 @@ "readable-stream": "^2.0.4", | ||
"svg-pathdata": "^4.0.1", | ||
"glob": "^7.1.2" | ||
"transformation-matrix-js": "^2.7.1" | ||
}, | ||
@@ -71,2 +72,5 @@ "devDependencies": { | ||
"author": "Nicolas Froidure", | ||
"contributors": [ | ||
"Adrian Leonhard <adrianleonhard@gmail.com> (https://github.com/NaridaL)" | ||
], | ||
"license": "MIT", | ||
@@ -73,0 +77,0 @@ "bugs": { |
@@ -32,9 +32,9 @@ <!-- | ||
## Usage | ||
## Usage | ||
### In your scripts | ||
### In your scripts | ||
```js | ||
var svgicons2svgfont = require('svgicons2svgfont'); | ||
var fs = require('fs'); | ||
var fontStream = svgicons2svgfont({ | ||
const SVGIcons2SVGFontStream = require('svgicons2svgfont'); | ||
const fs = require('fs'); | ||
const fontStream = new SVGIcons2SVGFontStream({ | ||
fontName: 'hello' | ||
@@ -53,3 +53,3 @@ }); | ||
// Writing glyphs | ||
var glyph1 = fs.createReadStream('icons/icon1.svg'); | ||
const glyph1 = fs.createReadStream('icons/icon1.svg'); | ||
glyph1.metadata = { | ||
@@ -61,3 +61,3 @@ unicode: ['\uE001\uE002'], | ||
// Multiple unicode values are possible | ||
var glyph2 = fs.createReadStream('icons/icon1.svg'); | ||
const glyph2 = fs.createReadStream('icons/icon1.svg'); | ||
glyph2.metadata = { | ||
@@ -69,3 +69,3 @@ unicode: ['\uE002', '\uEA02'], | ||
// Either ligatures are available | ||
var glyph3 = fs.createReadStream('icons/icon1.svg'); | ||
const glyph3 = fs.createReadStream('icons/icon1.svg'); | ||
glyph3.metadata = { | ||
@@ -94,3 +94,3 @@ unicode: ['\uE001\uE002'], | ||
There is a few more options for the CLI interface, you can list all of them: | ||
```js | ||
```txt | ||
svgicons2svgfont --help | ||
@@ -123,3 +123,3 @@ # Usage: svgicons2svgfont [options] <icons ...> | ||
### svgicons2svgfont(options) | ||
### new SVGIcons2SVGFontStream(options) | ||
@@ -225,11 +225,11 @@ #### options.fontName | ||
### Stylus plugin | ||
### Stylus plugin | ||
Use [stylus-iconfont](https://www.npmjs.org/package/stylus-iconfont). | ||
### Mimosa plugin | ||
### Mimosa plugin | ||
Use [mimosa-svgs-to-iconfonts](https://www.npmjs.org/package/mimosa-svgs-to-iconfonts). | ||
## CLI alternatives | ||
## CLI alternatives | ||
@@ -236,0 +236,0 @@ You can combine this plugin's CLI interface with |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable complexity */ | ||
'use strict'; | ||
@@ -2,0 +3,0 @@ |
@@ -0,5 +1,5 @@ | ||
/* eslint-disable prefer-template,no-confusing-arrow */ | ||
'use strict'; | ||
const fs = require('fs'); | ||
const util = require('util'); | ||
const fileSorter = require('./filesorter'); | ||
@@ -12,52 +12,45 @@ const initMetadataService = require('../src/metadata'); | ||
// Inherit of duplex stream | ||
util.inherits(SVGIconsDirStream, Readable); | ||
// Constructor | ||
function SVGIconsDirStream(dir, options) { | ||
const _this = this; | ||
const getMetadata = initMetadataService(options); | ||
let filesInfos; | ||
let gotFilesInfos = false; | ||
let dirCopy; | ||
class SVGIconsDirStream extends Readable { | ||
constructor(dir, options) { | ||
super({ objectMode: true }); | ||
this.getMetadata = initMetadataService(options); | ||
this.gotFilesInfos = false; | ||
this.dir = dir; | ||
// Ensure new were used | ||
if(!(this instanceof SVGIconsDirStream)) { | ||
return new SVGIconsDirStream(dir, options); | ||
} | ||
if(dir instanceof Array) { | ||
const dirCopy = this.dir; | ||
if(dir instanceof Array) { | ||
dirCopy = dir; | ||
dir = ''; | ||
_getFilesInfos(dirCopy); | ||
this.dir = ''; | ||
this._getFilesInfos(dirCopy); | ||
} | ||
} | ||
function _getFilesInfos(files) { | ||
_getFilesInfos(files) { | ||
let filesProcessed = 0; | ||
filesInfos = []; | ||
this.fileInfos = []; | ||
// Ensure prefixed files come first | ||
files = files.slice(0).sort(fileSorter); | ||
files.forEach((file) => { | ||
getMetadata((dir ? dir + '/' : '') + file, function(err, metadata) { | ||
this.getMetadata((this.dir ? this.dir + '/' : '') + file, (err, metadata) => { | ||
filesProcessed++; | ||
if(err) { | ||
_this.emit('error', err); | ||
this.emit('error', err); | ||
} else { | ||
if(metadata.renamed) { | ||
options.log('Saved codepoint: ' + | ||
'u' + metadata.unicode[0].codePointAt(0).toString(16).toUpperCase() + | ||
this.options.log('Saved codepoint: ' + | ||
'u' + metadata.unicode[0].codePointAt(0).toString(16) | ||
.toUpperCase() + | ||
' for the glyph "' + metadata.name + '"'); | ||
} | ||
filesInfos.push(metadata); | ||
this.fileInfos.push(metadata); | ||
} | ||
if(files.length === filesProcessed) { | ||
// Reorder files | ||
filesInfos = filesInfos.sort(function(infosA, infosB) { | ||
return infosA.unicode[0] > infosB.unicode[0] ? 1 : -1; | ||
}); | ||
this.fileInfos.sort((infosA, infosB) => infosA.unicode[0] > infosB.unicode[0] ? 1 : -1); | ||
// Mark directory as processed | ||
gotFilesInfos = true; | ||
this.gotFilesInfos = true; | ||
// Start processing | ||
_pushSVGIcons(); | ||
this._pushSVGIcons(); | ||
} | ||
@@ -68,8 +61,8 @@ }); | ||
function _pushSVGIcons() { | ||
_pushSVGIcons() { | ||
let fileInfo; | ||
let svgIconStream; | ||
while(filesInfos.length) { | ||
fileInfo = filesInfos.shift(); | ||
while(this.fileInfos.length) { | ||
fileInfo = this.fileInfos.shift(); | ||
svgIconStream = fs.createReadStream(fileInfo.path); | ||
@@ -80,23 +73,17 @@ svgIconStream.metadata = { | ||
}; | ||
if(!_this.push(svgIconStream)) { | ||
if(!this.push(svgIconStream)) { | ||
return; | ||
} | ||
} | ||
_this.push(null); | ||
this.push(null); | ||
} | ||
// Parent constructor | ||
Readable.call(this, { | ||
objectMode: true, | ||
}); | ||
this._read = function() { | ||
if(!filesInfos) { | ||
_read() { | ||
if(!this.fileInfos) { | ||
fs.readdir( | ||
dir, | ||
this.dir, | ||
(err, files) => { | ||
if(err) { | ||
_this.emit('error', err); | ||
this.emit('error', err); | ||
} | ||
_getFilesInfos(files); | ||
this._getFilesInfos(files); | ||
} | ||
@@ -106,6 +93,6 @@ ); | ||
} | ||
if(gotFilesInfos) { | ||
_pushSVGIcons(); | ||
if(this.gotFilesInfos) { | ||
this._pushSVGIcons(); | ||
} | ||
}; | ||
} | ||
@@ -112,0 +99,0 @@ } |
396
src/index.js
@@ -1,12 +0,12 @@ | ||
/* eslint no-multi-str:0 */ | ||
/* eslint-disable complexity,prefer-reflect,max-len,newline-after-var */ | ||
/* eslint no-multi-str:0 */ | ||
'use strict'; | ||
// Required modules | ||
var util = require('util'); | ||
var ucs2 = require('punycode').ucs2; | ||
var Stream = require('readable-stream'); | ||
var Sax = require('sax'); | ||
var SVGPathData = require('svg-pathdata').SVGPathData; | ||
var svgShapesToPath = require('./svgshapes2svgpath'); | ||
const { ucs2 } = require('punycode'); | ||
const { Transform } = require('stream'); | ||
const Sax = require('sax'); | ||
const { SVGPathData } = require('svg-pathdata'); | ||
const svgShapesToPath = require('./svgshapes2svgpath'); | ||
const { Matrix } = require('transformation-matrix-js'); | ||
@@ -18,24 +18,18 @@ require('string.prototype.codepointat'); | ||
return value.match( | ||
/(rotate|translate|scale|skewX|skewY|matrix)\s*\(([^\)]*)\)\s*/g | ||
).map(function(transform) { | ||
return transform.match(/[\w\.\-]+/g); | ||
}); | ||
/(rotate|translate|scale|skewX|skewY|matrix)\s*\(([^)]*)\)\s*/g | ||
).map(transform => transform.match(/[\w.-]+/g)); | ||
} | ||
function transformPath(path, transforms) { | ||
transforms.forEach(function(transform) { | ||
path[transform[0]].apply(path, transform.slice(1).map(function(n) { | ||
return parseFloat(n, 10); | ||
})); | ||
}); | ||
return path; | ||
} | ||
function applyTransforms(d, parents) { | ||
var transforms = []; | ||
function matrixFromTransformAttribute(transformAttributeString) { | ||
const result = new Matrix(); | ||
const map = { | ||
matrix: 'transform', | ||
rotate: 'rotateDeg', | ||
}; | ||
parents.forEach(function(parent) { | ||
if('undefined' !== typeof parent.attributes.transform) { | ||
transforms = transforms.concat(parseTransforms(parent.attributes.transform)); | ||
} | ||
}); | ||
return transformPath(new SVGPathData(d), transforms).encode(); | ||
for(const transform of parseTransforms(transformAttributeString)) { | ||
const method = map[transform[0]] || transform[0]; | ||
result[method](...transform.slice(1).map(parseFloat)); | ||
} | ||
return result; | ||
} | ||
@@ -45,5 +39,5 @@ | ||
function tagShouldRender(curTag, parents) { | ||
var values; | ||
let values; | ||
return !parents.some(function(tag) { | ||
return !parents.some((tag) => { | ||
if('undefined' !== typeof tag.attributes.display && | ||
@@ -54,7 +48,7 @@ 'none' === tag.attributes.display.toLowerCase()) { | ||
if('undefined' !== typeof tag.attributes.width && | ||
0 === parseFloat(tag.attributes.width, 0)) { | ||
0 === parseFloat(tag.attributes.width)) { | ||
return true; | ||
} | ||
if('undefined' !== typeof tag.attributes.height && | ||
0 === parseFloat(tag.attributes.height, 0)) { | ||
0 === parseFloat(tag.attributes.height)) { | ||
return true; | ||
@@ -76,6 +70,6 @@ } | ||
function getTagColor(currTag, parents) { | ||
var defaultColor = 'black'; | ||
var fillVal = currTag.attributes.fill; | ||
var color; | ||
var parentsLength = parents.length; | ||
const defaultColor = 'black'; | ||
const fillVal = currTag.attributes.fill; | ||
let color; | ||
const parentsLength = parents.length; | ||
@@ -106,88 +100,75 @@ if('none' === fillVal) { | ||
// Inherit of duplex stream | ||
util.inherits(SVGIcons2SVGFontStream, Stream.Transform); | ||
class SVGIcons2SVGFontStream extends Transform { | ||
// Constructor | ||
function SVGIcons2SVGFontStream(options) { | ||
var _this = this; | ||
var glyphs = []; | ||
var log; | ||
constructor(options) { | ||
super({ objectMode: true, writableObjectMode: true, readableObjectMode: false }); | ||
this.glyphs = []; | ||
options = options || {}; | ||
options.fontName = options.fontName || 'iconfont'; | ||
options.fontId = options.fontId || options.fontName; | ||
options.fixedWidth = options.fixedWidth || false; | ||
options.descent = options.descent || 0; | ||
options.round = options.round || 10e12; | ||
options.metadata = options.metadata || ''; | ||
this._options = options || {}; | ||
this._options.fontName = this._options.fontName || 'iconfont'; | ||
this._options.fontId = this._options.fontId || this._options.fontName; | ||
this._options.fixedWidth = this._options.fixedWidth || false; | ||
this._options.descent = this._options.descent || 0; | ||
this._options.round = this._options.round || 10e12; | ||
this._options.metadata = this._options.metadata || ''; | ||
log = options.log || console.log.bind(console); // eslint-disable-line | ||
// Ensure new were used | ||
if(!(this instanceof SVGIcons2SVGFontStream)) { | ||
return new SVGIcons2SVGFontStream(options); | ||
this.log = this._options.log || console.log.bind(console); // eslint-disable-line | ||
} | ||
// Parent constructor | ||
Stream.Transform.call(this, { | ||
objectMode: true, | ||
}); | ||
// Setting objectMode separately | ||
this._writableState.objectMode = true; | ||
this._readableState.objectMode = false; | ||
// Parse input | ||
this._transform = function _svgIcons2SVGFontStreamTransform( | ||
svgIconStream, unused, svgIconStreamCallback | ||
) { | ||
_transform(svgIconStream, _unused, svgIconStreamCallback) { | ||
// Parsing each icons asynchronously | ||
var saxStream = Sax.createStream(true); | ||
var parents = []; | ||
var glyph = svgIconStream.metadata || {}; | ||
const saxStream = Sax.createStream(true); | ||
const parents = []; | ||
const transformStack = [new Matrix()]; | ||
function applyTransform(d) { | ||
return new SVGPathData(d).matrix(...transformStack[transformStack.length - 1].toArray()); | ||
} | ||
const glyph = svgIconStream.metadata || {}; | ||
glyph.d = []; | ||
glyphs.push(glyph); | ||
glyph.paths = []; | ||
this.glyphs.push(glyph); | ||
if('string' !== typeof glyph.name) { | ||
_this.emit('error', new Error('Please provide a name for the glyph at' + | ||
' index ' + (glyphs.length - 1))); | ||
this.emit('error', new Error( | ||
`Please provide a name for the glyph at index ${this.glyphs.length - 1}`)); | ||
} | ||
if(glyphs.some(function(anotherGlyph) { | ||
return (anotherGlyph !== glyph && anotherGlyph.name === glyph.name); | ||
})) { | ||
_this.emit('error', new Error('The glyph name "' + glyph.name + | ||
'" must be unique.')); | ||
if(this.glyphs.some( | ||
anotherGlyph => (anotherGlyph !== glyph && anotherGlyph.name === glyph.name))) { | ||
this.emit('error', new Error(`The glyph name "${glyph.name}" must be unique.`)); | ||
} | ||
if(glyph.unicode && glyph.unicode instanceof Array && glyph.unicode.length) { | ||
if(glyph.unicode.some(function(unicodeA, i) { | ||
return glyph.unicode.some(function(unicodeB, j) { | ||
return i !== j && unicodeA === unicodeB; | ||
}); | ||
})) { | ||
_this.emit('error', new Error('Given codepoints for the glyph "' + | ||
glyph.name + '" contain duplicates.')); | ||
if(glyph.unicode.some( | ||
(unicodeA, i) => glyph.unicode.some((unicodeB, j) => i !== j && unicodeA === unicodeB))) { | ||
this.emit('error', new Error( | ||
`Given codepoints for the glyph "${glyph.name}" contain duplicates.`)); | ||
} | ||
} else if('string' !== typeof glyph.unicode) { | ||
_this.emit('error', new Error('Please provide a codepoint for the glyph "' + | ||
glyph.name + '"')); | ||
this.emit('error', new Error(`Please provide a codepoint for the glyph "${glyph.name}"`)); | ||
} | ||
if(glyphs.some(function(anotherGlyph) { | ||
return (anotherGlyph !== glyph && anotherGlyph.unicode === glyph.unicode); | ||
})) { | ||
_this.emit('error', new Error('The glyph "' + glyph.name + | ||
'" codepoint seems to be used already elsewhere.')); | ||
if(this.glyphs.some( | ||
anotherGlyph => (anotherGlyph !== glyph && anotherGlyph.unicode === glyph.unicode))) { | ||
this.emit('error', new Error( | ||
`The glyph "${glyph.name}" codepoint seems to be used already elsewhere.`)); | ||
} | ||
saxStream.on('opentag', function(tag) { | ||
var values; | ||
var color; | ||
saxStream.on('opentag', (tag) => { | ||
let values; | ||
let color; | ||
parents.push(tag); | ||
// Checking if any parent rendering is disabled and exit if so | ||
if(!tagShouldRender(tag, parents)) { | ||
return; | ||
} | ||
try { | ||
const currentTransform = transformStack[transformStack.length - 1]; | ||
if('undefined' !== typeof tag.attributes.transform) { | ||
const transform = matrixFromTransformAttribute(tag.attributes.transform); | ||
transformStack.push(currentTransform.clone().multiply(transform)); | ||
} else { | ||
transformStack.push(currentTransform); | ||
} | ||
// Checking if any parent rendering is disabled and exit if so | ||
if(!tagShouldRender(tag, parents)) { | ||
return; | ||
} | ||
// Save the view size | ||
@@ -201,48 +182,42 @@ if('svg' === tag.name) { | ||
values = tag.attributes.viewBox.split(/\s*,*\s|\s,*\s*|,/); | ||
glyph.dX = parseFloat(values[0], 10); | ||
glyph.dY = parseFloat(values[1], 10); | ||
glyph.width = parseFloat(values[2], 10); | ||
glyph.height = parseFloat(values[3], 10); | ||
glyph.dX = parseFloat(values[0]); | ||
glyph.dY = parseFloat(values[1]); | ||
glyph.width = parseFloat(values[2]); | ||
glyph.height = parseFloat(values[3]); | ||
if('width' in tag.attributes) { | ||
glyph.scaleX = glyph.width / | ||
parseFloat(tag.attributes.width, 10); | ||
glyph.width = parseFloat(tag.attributes.width, 10); | ||
parseFloat(tag.attributes.width); | ||
glyph.width = parseFloat(tag.attributes.width); | ||
} | ||
if('height' in tag.attributes) { | ||
glyph.scaleY = glyph.height / | ||
parseFloat(tag.attributes.height, 10); | ||
glyph.height = parseFloat(tag.attributes.height, 10); | ||
parseFloat(tag.attributes.height); | ||
glyph.height = parseFloat(tag.attributes.height); | ||
} | ||
} else { | ||
if('width' in tag.attributes) { | ||
glyph.width = parseFloat(tag.attributes.width, 10); | ||
glyph.width = parseFloat(tag.attributes.width); | ||
} | ||
if('height' in tag.attributes) { | ||
glyph.height = parseFloat(tag.attributes.height, 10); | ||
glyph.height = parseFloat(tag.attributes.height); | ||
} | ||
} | ||
if((!glyph.width) || !glyph.height) { | ||
log('Glyph "' + glyph.name + '" has no size attribute on which to' + | ||
' get the gylph dimensions (heigh and width or viewBox' + | ||
' attributes)'); | ||
this.log(`Glyph "${glyph.name}" has no size attribute on which to get the gylph dimensions (height and width or viewBox attributes)`); | ||
glyph.width = 150; | ||
glyph.height = 150; | ||
} | ||
// Clipping path unsupported | ||
// Clipping path unsupported | ||
} else if('clipPath' === tag.name) { | ||
log('Found a clipPath element in the icon "' + glyph.name + '" the' + | ||
'result may be different than expected.'); | ||
// Change rect elements to the corresponding path | ||
this.log(`Found a clipPath element in the icon "${glyph.name}" the result may be different than expected.`); | ||
} else if('rect' === tag.name && 'none' !== tag.attributes.fill) { | ||
glyph.d.push(applyTransforms(svgShapesToPath.rectToPath(tag.attributes), parents)); | ||
glyph.paths.push(applyTransform(svgShapesToPath.rectToPath(tag.attributes))); | ||
} else if('line' === tag.name && 'none' !== tag.attributes.fill) { | ||
log('Found a line element in the icon "' + glyph.name + '" the result' + | ||
' could be different than expected.'); | ||
glyph.d.push(applyTransforms(svgShapesToPath.lineToPath(tag.attributes), parents)); | ||
this.log(`Found a line element in the icon "${glyph.name}" the result could be different than expected.`); | ||
glyph.paths.push(applyTransform(svgShapesToPath.lineToPath(tag.attributes))); | ||
} else if('polyline' === tag.name && 'none' !== tag.attributes.fill) { | ||
log('Found a polyline element in the icon "' + glyph.name + '" the' + | ||
' result could be different than expected.'); | ||
glyph.d.push(applyTransforms(svgShapesToPath.polylineToPath(tag.attributes), parents)); | ||
this.log(`Found a polyline element in the icon "${glyph.name}" the result could be different than expected.`); | ||
glyph.paths.push(applyTransform(svgShapesToPath.polylineToPath(tag.attributes))); | ||
} else if('polygon' === tag.name && 'none' !== tag.attributes.fill) { | ||
glyph.d.push(applyTransforms(svgShapesToPath.polygonToPath(tag.attributes), parents)); | ||
glyph.paths.push(applyTransform(svgShapesToPath.polygonToPath(tag.attributes))); | ||
} else if( | ||
@@ -252,6 +227,6 @@ ['circle', 'ellipse'].includes(tag.name) && | ||
) { | ||
glyph.d.push(applyTransforms(svgShapesToPath.circleToPath(tag.attributes), parents)); | ||
glyph.paths.push(applyTransform(svgShapesToPath.circleToPath(tag.attributes))); | ||
} else if('path' === tag.name && tag.attributes.d && | ||
'none' !== tag.attributes.fill) { | ||
glyph.d.push(applyTransforms(tag.attributes.d, parents)); | ||
glyph.paths.push(applyTransform(tag.attributes.d)); | ||
} | ||
@@ -268,16 +243,17 @@ | ||
} catch (err) { | ||
_this.emit('error', new Error('Got an error parsing the glyph' + | ||
' "' + glyph.name + '": ' + err.message + '.')); | ||
this.emit('error', new Error( | ||
`Got an error parsing the glyph "${glyph.name}": ${err.message}.`)); | ||
} | ||
}); | ||
saxStream.on('error', function svgicons2svgfontSaxErrorCb(err) { | ||
_this.emit('error', err); | ||
saxStream.on('error', (err) => { | ||
this.emit('error', err); | ||
}); | ||
saxStream.on('closetag', function svgicons2svgfontSaxCloseTagCb() { | ||
saxStream.on('closetag', (tagName) => { | ||
transformStack.pop(); | ||
parents.pop(); | ||
}); | ||
saxStream.on('end', function svgicons2svgfontSaxEnbCb() { | ||
saxStream.on('end', () => { | ||
svgIconStreamCallback(); | ||
@@ -287,32 +263,26 @@ }); | ||
svgIconStream.pipe(saxStream); | ||
}; | ||
} | ||
// Output data | ||
this._flush = function _svgIcons2SVGFontStreamFlush(svgFontFlushCallback) { | ||
var fontWidth = ( | ||
1 < glyphs.length ? | ||
glyphs.reduce(function(curMax, glyph) { | ||
return Math.max(curMax, glyph.width); | ||
}, 0) : | ||
glyphs[0].width); | ||
var fontHeight = options.fontHeight || ( | ||
1 < glyphs.length ? glyphs.reduce(function(curMax, glyph) { | ||
return Math.max(curMax, glyph.height); | ||
}, 0) : | ||
glyphs[0].height); | ||
_flush(svgFontFlushCallback) { | ||
const fontWidth = ( | ||
1 < this.glyphs.length ? | ||
this.glyphs.reduce((curMax, glyph) => Math.max(curMax, glyph.width), 0) : | ||
this.glyphs[0].width); | ||
const fontHeight = this._options.fontHeight || ( | ||
1 < this.glyphs.length ? | ||
this.glyphs.reduce((curMax, glyph) => Math.max(curMax, glyph.height), 0) : | ||
this.glyphs[0].height); | ||
options.ascent = 'undefined' !== typeof options.ascent ? | ||
options.ascent : | ||
fontHeight - options.descent; | ||
this._options.ascent = 'undefined' !== typeof this._options.ascent ? | ||
this._options.ascent : | ||
fontHeight - this._options.descent; | ||
if( | ||
(!options.normalize) && | ||
fontHeight > (1 < glyphs.length ? | ||
glyphs.reduce(function(curMin, glyph) { | ||
return Math.min(curMin, glyph.height); | ||
}, Infinity) : | ||
glyphs[0].height | ||
(!this._options.normalize) && | ||
fontHeight > (1 < this.glyphs.length ? | ||
this.glyphs.reduce((curMin, glyph) => Math.min(curMin, glyph.height), Infinity) : | ||
this.glyphs[0].height | ||
) | ||
) { | ||
log('The provided icons does not have the same height it could lead' + | ||
this.log('The provided icons does not have the same height it could lead' + | ||
' to unexpected results. Using the normalize option could' + | ||
@@ -322,5 +292,5 @@ ' solve the problem.'); | ||
if(1000 > fontHeight) { | ||
log('The fontHeight should larger than 1000 or it will be converted ' + | ||
'into the wrong shape. Using the "normalize" and "fontHeight"' + | ||
' options can solve the problem.'); | ||
this.log('The fontHeight should larger than 1000 or it will be converted ' + | ||
'into the wrong shape. Using the "normalize" and "fontHeight"' + | ||
' options can solve the problem.'); | ||
} | ||
@@ -330,50 +300,43 @@ | ||
// (find a SAX parser that allows modifying SVG on the fly) | ||
_this.push('\ | ||
<?xml version="1.0" standalone="no"?>\n\ | ||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"' + | ||
' "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >\n\ | ||
<svg xmlns="http://www.w3.org/2000/svg">\n' + ( | ||
options.metadata ? '<metadata>' + options.metadata + '</metadata>\n' : '' | ||
) + '\ | ||
<defs>\n\ | ||
<font id="' + options.fontId + '" horiz-adv-x="' + fontWidth + '">\n\ | ||
<font-face font-family="' + options.fontName + '"\n\ | ||
units-per-em="' + fontHeight + '" ascent="' + options.ascent + '"\n\ | ||
descent="' + options.descent + '"' + (options.fontWeight ? '\n\ | ||
font-weight="' + options.fontWeight + '"' : '') + (options.fontStyle ? '\n\ | ||
font-style="' + options.fontStyle + '"' : '') + ' />\n\ | ||
<missing-glyph horiz-adv-x="0" />\n'); | ||
glyphs.forEach(function(glyph) { | ||
/* eslint-disable prefer-template */ | ||
this.push( | ||
'<?xml version="1.0" standalone="no"?>\n' + | ||
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >\n' + | ||
'<svg xmlns="http://www.w3.org/2000/svg">\n' + | ||
(this._options.metadata ? '<metadata>' + this._options.metadata + '</metadata>\n' : '') + | ||
'<defs>\n' + | ||
' <font id="' + this._options.fontId + '" horiz-adv-x="' + fontWidth + '">\n' + | ||
' <font-face font-family="' + this._options.fontName + '"\n' + | ||
' units-per-em="' + fontHeight + '" ascent="' + this._options.ascent + '"\n' + | ||
' descent="' + this._options.descent + '"' + | ||
(this._options.fontWeight ? '\n font-weight="' + this._options.fontWeight + '"' : '') + | ||
(this._options.fontStyle ? '\n font-style="' + this._options.fontStyle + '"' : '') + ' />\n' + | ||
' <missing-glyph horiz-adv-x="0" />\n'); | ||
this.glyphs.forEach((glyph) => { | ||
const ratio = fontHeight / glyph.height; | ||
const glyphPath = new SVGPathData(''); | ||
if(options.fixedWidth) { | ||
if(this._options.fixedWidth) { | ||
glyph.width = fontWidth; | ||
} | ||
if(options.normalize) { | ||
if(this._options.normalize) { | ||
glyph.height = fontHeight; | ||
if(!options.fixedWidth) { | ||
if(!this._options.fixedWidth) { | ||
glyph.width *= ratio; | ||
} | ||
} | ||
glyph.d.forEach((cD) => { | ||
Array.prototype.push.apply(glyphPath.commands, new SVGPathData(cD) | ||
const yOffset = glyph.height - this._options.descent; | ||
const glyphPathTransform = new Matrix() | ||
.transform(1, 0, 0, -1, 0, yOffset) // ySymmetry | ||
.scale( | ||
(this._options.normalize ? ratio : 1) * glyph.scaleX, | ||
(this._options.normalize ? ratio : 1) * glyph.scaleY) | ||
.translate(-glyph.dX, -glyph.dY); | ||
glyph.paths.forEach((path) => { | ||
glyphPath.commands.push(...path | ||
.toAbs() | ||
.translate(-glyph.dX, -glyph.dY) | ||
.scale( | ||
( | ||
options.normalize ? | ||
ratio : | ||
1 | ||
) * glyph.scaleX, | ||
( | ||
options.normalize ? | ||
ratio : | ||
1 | ||
) * glyph.scaleY | ||
) | ||
.ySymmetry(glyph.height - options.descent).commands); | ||
.matrix(...glyphPathTransform.toArray()).commands); | ||
}); | ||
if(options.centerHorizontally) { | ||
// Naive bounds calculation (should draw, then calculate bounds...) | ||
if(this._options.centerHorizontally) { | ||
const bounds = glyphPath.getBounds(); | ||
@@ -383,26 +346,27 @@ | ||
} | ||
delete glyph.d; | ||
delete glyph.running; | ||
glyph.unicode.forEach(function(unicode, i) { | ||
_this.push('\ | ||
<glyph glyph-name="' + glyph.name + (0 === i ? '' : '-' + i) + '"\n\ | ||
unicode="' + ucs2.decode(unicode).map(function(point) { | ||
return '&#x' + point.toString(16).toUpperCase() + ';'; | ||
}).join('') + '"\n\ | ||
horiz-adv-x="' + glyph.width + '" d="' + glyphPath.round(options.round).encode() + '" />\n'); | ||
delete glyph.paths; | ||
glyph.unicode.forEach((unicode, i) => { | ||
const unicodeStr = ucs2.decode(unicode) | ||
.map(point => '&#x' + point.toString(16).toUpperCase() + ';') | ||
.join(''); | ||
const d = glyphPath.round(this._options.round).encode(); | ||
this.push( | ||
' <glyph glyph-name="' + glyph.name + (0 === i ? '' : '-' + i) + '"\n' + | ||
' unicode="' + unicodeStr + '"\n' + | ||
' horiz-adv-x="' + glyph.width + '" d="' + d + '" />\n'); | ||
}); | ||
}); | ||
_this.push('\ | ||
</font>\n\ | ||
</defs>\n\ | ||
</svg>\n'); | ||
log('Font created'); | ||
if('function' === (typeof options.callback)) { | ||
(options.callback)(glyphs); | ||
this.push( | ||
' </font>\n' + | ||
'</defs>\n' + | ||
'</svg>\n'); | ||
this.log('Font created'); | ||
if('function' === (typeof this._options.callback)) { | ||
this._options.callback(this.glyphs); | ||
} | ||
svgFontFlushCallback(); | ||
}; | ||
} | ||
} | ||
module.exports = SVGIcons2SVGFontStream; |
@@ -0,5 +1,6 @@ | ||
/* eslint-disable prefer-template,newline-per-chained-call,complexity */ | ||
'use strict'; | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
@@ -10,3 +11,3 @@ require('string.fromcodepoint'); | ||
function getMetadataService(options) { | ||
var usedUnicodes = []; | ||
let usedUnicodes = []; | ||
@@ -31,4 +32,4 @@ // Default options | ||
return function getMetadataFromFile(file, cb) { | ||
var basename = path.basename(file); | ||
var metadata = { | ||
const basename = path.basename(file); | ||
const metadata = { | ||
path: file, | ||
@@ -39,3 +40,3 @@ name: '', | ||
}; | ||
var matches = basename.match(/^(?:((?:u[0-9a-f]{4,6},?)+)\-)?(.+)\.svg$/i); | ||
const matches = basename.match(/^(?:((?:u[0-9a-f]{4,6},?)+)-)?(.+)\.svg$/i); | ||
@@ -46,7 +47,5 @@ metadata.name = matches && matches[2] ? | ||
if(matches && matches[1]) { | ||
metadata.unicode = matches[1].split(',').map(function(match) { | ||
metadata.unicode = matches[1].split(',').map((match) => { | ||
match = match.substr(1); | ||
return match.split('u').map(function(code) { | ||
return String.fromCodePoint(parseInt(code, 16)); | ||
}).join(''); | ||
return match.split('u').map(code => String.fromCodePoint(parseInt(code, 16))).join(''); | ||
}); | ||
@@ -69,19 +68,15 @@ if(-1 !== usedUnicodes.indexOf(metadata.unicode[0])) { | ||
'-' + basename); | ||
fs.rename(file, metadata.path, | ||
function(err) { | ||
if(err) { | ||
cb(new Error('Could not save codepoint: ' + | ||
'u' + metadata.unicode[0].codePointAt(0).toString(16).toUpperCase() + | ||
' for ' + basename)); | ||
return; | ||
} | ||
cb(null, metadata); | ||
fs.rename(file, metadata.path, (err) => { | ||
if(err) { | ||
cb(new Error('Could not save codepoint: ' + | ||
'u' + metadata.unicode[0].codePointAt(0).toString(16).toUpperCase() + | ||
' for ' + basename)); | ||
return; | ||
} | ||
); | ||
cb(null, metadata); | ||
}); | ||
} | ||
} | ||
if(!metadata.renamed) { | ||
setImmediate(function() { | ||
cb(null, metadata); | ||
}); | ||
setImmediate(() => cb(null, metadata)); | ||
} | ||
@@ -88,0 +83,0 @@ }; |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable prefer-template,complexity */ | ||
'use strict'; | ||
@@ -2,0 +3,0 @@ |
@@ -0,20 +1,21 @@ | ||
/* eslint-disable prefer-template */ | ||
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var assert = require('assert'); | ||
var childProcess = require('child_process'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
const childProcess = require('child_process'); | ||
describe('Testing CLI', function() { | ||
describe('Testing CLI', () => { | ||
it('should work for simple SVG', function(done) { | ||
var command = 'node' + | ||
' ' + path.join(__dirname, '..', 'bin', 'svgicons2svgfont.js') + | ||
' -o ' + path.join(__dirname, 'results', 'originalicons-cli.svg') + | ||
' -s 0xE001' + | ||
' ' + path.join(__dirname, 'fixtures', 'originalicons', '*.svg'); | ||
it('should work for simple SVG', (done) => { | ||
const command = `${'node' + | ||
' '}${path.join(__dirname, '..', 'bin', 'svgicons2svgfont.js') | ||
} -o ${path.join(__dirname, 'results', 'originalicons-cli.svg') | ||
} -s 0xE001` + | ||
` ${path.join(__dirname, 'fixtures', 'originalicons', '*.svg')}`; | ||
(childProcess.exec)( | ||
childProcess.exec( | ||
command, | ||
function(err) { | ||
(err) => { | ||
if(err) { | ||
@@ -38,7 +39,8 @@ throw err; | ||
it('should work for more than 32 SVG icons', function(done) { | ||
var command = 'node' + | ||
it('should work for more than 32 SVG icons', (done) => { | ||
const command = 'node' + | ||
' ' + path.join(__dirname, '..', 'bin', 'svgicons2svgfont.js') + | ||
' -o ' + path.join(__dirname, 'results', 'lotoficons-cli.svg') + | ||
' -s 0xE001' + | ||
' -r 1e4' + | ||
' ' + path.join(__dirname, 'fixtures', 'cleanicons', '*.svg') + | ||
@@ -55,3 +57,3 @@ ' ' + path.join(__dirname, 'fixtures', 'hiddenpathesicons', '*.svg') + | ||
command, | ||
function(err) { | ||
(err) => { | ||
if(err) { | ||
@@ -75,13 +77,13 @@ throw err; | ||
describe('with nested icons', function() { | ||
describe('with nested icons', () => { | ||
it('should work', function(done) { | ||
var command = 'node' + | ||
' ' + path.join(__dirname, '..', 'bin', 'svgicons2svgfont.js') + | ||
' -o ' + path.join(__dirname, 'results', 'nestedicons-cli.svg') + | ||
' ' + path.join(__dirname, 'fixtures', 'nestedicons', '*.svg'); | ||
it('should work', (done) => { | ||
const command = `${'node' + | ||
' '}${path.join(__dirname, '..', 'bin', 'svgicons2svgfont.js') | ||
} -o ${path.join(__dirname, 'results', 'nestedicons-cli.svg') | ||
} ${path.join(__dirname, 'fixtures', 'nestedicons', '*.svg')}`; | ||
(childProcess.exec)( | ||
childProcess.exec( | ||
command, | ||
function(err) { | ||
(err) => { | ||
if(err) { | ||
@@ -88,0 +90,0 @@ throw err; |
'use strict'; | ||
var fileSorter = require('../src/filesorter.js'); | ||
var assert = require('assert'); | ||
const fileSorter = require('../src/filesorter.js'); | ||
const assert = require('assert'); | ||
describe('fileSorter', function() { | ||
describe('fileSorter', () => { | ||
it('should sort files per filename', function() { | ||
it('should sort files per filename', () => { | ||
assert.deepEqual([ | ||
@@ -26,3 +26,3 @@ '/var/plop/c.svg', | ||
it('should sort files per codepoints', function() { | ||
it('should sort files per codepoints', () => { | ||
assert.deepEqual([ | ||
@@ -45,3 +45,3 @@ '/var/plop/uAE01-c.svg', | ||
it('should put codepoints first', function() { | ||
it('should put codepoints first', () => { | ||
assert.deepEqual([ | ||
@@ -64,3 +64,3 @@ '/var/plop/uAE01-c.svg', | ||
it('should work with the @pinin files', function() { | ||
it('should work with the @pinin files', () => { | ||
assert.deepEqual([ | ||
@@ -67,0 +67,0 @@ 'bell-disabled.svg', |
@@ -0,26 +1,26 @@ | ||
/* eslint-disable newline-per-chained-call */ | ||
'use strict'; | ||
var assert = require('assert'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var ucs2 = require('punycode').ucs2; | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const ucs2 = require('punycode').ucs2; | ||
var svgicons2svgfont = require('../src/index.js'); | ||
var StringDecoder = require('string_decoder').StringDecoder; | ||
var svgiconsdir = require('../src/iconsdir'); | ||
var streamtest = require('streamtest'); | ||
const SVGIcons2SVGFontStream = require('../src/index.js'); | ||
const StringDecoder = require('string_decoder').StringDecoder; | ||
const SVGIconsDirStream = require('../src/iconsdir'); | ||
const streamtest = require('streamtest'); | ||
var neatequal = require('neatequal'); | ||
var codepoint = require('./expected/test-codepoint.json'); | ||
const neatequal = require('neatequal'); | ||
const codepoint = require('./expected/test-codepoint.json'); | ||
// Helpers | ||
function generateFontToFile(options, done, fileSuffix, startUnicode, files) { // eslint-disable-line | ||
var dest = path.join(__dirname, 'results', options.fontName + | ||
(fileSuffix || '') + '.svg'); | ||
var svgFontStream; | ||
const dest = path.join(__dirname, 'results', `${options.fontName + | ||
(fileSuffix || '')}.svg`); | ||
options.log = function() {}; | ||
svgFontStream = svgicons2svgfont(options); | ||
options.log = () => {}; | ||
const svgFontStream = new SVGIcons2SVGFontStream(options); | ||
svgFontStream.pipe(fs.createWriteStream(dest)).on('finish', function() { | ||
svgFontStream.pipe(fs.createWriteStream(dest)).on('finish', () => { | ||
assert.equal( | ||
@@ -30,3 +30,3 @@ fs.readFileSync(dest, { encoding: 'utf8' }), | ||
path.join(__dirname, 'expected', | ||
options.fontName + (fileSuffix || '') + '.svg'), | ||
`${options.fontName + (fileSuffix || '')}.svg`), | ||
{ encoding: 'utf8' } | ||
@@ -38,3 +38,3 @@ ) | ||
svgiconsdir( | ||
new SVGIconsDirStream( | ||
files || path.join(__dirname, 'fixtures', options.fontName), { | ||
@@ -48,23 +48,23 @@ startUnicode: startUnicode || 0xE001, | ||
function generateFontToMemory(options, done, files, startUnicode) { | ||
var content = ''; | ||
var decoder = new StringDecoder('utf8'); | ||
var svgFontStream; | ||
let content = ''; | ||
const decoder = new StringDecoder('utf8'); | ||
options.log = function() {}; | ||
options.log = () => {}; | ||
options.callback = function(glyphs) { | ||
var fontName = options.fontName; | ||
options.callback = (glyphs) => { | ||
const fontName = options.fontName; | ||
neatequal(glyphs, codepoint[fontName]); | ||
}; | ||
svgFontStream = svgicons2svgfont(options); | ||
const svgFontStream = new SVGIcons2SVGFontStream(options); | ||
svgFontStream.on('data', function(chunk) { | ||
svgFontStream.on('data', (chunk) => { | ||
content += decoder.write(chunk); | ||
}); | ||
svgFontStream.on('finish', function() { | ||
svgFontStream.on('finish', () => { | ||
assert.equal( | ||
fs.readFileSync( | ||
path.join(__dirname, 'expected', options.fontName + '.svg'), | ||
path.join(__dirname, 'expected', `${options.fontName}.svg`), | ||
{ encoding: 'utf8' } | ||
@@ -77,3 +77,3 @@ ), | ||
svgiconsdir(files || path.join(__dirname, 'fixtures', options.fontName), { | ||
new SVGIconsDirStream(files || path.join(__dirname, 'fixtures', options.fontName), { | ||
startUnicode: startUnicode || 0xE001, | ||
@@ -86,5 +86,5 @@ }) | ||
// Tests | ||
describe('Generating fonts to files', function() { | ||
describe('Generating fonts to files', () => { | ||
it('should work for simple SVG', function(done) { | ||
it('should work for simple SVG', (done) => { | ||
generateFontToFile({ | ||
@@ -95,3 +95,3 @@ fontName: 'originalicons', | ||
it('should work for simple fixedWidth and normalize option', function(done) { | ||
it('should work for simple fixedWidth and normalize option', (done) => { | ||
generateFontToFile({ | ||
@@ -104,3 +104,3 @@ fontName: 'originalicons', | ||
it('should work for simple SVG', function(done) { | ||
it('should work for simple SVG', (done) => { | ||
generateFontToFile({ | ||
@@ -111,3 +111,3 @@ fontName: 'cleanicons', | ||
it('should work for simple SVG and custom ascent', function(done) { | ||
it('should work for simple SVG and custom ascent', (done) => { | ||
generateFontToFile({ | ||
@@ -119,3 +119,3 @@ fontName: 'cleanicons', | ||
it('should work for simple SVG and custom properties', function(done) { | ||
it('should work for simple SVG and custom properties', (done) => { | ||
generateFontToFile({ | ||
@@ -128,10 +128,10 @@ fontName: 'cleanicons', | ||
it('should work for codepoint mapped SVG icons', function(done) { | ||
it('should work for codepoint mapped SVG icons', (done) => { | ||
generateFontToFile({ | ||
fontName: 'prefixedicons', | ||
callback: function() {}, | ||
callback: () => {}, | ||
}, done); | ||
}); | ||
it('should work with multipath SVG icons', function(done) { | ||
it('should work with multipath SVG icons', (done) => { | ||
generateFontToFile({ | ||
@@ -142,3 +142,3 @@ fontName: 'multipathicons', | ||
it('should work with simple shapes SVG icons', function(done) { | ||
it('should work with simple shapes SVG icons', (done) => { | ||
generateFontToFile({ | ||
@@ -149,3 +149,3 @@ fontName: 'shapeicons', | ||
it('should work with variable height icons', function(done) { | ||
it('should work with variable height icons', (done) => { | ||
generateFontToFile({ | ||
@@ -156,3 +156,3 @@ fontName: 'variableheighticons', | ||
it('should work with variable height icons and the normalize option', function(done) { | ||
it('should work with variable height icons and the normalize option', (done) => { | ||
generateFontToFile({ | ||
@@ -164,3 +164,3 @@ fontName: 'variableheighticons', | ||
it('should work with variable width icons', function(done) { | ||
it('should work with variable width icons', (done) => { | ||
generateFontToFile({ | ||
@@ -171,3 +171,3 @@ fontName: 'variablewidthicons', | ||
it('should work with centered variable width icons and the fixed width option', function(done) { | ||
it('should work with centered variable width icons and the fixed width option', (done) => { | ||
generateFontToFile({ | ||
@@ -180,3 +180,3 @@ fontName: 'variablewidthicons', | ||
it('should work with a font id', function(done) { | ||
it('should work with a font id', (done) => { | ||
generateFontToFile({ | ||
@@ -190,3 +190,3 @@ fontName: 'variablewidthicons', | ||
it('should work with scaled icons', function(done) { | ||
it('should work with scaled icons', (done) => { | ||
generateFontToFile({ | ||
@@ -200,3 +200,3 @@ fontName: 'scaledicons', | ||
it('should not display hidden pathes', function(done) { | ||
it('should not display hidden pathes', (done) => { | ||
generateFontToFile({ | ||
@@ -207,3 +207,3 @@ fontName: 'hiddenpathesicons', | ||
it('should work with real world icons', function(done) { | ||
it('should work with real world icons', (done) => { | ||
generateFontToFile({ | ||
@@ -214,3 +214,3 @@ fontName: 'realicons', | ||
it('should work with rendering test SVG icons', function(done) { | ||
it('should work with rendering test SVG icons', (done) => { | ||
generateFontToFile({ | ||
@@ -221,3 +221,3 @@ fontName: 'rendricons', | ||
it('should work with a single SVG icon', function(done) { | ||
it('should work with a single SVG icon', (done) => { | ||
generateFontToFile({ | ||
@@ -228,3 +228,3 @@ fontName: 'singleicon', | ||
it('should work with transformed SVG icons', function(done) { | ||
it('should work with transformed SVG icons', (done) => { | ||
generateFontToFile({ | ||
@@ -235,3 +235,3 @@ fontName: 'transformedicons', | ||
it('should work when horizontally centering SVG icons', function(done) { | ||
it('should work when horizontally centering SVG icons', (done) => { | ||
generateFontToFile({ | ||
@@ -243,3 +243,3 @@ fontName: 'tocentericons', | ||
it('should work with a icons with path with fill none', function(done) { | ||
it('should work with a icons with path with fill none', (done) => { | ||
generateFontToFile({ | ||
@@ -250,3 +250,3 @@ fontName: 'pathfillnone', | ||
it('should work with shapes with rounded corners', function(done) { | ||
it('should work with shapes with rounded corners', (done) => { | ||
generateFontToFile({ | ||
@@ -257,3 +257,3 @@ fontName: 'roundedcorners', | ||
it('should work with a lot of icons', function(done) { | ||
it('should work with a lot of icons', (done) => { | ||
generateFontToFile({ | ||
@@ -299,3 +299,3 @@ fontName: 'lotoficons', | ||
it('should work with rotated rectangle icon', function(done) { | ||
it('should work with rotated rectangle icon', (done) => { | ||
generateFontToFile({ | ||
@@ -306,7 +306,18 @@ fontName: 'rotatedrectangle', | ||
/** | ||
* Issue #6 | ||
* icon by @paesku | ||
* https://github.com/nfroidure/svgicons2svgfont/issues/6#issuecomment-125545925 | ||
*/ | ||
it('should work with complicated nested transforms', (done) => { | ||
generateFontToFile({ | ||
fontName: 'paesku', | ||
round: 1e3, | ||
}, done); | ||
}); | ||
}); | ||
describe('Generating fonts to memory', function() { | ||
describe('Generating fonts to memory', () => { | ||
it('should work for simple SVG', function(done) { | ||
it('should work for simple SVG', (done) => { | ||
generateFontToMemory({ | ||
@@ -317,3 +328,3 @@ fontName: 'originalicons', | ||
it('should work for simple SVG', function(done) { | ||
it('should work for simple SVG', (done) => { | ||
generateFontToMemory({ | ||
@@ -324,3 +335,3 @@ fontName: 'cleanicons', | ||
it('should work for codepoint mapped SVG icons', function(done) { | ||
it('should work for codepoint mapped SVG icons', (done) => { | ||
generateFontToMemory({ | ||
@@ -331,3 +342,3 @@ fontName: 'prefixedicons', | ||
it('should work with multipath SVG icons', function(done) { | ||
it('should work with multipath SVG icons', (done) => { | ||
generateFontToMemory({ | ||
@@ -338,3 +349,3 @@ fontName: 'multipathicons', | ||
it('should work with simple shapes SVG icons', function(done) { | ||
it('should work with simple shapes SVG icons', (done) => { | ||
generateFontToMemory({ | ||
@@ -347,5 +358,5 @@ fontName: 'shapeicons', | ||
describe('Using options', function() { | ||
describe('Using options', () => { | ||
it('should work with fixedWidth option set to true', function(done) { | ||
it('should work with fixedWidth option set to true', (done) => { | ||
generateFontToFile({ | ||
@@ -357,3 +368,3 @@ fontName: 'originalicons', | ||
it('should work with custom fontHeight option', function(done) { | ||
it('should work with custom fontHeight option', (done) => { | ||
generateFontToFile({ | ||
@@ -365,3 +376,3 @@ fontName: 'originalicons', | ||
it('should work with custom descent option', function(done) { | ||
it('should work with custom descent option', (done) => { | ||
generateFontToFile({ | ||
@@ -374,3 +385,3 @@ fontName: 'originalicons', | ||
it('should work with fixedWidth set to true and with custom fontHeight option', | ||
function(done) { | ||
(done) => { | ||
generateFontToFile({ | ||
@@ -385,3 +396,3 @@ fontName: 'originalicons', | ||
it('should work with fixedWidth and centerHorizontally set to true and with' + | ||
' custom fontHeight option', function(done) { | ||
' custom fontHeight option', (done) => { | ||
generateFontToFile({ | ||
@@ -397,3 +408,3 @@ fontName: 'originalicons', | ||
it('should work with fixedWidth, normalize and centerHorizontally set to' + | ||
' true and with custom fontHeight option', function(done) { | ||
' true and with custom fontHeight option', (done) => { | ||
generateFontToFile({ | ||
@@ -409,3 +420,3 @@ fontName: 'originalicons', | ||
it('should work with nested icons', function(done) { | ||
it('should work with nested icons', (done) => { | ||
generateFontToFile({ | ||
@@ -418,12 +429,12 @@ fontName: 'nestedicons', | ||
describe('Passing code points', function() { | ||
describe('Passing code points', () => { | ||
it('should work with multiple unicode values for a single icon', function(done) { | ||
var svgIconStream = fs.createReadStream( | ||
it('should work with multiple unicode values for a single icon', (done) => { | ||
const svgIconStream = fs.createReadStream( | ||
path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg') | ||
); | ||
var svgFontStream = svgicons2svgfont(); | ||
var content = ''; | ||
var decoder = new StringDecoder('utf8'); | ||
const svgFontStream = new SVGIcons2SVGFontStream(); | ||
let content = ''; | ||
const decoder = new StringDecoder('utf8'); | ||
@@ -435,7 +446,7 @@ svgIconStream.metadata = { | ||
svgFontStream.on('data', function(chunk) { | ||
svgFontStream.on('data', (chunk) => { | ||
content += decoder.write(chunk); | ||
}); | ||
svgFontStream.on('finish', function() { | ||
svgFontStream.on('finish', () => { | ||
assert.equal( | ||
@@ -452,9 +463,9 @@ fs.readFileSync(path.join(__dirname, 'expected', 'cleanicons-multi.svg'), | ||
it('should work with ligatures', function(done) { | ||
var svgIconStream = fs.createReadStream( | ||
it('should work with ligatures', (done) => { | ||
const svgIconStream = fs.createReadStream( | ||
path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg') | ||
); | ||
var svgFontStream = svgicons2svgfont(); | ||
var content = ''; | ||
var decoder = new StringDecoder('utf8'); | ||
const svgFontStream = new SVGIcons2SVGFontStream(); | ||
let content = ''; | ||
const decoder = new StringDecoder('utf8'); | ||
@@ -466,7 +477,7 @@ svgIconStream.metadata = { | ||
svgFontStream.on('data', function(chunk) { | ||
svgFontStream.on('data', (chunk) => { | ||
content += decoder.write(chunk); | ||
}); | ||
svgFontStream.on('finish', function() { | ||
svgFontStream.on('finish', () => { | ||
assert.equal( | ||
@@ -484,9 +495,9 @@ fs.readFileSync(path.join(__dirname, 'expected', 'cleanicons-lig.svg'), | ||
it('should work with high code points', function(done) { | ||
var svgIconStream = fs.createReadStream( | ||
it('should work with high code points', (done) => { | ||
const svgIconStream = fs.createReadStream( | ||
path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg') | ||
); | ||
var svgFontStream = svgicons2svgfont(); | ||
var content = ''; | ||
var decoder = new StringDecoder('utf8'); | ||
const svgFontStream = new SVGIcons2SVGFontStream(); | ||
let content = ''; | ||
const decoder = new StringDecoder('utf8'); | ||
@@ -498,7 +509,7 @@ svgIconStream.metadata = { | ||
svgFontStream.on('data', function(chunk) { | ||
svgFontStream.on('data', (chunk) => { | ||
content += decoder.write(chunk); | ||
}); | ||
svgFontStream.on('finish', function() { | ||
svgFontStream.on('finish', () => { | ||
assert.equal( | ||
@@ -516,6 +527,6 @@ fs.readFileSync(path.join(__dirname, 'expected', 'cleanicons-high.svg'), | ||
describe('Providing bad glyphs', function() { | ||
describe('Providing bad glyphs', () => { | ||
it('should fail when not providing glyph name', function(done) { | ||
var svgIconStream = fs.createReadStream( | ||
it('should fail when not providing glyph name', (done) => { | ||
const svgIconStream = fs.createReadStream( | ||
path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg') | ||
@@ -527,3 +538,3 @@ ); | ||
}; | ||
svgicons2svgfont().on('error', function(err) { | ||
new SVGIcons2SVGFontStream().on('error', (err) => { | ||
assert.equal(err instanceof Error, true); | ||
@@ -535,4 +546,4 @@ assert.equal(err.message, 'Please provide a name for the glyph at index 0'); | ||
it('should fail when not providing codepoints', function(done) { | ||
var svgIconStream = fs.createReadStream( | ||
it('should fail when not providing codepoints', (done) => { | ||
const svgIconStream = fs.createReadStream( | ||
path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg') | ||
@@ -544,3 +555,3 @@ ); | ||
}; | ||
svgicons2svgfont().on('error', function(err) { | ||
new SVGIcons2SVGFontStream().on('error', (err) => { | ||
assert.equal(err instanceof Error, true); | ||
@@ -552,4 +563,4 @@ assert.equal(err.message, 'Please provide a codepoint for the glyph "test"'); | ||
it('should fail when providing unicode value with duplicates', function(done) { | ||
var svgIconStream = fs.createReadStream( | ||
it('should fail when providing unicode value with duplicates', (done) => { | ||
const svgIconStream = fs.createReadStream( | ||
path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg') | ||
@@ -562,3 +573,3 @@ ); | ||
}; | ||
svgicons2svgfont().on('error', function(err) { | ||
new SVGIcons2SVGFontStream().on('error', (err) => { | ||
assert.equal(err instanceof Error, true); | ||
@@ -570,10 +581,10 @@ assert.equal(err.message, 'Given codepoints for the glyph "test" contain duplicates.'); | ||
it('should fail when providing the same codepoint twice', function(done) { | ||
var svgIconStream = fs.createReadStream( | ||
it('should fail when providing the same codepoint twice', (done) => { | ||
const svgIconStream = fs.createReadStream( | ||
path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg') | ||
); | ||
var svgIconStream2 = fs.createReadStream( | ||
const svgIconStream2 = fs.createReadStream( | ||
path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg') | ||
); | ||
var svgFontStream = svgicons2svgfont(); | ||
const svgFontStream = new SVGIcons2SVGFontStream(); | ||
@@ -588,3 +599,3 @@ svgIconStream.metadata = { | ||
}; | ||
svgFontStream.on('error', function(err) { | ||
svgFontStream.on('error', (err) => { | ||
assert.equal(err instanceof Error, true); | ||
@@ -598,10 +609,10 @@ assert.equal(err.message, 'The glyph "test2" codepoint seems to be used already elsewhere.'); | ||
it('should fail when providing the same name twice', function(done) { | ||
var svgIconStream = fs.createReadStream( | ||
it('should fail when providing the same name twice', (done) => { | ||
const svgIconStream = fs.createReadStream( | ||
path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg') | ||
); | ||
var svgIconStream2 = fs.createReadStream( | ||
const svgIconStream2 = fs.createReadStream( | ||
path.join(__dirname, 'fixtures', 'cleanicons', 'account.svg') | ||
); | ||
var svgFontStream = svgicons2svgfont(); | ||
const svgFontStream = new SVGIcons2SVGFontStream(); | ||
@@ -616,3 +627,3 @@ svgIconStream.metadata = { | ||
}; | ||
svgFontStream.on('error', function(err) { | ||
svgFontStream.on('error', (err) => { | ||
assert.equal(err instanceof Error, true); | ||
@@ -626,4 +637,4 @@ assert.equal(err.message, 'The glyph name "test" must be unique.'); | ||
it('should fail when providing bad pathdata', function(done) { | ||
var svgIconStream = fs.createReadStream( | ||
it('should fail when providing bad pathdata', (done) => { | ||
const svgIconStream = fs.createReadStream( | ||
path.join(__dirname, 'fixtures', 'badicons', 'pathdata.svg') | ||
@@ -636,3 +647,3 @@ ); | ||
}; | ||
svgicons2svgfont().on('error', function(err) { | ||
new SVGIcons2SVGFontStream().on('error', (err) => { | ||
assert.equal(err instanceof Error, true); | ||
@@ -642,3 +653,3 @@ assert.equal(err.message, 'Got an error parsing the glyph "test":' + | ||
done(); | ||
}).on('end', function() { | ||
}).on('end', () => { | ||
done(); | ||
@@ -648,4 +659,4 @@ }).write(svgIconStream); | ||
it('should fail when providing bad XML', function(done) { | ||
var svgIconStream = streamtest.v2.fromChunks(['bad', 'xml']); | ||
it('should fail when providing bad XML', (done) => { | ||
const svgIconStream = streamtest.v2.fromChunks(['bad', 'xml']); | ||
@@ -656,3 +667,3 @@ svgIconStream.metadata = { | ||
}; | ||
svgicons2svgfont().on('error', function(err) { | ||
new SVGIcons2SVGFontStream().on('error', (err) => { | ||
assert.equal(err instanceof Error, true); | ||
@@ -659,0 +670,0 @@ assert.equal(err.message, 'Non-whitespace before first tag.\nLine: 0\nColumn: 1\nChar: b'); |
@@ -1,14 +0,14 @@ | ||
/* eslint max-nested-callbacks:0 */ | ||
/* eslint max-nested-callbacks:0 */ | ||
'use strict'; | ||
var metadata = require('../src/metadata.js'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var assert = require('assert'); | ||
const metadata = require('../src/metadata.js'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
require('string.fromcodepoint'); | ||
describe('Metadata service', function() { | ||
it('should throw error when using old options', function() { | ||
describe('Metadata service', () => { | ||
it('should throw error when using old options', () => { | ||
assert.throws(metadata.bind(metadata, { | ||
@@ -19,8 +19,8 @@ appendUnicode: true, | ||
describe('for code generation', function() { | ||
describe('for code generation', () => { | ||
it('should extract right unicodes from files', function(done) { | ||
var metadataService = metadata(); | ||
it('should extract right unicodes from files', (done) => { | ||
const metadataService = metadata(); | ||
metadataService('/var/plop/hello.svg', function(err, infos) { | ||
metadataService('/var/plop/hello.svg', (err, infos) => { | ||
if(err) { | ||
@@ -42,7 +42,8 @@ done(err); | ||
it('should append unicodes to files when the option is set', function(done) { | ||
var metadataService = metadata({ | ||
it('should append unicodes to files when the option is set', (done) => { | ||
const metadataService = metadata({ | ||
prependUnicode: true, | ||
log: function() {}, | ||
error: function() { | ||
log: () => { | ||
}, | ||
error: () => { | ||
done(new Error('Not supposed to be here')); | ||
@@ -53,3 +54,3 @@ }, | ||
fs.writeFileSync(path.join(__dirname, 'results', 'plop.svg'), 'plop', 'utf-8'); | ||
metadataService(path.join(__dirname, 'results', 'plop.svg'), function(err, infos) { | ||
metadataService(path.join(__dirname, 'results', 'plop.svg'), (err, infos) => { | ||
if(err) { | ||
@@ -74,8 +75,9 @@ done(err); | ||
it('should log file rename errors', function(done) { | ||
var metadataService = metadata({ | ||
it('should log file rename errors', (done) => { | ||
const metadataService = metadata({ | ||
prependUnicode: true, | ||
startUnicode: 0xEA02, | ||
error: function() {}, | ||
log: function() { | ||
error: () => { | ||
}, | ||
log: () => { | ||
done(new Error('Not supposed to be here')); | ||
@@ -85,3 +87,3 @@ }, | ||
metadataService(path.join(__dirname, 'results', 'plop.svg'), function(err, infos) { | ||
metadataService(path.join(__dirname, 'results', 'plop.svg'), (err, infos) => { | ||
assert(!infos); | ||
@@ -96,8 +98,8 @@ assert(err); | ||
describe('for code extraction', function() { | ||
describe('for code extraction', () => { | ||
it('should work for simple codes', function(done) { | ||
var metadataService = metadata(); | ||
it('should work for simple codes', (done) => { | ||
const metadataService = metadata(); | ||
metadataService('/var/plop/u0001-hello.svg', function(err, infos) { | ||
metadataService('/var/plop/u0001-hello.svg', (err, infos) => { | ||
assert(!err); | ||
@@ -114,6 +116,6 @@ assert.deepEqual(infos, { | ||
it('should work for several codes', function(done) { | ||
var metadataService = metadata(); | ||
it('should work for several codes', (done) => { | ||
const metadataService = metadata(); | ||
metadataService('/var/plop/u0001,u0002-hello.svg', function(err, infos) { | ||
metadataService('/var/plop/u0001,u0002-hello.svg', (err, infos) => { | ||
assert(!err); | ||
@@ -130,6 +132,6 @@ assert.deepEqual(infos, { | ||
it('should work for higher codepoint codes', function(done) { | ||
var metadataService = metadata(); | ||
it('should work for higher codepoint codes', (done) => { | ||
const metadataService = metadata(); | ||
metadataService('/var/plop/u1F63A-hello.svg', function(err, infos) { | ||
metadataService('/var/plop/u1F63A-hello.svg', (err, infos) => { | ||
assert(!err); | ||
@@ -146,6 +148,6 @@ assert.deepEqual(infos, { | ||
it('should work for ligature codes', function(done) { | ||
var metadataService = metadata(); | ||
it('should work for ligature codes', (done) => { | ||
const metadataService = metadata(); | ||
metadataService('/var/plop/u0001u0002-hello.svg', function(err, infos) { | ||
metadataService('/var/plop/u0001u0002-hello.svg', (err, infos) => { | ||
assert(!err); | ||
@@ -162,6 +164,6 @@ assert.deepEqual(infos, { | ||
it('should work for nested codes', function(done) { | ||
var metadataService = metadata(); | ||
it('should work for nested codes', (done) => { | ||
const metadataService = metadata(); | ||
metadataService('/var/plop/u0001u0002,u0001-hello.svg', function(err, infos) { | ||
metadataService('/var/plop/u0001u0002,u0001-hello.svg', (err, infos) => { | ||
assert(!err); | ||
@@ -181,6 +183,6 @@ assert.deepEqual(infos, { | ||
it('should not set the same codepoint twice', function(done) { | ||
var metadataService = metadata(); | ||
it('should not set the same codepoint twice', (done) => { | ||
const metadataService = metadata(); | ||
metadataService('/var/plop/uEA01-hello.svg', function(err, infos) { | ||
metadataService('/var/plop/uEA01-hello.svg', (err, infos) => { | ||
assert(!err); | ||
@@ -193,3 +195,3 @@ assert.deepEqual(infos, { | ||
}); | ||
metadataService('/var/plop/plop.svg', function(err2, infos2) { | ||
metadataService('/var/plop/plop.svg', (err2, infos2) => { | ||
assert(!err2); | ||
@@ -207,6 +209,6 @@ assert.deepEqual(infos2, { | ||
it('should not set the same codepoint twice with different cases', function(done) { | ||
var metadataService = metadata(); | ||
it('should not set the same codepoint twice with different cases', (done) => { | ||
const metadataService = metadata(); | ||
metadataService('/var/plop/UEA01-hello.svg', function(err, infos) { | ||
metadataService('/var/plop/UEA01-hello.svg', (err, infos) => { | ||
assert(!err); | ||
@@ -219,3 +221,3 @@ assert.deepEqual(infos, { | ||
}); | ||
metadataService('/var/plop/uEA02-hello.svg', function(err2, infos2) { | ||
metadataService('/var/plop/uEA02-hello.svg', (err2, infos2) => { | ||
assert(!err2); | ||
@@ -228,3 +230,3 @@ assert.deepEqual(infos2, { | ||
}); | ||
metadataService('/var/plop/bell-o.svg', function(err3, infos3) { | ||
metadataService('/var/plop/bell-o.svg', (err3, infos3) => { | ||
assert(!err3); | ||
@@ -231,0 +233,0 @@ assert.deepEqual(infos3, { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
138
1
272174
10
1815
+ Addedtransformation-matrix-js@2.7.6(transitive)