Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update #48

Merged
merged 42 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
08fddb8
fix: 添加 FileStore 的异步缓存
KonghaYao Nov 6, 2023
9962656
feat: 添加 ss 族和 smpl 特性
KonghaYao Nov 6, 2023
6d36246
feat: blws,blwm,vatu
KonghaYao Nov 6, 2023
ecec3bc
docs: 更新部分特性信息
KonghaYao Nov 6, 2023
ada1198
feat: 支持 vkrn
KonghaYao Nov 6, 2023
9fb2adc
feat: 添加 ljmo tjmo vjmo
KonghaYao Nov 6, 2023
5f86707
fix: 修复下载错误
KonghaYao Nov 6, 2023
5ac4743
test: 添加多个浏览器测试环境
KonghaYao Nov 6, 2023
f362838
fix: 修正 vatu 状态
KonghaYao Nov 6, 2023
2f18d4b
fix: 修复测试用例
KonghaYao Nov 7, 2023
f790583
test: 更改部分示例
KonghaYao Nov 7, 2023
0b141e0
fix: 使用精度优先渲染测试环境
KonghaYao Nov 7, 2023
70992b4
feat: 新增四个特性
KonghaYao Nov 7, 2023
511f4ec
fix: 添加字体属性归零
KonghaYao Nov 7, 2023
7c03dae
feat: 调整测试文本和样式
KonghaYao Nov 8, 2023
4fb705d
fix: 修复 webkit 的宽度丢失问题
KonghaYao Nov 8, 2023
3ada0a7
feat: 约束测试结果的 width
KonghaYao Nov 9, 2023
f826399
fix: 修复测试用例
KonghaYao Nov 9, 2023
5d73a8d
docs: 调整文档说明
KonghaYao Nov 9, 2023
238b24d
feat: 添加测试环境颜色去除
KonghaYao Nov 9, 2023
2992138
build: 压缩原始文件
KonghaYao Nov 17, 2023
857273e
fix: 修复 opentype 解析 woff2 失效
KonghaYao Nov 20, 2023
d0f3c98
Merge remote-tracking branch 'origin/ts' into ts
KonghaYao Nov 20, 2023
39a681d
chore: 4.10.6
KonghaYao Nov 20, 2023
fd4f601
chore(woff2): 升级 node 版本的 woff2 压缩器
KonghaYao Dec 18, 2023
325d4cd
docs: 更新版本
KonghaYao Dec 18, 2023
b1f6baf
build(deps-dev): bump vite from 4.4.5 to 4.4.12
dependabot[bot] Dec 30, 2023
f851ba7
Merge pull request #39 from KonghaYao/dependabot/npm_and_yarn/vite-4.…
KonghaYao Dec 30, 2023
9349d85
Fix: Doesn't work in node.js v21.5.0
jynxio Dec 31, 2023
fd873ca
Merge pull request #40 from jynxio/ts
KonghaYao Dec 31, 2023
507baf6
chore(version): 4.11.1
KonghaYao Dec 31, 2023
0d82e4c
test(emoji): 测试用例完成,未开始测试
KonghaYao Jan 4, 2024
8a4ff12
test(emoji): 完善 emoji 测试
KonghaYao Jan 4, 2024
52d3bc1
fix(emoji): 修复 emoji 测试样例渲染
KonghaYao Jan 5, 2024
6b1a9d5
feat(analyze): 分析器添加 feature 和 svg 生成功能
KonghaYao Jan 7, 2024
71e1a82
fix(analyze): 修复获取的 feature 数据非 unicode 问题
KonghaYao Jan 7, 2024
1cbf4c3
Merge pull request #43 from KonghaYao/feature/analyze
KonghaYao Jan 7, 2024
d6a4a73
test(color-emoji): 采用 COLRv1 特性的字体测试通过
KonghaYao Jan 8, 2024
c661d20
Merge branch 'test/noto-color-emoji' into ts
KonghaYao Jan 14, 2024
13134a1
build(deps-dev): bump vite from 4.4.12 to 4.5.2
dependabot[bot] Jan 20, 2024
cefaf4b
Merge pull request #46 from KonghaYao/dependabot/npm_and_yarn/vite-4.5.2
KonghaYao Jan 20, 2024
818bf98
build(opentype.js): 升级 opentype.js
KonghaYao Jan 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# 中文 Web Font 切割工具

