/** * iconfont 处理器 * * @param {processContext} processContext 处理器上下文 * @param {Function} done 完成回调 */ function iconfont(processContext, done) { var destDir = path.resolve(processContext.baseDir, this.dest); var fontmin = new Fontmin() .src(this.files, {base: processContext.baseDir}) .use(Fontmin.svgs2ttf(this.fontName)) .use(Fontmin.ttf2eot()) .use(Fontmin.ttf2woff()) .use(Fontmin.ttf2svg()) .use(Fontmin.css({ glyph: true })) .dest(destDir); var me = this; fontmin.run(function (err, files, stream) { if (err) { me.log.error(err); } done(); }); }
/** * fontMinify 处理器 * * @param {FileObject} file 处理器文件对象 * @param {processContext} processContext 处理器上下文 * @param {Function} done 完成回调 */ function fontMinify(file, processContext, done) { var text = this.text || ''; var entryFiles = this.entryFiles; if (entryFiles) { var entryText = []; processContext .getFilesByPatterns(entryFiles) .forEach(function (entryFile) { entryText.push(entryFile.data); }); text += entryText.join(''); } var chineseOnly = this.chineseOnly; if (chineseOnly) { text = text.replace(/[^\u4e00-\u9fa5]/g, ''); } var srcPath = file.path; var outputDir = processContext.outputDir; var destPath = path.dirname(file.outputPath); destPath = path.resolve(outputDir, destPath); // 获取目标地址,传入 fontmin.dest file.outputPath = null; // 清除 edp 构建结果 var fontmin = new Fontmin() .src(srcPath) .use(Fontmin.glyph({ text: text })) .use(Fontmin.ttf2eot()) .use(Fontmin.ttf2woff()) .use(Fontmin.ttf2svg()) .dest(destPath); var me = this; fontmin.run(function (err, files, stream) { if (err) { me.log.error(err); } done(); }); }
return through.obj(function (file, enc, cb) { if (file.isNull()) { cb(null, file); return; } if (file.isStream()) { cb(new gutil.PluginError('gulp-fontmin', 'Streaming not supported')); return; } if (!isExt(file.path, 'svg')) { if (opts.verbose) { gutil.log('gulp-fontmin: Skipping unsupported ' + chalk.blue(file.relative)); } cb(null, file); return; } var fontmin = new Fontmin() .use(Fontmin.glyph(opts)) .use(Fontmin.ttf2eot()) .use(Fontmin.ttf2woff()) .use(Fontmin.ttf2svg()) .use(Fontmin.css(opts)); if (opts.use) { opts.use.forEach(fontmin.use.bind(fontmin)); } fontmin.run(function (err, files) { if (err) { cb(new gutil.PluginError('gulp-fontmin:', err, {fileName: file.path})); return; } cb(null, file); }); }, function (cb) {
}, function(flushCb){ var fontmin = null, _this = this; // remove duplication glyphListCacheStr = (function(str){ var o = {}, list=str.split(''), i; for (i=0; i<list.length; i++) { o[list[i]]=1; } return Object.keys(o).join(''); }(glyphListCacheStr + options.mustHaveGlyphs)); fontmin = new Fontmin() .src(options.fontPath) .use(Fontmin.glyph({ text: glyphListCacheStr })) .use(Fontmin.ttf2eot()) .use(Fontmin.ttf2woff()) .use(Fontmin.ttf2svg()); // .use(Fontmin.css()); fontmin.run(function (err, files) { if (err) { _this.emit('error', new gutil.PluginError(err)); return flushCb(); } for (var i=0; i<files.length; i++) { _this.push(files[i]); } flushCb(); }); });
return false; } }; if (src.length > 1 && !isFile(src[src.length - 1])) { dest = src[src.length - 1]; src.pop(); } // start fontmin new Fontmin() .src(src) .use(Fontmin.svgs2ttf(fmOpts.fontFamily, fmOpts)) .use(Fontmin.ttf2eot(fmOpts)) .use(Fontmin.ttf2woff(fmOpts)) .use(Fontmin.ttf2svg(fmOpts)) .use(Fontmin.css(fmOpts)) .use(dump(fmOpts)) .dest(dest || 'output') .run((err, files, stream) => { if (err) { log(err); process.exit(1); } files.forEach(file => { log(`created: ${file.path}`); }); log(`\nall ${files.length} files`);
fs.writeFile("../dist/MapkeyIcons.css",styleDocument, function(err) { if(err) { return console.error("ERROR: "+err); } }); /** CREATING FONTS **/ var Fontmin = require('fontmin'); var fontmin = new Fontmin() .src('../src/MapkeyIcons.ttf') .dest('../dist') .use(Fontmin.ttf2woff({})) .use(Fontmin.ttf2eot()) .use(Fontmin.ttf2svg()) fontmin.run(function (err, files) { if (err) { console.error("ERROR:"+err); return; } files.forEach(function(item){ }); }); var svg2png = require('svg2png');