
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
cn-font-split
Advanced tools
划时代的字体切割工具,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.
中文网字计划 | Github | 在线使用 |
---|
cn-font-split
是 中文网字计划 所使用的字体分包工具,通过高性能的各种技术将庞大的字体包拆分为适合网络分发的版本。经过七个大版本的字体研究与代码迭代,这项技术在我们的网站中得到了充分的应用,实现了中文字体在 Web 领域的加载速度与效率的双飞跃。
cn-font-split
不仅支持中文,针对于中韩日文字、少数民族文字、阿拉伯文等皆有优化,可以根据实际字体包内字符进行智能地分包。
WebAssembly
或者 Rust FFI
实现, 原生运行分包,进入秒级构建;7.0 版本更改了一些使用方式,请阅读文档进行修改。
Opentype Feature 支持情况 支持 95 | 部分支持 9| 等待测试 20
# 国内请设置环境变量, windows 用 set
export CN_FONT_SPLIT_GH_HOST=https://ik.imagekit.io/github
# set CN_FONT_SPLIT_GH_HOST=https://ik.imagekit.io/github # windows
pnpm i cn-font-split
import fs from 'fs';
import { fontSplit } from 'cn-font-split';
const inputBuffer = new Uint8Array(
fs.readFileSync('../demo/public/SmileySans-Oblique.ttf').buffer,
);
console.time('node');
await fontSplit({
input: inputBuffer,
outDir: './dist/font',
});
console.timeEnd('node');
import { fontSplit } from 'cn-font-split';
await fontSplit({
input: inputBuffer,
outDir: './dist/font',
previewImage: {
name: "preview", // 文件名称
text: "中文网字计划\nThe Chinese Web Font Project", // 需要渲染的字
},
testHtml: true,
reporter: true,
});
import { fontSplit } from 'cn-font-split';
await fontSplit({
input: inputBuffer,
outDir: './dist/font',
subsets: [
[65,66,67], // 第一个分包
[102,103,104], // 第二个分包
],
languageAreas: false, // 语言区域优化
autoSubset: false, // 超过指定大小是否自动包
fontFeature: false, // 是否支持字体特性
reduceMins: false, // 是否减少碎片分包的出现
renameOutputFont: '[hash:6].[ext]', // 重命名输出字体
silent: true, // 不打印任何数据
})
虽然在浏览器,但是速度极快。因为是 Wasm,所以 JS 环境基本都可以运行,我们甚至有一个 deno 版本的服务器。
# 首先安装 wasm 版本
cn-font-split i wasm32-wasip1
cn-font-split ls
import { fontSplit, StaticWasm } from 'cn-font-split/dist/wasm/index.js';
import wasmBuffer from 'cn-font-split/dist/libffi-wasm32-wasip1.wasm?url';
// 你的字体
const input = await fetch(
'https://jsdelivr.deno.dev/gh/KonghaYao/cn-font-split/packages/demo/public/SmileySans-Oblique.ttf',
).then((res) => res.arrayBuffer());
// 只需要初始化一次
const wasm = new StaticWasm(wasmBuffer);
const data = await fontSplit(
{
input: new Uint8Array(input),
outDir: "./dist"
},
wasm.WasiHandle,
{
logger(str, type) {
console.log(str);
},
},
);
console.log(data);
// { name: string, data: Uint8Array }[]
参数名 | 描述 |
---|---|
CN_FONT_SPLIT_BIN | 二进制动态链接库的地址 |
CN_FONT_SPLIT_GH_HOST | GitHub 域名(代理用) |
CN_FONT_SPLIT_PLATFORM | 覆盖默认判断的平台 |
Apache-2.0
FAQs
划时代的字体切割工具,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.
The npm package cn-font-split receives a total of 11,157 weekly downloads. As such, cn-font-split popularity was classified as popular.
We found that cn-font-split demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.