diff --git a/graphic/graphic_2d/native_drawing/drawing_text_declaration.h b/graphic/graphic_2d/native_drawing/drawing_text_declaration.h index a005e95af4f44867078ede00750e8eb4db91cca7..a6c2578bbf6d6d0ae5d653e3d267774a6a9d67a8 100644 --- a/graphic/graphic_2d/native_drawing/drawing_text_declaration.h +++ b/graphic/graphic_2d/native_drawing/drawing_text_declaration.h @@ -157,6 +157,12 @@ typedef struct OH_Drawing_TextLine OH_Drawing_TextLine; */ typedef struct OH_Drawing_Run OH_Drawing_Run; +/** + * @brief Defines an OH_Drawing_FontFullDescriptor, which describes the font information. + * + * @since 22 + */ +typedef struct OH_Drawing_FontFullDescriptor OH_Drawing_FontFullDescriptor; #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_drawing/drawing_text_font_descriptor.h b/graphic/graphic_2d/native_drawing/drawing_text_font_descriptor.h index e89a96b06dcf0679b729f05f3879325e3c2fc971..40f7de8bbb16d58ae3c79aafdd86c53bec5cd5cc 100644 --- a/graphic/graphic_2d/native_drawing/drawing_text_font_descriptor.h +++ b/graphic/graphic_2d/native_drawing/drawing_text_font_descriptor.h @@ -40,6 +40,8 @@ #ifndef DRAWING_TEXT_FONT_DESCRIPTOR_H #define DRAWING_TEXT_FONT_DESCRIPTOR_H +#include "drawing_memory_stream.h" +#include "drawing_text_declaration.h" #include "drawing_text_typography.h" #ifdef __cplusplus @@ -67,6 +69,34 @@ typedef enum { CUSTOMIZED = 1 << 4, } OH_Drawing_SystemFontType; +/** + * @brief An enumeration of font full descriptor attribute. + * + * @since 22 + */ +typedef enum { + /** The file path of the font */ + FULL_DESCRIPTOR_ATTR_S_PATH = 0, + /** A name that uniquely identifies the font */ + FULL_DESCRIPTOR_ATTR_S_POSTSCRIPT_NAME = 1, + /** The full name of the font */ + FULL_DESCRIPTOR_ATTR_S_FULL_NAME = 2, + /** The family name of the font */ + FULL_DESCRIPTOR_ATTR_S_FAMILY_NAME = 3, + /** The subfont family of the font */ + FULL_DESCRIPTOR_ATTR_S_SUB_FAMILY_NAME = 4, + /** The weight of the font */ + FULL_DESCRIPTOR_ATTR_I_WEIGHT = 5, + /** The width of the font */ + FULL_DESCRIPTOR_ATTR_I_WIDTH = 6, + /** Whether the font is tilted */ + FULL_DESCRIPTOR_ATTR_I_ITALIC = 7, + /** Whether the font is monospaced */ + FULL_DESCRIPTOR_ATTR_B_MONO = 8, + /** whether symbolic fonts are supported */ + FULL_DESCRIPTOR_ATTR_B_SYMBOLIC = 9, +} OH_Drawing_FontFullDescriptorAttributeId; + /** * @brief Obtain all system font descriptive symbols that match the specified font descriptor. Where the 'path' * fields are not considered as valid matching values, It takes effect when the remaining fields are not @@ -139,6 +169,100 @@ const OH_Drawing_String* OH_Drawing_GetSystemFontFullNameByIndex(OH_Drawing_Arra */ void OH_Drawing_DestroySystemFontFullNames(OH_Drawing_Array* fullNameArray); +/** + * @brief Obtains an array of font full descriptors from a memory stream. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param stream Indicates the pointer to the memory stream OH_Drawing_MemoryStream containing font data. + * @return Returns a pointer to OH_Drawing_Array structure containing font full descriptors. + * Returns NULL if parsing fails or the stream contains invalid data. + * @since 22 + */ +OH_Drawing_Array* OH_Drawing_GetFontFullDescriptorsFromStream(OH_Drawing_MemoryStream* stream); + +/** + * @brief Obtains an array of font full descriptors from font file path. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param path Indicates the pointer to the path to set. + * @return Returns a pointer to OH_Drawing_Array structure containing font full descriptors. + * Returns NULL if no fonts are found, invalid path, no permission, or non-font file. + * @since 22 + */ +OH_Drawing_Array* OH_Drawing_GetFontFullDescriptorsFromPath(char* path); + +/** + * @brief Retrieves a font full descriptor from an array by index. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param descriptorArray Pointer to the array of font full descriptors OH_Drawing_Array. + * @param index Zero-based index position of the descriptor to retrieve. + * @return Returns a pointer to OH_Drawing_FontFullDescriptor at the specified index. + * Returns NULL if the index is out of bounds or the array is invalid. + * @since 22 + */ +const OH_Drawing_FontFullDescriptor* OH_Drawing_GetFontFullDescriptorByIndex( + OH_Drawing_Array* descriptorArray, size_t index); + +/** + * @brief Releases the memory occupied by an array of font full descriptors. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param descriptorArray Pointer to the array of font full descriptors OH_Drawing_Array. + * @since 22 + */ +void OH_Drawing_DestroyFontFullDescriptors(OH_Drawing_Array* descriptorArray); + +/** + * @brief Retrieves an integer attribute value from a font full descriptor. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param descriptor Pointer to the font full descriptor OH_Drawing_FontFullDescriptor. + * @param id Attribute identifier from OH_Drawing_FontFullDescriptorAttributeId enumeration. + * @param value Output parameter to receive the requested integer attribute value. + * @return Returns OH_Drawing_ErrorCode indicating operation status: + * - OH_DRAWING_SUCCESS (0) if successful + * - OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE (26200001) if attribute ID is invalid + * - OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH (26200003) if parameter type mismatch occurs + * @since 22 + */ +OH_Drawing_ErrorCode OH_Drawing_GetFontFullDescriptorAttributeInt(OH_Drawing_FontFullDescriptor* descriptor, + OH_Drawing_FontFullDescriptorAttributeId id, int* value); + +/** + * @brief Retrieves a boolean attribute value from a font full descriptor. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param descriptor Pointer to the font full descriptor OH_Drawing_FontFullDescriptor. + * @param id Attribute identifier from OH_Drawing_FontFullDescriptorAttributeId enumeration. + * @param value Output parameter to receive the requested boolean attribute value. + * @return Returns OH_Drawing_ErrorCode indicating operation status: + * - OH_DRAWING_SUCCESS (0) if successful + * - OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE (26200001) if attribute ID is invalid + * - OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH (26200003) if parameter type mismatch occurs + * @since 22 + */ +OH_Drawing_ErrorCode OH_Drawing_GetFontFullDescriptorAttributeBool(OH_Drawing_FontFullDescriptor* descriptor, + OH_Drawing_FontFullDescriptorAttributeId id, bool* value); + +/** + * @brief Retrieves a string attribute value from a font full descriptor. + * + * @note The caller is responsible for manually releasing the internal strData member of the + * OH_Drawing_String structure when it is no longer needed. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param descriptor Pointer to the font full descriptor OH_Drawing_FontFullDescriptor. + * @param id Attribute identifier from OH_Drawing_FontFullDescriptorAttributeId enumeration. + * @param str Output parameter to receive pointer to the requested string attribute value. + * @return Returns OH_Drawing_ErrorCode indicating operation status: + * - OH_DRAWING_SUCCESS (0) if successful + * - OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE (26200001) if attribute ID is invalid + * - OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH (26200003) if parameter type mismatch occurs + * @since 22 + */ +OH_Drawing_ErrorCode OH_Drawing_GetFontFullDescriptorAttributeString(OH_Drawing_FontFullDescriptor* descriptor, + OH_Drawing_FontFullDescriptorAttributeId id, OH_Drawing_String* str); #ifdef __cplusplus } #endif