# 网页字体
# 目的
编撰此文的目的是为了说明:
- 下载字体文件的网站
- 转换字体文件类型 (如
.otf
转换成.ttf
) - 精简字体文件大小(生成只包含 指定字符 的字体文件)
- 生成网页可用的字体(如
.tff
生成eot
,woff2
,woff
)
# 下载字体的网站
- https://www.wfonts.com/font/rajdhani-semibold
- https://freefonts.top/font/60ab1e6c331cf308bd9e5412
# 转换字体类型
说明:
- 软件 —— FontCreator 14.0
- 下载 —— FontCreator(字体编辑软件)v14.0.0 破解版 附注册机 (opens new window)
# 使用
- 打开字体文件: File -> open file...
- 导出指定类型的文件: File -> Export Font...
# 精简字体
说明:
- 软件 —— FontMin
- 下载 —— 官网 (opens new window)
使用:
const Fontmin = require('fontmin');
function generateSubsetFont(src, dest, text) {
return new Fontmin()
.src(src)
.use(Fontmin.glyph({ text }))
.use(Fontmin.ttf2eot())
.use(Fontmin.ttf2woff())
.use(Fontmin.ttf2woff2())
.use(Fontmin.css())
.dest(dest)
.run((err) => {
if (err) {
console.error(err);
}
console.log('done'); // 成功
});
}
generateSubsetFont('./src/douyu.ttf', './dist/douyu');
// generateSubsetFont('./src/source-han-sans-cn-regular.ttf', './dist/source-han-sans-cn-regular');
# 参考
上一篇: 下一篇:
本章目录