diff --git a/graphic/graphic_2d/native_drawing/drawing_font_mgr.h b/graphic/graphic_2d/native_drawing/drawing_font_mgr.h new file mode 100755 index 0000000000000000000000000000000000000000..12e9589dc292f12f7b0044835906b2c83f028335 --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_font_mgr.h @@ -0,0 +1,230 @@ +/* + * Copyright (c) 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_FONT_MGR_H +#define C_INCLUDE_DRAWING_FONT_MGR_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 12 + * @version 1.0 + */ + +/** + * @file drawing_font_mgr.h + * + * @brief Declares functions related to the fontmgr object in the drawing module. + * + * @since 12 + * @version 1.0 + */ + +#include "drawing_types.h" +#include "drawing_text_typography.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates an OH_Drawing_FontMgr object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @return Returns the pointer to the OH_Drawing_FontMgr object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_FontMgr* OH_Drawing_FontMgrCreate(void); + +/** + * @brief Releases the memory occupied by an OH_Drawing_FontMgr object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontMgr Indicates the pointer to an OH_Drawing_FontMgr object. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_FontMgrDestroy(OH_Drawing_FontMgr*); + +/** + * @brief Gets the count of font families. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontMgr Indicates the pointer to an OH_Drawing_FontMgr object. + * @return Returns the count of font families. + * @since 12 + * @version 1.0 + */ +int OH_Drawing_FontMgrGetFamilyCount(OH_Drawing_FontMgr*); + +/** + * @brief Gets the font family name by the index. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontMgr Indicates the pointer to an OH_Drawing_FontMgr object. + * @param index Indicates the index to get the font family name. + * @return Returns the font family name corresponding to the index value. + * @since 12 + * @version 1.0 + */ +char* OH_Drawing_FontMgrGetFamilyName(OH_Drawing_FontMgr*, int index); + +/** + * @brief Releases the memory occupied by font family name. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param familyName Indicates the font family name. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_FontMgrDestroyFamilyName(char* familyName); + +/** + * @brief Creates an OH_Drawing_FontStyleSet object by OH_Drawing_FontMgr object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontMgr Indicates the pointer to an OH_Drawing_FontMgr object. + * @param index Indicates the index used to get the font style set object from the font manager object. + * @return Returns the pointer to the OH_Drawing_FontStyleSet object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_FontStyleSet* OH_Drawing_FontMgrCreateFontStyleSet(OH_Drawing_FontMgr*, int index); + +/** + * @brief Releases the memory occupied by an OH_Drawing_FontStyleSet object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontStyleSet Indicates the pointer to an OH_Drawing_FontStyleSet object. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_FontMgrDestroyFontStyleSet(OH_Drawing_FontStyleSet*); + +/** + * @brief Get the pointer to an OH_Drawing_FontStyleSet object for the given font style set family name. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontMgr Indicates the pointer to an OH_Drawing_FontMgr object. + * @param familyName Indicates the family name of a font style set to be matched. + * @return Returns the pointer to the OH_Drawing_FontStyleSet object matched. + * @since 12 + * @version 1.0 + */ +OH_Drawing_FontStyleSet* OH_Drawing_FontMgrMatchFamily(OH_Drawing_FontMgr*, const char* familyName); + +/** + * @brief Get the pointer to an OH_Drawing_Typeface object based on the given font style and family name. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontMgr Indicates the pointer to an OH_Drawing_FontMgr object. + * @param familyName Indicates the family name of a font style set to be matched. + * @param OH_Drawing_FontStyleStruct Indicates the pointer to an OH_Drawing_FontStyleStruct object. + * @return Returns the pointer to the OH_Drawing_Typeface object matched. + * @since 12 + * @version 1.0 + */ +OH_Drawing_Typeface* OH_Drawing_FontMgrMatchFamilyStyle(OH_Drawing_FontMgr*, + const char* familyName, OH_Drawing_FontStyleStruct*); + +/** + * @brief Get the pointer to an OH_Drawing_Typeface object for the given character. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontMgr Indicates the pointer to an OH_Drawing_FontMgr object. + * @param familyName Indicates the family name of a font style set to be matched. + * @param OH_Drawing_FontStyleStruct Indicates the pointer to an OH_Drawing_FontStyleStruct object. + * @param bcp47 Indicates an array of languages which indicate the language of character. + * @param bcp47Count Indicates the array size of bcp47. + * @param character Indicates a UTF8 value to be matched. + * @return Returns the pointer to the OH_Drawing_Typeface object matched. + * @since 12 + * @version 1.0 + */ +OH_Drawing_Typeface* OH_Drawing_FontMgrMatchFamilyStyleCharacter(OH_Drawing_FontMgr*, const char* familyName, + OH_Drawing_FontStyleStruct*, const char* bcp47[], int bcp47Count, int32_t character); + +/** + * @brief Create a typeface for the given index. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontStyleSet Indicates the pointer to an OH_Drawing_FontStyleSet object. + * @param index Indicates the index of the typeface in this fontStyleSet. + * @return If successful, return a pointer to OH_Drawing_Typeface object; if failed, return nullptr. + * @since 12 + * @version 1.0 + */ +OH_Drawing_Typeface* OH_Drawing_FontStyleSetCreateTypeface(OH_Drawing_FontStyleSet*, int index); + + /** + * @brief Get font style for the specified typeface. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontStyleSet Indicates the pointer to an OH_Drawing_FontStyleSet object. + * @param index Indicates the index of the typeface in this fontStyleSet. + * @param styleName Indicates the style name returned. + * @return Return the OH_Drawing_FontStyleStruct structure. + * @since 12 + * @version 1.0 + */ +OH_Drawing_FontStyleStruct OH_Drawing_FontStyleSetGetStyle(OH_Drawing_FontStyleSet*, int32_t index, + char** styleName); + + /** + * @brief Releases the memory styleName string. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param styleName Indicates the pointer to a string type. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_FontStyleSetFreeStyleName(char** styleName); + +/** + * @brief Get the closest matching typeface. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontStyleSet Indicates the pointer to an OH_Drawing_FontStyleSet object. + * @param fontStyleStruct Indicates the OH_Drawing_FontStyleStruct structure. + * @return A pointer to matched OH_Drawing_Typeface. + * @since 12 + * @version 1.0 + */ +OH_Drawing_Typeface* OH_Drawing_FontStyleSetMatchStyle(OH_Drawing_FontStyleSet*, + OH_Drawing_FontStyleStruct fontStyleStruct); + +/** + * @brief Get the count of typeface. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_FontStyleSet Indicates the pointer to an OH_Drawing_FontStyleSet object. + * @return The count of typeface in this font style set. + * @since 12 + * @version 1.0 + */ +int OH_Drawing_FontStyleSetCount(OH_Drawing_FontStyleSet*); + +#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 90c0ebb964acfeefceb261dc2d170995ffbbd781..adf1088d65de2801bc9b53dedd8b277c857e8032 100644 --- a/graphic/graphic_2d/native_drawing/drawing_text_typography.h +++ b/graphic/graphic_2d/native_drawing/drawing_text_typography.h @@ -366,6 +366,33 @@ typedef struct { int value; } OH_Drawing_FontFeature; +/** + * @brief Enumerates text style type. + * + * @since 12 + * @version 1.0 + */ +enum OH_Drawing_TextStyleType { + /** None style */ + TextStyle_NONE, + /** All attributes style */ + TextStyle_ALL_ATTRIBUTES, + /** Font style */ + TextStyle_FONT, + /** Foreground style */ + TextStyle_FOREGROUND, + /** Background style */ + TextStyle_BACKGROUND, + /** Shadow style */ + TextStyle_SHADOW, + /** Decorations style */ + TextStyle_DECORATIONS, + /** Letter spacing style */ + TextStyle_LETTER_SPACING, + /** Word spacing style */ + TextStyle_WORD_SPACING +}; + /** * @brief Creates an OH_Drawing_TypographyStyle object. * @@ -1943,6 +1970,87 @@ bool OH_Drawing_TextStyleGetHalfLeading(OH_Drawing_TextStyle*); */ const char* OH_Drawing_TextStyleGetLocale(OH_Drawing_TextStyle*); +/** + * @brief Gets whether the two TextStyle objects are equal. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param style Indicates source of comparison OH_Drawing_TextStyle object. + * @param comparedStyle Indicates comparison OH_Drawing_TextStyle object. + * @return Compare result. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_TextStyleIsEquals(const OH_Drawing_TextStyle* style, const OH_Drawing_TextStyle* comparedStyle); + +/** + * @brief Gets whether the font properties of two TextStyle objects are equal. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param style Indicates source of comparison OH_Drawing_TextStyle object. + * @param comparedStyle Indicates comparison OH_Drawing_TextStyle object. + * @return Compare result. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_TextStyleIsEqualsByFonts(const OH_Drawing_TextStyle* style, const OH_Drawing_TextStyle* comparedStyle); + +/** + * @brief Gets whether two TextStyle objects match attributes + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param textStyleType Indicates enumerates of text style type. + * @param style Indicates source of comparison OH_Drawing_TextStyle object. + * @param comparedStyle Indicates comparison OH_Drawing_TextStyle object. + * @return Match attributes result. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_TextStyleIsMatchOneAttribute(const OH_Drawing_TextStyle* style, + const OH_Drawing_TextStyle* comparedStyle, OH_Drawing_TextStyleType textStyleType); + +/** + * @brief Set placeholder of TextStyle. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_TextStyle Indicates the pointer to an OH_Drawing_TextStyle object. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_TextStyleSetPlaceholder(OH_Drawing_TextStyle* style); + +/** + * @brief Gets whether placeholder is enable. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_TextStyle Indicates the pointer to an OH_Drawing_TextStyle object. + * @return Whether placeholder is enable. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_TextStyleIsPlaceholder(OH_Drawing_TextStyle* style); + +/** + * @brief Gets text alignment mode. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_TypographyStyle Indicates the pointer to an OH_Drawing_TypographyStyle object. + * @return Returns text alignment mode. + * @since 12 + * @version 1.0 + */ +OH_Drawing_TextAlign OH_Drawing_TypographyStyleGetEffectiveAlignment(OH_Drawing_TypographyStyle* style); + +/** + * @brief Gets whether the hinting is enabled. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_TypographyStyle Indicates the pointer to an OH_Drawing_TypographyStyle object. + * @return True, if the hinting takes effect; False, if the hinting does not take effect. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_TypographyStyleIsHintingEnabled(OH_Drawing_TypographyStyle* style); + #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index b0ed71fce71647195f16c80b7b7b71d7bbb9ffe2..1c47a2874122f420ac803e50a72865c0325bb949 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -897,5 +897,53 @@ { "first_introduced": "12", "name": "OH_Drawing_TextStyleGetLocale" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_TextStyleIsEquals" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_TextStyleIsEqualsByFonts" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_TextStyleIsMatchOneAttribute" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_TextStyleSetPlaceholder" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_TextStyleIsPlaceholder" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_TypographyStyleGetEffectiveAlignment" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_TypographyStyleIsHintingEnabled" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontStyleSetCreateTypeface" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontStyleSetGetStyle" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontStyleSetFreeStyleName" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontStyleSetMatchStyle" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontStyleSetCount" } ] \ No newline at end of file