美文网首页
node实现简化字体文件到3500字

node实现简化字体文件到3500字

作者: NanaCti | 来源:发表于2023-08-03 13:43 被阅读0次

    在three中导入字体文件需要先将ttf文件转成json
    转换地址: http://gero3.github.io/facetype.js/
    转换后的字体json文件太大了, 处理成3500常用汉字的json

    const keys = require('./3500.json'); // 3500汉字+ 其他字符的集合
    const fs = require('fs');
    const fileName = 'HYXiaoBoZheZhiTiJ_Regular';
    
    (() => {
      try {
        const data = fs.readFileSync(`./${fileName}.json`, "utf-8")
        let fontAll = JSON.parse(data);
        const glyphs = {}
        keys.map(key => {
          if (fontAll.glyphs[key] === undefined) return
          glyphs[key] = fontAll.glyphs[key]
        })
        fontAll.glyphs = glyphs
        // let str = JSON.stringify(fontAll, "", "\t");
        let str = JSON.stringify(fontAll);
        
        const err = fs.writeFileSync(`./${fileName}_3500.json`, str)
        if (err) {console.error(err);}
    
        
      } catch (error) { console.log(error) }
    })()
    
    

    相关文章

      网友评论

          本文标题:node实现简化字体文件到3500字

          本文链接:https://www.haomeiwen.com/subject/brympdtx.html