Skip to content

Conversation

@kevingpqi123
Copy link
Collaborator

  • Add API version check using deviceInfo.sdkApiVersion
  • For API14+: use new text.getSystemFontFullNamesByType() and text.getFontDescriptorByFullName() APIs
  • Fallback to legacy font.getUIFontConfig() API if new API fails or on lower API versions
  • Add null checks for fontConfig and fallbackGroups
  • Fix paths.concat() bug (missing assignment)

Related: #3232

- Add API version check using deviceInfo.sdkApiVersion
- For API14+: use new text.getSystemFontFullNamesByType() and text.getFontDescriptorByFullName() APIs
- Fallback to legacy font.getUIFontConfig() API if new API fails or on lower API versions
- Add null checks for fontConfig and fallbackGroups
- Fix paths.concat() bug (missing assignment)

Related: #3232
@codecov-commenter
Copy link

codecov-commenter commented Jan 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.02%. Comparing base (d836825) to head (f6afdf9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3238      +/-   ##
==========================================
- Coverage   77.04%   77.02%   -0.03%     
==========================================
  Files         413      413              
  Lines       21922    21922              
  Branches     6298     6298              
==========================================
- Hits        16890    16885       -5     
- Misses       3821     3825       +4     
- Partials     1211     1212       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

let fontDescriptor = await text.getFontDescriptorByFullName(fontName, text.SystemFontType.ALL);
if (fontDescriptor && fontDescriptor.path) {
paths.push(fontDescriptor.path);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

性能优化建议:当前串行 await 每个字体描述符,系统字体较多时初始化会较慢。建议使用 Promise.all() 并行获取:

let descriptors = await Promise.all(fontNames.map(fontName =>
  text.getFontDescriptorByFullName(fontName, text.SystemFontType.ALL)
));
let paths = descriptors
  .filter(d => d && d.path)
  .map(d => d.path);

try {
let fontNames: string[] = await text.getSystemFontFullNamesByType(text.SystemFontType.ALL);
if (fontNames && fontNames.length > 0) {
let paths = new Array<string>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码简化建议:使用字面量初始化更简洁,如 let paths: string[] = [];

for (let fontName of fontNames) {
let fontDescriptor = await text.getFontDescriptorByFullName(fontName, text.SystemFontType.ALL);
if (fontDescriptor && fontDescriptor.path) {
paths.push(fontDescriptor.path);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

潜在风险:同一字体路径可能被多次添加(如同一字体在不同 fallbackGroup 出现),建议考虑去重处理。

Copy link
Collaborator

@domchen domchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@domchen domchen merged commit 9a09287 into main Jan 29, 2026
9 checks passed
@domchen domchen deleted the bugfix/ohos_font_fallback_crash branch January 29, 2026 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants