openharmony 鸿蒙 js-apis-font-manager-sys

2025-06-16 浏览 (1)

@ohos.fontManager (字体管理)

字体管理模块,提供给系统应用安装和卸载三方字体的能力。

说明:

  • 本模块首批接口从API version 19开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

  • 当前页面仅包含本模块的系统接口。

导入模块

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

installFont19+

installFont(path: string): Promise<number>

安装指定路径下的字体,使用promise异步回调。

需要权限: ohos.permission.UPDATE_FONT

系统能力: SystemCapability.Global.FontManager

参数:

参数名类型必填说明
pathstring安装字体文件路径。

返回值:

类型说明
Promise<number>返回安装结果。返回为0表示安装成功,否则安装失败。

错误码:

以下错误码的详细介绍请参见通用错误码资源管理错误码

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

示例:

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>

卸载指定名称的字体,使用promise异步回调。

需要权限: ohos.permission.UPDATE_FONT

系统能力: SystemCapability.Global.FontManager

参数:

参数名类型必填说明
fullNamestring需要卸载的字体名称,字体名称可通过打开.ttf或.ttc字体文件获取。

返回值:

类型说明
Promise<number>返回卸载结果。返回为0表示卸载成功,否则卸载失败。

错误码:

以下错误码的详细介绍请参见通用错误码资源管理错误码

错误码ID错误信息
201Permission denied.
202Non-system application.
31100107Font file does not exist.
31100108Font file delete error.
31100109Other error.

示例:

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 鸿蒙字体管理错误码

harmony 鸿蒙I18n错误码

harmony 鸿蒙资源管理错误码

harmony 鸿蒙@ohos.i18n (国际化-I18n)(系统接口)

harmony 鸿蒙@ohos.i18n (国际化-I18n)

harmony 鸿蒙@ohos.intl (国际化-Intl)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/CwWcUn