feat: support system fallback fonts#248
Open
labbbirder wants to merge 2 commits intofairygui:masterfrom
Open
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
特性介绍
使用TMP字体时,如果字形找不到,则从本机系统字体中查找并渲染,类似
Dynamic OS。已在以下平台通过测试:
效果对比
当输入“风调雨顺 龙行龘龘 前程朤朤”时
应用此特性前:


应用此特性后:
红色框选区域为使用系统字渲染的结果
实现方式
在UIConfig中指定systemFontFamily,默认已经提供了常用的系统字,覆盖Windows、Android、iOS。参数中可以指定多个字体名,使用逗号、分号或换行符分割。
每个字体名优先匹配
FamilyName+SubfamilyName(StyleName)(注意不是FullName),再匹配FamilyName。如:Microsoft YaHei能匹配任意样式的微软雅黑(通常匹配结果为Regular),Microsoft YaHei Bold能匹配加粗的微软雅黑。内部机制
引用的系统字不会嵌入到安装包中,因此能有效减少包体大小,并且有更低的字体侵权风险。
运行时,当一个字形无法识别时,从第一个匹配的系统字体路径开始尝试,如果系统字体未加载,则先加载系统字体资源,如果系统字体成功识别了字符,则结束查找,后续列表中的系统字体不会继续载入到内存中。
限制
WebGL平台无法应用此特性,鉴于WebGL受限的文件系统,系统字体的查找和加载环境支持不足。值得一提的是,使用
queryLocalFonts时,存在两个问题:参考
https://learn.microsoft.com/en-us/typography/opentype/spec/
https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html
https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
https://docs.unity3d.com/2022.3/Documentation/Manual/class-Font.html
https://wicg.github.io/local-font-access