1e41f4b71Sopenharmony_ci# @ohos.font (注册自定义字体) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci本模块提供注册自定义字体。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> 本模块功能依赖UI的执行上下文,不可在UI上下文不明确的地方使用,参见[UIContext](./js-apis-arkui-UIContext.md#uicontext)说明。 10e41f4b71Sopenharmony_ci> 11e41f4b71Sopenharmony_ci> 从API version 10开始,可以通过使用[UIContext](./js-apis-arkui-UIContext.md#uicontext)中的[getFont](./js-apis-arkui-UIContext.md#getfont)方法获取当前UI上下文关联的[Font](./js-apis-arkui-UIContext.md#font)对象。 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## 导入模块 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci```ts 16e41f4b71Sopenharmony_ciimport { font } from '@kit.ArkUI' 17e41f4b71Sopenharmony_ci``` 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## font.registerFont 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciregisterFont(options: FontOptions): void 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci在字体管理中注册自定义字体。 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**参数:** 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 32e41f4b71Sopenharmony_ci| ------- | --------------------------- | ---- | ----------- | 33e41f4b71Sopenharmony_ci| options | [FontOptions](#fontoptions) | 是 | 注册的自定义字体信息。 | 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci## FontOptions 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 42e41f4b71Sopenharmony_ci| ---------- | ------ | ---- | ------------ | 43e41f4b71Sopenharmony_ci| familyName | string\| [Resource](arkui-ts/ts-types.md#resource)<sup>10+</sup> | 是 | 设置注册的字体名称。 | 44e41f4b71Sopenharmony_ci| familySrc | string\| [Resource](arkui-ts/ts-types.md#resource)<sup>10+</sup> | 是 | 设置注册字体文件的路径。 | 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci**示例:** 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci> **说明** 49e41f4b71Sopenharmony_ci> 50e41f4b71Sopenharmony_ci> 推荐通过使用[UIContext](./js-apis-arkui-UIContext.md#uicontext)中的[getFont](./js-apis-arkui-UIContext.md#getfont)方法获取当前UI上下文关联的[Font](./js-apis-arkui-UIContext.md#font)对象。 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci```ts 53e41f4b71Sopenharmony_ci// xxx.ets 54e41f4b71Sopenharmony_ciimport { font } from '@kit.ArkUI'; 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci@Entry 57e41f4b71Sopenharmony_ci@Component 58e41f4b71Sopenharmony_cistruct FontExample { 59e41f4b71Sopenharmony_ci @State message: string = 'Hello World' 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci // iconFont示例,假设0000为指定icon的Unicode,实际需要开发者从注册的iconFont的ttf文件里面获取Unicode 62e41f4b71Sopenharmony_ci @State unicode: string = '\u0000' 63e41f4b71Sopenharmony_ci @State codePoint: string = String.fromCharCode(0x0000) 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci aboutToAppear() { 66e41f4b71Sopenharmony_ci // familyName和familySrc都支持系统Resource 67e41f4b71Sopenharmony_ci font.registerFont({ // 建议使用 this.getUIContext().getFont().registerFont()接口 68e41f4b71Sopenharmony_ci familyName: $r('app.string.font_name'), 69e41f4b71Sopenharmony_ci familySrc: $r('app.string.font_src') 70e41f4b71Sopenharmony_ci }) 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci // familySrc支持RawFile 73e41f4b71Sopenharmony_ci font.registerFont({ 74e41f4b71Sopenharmony_ci familyName: 'mediumRawFile', 75e41f4b71Sopenharmony_ci familySrc: $rawfile('font/medium.ttf') 76e41f4b71Sopenharmony_ci }) 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci // 注册iconFont 79e41f4b71Sopenharmony_ci font.registerFont({ 80e41f4b71Sopenharmony_ci familyName: 'iconFont', 81e41f4b71Sopenharmony_ci familySrc: '/font/iconFont.ttf' 82e41f4b71Sopenharmony_ci }) 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci // familyName和familySrc都支持string 85e41f4b71Sopenharmony_ci font.registerFont({ 86e41f4b71Sopenharmony_ci familyName: 'medium', 87e41f4b71Sopenharmony_ci familySrc: '/font/medium.ttf' // font文件夹与pages目录同级 88e41f4b71Sopenharmony_ci }) 89e41f4b71Sopenharmony_ci } 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci build() { 92e41f4b71Sopenharmony_ci Column() { 93e41f4b71Sopenharmony_ci Text(this.message) 94e41f4b71Sopenharmony_ci .align(Alignment.Center) 95e41f4b71Sopenharmony_ci .fontSize(20) 96e41f4b71Sopenharmony_ci .fontFamily('medium') // medium:注册自定义字体的名字($r('app.string.mediumFamilyName')、'mediumRawFile'等已注册字体也能正常使用) 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci // 使用iconFont的两种方式 99e41f4b71Sopenharmony_ci Text(this.unicode) 100e41f4b71Sopenharmony_ci .align(Alignment.Center) 101e41f4b71Sopenharmony_ci .fontSize(20) 102e41f4b71Sopenharmony_ci .fontFamily('iconFont') 103e41f4b71Sopenharmony_ci Text(this.codePoint) 104e41f4b71Sopenharmony_ci .align(Alignment.Center) 105e41f4b71Sopenharmony_ci .fontSize(20) 106e41f4b71Sopenharmony_ci .fontFamily('iconFont') 107e41f4b71Sopenharmony_ci }.width('100%') 108e41f4b71Sopenharmony_ci } 109e41f4b71Sopenharmony_ci} 110e41f4b71Sopenharmony_ci``` 111e41f4b71Sopenharmony_ci> **说明:** 112e41f4b71Sopenharmony_ci> 113e41f4b71Sopenharmony_ci> 应用若需全局使用自定义字体,请在EntryAbility.ets文件的[onWindowStageCreate](../apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate)生命周期中,通过[windowStage.loadContent](js-apis-window.md#loadcontent9)回调注册。 114e41f4b71Sopenharmony_ci> 115e41f4b71Sopenharmony_ci> 在HSP工程中,不推荐采用相对路径的方式注册自定义字体,详见[HSP资源引用](../../quick-start/in-app-hsp.md#通过$r访问hsp中的资源)。 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci## font.getSystemFontList<sup>10+</sup> 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_cigetSystemFontList(): Array\<string> 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci获取风格字体列表。 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci**返回值:** 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci| 类型 | 说明 | 130e41f4b71Sopenharmony_ci| -------------------- | ----------------- | 131e41f4b71Sopenharmony_ci| Array\<string> | 系统的字体名列表。 | 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci> **说明:** 134e41f4b71Sopenharmony_ci> 135e41f4b71Sopenharmony_ci> 该接口仅在2in1设备上生效。 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci**示例:** 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci> **说明** 140e41f4b71Sopenharmony_ci> 141e41f4b71Sopenharmony_ci> 推荐通过使用[UIContext](./js-apis-arkui-UIContext.md#uicontext)中的[getFont](./js-apis-arkui-UIContext.md#getfont)方法获取当前UI上下文关联的[Font](./js-apis-arkui-UIContext.md#font)对象。 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci```ts 144e41f4b71Sopenharmony_ci// xxx.ets 145e41f4b71Sopenharmony_ciimport { font } from '@kit.ArkUI'; 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci@Entry 148e41f4b71Sopenharmony_ci@Component 149e41f4b71Sopenharmony_cistruct FontExample { 150e41f4b71Sopenharmony_ci fontList: Array<string> = new Array<string>(); 151e41f4b71Sopenharmony_ci build() { 152e41f4b71Sopenharmony_ci Column() { 153e41f4b71Sopenharmony_ci Button("getSystemFontList") 154e41f4b71Sopenharmony_ci .width('60%') 155e41f4b71Sopenharmony_ci .height('6%') 156e41f4b71Sopenharmony_ci .onClick(()=>{ 157e41f4b71Sopenharmony_ci this.fontList = font.getSystemFontList() // 建议使用 this.getUIContext().getFont().getSystemFontList()接口 158e41f4b71Sopenharmony_ci }) 159e41f4b71Sopenharmony_ci }.width('100%') 160e41f4b71Sopenharmony_ci } 161e41f4b71Sopenharmony_ci} 162e41f4b71Sopenharmony_ci``` 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci## font.getFontByName<sup>10+</sup> 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_cigetFontByName(fontName: string): FontInfo 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci根据传入的系统字体名称获取系统字体的相关信息。 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci**参数:** 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 177e41f4b71Sopenharmony_ci| ---------- | --------- | ------- | ------------ | 178e41f4b71Sopenharmony_ci| fontName | string | 是 | 系统的字体名。 | 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci**返回值:** 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci| 类型 | 说明 | 183e41f4b71Sopenharmony_ci| ---------------- | ---------------------------- | 184e41f4b71Sopenharmony_ci| FontInfo | 字体的详细信息。 | 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci## FontInfo<sup>10+</sup> 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 193e41f4b71Sopenharmony_ci| -------------- | ------- | ------------------------- | ------------------------- | 194e41f4b71Sopenharmony_ci| path | string | 是 | 系统字体的文件路径。 | 195e41f4b71Sopenharmony_ci| postScriptName | string | 是 | 系统字体的postScript名称。 | 196e41f4b71Sopenharmony_ci| fullName | string | 是 | 系统字体的名称。 | 197e41f4b71Sopenharmony_ci| family | string | 是 | 系统字体的字体家族。 | 198e41f4b71Sopenharmony_ci| subfamily | string | 是 | 系统字体的子字体家族。 | 199e41f4b71Sopenharmony_ci| weight | number | 是 | 系统字体的粗细程度,单位px。 | 200e41f4b71Sopenharmony_ci| width | number | 是 | 系统字体的宽窄风格属性,单位px。 | 201e41f4b71Sopenharmony_ci| italic | boolean | 是 | 系统字体是否倾斜。 | 202e41f4b71Sopenharmony_ci| monoSpace | boolean | 是 | 系统字体是否紧凑。 | 203e41f4b71Sopenharmony_ci| symbolic | boolean | 是 | 系统字体是否支持符号字体。 | 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci**示例:** 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci> **说明** 208e41f4b71Sopenharmony_ci> 209e41f4b71Sopenharmony_ci> 推荐通过使用[UIContext](./js-apis-arkui-UIContext.md#uicontext)中的[getFont](./js-apis-arkui-UIContext.md#getfont)方法获取当前UI上下文关联的[Font](./js-apis-arkui-UIContext.md#font)对象。 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci```ts 212e41f4b71Sopenharmony_ci// xxx.ets 213e41f4b71Sopenharmony_ciimport { font } from '@kit.ArkUI'; 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci@Entry 216e41f4b71Sopenharmony_ci@Component 217e41f4b71Sopenharmony_cistruct FontExample { 218e41f4b71Sopenharmony_ci fontList: Array<string> = new Array<string>(); 219e41f4b71Sopenharmony_ci fontInfo: font.FontInfo = font.getFontByName(''); 220e41f4b71Sopenharmony_ci build() { 221e41f4b71Sopenharmony_ci Column() { 222e41f4b71Sopenharmony_ci Button("getFontByName") 223e41f4b71Sopenharmony_ci .onClick(() => { 224e41f4b71Sopenharmony_ci this.fontInfo = font.getFontByName('HarmonyOS Sans Italic') // 建议使用 this.getUIContext().getFont().getFontByName()接口 225e41f4b71Sopenharmony_ci console.log("getFontByName(): path = " + this.fontInfo.path) 226e41f4b71Sopenharmony_ci console.log("getFontByName(): postScriptName = " + this.fontInfo.postScriptName) 227e41f4b71Sopenharmony_ci console.log("getFontByName(): fullName = " + this.fontInfo.fullName) 228e41f4b71Sopenharmony_ci console.log("getFontByName(): Family = " + this.fontInfo.family) 229e41f4b71Sopenharmony_ci console.log("getFontByName(): Subfamily = " + this.fontInfo.subfamily) 230e41f4b71Sopenharmony_ci console.log("getFontByName(): weight = " + this.fontInfo.weight) 231e41f4b71Sopenharmony_ci console.log("getFontByName(): width = " + this.fontInfo.width) 232e41f4b71Sopenharmony_ci console.log("getFontByName(): italic = " + this.fontInfo.italic) 233e41f4b71Sopenharmony_ci console.log("getFontByName(): monoSpace = " + this.fontInfo.monoSpace) 234e41f4b71Sopenharmony_ci console.log("getFontByName(): symbolic = " + this.fontInfo.symbolic) 235e41f4b71Sopenharmony_ci }) 236e41f4b71Sopenharmony_ci }.width('100%') 237e41f4b71Sopenharmony_ci } 238e41f4b71Sopenharmony_ci} 239e41f4b71Sopenharmony_ci``` 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci## font.getUIFontConfig<sup>11+</sup> 242e41f4b71Sopenharmony_cigetUIFontConfig() : UIFontConfig 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci获取系统的UI字体配置。 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci**返回值:** 251e41f4b71Sopenharmony_ci| 类型 | 说明 | 252e41f4b71Sopenharmony_ci| ---------------- | ---------------------------- | 253e41f4b71Sopenharmony_ci| [UIFontConfig](#uifontconfig11) | 系统的UI字体配置信息。 | 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci## UIFontConfig<sup>11+</sup> 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 260e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 261e41f4b71Sopenharmony_ci| -------------- | ------- | ------------------------- | ------------------------- | 262e41f4b71Sopenharmony_ci| fontDir | Array\<string> | 是 | 系统字体文件所在的路径。 | 263e41f4b71Sopenharmony_ci| generic | Array\<[UIFontGenericInfo](#uifontgenericinfo11)> | 是 | 系统所支持的通用字体集列表。 | 264e41f4b71Sopenharmony_ci| fallbackGroups | Array\<[UIFontFallbackGroupInfo](#uifontfallbackgroupinfo11)> | 是 | 备用字体集。 | 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci## UIFontGenericInfo<sup>11+</sup> 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 271e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 272e41f4b71Sopenharmony_ci| -------------- | ------- | ------------------------- | ------------------------- | 273e41f4b71Sopenharmony_ci| family | string | 是 | 字体集名,字体文件中指定的"family"值。 | 274e41f4b71Sopenharmony_ci| alias | Array\<[UIFontAliasInfo](#uifontaliasinfo11)> | 是 | 别名列表。 | 275e41f4b71Sopenharmony_ci| adjust | Array\<[UIFontAdjustInfo](#uifontadjustinfo11)> | 是 | 字体原本的weight值对应需显示的值。 | 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci## UIFontFallbackGroupInfo<sup>11+</sup> 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 282e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 283e41f4b71Sopenharmony_ci| -------------- | ------- | ------------------------- | ------------------------- | 284e41f4b71Sopenharmony_ci| fontSetName | string | 是 | 备用字体集所对应的字体集名称。 | 285e41f4b71Sopenharmony_ci| fallback | Array\<[UIFontFallbackInfo](#uifontfallbackinfo11)> | 是 | 表示以下列表为该字体集的备用字体,如果fontSetName为"",表示可以作为所有字体集的备用字体。 | 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_ci## UIFontAliasInfo<sup>11+</sup> 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 292e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 293e41f4b71Sopenharmony_ci| -------------- | ------- | ------------------------- | ------------------------- | 294e41f4b71Sopenharmony_ci| name | string | 是 | 别名名称。 | 295e41f4b71Sopenharmony_ci| weight | number | 是 | 当weight>0时表示此字体集只包含所指定weight的字体,当weight=0时,表示此字体集包含所有字体。 | 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci## UIFontAdjustInfo<sup>11+</sup> 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 302e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 303e41f4b71Sopenharmony_ci| -------------- | ------- | ------------------------- | ------------------------- | 304e41f4b71Sopenharmony_ci| weight | number | 是 | 字体原本的weight值。 | 305e41f4b71Sopenharmony_ci| to | number | 是 | 字体在应用中显示的weight值。 | 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci## UIFontFallbackInfo<sup>11+</sup> 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 312e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 313e41f4b71Sopenharmony_ci| -------------- | ------- | ------------------------- | ------------------------- | 314e41f4b71Sopenharmony_ci| language | string | 是 | 字体集所支持的语言类型,语言格式为bcp47。 | 315e41f4b71Sopenharmony_ci| family | string | 是 | 字体集名,字体文件中指定的"family"值。 | 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ci**示例:** 318e41f4b71Sopenharmony_ci 319e41f4b71Sopenharmony_ci```ts 320e41f4b71Sopenharmony_ci// xxx.ets 321e41f4b71Sopenharmony_ciimport { font } from '@kit.ArkUI'; 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_ci@Entry 324e41f4b71Sopenharmony_ci@Component 325e41f4b71Sopenharmony_cistruct FontExample { 326e41f4b71Sopenharmony_ci build() { 327e41f4b71Sopenharmony_ci Column() { 328e41f4b71Sopenharmony_ci Button("getUIFontConfig") 329e41f4b71Sopenharmony_ci .width('60%') 330e41f4b71Sopenharmony_ci .height('6%') 331e41f4b71Sopenharmony_ci .margin(50) 332e41f4b71Sopenharmony_ci .onClick(()=>{ 333e41f4b71Sopenharmony_ci let fontConfig = font.getUIFontConfig(); 334e41f4b71Sopenharmony_ci console.log("font-dir -----------" + String(fontConfig.fontDir.length)); 335e41f4b71Sopenharmony_ci for (let i = 0; i < fontConfig.fontDir.length; i ++) { 336e41f4b71Sopenharmony_ci console.log(fontConfig.fontDir[i]); 337e41f4b71Sopenharmony_ci } 338e41f4b71Sopenharmony_ci console.log("generic-------------" + String(fontConfig.generic.length)); 339e41f4b71Sopenharmony_ci for (let i = 0; i < fontConfig.generic.length; i ++){ 340e41f4b71Sopenharmony_ci console.log("family:" + fontConfig.generic[i].family); 341e41f4b71Sopenharmony_ci for (let j = 0; j < fontConfig.generic[i].alias.length; j ++){ 342e41f4b71Sopenharmony_ci console.log(fontConfig.generic[i].alias[j].name + " " + fontConfig.generic[i].alias[j].weight); 343e41f4b71Sopenharmony_ci } 344e41f4b71Sopenharmony_ci for (let j = 0; j < fontConfig.generic[i].adjust.length; j ++){ 345e41f4b71Sopenharmony_ci console.log(fontConfig.generic[i].adjust[j].weight + " " + fontConfig.generic[i].adjust[j].to); 346e41f4b71Sopenharmony_ci } 347e41f4b71Sopenharmony_ci } 348e41f4b71Sopenharmony_ci console.log("fallback------------" + String(fontConfig.fallbackGroups.length)); 349e41f4b71Sopenharmony_ci for (let i = 0; i < fontConfig.fallbackGroups.length; i ++){ 350e41f4b71Sopenharmony_ci console.log("fontSetName:" + fontConfig.fallbackGroups[i].fontSetName); 351e41f4b71Sopenharmony_ci for (let j = 0; j < fontConfig.fallbackGroups[i].fallback.length; j ++){ 352e41f4b71Sopenharmony_ci console.log("language:" + fontConfig.fallbackGroups[i].fallback[j].language + " family:" + fontConfig.fallbackGroups[i].fallback[j].family); 353e41f4b71Sopenharmony_ci } 354e41f4b71Sopenharmony_ci } 355e41f4b71Sopenharmony_ci }) 356e41f4b71Sopenharmony_ci }.width('100%') 357e41f4b71Sopenharmony_ci } 358e41f4b71Sopenharmony_ci} 359e41f4b71Sopenharmony_ci``` 360