svgicons2svgfont
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "svgicons2svgfont", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Read a set of SVG icons and ouput a SVG font", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/nfroidure/svgicons2svgfont", |
@@ -15,5 +15,6 @@ /* | ||
var Path = require("path") | ||
, Stream = require("stream").PassThrough | ||
, Stream = require("stream") | ||
, Sax = require("sax") | ||
, SVGPathData = require("svg-pathdata"); | ||
, SVGPathData = require("svg-pathdata") | ||
; | ||
@@ -25,3 +26,3 @@ function svgicons2svgfont(glyphs, options) { | ||
options.descent = options.descent || 0; | ||
var outputStream = new Stream() | ||
var outputStream = new Stream.PassThrough() | ||
, log = (options.log || console.log.bind(console)) | ||
@@ -33,4 +34,16 @@ , error = options.error || console.error.bind(console); | ||
saxStream.on('opentag', function(tag) { | ||
if(tag.attributes.display | ||
&& 'none' == tag.attributes.display.toLowerCase()) { | ||
return; | ||
} | ||
// Save the view size | ||
if('svg' === tag.name) { | ||
if('width' in tag.attributes) { | ||
glyph.width = parseFloat(tag.attributes.width, 10); | ||
} | ||
if('height' in tag.attributes) { | ||
glyph.height = parseFloat(tag.attributes.height, 10); | ||
} | ||
// Change rect elements to the corresponding path | ||
if('rect' === tag.name) { | ||
} else if('rect' === tag.name) { | ||
glyph.d.push( | ||
@@ -94,15 +107,6 @@ // Move to the left corner | ||
); | ||
} else if('path' === tag.name && tag.attributes.d) { | ||
glyph.d.push(tag.attributes.d); | ||
} | ||
}); | ||
saxStream.on('attribute', function(attr) { | ||
if('width' === attr.name && 'svg' === saxStream._parser.tag.name) { | ||
glyph.width = parseFloat(attr.value, 10); | ||
} else if('height' === attr.name && 'svg' === saxStream._parser.tag.name) { | ||
glyph.height = parseFloat(attr.value, 10); | ||
} else if('d' === attr.name && 'path' === saxStream._parser.tag.name) { | ||
if(attr.value) { | ||
glyph.d.push(attr.value); | ||
} | ||
} | ||
}); | ||
saxStream.on('end', function() { | ||
@@ -134,3 +138,3 @@ glyph.running = false; | ||
<font-face font-family="' + options.fontName + '"\n\ | ||
units-per-em="' + fontHeight + '" ascent="' + (fontHeight - options.descent) + '"\n\ | ||
units-per-em="' + fontHeight + '" ascent="' + (fontHeight + options.descent) + '"\n\ | ||
descent="' + options.descent + '" />\n\ | ||
@@ -137,0 +141,0 @@ <missing-glyph horiz-adv-x="0" />\n'); |
@@ -98,2 +98,8 @@ var assert = require('assert') | ||
it("should not display hidden pathes", function(done) { | ||
generateFontToFile({ | ||
fontName: 'hiddenpathesicons' | ||
}, done); | ||
}); | ||
}); | ||
@@ -154,3 +160,3 @@ | ||
fontName: 'originalicons', | ||
descent: 200 | ||
descent: -200 | ||
}, done, '4'); | ||
@@ -157,0 +163,0 @@ }); |
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
63544
49
374