openharmony 鸿蒙 capi-drawing-register-font-h

2026-08-25 浏览 (1)

drawing_register_font.h

Overview

This file declares the functions related to the font manager in the drawing module.

File to include: <native_drawing/drawing_register_font.h>

Library: libnative_drawing.so

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Related module: Drawing

Summary

Functions

NameDescription
uint32_t OH_Drawing_RegisterFont(OH_Drawing_FontCollection*, const char* fontFamily, const char* familySrc)Registers a custom font with the font manager. The supported font file formats are .ttf and .otf.
uint32_t OH_Drawing_RegisterFontBuffer(OH_Drawing_FontCollection*, const char* fontFamily, uint8_t* fontBuffer,size_t length)Registers a font buffer with the font manager.
uint32_t OH_Drawing_UnregisterFont(OH_Drawing_FontCollection* fontCollection, const char* fontFamily)Unregisters a custom font by font family name.
Unregistering a font that is currently in use may lead to text rendering exceptions (such as garbled characters or missing glyphs).
All typography objects using the unregistered font family should be destroyed and re-created.
uint32_t OH_Drawing_RegisterFontByIndex(OH_Drawing_FontCollection* fontCollection, const char* fontFamily, const char* familySrc, uint32_t index)Registers a custom font using a TTC/OTC file.
uint32_t OH_Drawing_RegisterFontBufferByIndex(OH_Drawing_FontCollection* fontCollection, const char* fontFamily, uint8_t* fontBuffer, size_t length, uint32_t index)Registers a font using the font buffer of a TTC/OTC file.
bool OH_Drawing_IsFontSupportedFromPath(const char* path)Checks whether the system supports the font format of the specified path.
bool OH_Drawing_IsFontSupportedFromBuffer(uint8_t* data, size_t dataLength)Checks whether the system supports the font format specified in the buffer.

Function Description

OH_Drawing_RegisterFont()

uint32_t OH_Drawing_RegisterFont(OH_Drawing_FontCollection*, const char* fontFamily, const char* familySrc)

Description

Registers a custom font with the font manager. The supported font file formats are .ttf and .otf.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_FontCollection*Pointer to an OH_Drawing_FontCollection object.
const char* fontFamilyPointer to the family name of the font to register.
const char* familySrcPointer to the path of the font file to register.

Returns

TypeDescription
uint32_tReturns 0 if the font is registered; returns 1 if the file does not exist; returns 2 if opening the file fails; returns 3 if reading the file fails; returns 4 if the file is not found; returns 5 if the file size is not obtained; returns 9 if the file is damaged.

OH_Drawing_RegisterFontBuffer()

uint32_t OH_Drawing_RegisterFontBuffer(OH_Drawing_FontCollection*, const char* fontFamily, uint8_t* fontBuffer,size_t length)

Description

Registers a font buffer with the font manager.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_FontCollection*Pointer to an OH_Drawing_FontCollection object.
const char* fontFamilyPointer to the family name of the font to register.
uint8_t* fontBufferPointer to the buffer of the font file.
size_t lengthLength of the font file.

Returns

TypeDescription
uint32_tReturns 0 if the font is registered; returns 6 if the buffer size is zero; returns 7 if the font set is empty; returns 9 if the file is damaged.

OH_Drawing_UnregisterFont()

uint32_t OH_Drawing_UnregisterFont(OH_Drawing_FontCollection* fontCollection, const char* fontFamily)

Description

Unregisters a custom font by font family name.

Unregistering a font that is currently in use may lead to text rendering exceptions (such as garbled characters or missing glyphs).

All typography objects using the unregistered font family should be destroyed and re-created.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_FontCollection* fontCollectionPointer to an OH_Drawing_FontCollection object.
const char* fontFamilyName of the font family to be unregistered.

Returns

TypeDescription
uint32_tReturns the result code. 0: success; 8: invalid input parameter; 1: failure.

OH_Drawing_RegisterFontByIndex()

uint32_t OH_Drawing_RegisterFontByIndex(OH_Drawing_FontCollection* fontCollection, const char* fontFamily, const char* familySrc, uint32_t index)

Description

Registers a custom font using a TTC/OTC file.

Since: 23

Parameters

NameDescription
OH_Drawing_FontCollection* fontCollectionPointer to an OH_Drawing_FontCollection object.
const char* fontFamilyFamily name of the font to register.
const char* familySrcPath of the font file to register.
uint32_t indexIndex of the font in the TTC/OTC file. Set this parameter to 0 if the file is not in TTC/OTC format.

Returns

TypeDescription
uint32_tReturns the execution result. 0: success; 1: file does not exist; 2: failed to open the file; 3: failed to read the file; 4: failed to find the file; 5: failed to obtain the size; 8: fontCollection is null; 9: file is corrupted.

OH_Drawing_RegisterFontBufferByIndex()

uint32_t OH_Drawing_RegisterFontBufferByIndex(OH_Drawing_FontCollection* fontCollection, const char* fontFamily, uint8_t* fontBuffer, size_t length, uint32_t index)

Description

Registers a font using the font buffer of a TTC/OTC file.

Since: 23

Parameters

NameDescription
OH_Drawing_FontCollection* fontCollectionPointer to an OH_Drawing_FontCollection object.
const char* fontFamilyFamily name of the font to register.
uint8_t* fontBufferFont buffer of the font file to register.
size_t lengthFont buffer data length.
uint32_t indexIndex of the font in the TTC/OTC file. Set this parameter to 0 if the file is not in TTC/OTC format.

Returns

TypeDescription
uint32_tReturns the execution result. 0: success; 6: the font buffer pointer is null; 7: the font buffer data length is zero; 8: fontCollection is null; 9: file is corrupted.

OH_Drawing_IsFontSupportedFromPath()

bool OH_Drawing_IsFontSupportedFromPath(const char* path)

Description

Checks whether the system supports the font format of the specified path.

Since: 23

Parameters

NameDescription
const char* pathAbsolute path of the font file.

Returns

TypeDescription
boolReturns true if the font is supported; returns false otherwise.

OH_Drawing_IsFontSupportedFromBuffer()

bool OH_Drawing_IsFontSupportedFromBuffer(uint8_t* data, size_t dataLength)

Description

Checks whether the system supports the font format specified in the buffer.

Since: 23

Parameters

NameDescription
uint8_t* dataPointer to the buffer that contains the font data.
size_t dataLengthSize of the font data, in bytes.

Returns

TypeDescription
boolReturns true if the font is supported; returns false otherwise.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-drawing-gpu-context-h

openharmony 鸿蒙 capi-drawing-nativepixelmap-

openharmony 鸿蒙 capi-nativevsync-oh-nativevsync-expectedraterange

openharmony 鸿蒙 capi-drawing-oh-drawing-brush

openharmony 鸿蒙 capi-drawing-oh-drawing-image-info

openharmony 鸿蒙 capi-drawing-text-linetypography-h

openharmony 鸿蒙 capi-oh-nativeimage-oh-nativeimage

openharmony 鸿蒙 capi-drawing-typeface-h

openharmony 鸿蒙 capi-drawing-brush-h

openharmony 鸿蒙 capi-nativewindow

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