• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.fontManager (Font Management)
2
3The **fontManager** module provides APIs for system applications to install and uninstall third-party fonts.
4
5>  **NOTE**
6>
7>  - 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.
8>
9>  - This topic describes only the system APIs provided by the module.
10
11## Modules to Import
12
13```js
14import { fontManager } from '@kit.LocalizationKit';
15```
16
17### installFont<sup>19+</sup>
18
19installFont(path: string): Promise&lt;number&gt;
20
21Installs a font in the specified path. This API uses a promise to return the result.
22
23**Required permissions**: ohos.permission.UPDATE_FONT
24
25**System capability**: SystemCapability.Global.FontManager
26
27**Parameters**
28
29| Name  | Type    | Mandatory  | Description   |
30| ----- | ------ | ---- | ----- |
31| path | string | Yes   | Path of the font file to be installed.|
32
33**Return value**
34
35| Type                   | Description                    |
36| --------------------- | ---------------------- |
37| Promise&lt;number&gt; | 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.|
38
39**Error codes**
40
41For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Resource Manager Error Codes](errorcode-resource-manager.md).
42
43| ID| Error Message|
44| -------- | ---------------------------------------- |
45| 201 | Permission denied.                 |
46| 202 | Non-system application.            |
47| 31100101 | Font does not exist.          |
48| 31100102 | Font is not supported.        |
49| 31100103 | Font file copy failed.        |
50| 31100104 | Font file installed.          |
51| 31100105 | Exceeded maximum number of installed files.     |
52| 31100106 | Other error.     |
53
54**Example:**
55  ```ts
56  import { fontManager } from '@kit.LocalizationKit';
57
58  async installFont() {
59    try {
60      let res = await fontManager.installFont('fontPath');
61      console.info('installFont suc. res is ' + res);
62    } catch (error) {
63      console.error('installFont err.' + error.code);
64    }
65    return;
66  }
67  ```
68
69### uninstallFont<sup>19+</sup>
70
71uninstallFont(fullName: string): Promise&lt;number&gt;
72
73Uninstalls a font by name. This API uses a promise to return the result.
74
75**Required permissions**: ohos.permission.UPDATE_FONT
76
77**System capability**: SystemCapability.Global.FontManager
78
79**Parameters**
80
81| Name  | Type    | Mandatory  | Description   |
82| ----- | ------ | ---- | ----- |
83| fullName | string | Yes   | Name of the font to be uninstalled. You can obtain the font name by opening the **.ttf** or **.ttc** font file.|
84
85**Return value**
86
87| Type                   | Description                    |
88| --------------------- | ---------------------- |
89| Promise&lt;number&gt; | 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.|
90
91**Error codes**
92
93For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Resource Manager Error Codes](errorcode-resource-manager.md).
94
95| ID| Error Message|
96| -------- | ---------------------------------------- |
97| 201 | Permission denied.                |
98| 202 | Non-system application.           |
99| 31100107 | Font file does not exist.    |
100| 31100108 | Font file delete error.      |
101| 31100109 | Other error.                 |
102
103**Example:**
104  ```ts
105  import { fontManager } from '@kit.LocalizationKit';
106
107  async uninstallFont() {
108    try {
109      let res = await fontManager.uninstallFont('fontName');
110      console.info('uninstallFont suc. res is ' + res);
111    } catch (error) {
112      console.error('uninstallFont err.' + error.code);
113    }
114    return;
115  }
116  ```
117