KonghaYao / cn-font-split

划时代的字体切割工具,CJK与任何字符!支持 otf、ttf、woff2 字体多线程切割,完美地细颗粒度地进行包大小控制。A revolutionary font subetter that supports CJK and any characters! It enables multi-threaded subset of otf, ttf, and woff2 fonts, allowing for precise control over package size.
https://chinese-font.netlify.app/
Apache License 2.0
442 stars 15 forks source link

如何在程序中获取字体的实际fontFamily? #54

Closed zzzmj closed 3 months ago

zzzmj commented 4 months ago

例如:隶书.ttf

在程序分包后,css中实际渲染的是font-family: "LiSu";

必须要去css文件中查看对应的font-family, 有没有办法在分包结束后获取到这个实际的fontFamily?

目前的功能似乎只支持覆盖,但是我想提取实际更准确的font-family


fontSplit({
    FontPath: './fonts/隶书.ttf',
    destFold: './build',
    chunkSize: 70 * 1024, // 如果需要的话,自己定制吧
    testHTML: true, // 输出一份 html 报告文件
    reporter: true, // 输出 json 格式报告
    previewImage: {}, // 只要填入 这个参数,就会进行图片预览文件生成,文件为 SVG 格式
    threads: {}, // 默认开启多线程,速度飞快
    css: {
        // 覆盖默认的 css 设置,一般不需要进行更改
        // fontFamily: "站酷庆科黄油体",
        // fontWeight: 400,
    },
    // 自定义分包输出的文件名为 10 位短哈希,或者使用自增索引: '[index][ext]'
    renameOutputFont: '[hash:10][ext]',
    // renameOutputFont: ({ transferred, ext, index }) => {
    //   return index.toString(36) + ext
    // } // 或者也可以像这样传入一个函数返回自定义的文件名
});
KonghaYao commented 4 months ago

image 生成的文件中,有一个 reporter 文件,你可以结束之后去获取它,它里面有关于分包的所有数据