cn-font-split icon indicating copy to clipboard operation
cn-font-split copied to clipboard

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

Open zzzmj opened this issue 9 months ago • 1 comments

例如:隶书.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
    // } // 或者也可以像这样传入一个函数返回自定义的文件名
});

zzzmj avatar Apr 29 '24 04:04 zzzmj

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

KonghaYao avatar Apr 30 '24 02:04 KonghaYao