目录

How do I register custom fonts? How do I obtain font resources from the storage path?

To use custom fonts in your project: Store the custom font files in the project directory, register the fonts using the registerFont API in the code, and use the fontFamily attribute in the text component to reference the custom font.

To reference custom font resources, the $rawfile mode is recommended. The resources must be stored in the resources/rawfile directory.

To obtain font resources, refer to the following sample code:

this.getUIContext().getFont().registerFont({
  familyName: 'Gealova',
  familySrc: $rawfile('font/gealova.otf')
})

Reference

@ohos.font (Custom Font Registration)