1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef C_INCLUDE_DRAWING_TYPEFACE_H 17 #define C_INCLUDE_DRAWING_TYPEFACE_H 18 19 /** 20 * @addtogroup Drawing 21 * @{ 22 * 23 * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. 24 * 25 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 26 * 27 * @since 11 28 * @version 1.0 29 */ 30 31 /** 32 * @file drawing_typeface.h 33 * 34 * @brief Declares functions related to the <b>typeface</b> object in the drawing module. 35 * 36 * @kit ArkGraphics2D 37 * @library libnative_drawing.so 38 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 39 * @since 11 40 * @version 1.0 41 */ 42 43 #include "drawing_error_code.h" 44 #include "drawing_types.h" 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 /** 51 * @brief Creates a default <b>OH_Drawing_Typeface</b> object. 52 * 53 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 54 * @return Returns the pointer to the <b>OH_Drawing_Typeface</b> object created. 55 * @since 11 56 * @version 1.0 57 */ 58 OH_Drawing_Typeface* OH_Drawing_TypefaceCreateDefault(void); 59 60 /** 61 * @brief Creates an <b>OH_Drawing_Typeface</b> object by file. 62 * 63 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 64 * @param path file path. 65 * @param index file index. 66 * @return Returns the pointer to the <b>OH_Drawing_Typeface</b> object created. 67 * @since 12 68 * @version 1.0 69 */ 70 OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromFile(const char* path, int index); 71 72 /** 73 * @brief Creates an <b>OH_Drawing_Typeface</b> object with the specified font arguments from a file. 74 * If the <b>OH_Drawing_Typeface</b> object does not support the variations described in fontArguments, 75 * this function creates an <b>OH_Drawing_Typeface</b> object without font arguments. 76 * In this case, this function provides the same capability as {@link OH_Drawing_TypefaceCreateFromFile}. 77 * 78 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 79 * @param path Indicates the file path. 80 * @param fontArguments Indicates the pointer to an <b>OH_Drawing_FontArguments</b> object. 81 * @return Returns the pointer to the <b>OH_Drawing_Typeface</b> object created. 82 * If nullptr is returned, the creation fails. 83 * The possible cause of the failure is that the available memory is empty, 84 * or either path or fontArguments is nullptr, or the path is invalid. 85 * @since 13 86 * @version 1.0 87 */ 88 OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromFileWithArguments(const char* path, 89 const OH_Drawing_FontArguments* fontArguments); 90 91 /** 92 * @brief Creates an <b>OH_Drawing_Typeface</b> object with the specified font arguments from 93 * an existing <b>OH_Drawing_Typeface</b> object. 94 * 95 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 96 * @param current Indicates the existing <b>OH_Drawing_Typeface</b> object. 97 * @param fontArguments Indicates the pointer to an <b>OH_Drawing_FontArguments</b> object. 98 * @return Returns the pointer to the <b>OH_Drawing_Typeface</b> object created. 99 * If nullptr is returned, the creation fails. 100 * The possible cause of the failure is that the available memory is empty, 101 * or either current or fontArguments is nullptr, 102 * or current does not support the variations described in fontArguments. 103 * @since 13 104 * @version 1.0 105 */ 106 OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromCurrent(const OH_Drawing_Typeface* current, 107 const OH_Drawing_FontArguments* fontArguments); 108 109 /** 110 * @brief Creates an <b>OH_Drawing_Typeface</b> object by given a stream. If the stream is not a valid 111 * font file, returns nullptr. Ownership of the stream is transferred, so the caller must not reference 112 * it or free it again. 113 * 114 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 115 * @param OH_Drawing_MemoryStream Indicates the pointer to an <b>OH_Drawing_MemoryStream</b> object. 116 * @param index memory stream index. 117 * @return Returns the pointer to the <b>OH_Drawing_Typeface</b> object created. 118 * @since 12 119 * @version 1.0 120 */ 121 OH_Drawing_Typeface* OH_Drawing_TypefaceCreateFromStream(OH_Drawing_MemoryStream*, int32_t index); 122 123 /** 124 * @brief Destroys an <b>OH_Drawing_Typeface</b> object and reclaims the memory occupied by the object. 125 * 126 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 127 * @param OH_Drawing_Typeface Indicates the pointer to an <b>OH_Drawing_Typeface</b> object. 128 * @since 11 129 * @version 1.0 130 */ 131 void OH_Drawing_TypefaceDestroy(OH_Drawing_Typeface*); 132 133 /** 134 * @brief Creates an <b>OH_Drawing_FontArguments</b> object. 135 * 136 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 137 * @return Returns the pointer to the <b>OH_Drawing_FontArguments</b> object created. 138 * If nullptr is returned, the creation fails. 139 * The possible cause of the failure is that the available memory is empty. 140 * @since 13 141 * @version 1.0 142 */ 143 OH_Drawing_FontArguments* OH_Drawing_FontArgumentsCreate(void); 144 145 /** 146 * @brief Adds a font variation axis for an <b>OH_Drawing_FontArguments</b> object. 147 * 148 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 149 * @param fontArguments Indicates the pointer to an <b>OH_Drawing_FontArguments</b> object. 150 * @param axis Indicates the axis tag, which must contain four ASCII characters. 151 * @param value Indicates the value of the axis field. 152 * @return Returns the error code. 153 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 154 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if either fontArguments or axis is nullptr, 155 * or the length of axis is not 4. 156 * @since 13 157 * @version 1.0 158 */ 159 OH_Drawing_ErrorCode OH_Drawing_FontArgumentsAddVariation(OH_Drawing_FontArguments* fontArguments, 160 const char* axis, float value); 161 162 /** 163 * @brief Destroys an <b>OH_Drawing_FontArguments</b> object and reclaims the memory occupied by the object. 164 * 165 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 166 * @param fontArguments Indicates the pointer to an <b>OH_Drawing_FontArguments</b> object. 167 * @return Returns the error code. 168 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 169 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if fontArguments is nullptr. 170 * @since 13 171 * @version 1.0 172 */ 173 OH_Drawing_ErrorCode OH_Drawing_FontArgumentsDestroy(OH_Drawing_FontArguments* fontArguments); 174 175 #ifdef __cplusplus 176 } 177 #endif 178 /** @} */ 179 #endif 180