• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# drawing_font_mgr.h
2<!--Kit: ArkGraphics 2D-->
3<!--Subsystem: Graphics-->
4<!--Owner: @oh_wangxk; @gmiao522; @Lem0nC-->
5<!--Designer: @liumingxiang-->
6<!--Tester: @yhl0101-->
7<!--Adviser: @ge-yafang-->
8## 概述
9
10文件中定义了与字体管理相关的功能函数,用于加载和匹配系统中可用的字体。
11
12**引用文件:** <native_drawing/drawing_font_mgr.h>
13
14**库:** libnative_drawing.so
15
16**起始版本:** 12
17
18**相关模块:** [Drawing](capi-drawing.md)
19
20## 汇总
21
22### 函数
23
24| 名称 | 描述 |
25| -- | -- |
26| [OH_Drawing_FontMgr* OH_Drawing_FontMgrCreate(void)](#oh_drawing_fontmgrcreate) | 创建字体管理对象,只支持管理系统字体。 |
27| [void OH_Drawing_FontMgrDestroy(OH_Drawing_FontMgr* drawingFontMgr)](#oh_drawing_fontmgrdestroy) | 释放字体管理对象占用的内存。 |
28| [int OH_Drawing_FontMgrGetFamilyCount(OH_Drawing_FontMgr* drawingFontMgr)](#oh_drawing_fontmgrgetfamilycount) | 获取字体家族的数量。 |
29| [char* OH_Drawing_FontMgrGetFamilyName(OH_Drawing_FontMgr* drawingFontMgr, int index)](#oh_drawing_fontmgrgetfamilyname) | 由索引值获取字体家族名称。 |
30| [void OH_Drawing_FontMgrDestroyFamilyName(char* familyName)](#oh_drawing_fontmgrdestroyfamilyname) | 释放指定字体家族名称占用的内存。 |
31| [OH_Drawing_FontStyleSet* OH_Drawing_FontMgrCreateFontStyleSet(OH_Drawing_FontMgr* drawingFontMgr, int index)](#oh_drawing_fontmgrcreatefontstyleset) | 由字体管理对象构造字体样式集对象。 |
32| [void OH_Drawing_FontMgrDestroyFontStyleSet(OH_Drawing_FontStyleSet* drawingFontStyleSet)](#oh_drawing_fontmgrdestroyfontstyleset) | 释放字体样式集对象占用的内存。 |
33| [OH_Drawing_FontStyleSet* OH_Drawing_FontMgrMatchFamily(OH_Drawing_FontMgr* drawingFontMgr, const char* familyName)](#oh_drawing_fontmgrmatchfamily) | 由指定的字体家族名称,获取字体样式集对象。 |
34| [OH_Drawing_Typeface* OH_Drawing_FontMgrMatchFamilyStyle(OH_Drawing_FontMgr* drawingFontMgr,const char* familyName, OH_Drawing_FontStyleStruct fontStyle)](#oh_drawing_fontmgrmatchfamilystyle) | 根据指定的字体样式信息和字体家族名称,获取字型对象。 |
35| [OH_Drawing_Typeface* OH_Drawing_FontMgrMatchFamilyStyleCharacter(OH_Drawing_FontMgr* drawingFontMgr,const char* familyName, OH_Drawing_FontStyleStruct fontStyle,const char* bcp47[], int bcp47Count, int32_t character)](#oh_drawing_fontmgrmatchfamilystylecharacter) | 为指定字符获取字型对象,仅在传入字体管理对象中无法找到传入UTF8字符值对应的字型对象时返回空指针。 |
36| [OH_Drawing_Typeface* OH_Drawing_FontStyleSetCreateTypeface(OH_Drawing_FontStyleSet* fontStyleSet, int index)](#oh_drawing_fontstylesetcreatetypeface) | 为指定索引获取字型对象。 |
37| [OH_Drawing_FontStyleStruct OH_Drawing_FontStyleSetGetStyle(OH_Drawing_FontStyleSet* fontStyleSet, int32_t index,char** styleName)](#oh_drawing_fontstylesetgetstyle) | 获取字体样式,styleName会申请内存,不再需要styleName时,请使用[OH_Drawing_FontStyleSetFreeStyleName](#oh_drawing_fontstylesetfreestylename)释放该对象指针。 |
38| [void OH_Drawing_FontStyleSetFreeStyleName(char** styleName)](#oh_drawing_fontstylesetfreestylename) | 释放指定字体样式名称的内存。 |
39| [OH_Drawing_Typeface* OH_Drawing_FontStyleSetMatchStyle(OH_Drawing_FontStyleSet* fontStyleSet,OH_Drawing_FontStyleStruct fontStyleStruct)](#oh_drawing_fontstylesetmatchstyle) | 获取最接近字体样式的字型对象。 |
40| [int OH_Drawing_FontStyleSetCount(OH_Drawing_FontStyleSet* fontStyleSet)](#oh_drawing_fontstylesetcount) | 获取字体样式集中字体的个数。 |
41
42## 函数说明
43
44### OH_Drawing_FontMgrCreate()
45
46```
47OH_Drawing_FontMgr* OH_Drawing_FontMgrCreate(void)
48```
49
50**描述**
51
52创建字体管理对象,只支持管理系统字体。
53
54**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
55
56**起始版本:** 12
57
58**返回:**
59
60| 类型 | 说明 |
61| -- | -- |
62| [OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)* | 返回指向已创建的字体管理对象[OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)的指针。 |
63
64### OH_Drawing_FontMgrDestroy()
65
66```
67void OH_Drawing_FontMgrDestroy(OH_Drawing_FontMgr* drawingFontMgr)
68```
69
70**描述**
71
72释放字体管理对象占用的内存。
73
74**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
75
76**起始版本:** 12
77
78
79**参数:**
80
81| 参数项 | 描述 |
82| -- | -- |
83| [OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)* drawingFontMgr | 指向字体管理对象[OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)的指针,由[OH_Drawing_FontMgrCreate](capi-drawing-font-mgr-h.md#oh_drawing_fontmgrcreate)获取。 |
84
85### OH_Drawing_FontMgrGetFamilyCount()
86
87```
88int OH_Drawing_FontMgrGetFamilyCount(OH_Drawing_FontMgr* drawingFontMgr)
89```
90
91**描述**
92
93获取字体家族的数量。
94
95**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
96
97**起始版本:** 12
98
99
100**参数:**
101
102| 参数项 | 描述 |
103| -- | -- |
104| [OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)* drawingFontMgr | 指向字体管理对象[OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)的指针,由[OH_Drawing_FontMgrCreate](capi-drawing-font-mgr-h.md#oh_drawing_fontmgrcreate)获取。 |
105
106**返回:**
107
108| 类型 | 说明 |
109| -- | -- |
110| int | 返回字体家族的数量。 |
111
112### OH_Drawing_FontMgrGetFamilyName()
113
114```
115char* OH_Drawing_FontMgrGetFamilyName(OH_Drawing_FontMgr* drawingFontMgr, int index)
116```
117
118**描述**
119
120由索引值获取字体家族名称。
121
122**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
123
124**起始版本:** 12
125
126
127**参数:**
128
129| 参数项 | 描述 |
130| -- | -- |
131| [OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)* drawingFontMgr | 指向字体管理对象[OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)的指针,由[OH_Drawing_FontMgrCreate](capi-drawing-font-mgr-h.md#oh_drawing_fontmgrcreate)获取。 |
132| int index | 用于获取对应字体家族名称的索引值。 |
133
134**返回:**
135
136| 类型 | 说明 |
137| -- | -- |
138| char* | 返回索引值对应的字体家族名称,不再需要时,请使用[OH_Drawing_FontMgrDestroyFamilyName](capi-drawing-font-mgr-h.md#oh_drawing_fontmgrdestroyfamilyname)释放该对象指针。 |
139
140### OH_Drawing_FontMgrDestroyFamilyName()
141
142```
143void OH_Drawing_FontMgrDestroyFamilyName(char* familyName)
144```
145
146**描述**
147
148释放指定字体家族名称占用的内存。
149
150**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
151
152**起始版本:** 12
153
154
155**参数:**
156
157| 参数项 | 描述 |
158| -- | -- |
159| char* familyName | 指定字体家族名称数组。 |
160
161### OH_Drawing_FontMgrCreateFontStyleSet()
162
163```
164OH_Drawing_FontStyleSet* OH_Drawing_FontMgrCreateFontStyleSet(OH_Drawing_FontMgr* drawingFontMgr, int index)
165```
166
167**描述**
168
169由字体管理对象构造字体样式集对象。
170
171**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
172
173**起始版本:** 12
174
175
176**参数:**
177
178| 参数项 | 描述 |
179| -- | -- |
180| [OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)* drawingFontMgr | 指向字体管理对象[OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)的指针,由[OH_Drawing_FontMgrCreate](capi-drawing-font-mgr-h.md#oh_drawing_fontmgrcreate)获取。 |
181| int index | 用于从字体管理对象获取字体样式集对象的索引值。 |
182
183**返回:**
184
185| 类型 | 说明 |
186| -- | -- |
187| [OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md)* | 返回指向已创建的字体样式集对象[OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md)的指针。 |
188
189### OH_Drawing_FontMgrDestroyFontStyleSet()
190
191```
192void OH_Drawing_FontMgrDestroyFontStyleSet(OH_Drawing_FontStyleSet* drawingFontStyleSet)
193```
194
195**描述**
196
197释放字体样式集对象占用的内存。
198
199**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
200
201**起始版本:** 12
202
203
204**参数:**
205
206| 参数项 | 描述 |
207| -- | -- |
208| [OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md)* drawingFontStyleSet | 指向字体样式集对象[OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md)的指针。 |
209
210### OH_Drawing_FontMgrMatchFamily()
211
212```
213OH_Drawing_FontStyleSet* OH_Drawing_FontMgrMatchFamily(OH_Drawing_FontMgr* drawingFontMgr, const char* familyName)
214```
215
216**描述**
217
218由指定的字体家族名称,获取字体样式集对象。
219
220**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
221
222**起始版本:** 12
223
224
225**参数:**
226
227| 参数项 | 描述 |
228| -- | -- |
229| [OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)* drawingFontMgr | 指向字体管理对象[OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)的指针,由[OH_Drawing_FontMgrCreate](capi-drawing-font-mgr-h.md#oh_drawing_fontmgrcreate)获取。 |
230| const char* familyName | 指定的字体家族名称。 |
231
232**返回:**
233
234| 类型 | 说明 |
235| -- | -- |
236| [OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md)* | 返回对应的字体样式集对象[OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md),不再需要时,请使用[OH_Drawing_FontMgrDestroyFontStyleSet](capi-drawing-font-mgr-h.md#oh_drawing_fontmgrdestroyfontstyleset)释放该对象指针。 |
237
238### OH_Drawing_FontMgrMatchFamilyStyle()
239
240```
241OH_Drawing_Typeface* OH_Drawing_FontMgrMatchFamilyStyle(OH_Drawing_FontMgr* drawingFontMgr,const char* familyName, OH_Drawing_FontStyleStruct fontStyle)
242```
243
244**描述**
245
246根据指定的字体样式信息和字体家族名称,获取字型对象。
247
248**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
249
250**起始版本:** 12
251
252
253**参数:**
254
255| 参数项 | 描述 |
256| -- | -- |
257| [OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)* drawingFontMgr | 指向字体管理对象[OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)的指针,由[OH_Drawing_FontMgrCreate](capi-drawing-font-mgr-h.md#oh_drawing_fontmgrcreate)获取。 |
258| const char* familyName | 指定的字体家族名称。 |
259| [OH_Drawing_FontStyleStruct](capi-drawing-oh-drawing-fontstylestruct.md) fontStyle | 字体样式对象,包括字体字重、字体宽度和字体斜度信息。 |
260
261**返回:**
262
263| 类型 | 说明 |
264| -- | -- |
265| [OH_Drawing_Typeface](capi-drawing-oh-drawing-typeface.md)* | 返回对应的字体样式的字型对象[OH_Drawing_Typeface](capi-drawing-oh-drawing-typeface.md),不再需要时,请使用[OH_Drawing_TypefaceDestroy](capi-drawing-typeface-h.md#oh_drawing_typefacedestroy)释放该对象指针。 |
266
267### OH_Drawing_FontMgrMatchFamilyStyleCharacter()
268
269```
270OH_Drawing_Typeface* OH_Drawing_FontMgrMatchFamilyStyleCharacter(OH_Drawing_FontMgr* drawingFontMgr,const char* familyName, OH_Drawing_FontStyleStruct fontStyle,const char* bcp47[], int bcp47Count, int32_t character)
271```
272
273**描述**
274
275为指定字符获取字型对象,仅在传入字体管理对象中无法找到传入UTF8字符值对应的字型对象时返回空指针。
276
277**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
278
279**起始版本:** 12
280
281
282**参数:**
283
284| 参数项 | 描述 |
285| -- | -- |
286| [OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)* drawingFontMgr | 指向字体管理对象[OH_Drawing_FontMgr](capi-drawing-oh-drawing-fontmgr.md)的指针,由[OH_Drawing_FontMgrCreate](capi-drawing-font-mgr-h.md#oh_drawing_fontmgrcreate)获取。 |
287| const char* familyName | 指定的字体家族名称。 |
288| [OH_Drawing_FontStyleStruct](capi-drawing-oh-drawing-fontstylestruct.md) fontStyle | 字体样式对象,包括字体字重、字体宽度和字体斜度信息。 |
289| bcp47 |  用来指示character语言编码数组,是ISO 639、15924和3166-1语言编码的组合。 |
290| int bcp47Count | 参数bcp47数组大小。 |
291| int32_t character | 待匹配的UTF8字符值。 |
292
293**返回:**
294
295| 类型 | 说明 |
296| -- | -- |
297| [OH_Drawing_Typeface](capi-drawing-oh-drawing-typeface.md)* | 返回对应的字型对象[OH_Drawing_Typeface](capi-drawing-oh-drawing-typeface.md)。 |
298
299### OH_Drawing_FontStyleSetCreateTypeface()
300
301```
302OH_Drawing_Typeface* OH_Drawing_FontStyleSetCreateTypeface(OH_Drawing_FontStyleSet* fontStyleSet, int index)
303```
304
305**描述**
306
307为指定索引获取字型对象。
308
309**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
310
311**起始版本:** 12
312
313
314**参数:**
315
316| 参数项 | 描述 |
317| -- | -- |
318| [OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md)* fontStyleSet | 指向字体样式集对象[OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md)的指针。 |
319| int index | 指定的字型对象的索引。 |
320
321**返回:**
322
323| 类型 | 说明 |
324| -- | -- |
325| [OH_Drawing_Typeface](capi-drawing-oh-drawing-typeface.md)* | 如果成功,返回对应的字型对象[OH_Drawing_Typeface](capi-drawing-oh-drawing-typeface.md); 如果失败,返回nullptr。 |
326
327### OH_Drawing_FontStyleSetGetStyle()
328
329```
330OH_Drawing_FontStyleStruct OH_Drawing_FontStyleSetGetStyle(OH_Drawing_FontStyleSet* fontStyleSet, int32_t index,char** styleName)
331```
332
333**描述**
334
335获取字体样式,styleName会申请内存,不再需要styleName时,请使用[OH_Drawing_FontStyleSetFreeStyleName](#oh_drawing_fontstylesetfreestylename)释放该对象指针。
336
337**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
338
339**起始版本:** 12
340
341
342**参数:**
343
344| 参数项 | 描述 |
345| -- | -- |
346| [OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md)* fontStyleSet | 指向字体样式集对象[OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md)的指针。 |
347| int32_t index | 指定的字体样式的索引。 |
348| char** styleName | 指定字体样式名称的字符串,会申请内存,不再需要时,请使用[OH_Drawing_FontStyleSetFreeStyleName](#oh_drawing_fontstylesetfreestylename)释放该对象指针。 |
349
350**返回:**
351
352| 类型 | 说明 |
353| -- | -- |
354| [OH_Drawing_FontStyleStruct](capi-drawing-oh-drawing-fontstylestruct.md) | 返回对应的字体样式。 |
355
356### OH_Drawing_FontStyleSetFreeStyleName()
357
358```
359void OH_Drawing_FontStyleSetFreeStyleName(char** styleName)
360```
361
362**描述**
363
364释放指定字体样式名称的内存。
365
366**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
367
368**起始版本:** 12
369
370
371**参数:**
372
373| 参数项 | 描述 |
374| -- | -- |
375| char** styleName | 指定字体样式名称的字符串。 |
376
377### OH_Drawing_FontStyleSetMatchStyle()
378
379```
380OH_Drawing_Typeface* OH_Drawing_FontStyleSetMatchStyle(OH_Drawing_FontStyleSet* fontStyleSet,OH_Drawing_FontStyleStruct fontStyleStruct)
381```
382
383**描述**
384
385获取最接近字体样式的字型对象。
386
387**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
388
389**起始版本:** 12
390
391
392**参数:**
393
394| 参数项 | 描述 |
395| -- | -- |
396| [OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md)* fontStyleSet | 指向字体样式集对象[OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md)的指针。 |
397| [OH_Drawing_FontStyleStruct](capi-drawing-oh-drawing-fontstylestruct.md) fontStyleStruct | 字体样式对象,包括字体字重、字体宽度和字体斜度信息。 |
398
399**返回:**
400
401| 类型 | 说明 |
402| -- | -- |
403| [OH_Drawing_Typeface](capi-drawing-oh-drawing-typeface.md)* | 返回对应的字型对象[OH_Drawing_Typeface](capi-drawing-oh-drawing-typeface.md)。 |
404
405### OH_Drawing_FontStyleSetCount()
406
407```
408int OH_Drawing_FontStyleSetCount(OH_Drawing_FontStyleSet* fontStyleSet)
409```
410
411**描述**
412
413获取字体样式集中字体的个数。
414
415**系统能力:** SystemCapability.Graphic.Graphic2D.NativeDrawing
416
417**起始版本:** 12
418
419
420**参数:**
421
422| 参数项 | 描述 |
423| -- | -- |
424| [OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md)* fontStyleSet | 指向字体样式集对象[OH_Drawing_FontStyleSet](capi-drawing-oh-drawing-fontstyleset.md)的指针。 |
425
426**返回:**
427
428| 类型 | 说明 |
429| -- | -- |
430| int | 返回此字体样式集中字体的个数。 |