![updateTime](https://img.shields.io/badge/更新时间-2023/11/4-green)
![updateTime](https://img.shields.io/badge/更新时间-2023/12/18-green)
![author](https://img.shields.io/badge/author-江夏尧-green)
![npmVersion](https://img.shields.io/badge/LTS_version-4.10.5-green)
![npmVersion](https://img.shields.io/badge/LTS_version-4.11.0-green)
[![](https://data.jsdelivr.com/v1/package/npm/@konghayao/cn-font-split/badge)](https://www.jsdelivr.com/package/npm/@konghayao/cn-font-split)

![CodeFactor](https://www.codefactor.io/repository/github/konghayao/cn-font-split/badge)
![NPM License](https://img.shields.io/npm/l/%40konghayao%2Fcn-font-split)
![downloadCount](https://img.shields.io/npm/dw/%40konghayao%2Fcn-font-split)

| [中文网字计划](https://chinese-font.netlify.app/) | [Github](https://github.com/KonghaYao/cn-font-split) |
| ------------------------------------------------- | ---------------------------------------------------- |
| [中文网字计划](https://chinese-font.netlify.app/) | [Github](https://github.com/KonghaYao/cn-font-split) | [在线使用](https://chinese-font.netlify.app/online-split/)|
| ------------------------------------------------- | ---------------------------------------------------- |---------------------------------------------------- |

## 简介

Expand All @@ -24,7 +22,7 @@

> 我们正在对 cn-font-split 的实战效果进行测试,并积极提升分包效果!
>
> [Opentype Feature 测试情况](/packages/test/SUPPORT_FEATURE.md) 支持 100 | 部分支持 4| 等待测试 39
> [Opentype Feature 测试情况](/packages/test/SUPPORT_FEATURE.md) 支持 95 | 部分支持 9| 等待测试 20

[详见兼容性章节](#兼容性提醒)。
| [Nodejs](#nodejs) | [Deno](#deno) | [Chrome](#browser) | [FireFox](#browser) | [Safari](#browser) | [Bun](#bun) |
Expand Down
4 changes: 2 additions & 2 deletions packages/font-analyze/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "font-analyze",
"version": "1.3.1",
"version": "1.3.4",
"description": "",
"main": "dist/index.js",
"type": "module",
Expand All @@ -17,7 +17,7 @@
"license": "ISC",
"dependencies": {
"@types/opentype.js": "^1.3.4",
"@konghayao/opentype.js": "^2023.10.5"
"@konghayao/opentype.js": "^2023.11.20"
},
"devDependencies": {
"compressing": "^1.9.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/font-analyze/src/Charset/FontSetMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export const calcCharset = (charset: Charset) => {
}, 0);
};

/** 字符集判断 */
/** 判断字体中是否包含 json 文件的 unicode 字符 */
export const FontSetMatch = (
font: Font,
items: Set<number>,
charset: Charset,
name: string
name: string,
): CharsetReporter => {
let support_count = 0;
let area_count = 0;
Expand Down
3 changes: 3 additions & 0 deletions packages/font-analyze/src/Charset/defaultCharsetLoader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Charset } from './FontSetMatch.js';
import { UnicodeCharset } from './UnicodeMatch.js';

/** 字符集支持报告的表格 */
export interface CharsetReporter {
name: string;
cn?: string;
Expand All @@ -11,6 +12,8 @@ export interface CharsetReporter {
coverage: string;
in_set_rate: string;
}

/** 从远程加载数据 json 文件 */
export type CharsetLoader = (path: string) => Promise<Charset | UnicodeCharset>;
export const defaultCharsetLoader: CharsetLoader = async (path) => {
const { default: D } = await import('../data/' + path);
Expand Down
13 changes: 7 additions & 6 deletions packages/font-analyze/src/Charset/getCharsetReport.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { Font } from '@konghayao/opentype.js';
import { Charset, FontSetMatch } from './FontSetMatch.js';
import { UnicodeCharset, UnicodeMatch } from './UnicodeMatch.js';
import { CharsetLoader } from './defaultCharsetLoader.js';

/** 获取 unicode 字符集检测报告 */
export async function getCharsetReport(
charsetLoader: CharsetLoader,
font: any,
unicodeSet: Set<number>
font: Font,
unicodeSet: Set<number>,
) {
const standard = await getCharsetStandard(charsetLoader, font, unicodeSet);
// console.table(standard);
const Unicode = await charsetLoader('unicodes.json');
const unicodeReport = UnicodeMatch(
font,
unicodeSet,
Unicode as UnicodeCharset
Unicode as UnicodeCharset,
);
return { unicodeReport, standard };
}
/** 获取标准字符集数据 */
async function getCharsetStandard(
charsetLoader: CharsetLoader,
font: any,
unicodeSet: Set<number>
font: Font,
unicodeSet: Set<number>,
) {
return await Promise.all(
[
Expand All @@ -45,6 +46,6 @@ async function getCharsetStandard(
].map(async ([_path, name]) => {
const set = await charsetLoader(_path);
return FontSetMatch(font, unicodeSet, set as Charset, name);
})
}),
);
}
147 changes: 147 additions & 0 deletions packages/font-analyze/src/Feature/FeatureList.ts
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',
];
27 changes: 27 additions & 0 deletions packages/font-analyze/src/Feature/index.ts
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[][] }[]>,
);
};
24 changes: 21 additions & 3 deletions packages/font-analyze/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { parse, type Font } from '@konghayao/opentype.js';
import { RenderOptions, parse } from '@konghayao/opentype.js';
import { getCharsetReport } from './Charset/getCharsetReport.js';
import {
defaultCharsetLoader,
CharsetLoader,
} from './Charset/defaultCharsetLoader.js';
import { getFeatureReport } from './Feature/index.js';

export * from './Charset/defaultCharsetLoader.js';

/** 分析字体中的字符集和字型相关信息 */
export const FontAnalyze = async (
input: Buffer | ArrayBuffer,
{ charsetLoader = defaultCharsetLoader }: { charsetLoader: CharsetLoader }
{ charsetLoader = defaultCharsetLoader }: { charsetLoader: CharsetLoader },
) => {
const font = parse(input);

Expand All @@ -22,8 +25,9 @@ export const FontAnalyze = async (
const { unicodeReport, standard } = await getCharsetReport(
charsetLoader,
font,
unicodeSet
unicodeSet,
);
const features = getFeatureReport(font, unicodeSet);
return {
file: {
size: input.byteLength,
Expand All @@ -35,5 +39,19 @@ export const FontAnalyze = async (
unicode: unicodeReport,
/** 各大标准字符集检测 */
standard,
/** opentype feature 的替换表 */
features,
/** 将文本绘制成图片 */
drawTextToSVG(
text: string,
x: number,
y: number,
fontSize: number,
options?: RenderOptions,
) {
return font
.getPaths(text, x, y, fontSize, options)
.map((i) => i.toSVG(1));
},
};
};
12 changes: 5 additions & 7 deletions packages/subsets/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# 中文 Web Font 切割工具

![updateTime](https://img.shields.io/badge/更新时间-2023/11/4-green)
![updateTime](https://img.shields.io/badge/更新时间-2023/12/18-green)
![author](https://img.shields.io/badge/author-江夏尧-green)
![npmVersion](https://img.shields.io/badge/LTS_version-4.10.5-green)
![npmVersion](https://img.shields.io/badge/LTS_version-4.11.0-green)
[![](https://data.jsdelivr.com/v1/package/npm/@konghayao/cn-font-split/badge)](https://www.jsdelivr.com/package/npm/@konghayao/cn-font-split)

![CodeFactor](https://www.codefactor.io/repository/github/konghayao/cn-font-split/badge)
![NPM License](https://img.shields.io/npm/l/%40konghayao%2Fcn-font-split)
![downloadCount](https://img.shields.io/npm/dw/%40konghayao%2Fcn-font-split)

| [中文网字计划](https://chinese-font.netlify.app/) | [Github](https://github.com/KonghaYao/cn-font-split) |
| ------------------------------------------------- | ---------------------------------------------------- |
| [中文网字计划](https://chinese-font.netlify.app/) | [Github](https://github.com/KonghaYao/cn-font-split) | [在线使用](https://chinese-font.netlify.app/online-split/)|
| ------------------------------------------------- | ---------------------------------------------------- |---------------------------------------------------- |

## 简介

Expand All @@ -24,7 +22,7 @@

> 我们正在对 cn-font-split 的实战效果进行测试,并积极提升分包效果!
>
> [Opentype Feature 测试情况](/packages/test/SUPPORT_FEATURE.md) 支持 100 | 部分支持 4| 等待测试 39
> [Opentype Feature 测试情况](/packages/test/SUPPORT_FEATURE.md) 支持 95 | 部分支持 9| 等待测试 20

[详见兼容性章节](#兼容性提醒)。
| [Nodejs](#nodejs) | [Deno](#deno) | [Chrome](#browser) | [FireFox](#browser) | [Safari](#browser) | [Bun](#bun) |
Expand Down
Loading