• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.font (Custom Font Registration)
2
3The **font** module provides APIs for registering custom fonts.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import font from '@ohos.font'
13```
14
15## font.registerFont
16
17registerFont(options: FontOptions): void
18
19Registers a custom font with the font manager.
20
21**System capability**: SystemCapability.ArkUI.ArkUI.Full
22
23**Parameters**
24
25| Name    | Type                         | Mandatory  | Description         |
26| ------- | --------------------------- | ---- | ----------- |
27| options | [FontOptions](#fontoptions) | Yes   | Information about the custom font to register.|
28
29## FontOptions
30
31| Name        | Type    | Mandatory  | Description          |
32| ---------- | ------ | ---- | ------------ |
33| familyName | string | Yes   | Name of the custom font to register.  |
34| familySrc  | string | Yes   | Path of the custom font to register.|
35
36## Example
37
38```ts
39// xxx.ets
40import font from '@ohos.font';
41
42@Entry
43@Component
44struct FontExample {
45  @State message: string =' Hello, World'
46
47  aboutToAppear() {
48    font.registerFont({
49      familyName: 'medium',
50      familySrc: '/font/medium.ttf'
51    })
52  }
53
54  build() {
55    Column() {
56      Text(this.message)
57        .align(Alignment.Center)
58        .fontSize(20)
59        .fontFamily('medium') // medium: name of the custom font to register.
60        .height('100%')
61    }.width('100%')
62  }
63}
64```
65