cn-font-split
Version:
划时代的字体切割工具,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.
37 lines (35 loc) • 1.22 kB
text/typescript
import { FontSplitProps } from '../interface.js';
import { getBinName, matchPlatform } from '../load.js';
import { createAPI } from '../createAPI.js';
export * from '../interface.js';
export * from '../createAPI.js';
/** @ts-ignore */
const _Deno = Deno;
let binPath = _Deno.env.get('CN_FONT_SPLIT_BIN');
if (!binPath) {
binPath = new URL(
'../' +
getBinName(
matchPlatform(process.platform, process.arch, () => false),
),
import.meta.url,
);
// throw new Error('CN_FONT_SPLIT_BIN is undefined!');
}
const dylib = _Deno.dlopen(binPath, {
font_split: { parameters: ['buffer', 'usize', 'function'], result: 'void' },
} as const);
const createCallback = (cb: (data: Uint8Array) => void) =>
new _Deno.UnsafeCallback(
{
parameters: ['pointer', 'usize'],
result: 'void',
} as const,
(success: any, length: number) => {
let buffer = new _Deno.UnsafePointerView(success).getArrayBuffer(
Number(length),
);
cb(new Uint8Array(buffer.slice()));
},
).pointer;
export const fontSplit = createAPI(dylib.symbols.font_split, createCallback);