harmony 鸿蒙@ohos.fontManager (Font Management)

  • 2025-06-12
  • 浏览 (4)

@ohos.fontManager (Font Management)

The fontManager module provides APIs for system applications to install and uninstall third-party fonts.

NOTE

  • The initial APIs of this module are supported since API version 19. Newly added APIs will be marked with a superscript to indicate their earliest API version.

  • This topic describes only the system APIs provided by the module.

Modules to Import

import { fontManager } from '@kit.LocalizationKit';

installFont19+

installFont(path: string): Promise<number>

Installs a font in the specified path. This API uses a promise to return the result.

Required permissions: ohos.permission.UPDATE_FONT

System capability: SystemCapability.Global.FontManager

Parameters

Name Type Mandatory Description
path string Yes Path of the font file to be installed.

Return value

Type Description
Promise<number> Promise used to return the result. The value 0 indicates that the installation is successful, and any other value indicates that the installation has failed.

Error codes

For details about the error codes, see Universal Error Codes and Resource Manager Error Codes.

ID Error Message
201 Permission denied.
202 Non-system application.
31100101 Font does not exist.
31100102 Font is not supported.
31100103 Font file copy failed.
31100104 Font file installed.
31100105 Exceeded maximum number of installed files.
31100106 Other error.

Example:

  import { fontManager } from '@kit.LocalizationKit';

  async installFont() {
    try {
      let res = await fontManager.installFont('fontPath');
      console.info('installFont suc. res is ' + res);
    } catch (error) {
      console.error('installFont err.' + error.code);
    }
    return;
  }

uninstallFont19+

uninstallFont(fullName: string): Promise<number>

Uninstalls a font by name. This API uses a promise to return the result.

Required permissions: ohos.permission.UPDATE_FONT

System capability: SystemCapability.Global.FontManager

Parameters

Name Type Mandatory Description
fullName string Yes Name of the font to be uninstalled. You can obtain the font name by opening the .ttf or .ttc font file.

Return value

Type Description
Promise<number> Promise used to return the result. The value 0 indicates that the uninstallation is successful, and any other value indicates that the uninstallation has failed.

Error codes

For details about the error codes, see Universal Error Codes and Resource Manager Error Codes.

ID Error Message
201 Permission denied.
202 Non-system application.
31100107 Font file does not exist.
31100108 Font file delete error.
31100109 Other error.

Example:

  import { fontManager } from '@kit.LocalizationKit';

  async uninstallFont() {
    try {
      let res = await fontManager.uninstallFont('fontName');
      console.info('uninstallFont suc. res is ' + res);
    } catch (error) {
      console.error('uninstallFont err.' + error.code);
    }
    return;
  }

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Localization Kit

harmony 鸿蒙RawFileDescriptor

harmony 鸿蒙RawFileDescriptor64

harmony 鸿蒙ResourceManager_Configuration

harmony 鸿蒙Font Management Error Codes

harmony 鸿蒙I18N Error Codes

harmony 鸿蒙Resource Manager Error Codes

harmony 鸿蒙@ohos.i18n (Internationalization) (System API)

harmony 鸿蒙@ohos.i18n (Internationalization)

harmony 鸿蒙@ohos.intl (Internationalization)

0  赞