-
Notifications
You must be signed in to change notification settings - Fork 14
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 #360 from galacean/dev
Merge origin/dev into origin/main
- Loading branch information
Showing
9 changed files
with
83 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* 判断是否为可解析的字体 | ||
* - 首字母不能为数字或 `.` | ||
* - 不能包含特殊字符,`_-` 是被允许的 | ||
* @param fontFamily - 字体名称 | ||
* @returns | ||
*/ | ||
export function isValidFontFamily (fontFamily: string): boolean { | ||
// iOS 11/12 不支持自定义字体开头为数字的名称,特殊字符也有风险 | ||
return /^[^\d.][\w-]*$/.test(fontFamily); | ||
} |
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,35 @@ | ||
import { isValidFontFamily } from '@galacean/effects'; | ||
|
||
const { expect } = chai; | ||
|
||
describe('isValidFontFamily 判断是否合法字体名称', () => { | ||
it('合法的字体名称', () => { | ||
expect(isValidFontFamily('_BDFZ_FZZeBrach-Regular')).eq(true); | ||
expect(isValidFontFamily('_BDFZ_FZZeBrach88-Regular')).eq(true); | ||
expect(isValidFontFamily('FZZeBrach')).eq(true); | ||
}); | ||
it('首字母不能为数字或.', () => { | ||
expect(isValidFontFamily('200_BDFZ_FZZeBrach-Regular')).eq(false); | ||
expect(isValidFontFamily('._BDFZ_FZZeBrach-Regular')).eq(false); | ||
expect(isValidFontFamily('.01_BDFZ_FZZeBrach-Regular')).eq(false); | ||
expect(isValidFontFamily('.')).eq(false); | ||
expect(isValidFontFamily('01')).eq(false); | ||
}); | ||
it('不能包含特殊字符', () => { | ||
expect(isValidFontFamily('BDFZ_FZZeB@rach-Regular')).eq(false); | ||
expect(isValidFontFamily('BDFZ_FZZeB??rach-Regular')).eq(false); | ||
expect(isValidFontFamily('BDFZ_FZZeB.rach-Regular')).eq(false); | ||
expect(isValidFontFamily('_BD!FZ_FZZeBrach-Regular')).eq(false); | ||
expect(isValidFontFamily('_BD::FZ_FZZeBrach-Regular')).eq(false); | ||
expect(isValidFontFamily('_BD<01>_FZZeBrach-Regular')).eq(false); | ||
expect(isValidFontFamily('1 ?2@3')).eq(false); | ||
expect(isValidFontFamily('1?2@3')).eq(false); | ||
expect(isValidFontFamily('r1<23')).eq(false); | ||
expect(isValidFontFamily('x1|2|3')).eq(false); | ||
expect(isValidFontFamily('??qg?e_ewe')).eq(false); | ||
expect(isValidFontFamily('qge_ew\'e')).eq(false); | ||
expect(isValidFontFamily('qge_e$we')).eq(false); | ||
expect(isValidFontFamily('2.00;BDFZ;FZZeBrach-Regular;2000; FLVI-612')).eq(false); | ||
expect(isValidFontFamily('2.00;BDFZ;FZZeBrach-Regular;2000;FL720')).eq(false); | ||
}); | ||
}); |