HarmonyOS 如何获取用户设备系统字体信息?

HarmonyOS 如何获取用户设备系统字体信息?

HarmonyOS
2024-10-24 12:46:59
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

支持的字体库可以通过 镜像的 /system/fonts 路径查看。

此外可以通过getSystemFontList()获取系统支持的字体名称列表。 参考:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-font-V5#fontgetsystemfontlist10

【参考demo】:

// xxx.ets

import font from '@ohos.font';  
@Entry  
@Component  
struct FontExample {  
  build() {  
    Column() {  
      Button("getUIFontConfig")  
        .width('60%')  
        .height('6%')  
        .margin(50)  
        .onClick(()=>{  
          let fontConfig = font.getUIFontConfig();  
          console.log("font-dir -----------" + String(fontConfig.fontDir.length));  
          for (let i = 0; i < fontConfig.fontDir.length; i ++) {  
            console.log(fontConfig.fontDir[i]);  
          }  
          console.log("generic-------------" + String(fontConfig.generic.length));  
          for (let i = 0; i < fontConfig.generic.length; i ++){  
            console.log("family:" + fontConfig.generic[i].family);  
            for (let j = 0; j < fontConfig.generic[i].alias.length; j ++){  
              console.log(fontConfig.generic[i].alias[j].name + " " + fontConfig.generic[i].alias[j].weight);  
            }  
            for (let j = 0; j < fontConfig.generic[i].adjust.length; j ++){  
              console.log(fontConfig.generic[i].adjust[j].weight + " " + fontConfig.generic[i].adjust[j].to);  
            }  
          }  
          console.log("fallback------------" + String(fontConfig.fallbackGroups.length));  
          for (let i = 0; i < fontConfig.fallbackGroups.length; i ++){  
            console.log("fontSetName:" + fontConfig.fallbackGroups[i].fontSetName);  
            for (let j = 0; j < fontConfig.fallbackGroups[i].fallback.length; j ++){  
              console.log("language:" + fontConfig.fallbackGroups[i].fallback[j].language + " family:" + fontConfig.fallbackGroups[i].fallback[j].family);  
            }  
          }  
        })  
    }.width('100%')  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
分享
微博
QQ
微信
回复
2024-10-24 15:27:24


相关问题
HarmonyOS如何获取用户相册所有目录?
2680浏览 • 1回复 待解决
HarmonyOS 如何获取用户所在省市区?
1267浏览 • 1回复 待解决
HarmonyOS 获取用户的步数
767浏览 • 2回复 待解决
使用Account Kit 获取用户头像昵称
800浏览 • 1回复 待解决
如何获取设备相关信息
2398浏览 • 1回复 待解决
HarmonyOS 应用如何获取设备信息
611浏览 • 1回复 待解决
取消Account Kit 获取用户头像昵称授权
993浏览 • 1回复 待解决
HarmonyOS 如何获取对应的设备信息
247浏览 • 1回复 待解决
如何获取设备的CPU信息
2988浏览 • 1回复 待解决
HarmonyOS RN侧如何获取HarmonyOS设备信息
551浏览 • 1回复 待解决
HarmonyOS如何获取规范格式的设备信息
777浏览 • 1回复 待解决