Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
paths[extname] = {
file: file,
dirname: path.dirname(relative),
basename: basename,
extname: extname
};
export function generateFonts(done) {
const fontmin = new Fontmin()
.src(`${config.src}/styles/fonts/*.{ttf,otf}`)
.use(Fontmin.otf2ttf({
clone: true
}))
.use(Fontmin.ttf2eot({
clone: true
}))
.use(Fontmin.ttf2woff({
clone: true
}))
.use(Fontmin.ttf2svg({
clone: true
}))
.dest(`${config.dist}/styles/fonts`);
return fontmin.run((err) => {
if (err) {
console.log(err);
job.run(function (err, files) {
if (err) {
reject(err);
} else {
resolve(files);
}
});
});
}
/**
* Convert the source OTF to TTF
* Auto-hint the TTF
* Convert the TTF to EOT and WOFF
*/
runFontminJob(new Fontmin().src(otfPath).dest(destPath).use(Fontmin.otf2ttf()))
.then(function (files) {
if (files.length !== 1) {
throw 'Unable to find generated TTF webfont';
} else {
return applyAutohinting(files[0].path);
}
})
.then(function (hintedTtf) {
var input = fs.readFileSync(hintedTtf);
fs.writeFileSync('fonts/core-icons.woff2', ttf2woff2(input));
return Promise.all([
runFontminJob(new Fontmin().src(hintedTtf).dest(destPath).use(Fontmin.ttf2eot())),
runFontminJob(new Fontmin().src(hintedTtf).dest(destPath).use(Fontmin.ttf2woff()))
])