IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    js字体子集服务:Fontmin

    1900发表于 2016-08-04 10:38:02
    love 0

    Fontmin是百度EFE推出的一个前端项目,是使用js动态生成精简化的字体子集提高载入速度,让既漂亮又臃肿的中文字库也可以拿到web网页上来使用。

    目前准备拿到自己的网站上来试试,看能不能把文章主题标题使用上这个功能。

    这是一个简单的DEMO。

    See the Pen Fontmin Example by Firede (@firede) on CodePen.

    如何使用
    var srcPath = ‘src/font/*.ttf’; // 字体源文件
    var destPath = ‘asset/font’; // 输出路径
    var text = ‘我说你是人间的四月天;笑响点亮了四面风;轻灵在春的光艳中交舞着变。’;

    // 初始化
    var fontmin = new Fontmin()
    .src(srcPath) // 输入配置
    .use(Fontmin.glyph({ // 字型提取插件
    text: text // 所需文字
    }))
    .use(Fontmin.ttf2eot()) // eot 转换插件
    .use(Fontmin.ttf2woff()) // woff 转换插件
    .use(Fontmin.ttf2svg()) // svg 转换插件
    .use(Fontmin.css()) // css 生成插件
    .dest(destPath); // 输出配置

    // 执行
    fontmin.run(function (err, files, stream) {

    if (err) { // 异常捕捉
    console.error(err);
    }

    console.log(‘done’); // 成功
    });
    Fontmin 提供了 Node.js 模块和客户端 2 种使用方法,具体介绍请移步 Fontmin 快速指南。

    Fontmin:Node.js 模块 | Windows 客户端 | OS X 客户端 | GitHub



沪ICP备19023445号-2号
友情链接