Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
};
// word count
function wordCount(str) {
var text = removeDupicateText(str)
var matches = text.match(/[\u00ff-\uffff]|\S+/g);
return matches ? matches.length : 0;
}
// print all text
console.log('Converted words : ' + removeDupicateText(allText),'(' + wordCount(allText) + ')');
// convert file type
var fontmin = new Fontmin()
.src(fontsSource)
.use(Fontmin.glyph({
text: allText
}))
.use(ttf2woff2({
clone: true
})) // add woff2
.dest(outputPath)
.use(Fontmin.ttf2eot())
.use(Fontmin.ttf2woff({
deflate: true
}))
.use(Fontmin.ttf2svg());
imagemin([outputPath + '*.svg'], outputPath + 'optimize', {
use: [svgo()]
}).then(() => {
console.log('Convert finished'); // Finished
});
}, function(err, css) {
// Remove unused glyphs from icon font
var rIconFontUrl = /(url\(".*?materialdesignicons-webfont.woff.*?base64,)(.*?)("\))/;
var rIconRuleMatch = /\.icon-.*?:before {\n content: "\\([\da-f]+)";\n}/g;
var rIconRuleExtract = /\.icon-.*?:before {\n content: "\\([\da-f]+)";\n}/; // not global
window.language = 'en-US'; // Since there is a window, fontmin expects window.language
var Fontmin = require('fontmin');
var fontmin = new Fontmin()
.src(argv._[0].replace(/[^\/]*\.html/, 'style/fonts/materialdesignicons-webfont.ttf'))
.use(Fontmin.glyph({
text: css.match(rIconRuleMatch).map(function(iconRule) {
return String.fromCharCode(parseInt(iconRule.match(rIconRuleExtract)[1], 16));
}).join(''),
}))
.use(Fontmin.ttf2woff({
deflate: true // Does nothing but shouldn't hurt
}));
fontmin.run(function(err, files) {
if(err) {
throw err;
}
css = css.replace(rIconFontUrl,
'$1' +
files[0].contents.toString('base64') +
'$3'
var Fontmin = require('fontmin');
var htmlToText = require('html-to-text');
var path = require('path');
var fs = require('fs');
var text = ['index', 'echarts3', 'map3'].map(function (name) {
return htmlToText.fromString(fs.readFileSync(path.join(__dirname, '../../' + name + '.html'), 'utf-8'));
}).join('');
// htmlToText.fromString(html, {}, function (err, text) {
new Fontmin()
.src('./noto-thin.ttf')
.use(Fontmin.glyph({
text: text
}))
.run(function (err, files) {
if (err) {
throw new Error(err);
}
require('fs').writeFileSync('./noto-thin.min.ttf', files[0]._contents);
});
// });
function fontmin(font, opts, callback) {
var fmOpts = extend({}, opts);
// for css font path
fmOpts.fontPath = ['.', opts.dest, ''].join('/');
// font css font family
fmOpts.fontFamily = font.name || font.basename;
var stream = storage.src(font.srcPath)
.pipe(Fontmin.glyph({
text: font.text
})())
.pipe(streamRename({
basename: font.hash
}))
.pipe(Fontmin.ttf2eot(fmOpts)())
.pipe(Fontmin.ttf2woff(fmOpts)())
.pipe(Fontmin.ttf2svg(fmOpts)())
.pipe(Fontmin.css(fmOpts)())
.pipe(storage.dest(opts.dest));
stream.on('error', callback);
stream.pipe(concat(callback.bind(null, null)));
}
var webFont = this.webFont;
var files = this.files;
var source = this.source;
var dirname = this.dirname;
var basename = this.basename;
var originalSize = fs.statSync(source).size;
var fontmin = new Fontmin().src(source);
var temp = path.join(dirname, TEMP + number);
// 有些 webfont 使用 content 属性加字体继承,查询不到 chars
// 不压缩,避免意外将 fonticon 干掉了
if (webFont.chars) {
fontmin.use(Fontmin.glyph({
text: webFont.chars
}));
}
Object.keys(files).forEach(function (key) {
key = key.toLocaleLowerCase();
if (typeof Fontmin['ttf2' + key] === 'function') {
fontmin.use(Fontmin['ttf2' + key]({clone: true}));
}
});
fontmin.dest(temp);
fontmin.run(function (errors /*, buffer*/) {
if (!fs.existsSync(source.url)) {
return callback(new Error('"' + source.url + '" file not found'));
}
var originalSize = fs.statSync(source.url).size;
var fontmin = new Fontmin().src(source.url);
var paths = {};
var types = {
'embedded-opentype': 'ttf2eot',
'woff': 'ttf2woff',
'woff2': 'ttf2woff2',
'svg': 'ttf2svg'
};
fontmin.use(Fontmin.glyph({
trim: false,
text: webFont.chars || '#' // 传入任意字符避免 fontmin@0.9.5 BUG
}));
if (source.format === 'opentype') {
fontmin.use(Fontmin.otf2ttf());
}
webFont.files.forEach(function(file) {
var format = file.format;
var fn = types[format];
var extname = path.extname(file.url);
var basename = path.basename(file.url, extname);
var relative = path.relative(dirname, file.url);
const start = (src, txt, removeJa = false) => {
if (removeJa) {
txt = txt.replace(/[\u3040-\u30ff\uff66-\uff9f]/g, '')
}
const fontmin = new Fontmin()
.src(src)
.use(Fontmin.glyph({
text: txt,
hinting: false
}))
.use(ttf2woff2({ clone: false }))
.dest(destPath)
fontmin.run(function (err, files, stream) {
if (err) {
console.error(err)
}
})
}
setupFontmin(extensions, usedGlyphs = []) {
usedGlyphs = _.isArray(usedGlyphs) ? usedGlyphs : [usedGlyphs]
let fontmin = new Fontmin().use(Fontmin.glyph({text: usedGlyphs.join(' ')}))
FONTMIN_EXTENSIONS.forEach(ext => {
if (extensions.includes('.' + ext)) {
fontmin = fontmin.use(Fontmin[`ttf2${ext}`]())
}
})
return fontmin
}
}
var text = opts.text || '';
if (text && opts.chineseOnly) {
text = text.replace(/[^\u4e00-\u9fa5]/g, '');
}
opts.text = text;
var fontmin = new Fontmin()
.src(file.contents)
.use(rename({
path: file.path
}))
.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));
}
var fileStream = this;
fontmin.run(function (err, files) {
if (err) {
cb(new gutil.PluginError('gulp-fontmin:', err, {fileName: file.path}));
return;
}