-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from KonghaYao/feature/analyze
Feature/analyze
- Loading branch information
Showing
7 changed files
with
209 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
export const FeatureList = [ | ||
'aalt', | ||
'abvf', | ||
'abvm', | ||
'abvs', | ||
'afrc', | ||
'akhn', | ||
'blwf', | ||
'blwm', | ||
'blws', | ||
'calt', | ||
'case', | ||
'ccmp', | ||
'cfar', | ||
'chws', | ||
'cjct', | ||
'clig', | ||
'cpct', | ||
'cpsp', | ||
'cswh', | ||
'curs', | ||
...[...Array(99).keys()].map( | ||
(i) => 'cv' + (i + 1).toString().padStart(2, '0'), | ||
), | ||
'c2pc', | ||
'c2sc', | ||
'dist', | ||
'dlig', | ||
'dnom', | ||
'dtls', | ||
'expt', | ||
'falt', | ||
'fin2', | ||
'fin3', | ||
'fina', | ||
'flac', | ||
'frac', | ||
'fwid', | ||
'half', | ||
'haln', | ||
'halt', | ||
'hist', | ||
'hkna', | ||
'hlig', | ||
'hngl', | ||
'hojo', | ||
'hwid', | ||
'init', | ||
'isol', | ||
'ital', | ||
'jalt', | ||
'jp78', | ||
'jp83', | ||
'jp90', | ||
'jp04', | ||
'kern', | ||
'lfbd', | ||
'liga', | ||
'ljmo', | ||
'lnum', | ||
'locl', | ||
'ltra', | ||
'ltrm', | ||
'mark', | ||
'med2', | ||
'medi', | ||
'mgrk', | ||
'mkmk', | ||
'mset', | ||
'nalt', | ||
'nlck', | ||
'nukt', | ||
'numr', | ||
'onum', | ||
'opbd', | ||
'ordn', | ||
'ornm', | ||
'palt', | ||
'pcap', | ||
'pkna', | ||
'pnum', | ||
'pref', | ||
'pres', | ||
'pstf', | ||
'psts', | ||
'pwid', | ||
'qwid', | ||
'rand', | ||
'rclt', | ||
'rkrf', | ||
'rlig', | ||
'rphf', | ||
'rtbd', | ||
'rtla', | ||
'rtlm', | ||
'ruby', | ||
'rvrn', | ||
'salt', | ||
'sinf', | ||
'size', | ||
'smcp', | ||
'smpl', | ||
'ss01', | ||
'ss02', | ||
'ss03', | ||
'ss04', | ||
'ss05', | ||
'ss06', | ||
'ss07', | ||
'ss08', | ||
'ss09', | ||
'ss10', | ||
'ss11', | ||
'ss12', | ||
'ss13', | ||
'ss14', | ||
'ss15', | ||
'ss16', | ||
'ss17', | ||
'ss18', | ||
'ss19', | ||
'ss20', | ||
'ssty', | ||
'stch', | ||
'subs', | ||
'sups', | ||
'swsh', | ||
'titl', | ||
'tjmo', | ||
'tnam', | ||
'tnum', | ||
'trad', | ||
'twid', | ||
'unic', | ||
'valt', | ||
'vatu', | ||
'vchw', | ||
'vert', | ||
'vhal', | ||
'vjmo', | ||
'vkna', | ||
'vkrn', | ||
'vpal', | ||
'vrt2', | ||
'vrtr', | ||
'zero', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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[][] }[]>, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters