openharmony 鸿蒙 capi-drawing-typeface-h

2026-08-25 浏览 (1)

drawing_typeface.h

Overview

This file declares the functions related to the typeface in the drawing module.
Different platforms have their own default typefaces. You can also parse the .ttf file to obtain the typefaces specified by the third party, such as SimSun and SimHei.

File to include: <native_drawing/drawing_typeface.h>

Library: libnative_drawing.so

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Related module: Drawing

Summary

Functions

NameDescription
OH_Drawing_Typeface* OH_Drawing_TypefaceCreateDefault(void)Creates a default OH_Drawing_Typeface object.
OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromFile(const char* path, int index)Creates an OH_Drawing_Typeface object through a file.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If path is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromFileWithArguments(const char* path,const OH_Drawing_FontArguments* fontArguments)Creates an OH_Drawing_Typeface object with font arguments through a file.
If the OH_Drawing_Typeface object does not support the variation described in the font arguments, this function creates an OH_Drawing_Typeface object with the default font arguments.
In this case, this function provides the same capability as OH_Drawing_TypefaceCreateFromFile.
OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromCurrent(const OH_Drawing_Typeface* current,const OH_Drawing_FontArguments* fontArguments)Creates an OH_Drawing_Typeface object with font arguments based on an existing OH_Drawing_Typeface object.
OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromStream(OH_Drawing_MemoryStream* memoryStream, int32_t index)Creates an OH_Drawing_Typeface object through a memory stream. If the memory stream is an invalid font file, a null pointer is returned. After the memory stream is passed in, the ownership is transferred and you cannot release it.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If memoryStream is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.
void OH_Drawing_TypefaceDestroy(OH_Drawing_Typeface* typeface)Destroys an OH_Drawing_Typeface object and reclaims the memory occupied by the object.
OH_Drawing_FontArguments* OH_Drawing_FontArgumentsCreate(void)Creates an OH_Drawing_FontArguments object. The font arguments are used to create an OH_Drawing_Typeface object with custom attributes.
OH_Drawing_ErrorCode OH_Drawing_FontArgumentsAddVariation(OH_Drawing_FontArguments* fontArguments,const char* axis, float value)Adds a variation to an OH_Drawing_FontArguments object.
OH_Drawing_ErrorCode OH_Drawing_FontArgumentsDestroy(OH_Drawing_FontArguments* fontArguments)Destroys an OH_Drawing_FontArguments object.
OH_Drawing_ErrorCode OH_Drawing_TypefaceIsBold(const OH_Drawing_Typeface* typeface, bool* isBold)Checks whether the typeface is bold.
OH_Drawing_ErrorCode OH_Drawing_TypefaceIsItalic(const OH_Drawing_Typeface* typeface, bool* isItalic)Checks whether the typeface is italic.

Function Description

OH_Drawing_TypefaceCreateDefault()

OH_Drawing_Typeface* OH_Drawing_TypefaceCreateDefault(void)

Description

Creates a default OH_Drawing_Typeface object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Returns

TypeDescription
OH_Drawing_Typeface*Returns the pointer to the OH_Drawing_Typeface object created.

OH_Drawing_TypefaceCreateFromFile()

OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromFile(const char* path, int index)

Description

Creates an OH_Drawing_Typeface object through a file.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If path is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
const char* pathPointer to the file path.
int indexFile index.

Returns

TypeDescription
OH_Drawing_Typeface*Returns a pointer to the created OH_Drawing_Typeface object.

OH_Drawing_TypefaceCreateFromFileWithArguments()

OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromFileWithArguments(const char* path,const OH_Drawing_FontArguments* fontArguments)

Description

Creates an OH_Drawing_Typeface object with font arguments through a file.
If the OH_Drawing_Typeface object does not support the variation described in the font arguments, this function creates an OH_Drawing_Typeface object with the default font arguments.
In this case, this function provides the same capability as OH_Drawing_TypefaceCreateFromFile.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 13

Parameters

NameDescription
const char* pathPointer to the file path.
const OH_Drawing_FontArguments* fontArgumentsPointer to an OH_Drawing_FontArguments object.

Returns

TypeDescription
OH_Drawing_Typeface*Returns a pointer to the created OH_Drawing_Typeface object.
If a null pointer is returned, the creation fails. Possible causes are that no memory is available, the passed-in path or fontArguments is NULL, or the path is invalid.

OH_Drawing_TypefaceCreateFromCurrent()

OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromCurrent(const OH_Drawing_Typeface* current,const OH_Drawing_FontArguments* fontArguments)

Description

