-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathindex.ts
27 lines (26 loc) · 1.03 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Font } from '@konghayao/opentype.js';
import { FeatureList } from './FeatureList';
/** Opentype 的 feature 报告 */
export const getFeatureReport = (font: Font, unicodeSet: Set<number>) => {
return FeatureList.reduce(
(col, i) => {
const arr: { sub: number | number[]; by: number | number[] }[] = (
font.substitution as any
).getFeature(i);
const idToUnicode = (id: number) => font.glyphs.get(id).unicodes;
if (arr && arr.length)
col[i] = arr.map((i) => {
return {
sub: (typeof i.sub === 'number' ? [i.sub] : i.sub).map(
(i) => idToUnicode(i),
),
by: (typeof i.by === 'number' ? [i.by] : i.by).map(
(i) => idToUnicode(i),
),
};
});
return col;
},
{} as Record<string, { sub: number[][]; by: number[][] }[]>,
);
};