From 00703ffc696c11ea9ad76f3821dd03293132621b Mon Sep 17 00:00:00 2001 From: changleipeng Date: Sat, 3 Aug 2024 11:26:40 +0800 Subject: [PATCH 1/2] add GetSystemFontList and GetFontdescriptorByName NDK interface Signed-off-by: changleipeng --- .../native_drawing/drawing_text_typography.h | 61 +++++++++++++++++++ .../native_drawing/libnative_drawing.ndk.json | 16 +++++ 2 files changed, 77 insertions(+) diff --git a/graphic/graphic_2d/native_drawing/drawing_text_typography.h b/graphic/graphic_2d/native_drawing/drawing_text_typography.h index d821c3855..cf0135e93 100644 --- a/graphic/graphic_2d/native_drawing/drawing_text_typography.h +++ b/graphic/graphic_2d/native_drawing/drawing_text_typography.h @@ -441,6 +441,23 @@ typedef struct OH_Drawing_FontDescriptor { bool symbolic; } OH_Drawing_FontDescriptor; +/** + * @brief An enumeration of system font types. + * + * @since 14 + * @version 1.0 + */ +typedef enum { + /** All font types */ + ALL = 1 << 0, + /** System generic font type */ + GENERIC = 1 << 1, + /** Stylish font type */ + STYLISH = 1 << 2, + /** Installed font types */ + INSTALLED = 1 << 3, +} OH_Drawing_SystemFontType; + /** * @brief The metrics of line. * @@ -1480,6 +1497,50 @@ OH_Drawing_FontParser* OH_Drawing_CreateFontParser(void); */ void OH_Drawing_DestroyFontParser(OH_Drawing_FontParser*); +/** + * @brief Get font details by the full name of the font. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param char* Indicates the full name of the font. + * @return Indicates the pointer to a font descriptor object OH_Drawing_FontDescriptor. + * @since 14 + * @version 1.0 + */ +OH_Drawing_FontDescriptor* OH_Drawing_GetFontDescriptorByName(const char* fullName); + +/** + * @brief Obtain the corresponding font full name list by the font type. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_SystemFontType Indicates enumerates of system font type. + * @return Returns an array of full name. + * @since 14 + * @version 1.0 + */ +OH_Drawing_Array* OH_Drawing_GetSystemFontFullNameListByType(OH_Drawing_SystemFontType fontType); + +/** + * @brief Gets the full name indices by index. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Array Indicates an array of full name. + * @param size_t The index of full name. + * @return Returns a full name of the font. + * @since 14 + * @version 1.0 + */ +const char* OH_Drawing_GetSystemFontFullNameListElement(OH_Drawing_Array* fullNameList, size_t index); + +/** + * @brief Releases the memory occupied by a list of system font names. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Array Indicates an array of full name. + * @since 14 + * @version 1.0 + */ +void OH_Drawing_DestroySystemFontFullNameList(OH_Drawing_Array* fullNameList); + /** * @brief Gets a list of system font names. * diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index f0d6835c1..b58c3b8bd 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -910,6 +910,22 @@ "first_introduced": "12", "name": "OH_Drawing_DestroyFontParser" }, + { + "first_introduced": "14", + "name": "OH_Drawing_GetFontDescriptorByName" + }, + { + "first_introduced": "14", + "name": "OH_Drawing_GetSystemFontFullNameListByType" + }, + { + "first_introduced": "14", + "name": "OH_Drawing_GetSystemFontFullNameListElement" + }, + { + "first_introduced": "14", + "name": "OH_Drawing_DestroySystemFontFullNameList" + }, { "first_introduced": "12", "name": "OH_Drawing_FontParserGetSystemFontList" -- Gitee From abcf1c5b925c6605b0067859c107c4be980073de Mon Sep 17 00:00:00 2001 From: changleipeng Date: Mon, 1 Jul 2024 16:31:30 +0800 Subject: [PATCH 2/2] font descriptor ndk interface Signed-off-by: changleipeng --- .../kit_sub_system/c_file_kit_sub_system.json | 5 + graphic/graphic_2d/native_drawing/BUILD.gn | 2 + .../drawing_text_font_descriptor.h | 216 ++++++++++++++++++ .../native_drawing/drawing_text_typography.h | 123 +--------- .../graphic_2d/native_drawing/drawing_types.h | 13 ++ .../native_drawing/libnative_drawing.ndk.json | 16 +- 6 files changed, 249 insertions(+), 126 deletions(-) create mode 100644 graphic/graphic_2d/native_drawing/drawing_text_font_descriptor.h diff --git a/build-tools/capi_parser/src/coreImpl/parser/kit_sub_system/c_file_kit_sub_system.json b/build-tools/capi_parser/src/coreImpl/parser/kit_sub_system/c_file_kit_sub_system.json index 668e349de..05882fd41 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/kit_sub_system/c_file_kit_sub_system.json +++ b/build-tools/capi_parser/src/coreImpl/parser/kit_sub_system/c_file_kit_sub_system.json @@ -274,6 +274,11 @@ "kitName": "ArkGraphicsD", "subSystem": "图形图像" }, + { + "filePath": "graphic/graphic_2d/native_drawing/drawing_text_font_descriptor.h", + "kitName": "ArkGraphicsD", + "subSystem": "图形图像" + }, { "filePath": "graphic/graphic_2d/native_drawing/drawing_typeface.h", "kitName": "ArkGraphicsD", diff --git a/graphic/graphic_2d/native_drawing/BUILD.gn b/graphic/graphic_2d/native_drawing/BUILD.gn index fa8656ce6..6f6feea4a 100644 --- a/graphic/graphic_2d/native_drawing/BUILD.gn +++ b/graphic/graphic_2d/native_drawing/BUILD.gn @@ -49,6 +49,7 @@ ohos_ndk_headers("native_drawing_header") { "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_surface.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_text_blob.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_text_declaration.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_text_font_descriptor.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_text_typography.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_typeface.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_types.h", @@ -93,6 +94,7 @@ ohos_ndk_library("libnative_drawing_ndk") { "native_drawing/drawing_surface.h", "native_drawing/drawing_text_blob.h", "native_drawing/drawing_text_declaration.h", + "native_drawing/drawing_text_font_descriptor.h", "native_drawing/drawing_text_typography.h", "native_drawing/drawing_typeface.h", "native_drawing/drawing_types.h", diff --git a/graphic/graphic_2d/native_drawing/drawing_text_font_descriptor.h b/graphic/graphic_2d/native_drawing/drawing_text_font_descriptor.h new file mode 100644 index 000000000..9ec80657e --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_text_font_descriptor.h @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_TEXT_FONT_DESCRIPTOR_H +#define C_INCLUDE_DRAWING_TEXT_FONT_DESCRIPTOR_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides the font descriptor capability. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 8 + * @version 1.0 + */ + +/** + * @file drawing_text_font_descriptor.h + * + * @brief Provide the ability to provide OH_Drawing_FontDescriptor. + * + * @kit ArkGraphics2D + * @library libnative_drawing.so + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @since 8 + * @version 1.0 + */ + +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Type style flag. + * + * @since 14 + * @version 1.0 + */ +typedef enum { + /** Italic font */ + ITALIC = 1 << 0, + /** Bold font */ + BOLD = 1 << 1, +} OH_Drawing_FontTypeStyle; + +/** + * @brief An enumeration of system font types. + * + * @since 14 + */ +typedef enum OH_Drawing_SystemFontType { + /** All font types */ + ALL = 1 << 0, + /** System generic font type */ + GENERIC = 1 << 1, + /** Stylish font type */ + STYLISH = 1 << 2, + /** Installed font types */ + INSTALLED = 1 << 3, +} OH_Drawing_SystemFontType; + +/** + * @brief Describes the font information. + * + * @since 12 + * @version 1.0 + */ +typedef struct OH_Drawing_FontDescriptor { + /** The file path of System font */ + char* path = NULL; + /** A name that uniquely identifies the font */ + char* postScriptName = NULL; + /** The name of System font */ + char* fullName = NULL; + /** The family of System font */ + char* fontFamily = NULL; + /** The subfont family of the system font */ + char* fontSubfamily = NULL; + /** The weight of System font */ + int weight = 0; + /** The width of System font */ + int width = 0; + /** Whether the system font is tilted */ + int italic = 0; + /** Whether the system font is compact */ + bool monoSpace = false; + /** whether symbolic fonts are supported */ + bool symbolic = false; + /** Font size */ + size_t size = 0; + /** Font style flag, from OH_Drawing_FontTypeStyle */ + int typeStyle = 0; +} OH_Drawing_FontDescriptor; + +/** + * @brief Creates an OH_Drawing_FontDescriptor object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @return Returns the pointer to the font descriptor object OH_Drawing_FontDescriptor created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_FontDescriptor* OH_Drawing_CreateFontDescriptor(void); + +/** + * @brief Releases the memory occupied by an OH_Drawing_FontDescriptor object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontDescriptor the pointer to the font descriptor object OH_Drawing_FontDescriptor. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_DestroyFontDescriptor(OH_Drawing_FontDescriptor*); + +/** + * @brief Obtain all system font descriptive symbols that match the specified font descriptor. Where the 'path' and + * 'size' fields are not considered as valid matching values, It takes effect when the remaining fields are not + * default values, If all the fields of the parameters OH_Drawing_FontDescriptor are default, obtain all system + * font descriptors. If the match fails, return nullptr. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontDescriptor The pointer to the OH_Drawing_FontDescriptor object. + * @param size_t Indicates the count of obtained OH_Drawing_FontDescriptor. + * @return Returns an array of OH_Drawing_FontDescriptor. + * @since 14 + * @version 1.0 + */ +OH_Drawing_FontDescriptor* OH_Drawing_MatchFontDescriptors(OH_Drawing_FontDescriptor*, size_t*); + +/** + * @brief Releases the OH_Drawing_FontDescriptor array. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontDescriptor Pointer to OH_Drawing_FontDescriptor array. + * @param size_t Represents the number of members of the OH_Drawing_FontDescriptor array. + * @since 14 + * @version 1.0 + */ +void OH_Drawing_DestroyFontDescriptors(OH_Drawing_FontDescriptor*, size_t); + +/** + * @brief Gets information about the system font by font name. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontParser Indicates the pointer to the font parser object OH_Drawing_FontParser. + * @param char** font name. + * @return Returns system fonts information. + * @since 12 + * @version 1.0 + */ +OH_Drawing_FontDescriptor* OH_Drawing_FontParserGetFontByName(OH_Drawing_FontParser*, const char*); + +/** + * @brief Get the OH_Drawing_FontDescriptor object by the font full name and the font type, supporting generic + * fonts, stylish fonts, and installed fonts. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_String Indicates the full name object OH_Drawing_String. + * @param OH_Drawing_SystemFontType Indicates enumerates of system font type object OH_Drawing_SystemFontType. + * @return Returns the pointer to a font descriptor object OH_Drawing_FontDescriptor. + * @since 14 + */ +OH_Drawing_FontDescriptor* OH_Drawing_GetFontDescriptorByFullName(const OH_Drawing_String*, OH_Drawing_SystemFontType); + +/** + * @brief Obtain the corresponding font full name array by the font type. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_SystemFontType Indicates enumerates of system font type object OH_Drawing_SystemFontType. + * @return Returns the pointer to full name array object OH_Drawing_Array. + * @since 14 + */ +OH_Drawing_Array* OH_Drawing_GetSystemFontFullNamesByType(OH_Drawing_SystemFontType); + +/** + * @brief Get the specified full name object OH_Drawing_String by index from the + * OH_Drawing_Array object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Array Indicates an array of full name object OH_Drawing_Array. + * @param size_t The index of full name. + * @return Returns a full name object OH_Drawing_String. + * @since 14 + */ +const OH_Drawing_String* OH_Drawing_GetSystemFontFullNameByIndex(OH_Drawing_Array*, size_t); + +/** + * @brief Releases the memory occupied by an array of font full names. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Array Indicates an array of full name object OH_Drawing_Array. + * @since 14 + */ +void OH_Drawing_DestroySystemFontFullNames(OH_Drawing_Array*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif \ No newline at end of file diff --git a/graphic/graphic_2d/native_drawing/drawing_text_typography.h b/graphic/graphic_2d/native_drawing/drawing_text_typography.h index cf0135e93..eefccd524 100644 --- a/graphic/graphic_2d/native_drawing/drawing_text_typography.h +++ b/graphic/graphic_2d/native_drawing/drawing_text_typography.h @@ -45,6 +45,7 @@ #include "drawing_color.h" #include "drawing_font.h" #include "drawing_text_declaration.h" +#include "drawing_text_font_descriptor.h" #include "drawing_types.h" #include "stdint.h" @@ -412,52 +413,6 @@ typedef struct OH_Drawing_FontConfigInfo { OH_Drawing_FontFallbackGroup* fallbackGroupSet; } OH_Drawing_FontConfigInfo; -/** - * @brief Describes the font information. - * - * @since 12 - * @version 1.0 - */ -typedef struct OH_Drawing_FontDescriptor { - /** The file path of System font */ - char* path; - /** A name that uniquely identifies the font */ - char* postScriptName; - /** The name of System font */ - char* fullName; - /** The family of System font */ - char* fontFamily; - /** The subfont family of the system font */ - char* fontSubfamily; - /** The weight of System font */ - int weight; - /** The width of System font */ - int width; - /** Whether the system font is tilted */ - int italic; - /** Whether the system font is compact */ - bool monoSpace; - /** whether symbolic fonts are supported */ - bool symbolic; -} OH_Drawing_FontDescriptor; - -/** - * @brief An enumeration of system font types. - * - * @since 14 - * @version 1.0 - */ -typedef enum { - /** All font types */ - ALL = 1 << 0, - /** System generic font type */ - GENERIC = 1 << 1, - /** Stylish font type */ - STYLISH = 1 << 2, - /** Installed font types */ - INSTALLED = 1 << 3, -} OH_Drawing_SystemFontType; - /** * @brief The metrics of line. * @@ -1457,26 +1412,6 @@ double OH_Drawing_TypographyGetLineWidth(OH_Drawing_Typography*, int); */ OH_Drawing_Range* OH_Drawing_TypographyGetLineTextRange(OH_Drawing_Typography*, int, bool); -/** - * @brief Creates an OH_Drawing_FontDescriptor object. - * - * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing - * @return Returns the pointer to the font descriptor object OH_Drawing_FontDescriptor created. - * @since 12 - * @version 1.0 - */ -OH_Drawing_FontDescriptor* OH_Drawing_CreateFontDescriptor(void); - -/** - * @brief Releases the memory occupied by an OH_Drawing_FontDescriptor object. - * - * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing - * @param OH_Drawing_FontDescriptor the pointer to the font descriptor object OH_Drawing_FontDescriptor. - * @since 12 - * @version 1.0 - */ -void OH_Drawing_DestroyFontDescriptor(OH_Drawing_FontDescriptor*); - /** * @brief Creates an OH_Drawing_FontParser object. * @@ -1497,50 +1432,6 @@ OH_Drawing_FontParser* OH_Drawing_CreateFontParser(void); */ void OH_Drawing_DestroyFontParser(OH_Drawing_FontParser*); -/** - * @brief Get font details by the full name of the font. - * - * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing - * @param char* Indicates the full name of the font. - * @return Indicates the pointer to a font descriptor object OH_Drawing_FontDescriptor. - * @since 14 - * @version 1.0 - */ -OH_Drawing_FontDescriptor* OH_Drawing_GetFontDescriptorByName(const char* fullName); - -/** - * @brief Obtain the corresponding font full name list by the font type. - * - * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing - * @param OH_Drawing_SystemFontType Indicates enumerates of system font type. - * @return Returns an array of full name. - * @since 14 - * @version 1.0 - */ -OH_Drawing_Array* OH_Drawing_GetSystemFontFullNameListByType(OH_Drawing_SystemFontType fontType); - -/** - * @brief Gets the full name indices by index. - * - * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing - * @param OH_Drawing_Array Indicates an array of full name. - * @param size_t The index of full name. - * @return Returns a full name of the font. - * @since 14 - * @version 1.0 - */ -const char* OH_Drawing_GetSystemFontFullNameListElement(OH_Drawing_Array* fullNameList, size_t index); - -/** - * @brief Releases the memory occupied by a list of system font names. - * - * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing - * @param OH_Drawing_Array Indicates an array of full name. - * @since 14 - * @version 1.0 - */ -void OH_Drawing_DestroySystemFontFullNameList(OH_Drawing_Array* fullNameList); - /** * @brief Gets a list of system font names. * @@ -1564,18 +1455,6 @@ char** OH_Drawing_FontParserGetSystemFontList(OH_Drawing_FontParser*, size_t*); */ void OH_Drawing_DestroySystemFontList(char**, size_t); -/** - * @brief Gets information about the system font by font name. - * - * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing - * @param OH_Drawing_FontParser Indicates the pointer to the font parser object OH_Drawing_FontParser. - * @param char** font name. - * @return Returns system fonts information. - * @since 12 - * @version 1.0 - */ -OH_Drawing_FontDescriptor* OH_Drawing_FontParserGetFontByName(OH_Drawing_FontParser*, const char*); - /** * @brief Get line metrics information. * diff --git a/graphic/graphic_2d/native_drawing/drawing_types.h b/graphic/graphic_2d/native_drawing/drawing_types.h index edcc71cb8..b1b480343 100644 --- a/graphic/graphic_2d/native_drawing/drawing_types.h +++ b/graphic/graphic_2d/native_drawing/drawing_types.h @@ -470,6 +470,19 @@ typedef struct { double leftBottomRadius; } OH_Drawing_RectStyle_Info; +/** + * @brief Defines the string information struct. + * + * @since 14 + * @version 1.0 + */ +typedef struct { + /** A pointer to a byte string containing UTF-16BE(Big Endian) encoded entities */ + uint8_t* strData; + /** The length of `strData` in bytes */ + uint32_t strLen; +} OH_Drawing_String; + /** * @brief Enumerates text encoding types. * @since 12 diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index b58c3b8bd..d1fcb4fc4 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -902,6 +902,14 @@ "first_introduced": "12", "name": "OH_Drawing_DestroyFontDescriptor" }, + { + "first_introduced": "14", + "name": "OH_Drawing_MatchFontDescriptors" + }, + { + "first_introduced": "14", + "name": "OH_Drawing_DestroyFontDescriptors" + }, { "first_introduced": "12", "name": "OH_Drawing_CreateFontParser" @@ -912,19 +920,19 @@ }, { "first_introduced": "14", - "name": "OH_Drawing_GetFontDescriptorByName" + "name": "OH_Drawing_GetFontDescriptorByFullName" }, { "first_introduced": "14", - "name": "OH_Drawing_GetSystemFontFullNameListByType" + "name": "OH_Drawing_GetSystemFontFullNamesByType" }, { "first_introduced": "14", - "name": "OH_Drawing_GetSystemFontFullNameListElement" + "name": "OH_Drawing_GetSystemFontFullNameByIndex" }, { "first_introduced": "14", - "name": "OH_Drawing_DestroySystemFontFullNameList" + "name": "OH_Drawing_DestroySystemFontFullNames" }, { "first_introduced": "12", -- Gitee