Creates an OH_Drawing_Typeface object with font arguments based on an existing OH_Drawing_Typeface object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 13

Parameters

NameDescription
const OH_Drawing_Typeface* currentPointer to the OH_Drawing_Typeface object.
const OH_Drawing_FontArguments* fontArgumentsPointer to an OH_Drawing_FontArguments object.

Returns

TypeDescription
OH_Drawing_Typeface*Returns a pointer to the created OH_Drawing_Typeface object.
If a null pointer is returned, the creation fails. Possible causes are that no memory is available, the passed-in path or fontArguments is NULL, or the existing OH_Drawing_FontArguments object does not support the variation described in the font arguments.

OH_Drawing_TypefaceCreateFromStream()

OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromStream(OH_Drawing_MemoryStream* memoryStream, int32_t index)

Description

Creates an OH_Drawing_Typeface object through a memory stream. If the memory stream is an invalid font file, a null pointer is returned. After the memory stream is passed in, the ownership is transferred and you cannot release it.
This API may return an error code. For details, call OH_Drawing_ErrorCodeGet.
If memoryStream is NULL, OH_DRAWING_ERROR_INVALID_PARAMETER is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_MemoryStream* memoryStreamPointer to an OH_Drawing_MemoryStream object.
int32_t indexIndex of the memory stream.

Returns

TypeDescription
OH_Drawing_Typeface*Returns a pointer to the created OH_Drawing_Typeface object.

OH_Drawing_TypefaceDestroy()

void OH_Drawing_TypefaceDestroy(OH_Drawing_Typeface* typeface)

Description

Destroys an OH_Drawing_Typeface object and reclaims the memory occupied by the object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Typeface* typefacePointer to an OH_Drawing_Typeface object.

OH_Drawing_FontArgumentsCreate()

OH_Drawing_FontArguments* OH_Drawing_FontArgumentsCreate(void)

Description

Creates an OH_Drawing_FontArguments object. The font arguments are used to create an OH_Drawing_Typeface object with custom attributes.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 13

Returns

TypeDescription
OH_Drawing_FontArguments*Returns the pointer to the OH_Drawing_FontArguments object created.

OH_Drawing_FontArgumentsAddVariation()

OH_Drawing_ErrorCode OH_Drawing_FontArgumentsAddVariation(OH_Drawing_FontArguments* fontArguments,const char* axis, float value)

Description

Adds a variation to an OH_Drawing_FontArguments object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 13

Parameters

NameDescription
OH_Drawing_FontArguments* fontArgumentsPointer to an OH_Drawing_FontArguments object.
const char* axisPointer to the label of the variation. The value must contain four ASCII characters. The supported labels depend on the loaded font file. For example, 'wght' is the font weight label.
float valueValue of the variation label.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if either fontArguments or axis is NULL or the length of axis is not 4.

OH_Drawing_FontArgumentsDestroy()

OH_Drawing_ErrorCode OH_Drawing_FontArgumentsDestroy(OH_Drawing_FontArguments* fontArguments)

Description

Destroys an OH_Drawing_FontArguments object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 13

Parameters

NameDescription
OH_Drawing_FontArguments* fontArgumentsPointer to an OH_Drawing_FontArguments object.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns one of the following result codes:
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if fontArguments is NULL.

OH_Drawing_TypefaceIsBold()

OH_Drawing_ErrorCode OH_Drawing_TypefaceIsBold(const OH_Drawing_Typeface* typeface, bool* isBold)

Description

Checks whether the typeface is bold.

Since: 23

Parameters

NameDescription
const OH_Drawing_Typeface* typefacePointer to the OH_Drawing_Typeface object.
bool* isBoldWhether the typeface is bold. It is used as an output parameter. true if the typeface is bold; false otherwise.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if typeface or isBold is a null pointer.

OH_Drawing_TypefaceIsItalic()

OH_Drawing_ErrorCode OH_Drawing_TypefaceIsItalic(const OH_Drawing_Typeface* typeface, bool* isItalic)

Description

Checks whether the typeface is italic.

Since: 23

Parameters

NameDescription
const OH_Drawing_Typeface* typefacePointer to the OH_Drawing_Typeface object.
bool* isItalicWhether the typeface is italic. It is used as an output parameter. true if the typeface is italic; false otherwise.

Returns

TypeDescription
OH_Drawing_ErrorCodeExecution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if typeface or isItalic is a null pointer.

你可能感兴趣的鸿蒙文章

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-brush-h

openharmony 鸿蒙 capi-nativewindow

openharmony 鸿蒙 js-apis-uiEffect

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