generate iconFont
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

66 lines
1.7 KiB

var express = require('express');
var router = express.Router();
router.post('/createIconFont', async (req, res) => {
svgFiles = []
let fontId = await font.findOne( {
where : {
name : req.body.fontName,
}
})
let svgList = await font.findAll({
include : [{model: iconFont , where : {
varient : "Bulks",
iconfontID :fontId.dataValues.id,
}}, ],
})
svgList = svgList[0].dataValues.iconfonts
res.send(svgList)
if (!fs.existsSync("iconFont/svg/"+req.body.fontName)){
fs.mkdirSync("iconFont/svg/"+req.body.fontName);
}
svgtofont({
src: path.resolve('iconFont/svg/'+req.body.fontName),
dist: path.resolve('iconFont/iconFontsOf'+req.body.fontName),
fontName: req.body.fontName,
// css: true,
emptyDist: true,
useNameAsUnicode : true,
});
const cssFileGenerator = `
@font-face {
font-family: ${req.body.fontName};
src: url('${req.body.fontName}.eot'); /* IE9*/
src: url('${req.body.fontName}.eot') format('embedded-opentype'), /* IE6-IE8 */
url("${req.body.fontName}.woff2") format("woff2"),
url("${req.body.fontName}.woff") format("woff"),
url('${req.body.fontName}.ttf') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
url('${req.body.fontName}.svg') format('svg'); /* iOS 4.1- */
}
.characters {
font-family: '${req.body.fontName}' !important;
font-size:16px;
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
`
fs.writeFile('iconFont/iconFontsOf'+req.body.fontName + "/"+req.body.fontName+".css", cssFileGenerator, err => {
if (err) {
console.error(err);
}
// file written successfully
});
});
module.exports = router;