1 /* 2 * Copyright (c) 2023-2024 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 /** 17 * @addtogroup Drawing 18 * @{ 19 * 20 * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. 21 * 22 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 23 * 24 * @since 11 25 * @version 1.0 26 */ 27 28 /** 29 * @file drawing_font.h 30 * 31 * @brief Declares functions related to the <b>font</b> object in the drawing module. 32 * 33 * @kit ArkGraphics2D 34 * @library libnative_drawing.so 35 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 36 * @since 11 37 * @version 1.0 38 */ 39 40 #ifndef C_INCLUDE_DRAWING_FONT_H 41 #define C_INCLUDE_DRAWING_FONT_H 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 an <b>OH_Drawing_Font</b> object. 52 * 53 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 54 * @return Returns the pointer to the <b>OH_Drawing_Font</b> object created. 55 * @since 11 56 * @version 1.0 57 */ 58 OH_Drawing_Font* OH_Drawing_FontCreate(void); 59 60 /** 61 * @brief Enumerates font hinting pattern. 62 * 63 * @since 12 64 * @version 1.0 65 */ 66 typedef enum { 67 /** glyph outlines unchanged */ 68 FONT_HINTING_NONE, 69 /** minimal modification to improve contrast */ 70 FONT_HINTING_SLIGHT, 71 /** glyph outlines modified to improve contrast */ 72 FONT_HINTING_NORMAL, 73 /** modifies glyph outlines for maximum contrast */ 74 FONT_HINTING_FULL, 75 } OH_Drawing_FontHinting; 76 77 /** 78 * @brief Enumerates font edging effect. 79 * 80 * @since 12 81 * @version 1.0 82 */ 83 typedef enum { 84 /** no transparent pixels on glyph edges */ 85 FONT_EDGING_ALIAS, 86 /** may have transparent pixels on glyph edges */ 87 FONT_EDGING_ANTI_ALIAS, 88 /** glyph positioned in pixel using transparency */ 89 FONT_EDGING_SUBPIXEL_ANTI_ALIAS, 90 } OH_Drawing_FontEdging; 91 92 /** 93 * @brief Sets whether the font baselines and pixels alignment when the transformation matrix is axis aligned. 94 * 95 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 96 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 97 * @param baselineSnap Indicates whether the font baselines and pixels alignment. 98 * @since 12 99 * @version 1.0 100 */ 101 void OH_Drawing_FontSetBaselineSnap(OH_Drawing_Font* font, bool baselineSnap); 102 103 /** 104 * @brief Gets whether the font baselines and pixels alignment when the transformation matrix is axis aligned. 105 * 106 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 107 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 108 * @return Returns <b>true</b> if the font baselines and pixels alignment; returns <b>false</b> otherwise. 109 * @since 12 110 * @version 1.0 111 */ 112 bool OH_Drawing_FontIsBaselineSnap(const OH_Drawing_Font* font); 113 114 /** 115 * @brief Sets whether the font uses sub-pixel rendering. 116 * 117 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 118 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 119 * @param isSubpixel Indicates whether the font uses sub-pixel rendering. 120 * @since 12 121 * @version 1.0 122 */ 123 void OH_Drawing_FontSetSubpixel(OH_Drawing_Font* font, bool isSubpixel); 124 125 /** 126 * @brief Gets whether the font uses sub-pixel rendering. 127 * 128 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 129 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 130 * @return Returns <b>true</b> if the font uses sub-pixel rendering; returns <b>false</b> otherwise. 131 * @since 12 132 * @version 1.0 133 */ 134 bool OH_Drawing_FontIsSubpixel(const OH_Drawing_Font* font); 135 136 /** 137 * @brief Sets whether the font outline is automatically adjusted. 138 * 139 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 140 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 141 * @param isForceAutoHinting Indicates whether the font outline is automatically adjusted. 142 * @since 12 143 * @version 1.0 144 */ 145 void OH_Drawing_FontSetForceAutoHinting(OH_Drawing_Font* font, bool isForceAutoHinting); 146 147 /** 148 * @brief Gets whether the font outline is automatically adjusted. 149 * 150 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 151 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 152 * @return Returns <b>true</b> if the font outline is automatically adjusted; returns <b>false</b> otherwise. 153 * @since 12 154 * @version 1.0 155 */ 156 bool OH_Drawing_FontIsForceAutoHinting(const OH_Drawing_Font* font); 157 158 /** 159 * @brief Sets an <b>OH_Drawing_Typeface</b> object for an <b>OH_Drawing_Font</b> object. 160 * 161 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 162 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 163 * @param typeface Indicates the pointer to an <b>OH_Drawing_Typeface</b> object. 164 * @since 11 165 * @version 1.0 166 */ 167 void OH_Drawing_FontSetTypeface(OH_Drawing_Font* font, OH_Drawing_Typeface* typeface); 168 169 /** 170 * @brief Gets an <b>OH_Drawing_Typeface</b> object from the <b>OH_Drawing_Typeface</b> object. 171 * 172 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 173 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 174 * @return OH_Drawing_Typeface Indicates the pointer to an <b>OH_Drawing_Typeface</b> object. 175 * @since 12 176 * @version 1.0 177 */ 178 OH_Drawing_Typeface* OH_Drawing_FontGetTypeface(OH_Drawing_Font* font); 179 180 /** 181 * @brief Sets text size for an <b>OH_Drawing_Font</b> object. 182 * 183 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 184 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 185 * @param textSize Indicates the text size. 186 * @since 11 187 * @version 1.0 188 */ 189 void OH_Drawing_FontSetTextSize(OH_Drawing_Font* font, float textSize); 190 191 /** 192 * @brief Gets text size for an <b>OH_Drawing_Font</b> object. 193 * 194 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 195 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 196 * @return Returns the size of text. 197 * @since 12 198 * @version 1.0 199 */ 200 float OH_Drawing_FontGetTextSize(const OH_Drawing_Font* font); 201 202 /** 203 * @brief Calculate number of glyphs represented by text. 204 * 205 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 206 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 207 * @param text Indicates the character storage encoded with text encoding. 208 * @param byteLength Indicates the text length in bytes. 209 * @param encoding Indicates the text encoding. 210 * @since 12 211 * @version 1.0 212 */ 213 int OH_Drawing_FontCountText(OH_Drawing_Font* font, const void* text, size_t byteLength, 214 OH_Drawing_TextEncoding encoding); 215 216 /** 217 * @brief Converts text into glyph indices. 218 * 219 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 220 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 221 * @param text Indicates the character storage encoded with text encoding. 222 * @param byteLength Indicates the text length in bytes. 223 * @param encoding Indicates the text encoding. 224 * @param glyphs Indicates the storage for glyph indices. 225 * @param maxGlyphCount Indicates the storage capacity. 226 * @return Returns the number of glyph indices represented by text. 227 * @since 12 228 * @version 1.0 229 */ 230 uint32_t OH_Drawing_FontTextToGlyphs(const OH_Drawing_Font* font, const void* text, uint32_t byteLength, 231 OH_Drawing_TextEncoding encoding, uint16_t* glyphs, int maxGlyphCount); 232 233 /** 234 * @brief Retrieves the advance for each glyph in glyphs. 235 * 236 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 237 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 238 * @param glyphs Indicates the array of glyph indices to be measured. 239 * @param count Indicates the number of glyphs. 240 * @param widths Indicates the text advances for each glyph returned to the caller. 241 * @since 12 242 * @version 1.0 243 */ 244 void OH_Drawing_FontGetWidths(const OH_Drawing_Font* font, const uint16_t* glyphs, int count, float* widths); 245 246 /** 247 * @brief Measures the width of a single character. 248 * 249 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 250 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 251 * @param str Indicates the single character encoded in UTF-8. 252 * @param textWidth Indicates the width of the single character. 253 * @return Returns the error code. 254 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 255 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of font, str 256 * and textWidth is nullptr or strlen(str) is 0. 257 * @since 12 258 * @version 1.0 259 */ 260 OH_Drawing_ErrorCode OH_Drawing_FontMeasureSingleCharacter(const OH_Drawing_Font* font, const char* str, 261 float* textWidth); 262 263 /** 264 * @brief Measures the width of a single character with font features. 265 * 266 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 267 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 268 * @param str Indicates the single character encoded in UTF-8. 269 * @param fontFeatures Indicates the pointer to an <b>OH_Drawing_FontFeatures</b> object. 270 * @param textWidth Indicates the width of the single character. 271 * @return Returns the error code. 272 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 273 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of font, str 274 * fontFeatures or textWidth is nullptr, or if strlen(str) is 0. 275 * @since 20 276 * @version 1.0 277 */ 278 OH_Drawing_ErrorCode OH_Drawing_FontMeasureSingleCharacterWithFeatures(const OH_Drawing_Font* font, const char* str, 279 const OH_Drawing_FontFeatures* fontFeatures, float* textWidth); 280 281 /** 282 * @brief Measures the width of text. 283 * 284 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 285 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 286 * @param text Indicates the character storage encoded with text encoding. 287 * @param byteLength Indicates the text length in bytes. 288 * @param encoding Indicates the text encoding. 289 * @param bounds Gets the bounding box relative to (0, 0) if not nullptr. 290 * @param textWidth Indicates the width of text. 291 * @return Returns the error code. 292 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 293 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of font, text 294 * and textWidth is nullptr or byteLength is 0. 295 * @since 12 296 * @version 1.0 297 */ 298 OH_Drawing_ErrorCode OH_Drawing_FontMeasureText(const OH_Drawing_Font* font, const void* text, size_t byteLength, 299 OH_Drawing_TextEncoding encoding, OH_Drawing_Rect* bounds, float* textWidth); 300 301 /** 302 * @brief Measures the width of text with brush or pen. 303 * 304 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 305 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 306 * @param text Indicates the character storage encoded with text encoding. 307 * @param byteLength Indicates the text length in bytes. 308 * @param encoding Indicates the text encoding. 309 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 310 * @param pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 311 * @param bounds Gets the bounding box relative to (0, 0) if not nullptr. 312 * @param textWidth Indicates the width of text. 313 * @return Returns the error code. 314 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 315 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of font, text 316 * and textWidth is nullptr or byteLength is 0 or brush and pen are both not empty. 317 * @since 19 318 * @version 1.0 319 */ 320 OH_Drawing_ErrorCode OH_Drawing_FontMeasureTextWithBrushOrPen(const OH_Drawing_Font* font, const void* text, 321 size_t byteLength, OH_Drawing_TextEncoding encoding, const OH_Drawing_Brush* brush, const OH_Drawing_Pen* pen, 322 OH_Drawing_Rect* bounds, float* textWidth); 323 324 /** 325 * @brief Retrieves the advance and bounding box for each glyph in glyphs. 326 * 327 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 328 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 329 * @param glyphs Indicates the array of glyph indices to be measured. 330 * @param count Indicates the number of glyphs. 331 * @param brush Indicates the pointer to an <b>OH_Drawing_Brush</b> object. 332 * @param pen Indicates the pointer to an <b>OH_Drawing_Pen</b> object. 333 * @param widths Indicates the text advances for each glyph returned to the caller. 334 * @param bounds Indicates the text bounding box for each glyph returned to the caller. 335 * @return Returns the error code. 336 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 337 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of font and glyphs is nullptr 338 * or count is no larger than 0 or brush and pen are both not empty. 339 * @since 19 340 * @version 1.0 341 */ 342 OH_Drawing_ErrorCode OH_Drawing_FontGetWidthsBounds(const OH_Drawing_Font* font, const uint16_t* glyphs, int count, 343 const OH_Drawing_Brush* brush, const OH_Drawing_Pen* pen, float* widths, OH_Drawing_Array* bounds); 344 345 /** 346 * @brief Retrieves the positions for each glyph, beginning at the specified origin. 347 * 348 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 349 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 350 * @param glyphs Indicates the array of glyph indices to be measured. 351 * @param count Indicates the number of glyphs. 352 * @param origin Indicates the location of the first glyph. 353 * @param points Indicates the relative position for each glyph returned to the caller. 354 * @return Returns the error code. 355 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 356 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of font, glyphs and points is nullptr or 357 * count is no larger than 0. 358 * @since 19 359 * @version 1.0 360 */ 361 OH_Drawing_ErrorCode OH_Drawing_FontGetPos(const OH_Drawing_Font* font, const uint16_t* glyphs, int count, 362 const OH_Drawing_Point* origin, OH_Drawing_Point2D* points); 363 364 /** 365 * @brief Returns the recommended spacing between lines. 366 * 367 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 368 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 369 * @param spacing Indicates the recommended spacing between lines. 370 * @return Returns the error code. 371 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 372 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of font and spacing is nullptr. 373 * @since 19 374 * @version 1.0 375 */ 376 OH_Drawing_ErrorCode OH_Drawing_FontGetSpacing(const OH_Drawing_Font* font, float* spacing); 377 378 /** 379 * @brief Enables or disables linearly scalable font for an <b>OH_Drawing_Font</b> object. 380 * 381 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 382 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 383 * @param isLinearText Indicates whether to enable linearly scalable font. 384 * @since 11 385 * @version 1.0 386 */ 387 void OH_Drawing_FontSetLinearText(OH_Drawing_Font* font, bool isLinearText); 388 389 /** 390 * @brief Gets whether the font is linearly scalable. 391 * 392 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 393 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 394 * @return Returns <b>true</b> if the font is linearly scalable; returns <b>false</b> otherwise. 395 * @since 12 396 * @version 1.0 397 */ 398 bool OH_Drawing_FontIsLinearText(const OH_Drawing_Font* font); 399 400 /** 401 * @brief Sets text skew on x-axis for an <b>OH_Drawing_Font</b> object. 402 * 403 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 404 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 405 * @param skewX Indicates the additional shear on x-axis relative to y-axis. 406 * @since 11 407 * @version 1.0 408 */ 409 void OH_Drawing_FontSetTextSkewX(OH_Drawing_Font* font, float skewX); 410 411 /** 412 * @brief Gets text skew on x-axis for an <b>OH_Drawing_Font</b> object. 413 * 414 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 415 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 416 * @return Returns additional skew on x-axis relative to y-axis. 417 * @since 12 418 * @version 1.0 419 */ 420 float OH_Drawing_FontGetTextSkewX(const OH_Drawing_Font* font); 421 422 /** 423 * @brief Enables or disables to increase stroke width to approximate bold fonts for an <b>OH_Drawing_Font</b> object. 424 * 425 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 426 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 427 * @param isFakeBoldText Indicates whether to enable to increase stroke width. 428 * @since 11 429 * @version 1.0 430 */ 431 void OH_Drawing_FontSetFakeBoldText(OH_Drawing_Font* font, bool isFakeBoldText); 432 433 /** 434 * @brief Gets whether to increase the stroke width to approximate bold fonts. 435 * 436 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 437 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 438 * @return Returns <b>true</b> to increase the stroke width to approximate bold fonts; returns <b>false</b> otherwise. 439 * @since 12 440 * @version 1.0 441 */ 442 bool OH_Drawing_FontIsFakeBoldText(const OH_Drawing_Font* font); 443 444 /** 445 * @brief Sets text scale on x-axis for an <b>OH_Drawing_Font</b> object. 446 * 447 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 448 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 449 * @param scaleX Indicates the text horizontal scale. 450 * @since 12 451 * @version 1.0 452 */ 453 void OH_Drawing_FontSetScaleX(OH_Drawing_Font* font, float scaleX); 454 455 /** 456 * @brief Gets text scale on x-axis from an <b>OH_Drawing_Font</b> object. 457 * 458 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 459 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 460 * @return Returns text horizontal scale on x-axis. 461 * @since 12 462 * @version 1.0 463 */ 464 float OH_Drawing_FontGetScaleX(const OH_Drawing_Font* font); 465 466 /** 467 * @brief Sets hinting pattern for an <b>OH_Drawing_Font</b> object. 468 * 469 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 470 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 471 * @param fontHinting Indicates the font hinting pattern. 472 * @since 12 473 * @version 1.0 474 */ 475 void OH_Drawing_FontSetHinting(OH_Drawing_Font* font, OH_Drawing_FontHinting fontHinting); 476 477 /** 478 * @brief Gets hinting pattern from an <b>OH_Drawing_Font</b> object. 479 * 480 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 481 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 482 * @return Returns the font hinting pattern. 483 * @since 12 484 * @version 1.0 485 */ 486 OH_Drawing_FontHinting OH_Drawing_FontGetHinting(const OH_Drawing_Font* font); 487 488 /** 489 * @brief Sets whether to use bitmaps instead of outlines in the <b>OH_Drawing_Font</b> object. 490 * 491 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 492 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 493 * @param isEmbeddedBitmaps Indicates whether to use bitmaps instead of outlines. 494 * @since 12 495 * @version 1.0 496 */ 497 void OH_Drawing_FontSetEmbeddedBitmaps(OH_Drawing_Font* font, bool isEmbeddedBitmaps); 498 499 /** 500 * @brief Gets whether to use bitmaps instead of outlines in the <b>OH_Drawing_Font</b> object. 501 * 502 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 503 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 504 * @return Returns <b>true</b> if using bitmaps instead of outlines; returns <b>false</b> otherwise. 505 * @since 12 506 * @version 1.0 507 */ 508 bool OH_Drawing_FontIsEmbeddedBitmaps(const OH_Drawing_Font* font); 509 510 /** 511 * @brief Sets the font edging effect for an <b>OH_Drawing_Font</b> object. 512 * 513 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 514 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 515 * @param fontEdging Indicates the font edging effect. 516 * @since 12 517 * @version 1.0 518 */ 519 void OH_Drawing_FontSetEdging(OH_Drawing_Font* font, OH_Drawing_FontEdging fontEdging); 520 521 /** 522 * @brief Gets the font edging effect from an <b>OH_Drawing_Font</b> object. 523 * 524 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 525 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 526 * @return Returns the font edging effect. 527 * @since 12 528 * @version 1.0 529 */ 530 OH_Drawing_FontEdging OH_Drawing_FontGetEdging(const OH_Drawing_Font* font); 531 532 /** 533 * @brief Destroys an <b>OH_Drawing_Font</b> object and reclaims the memory occupied by the object. 534 * 535 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 536 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 537 * @since 11 538 * @version 1.0 539 */ 540 void OH_Drawing_FontDestroy(OH_Drawing_Font* font); 541 542 /** 543 * @brief Defines a run, supplies storage for the metrics of an <b>OH_Drawing_Font</b>. 544 * 545 * @since 12 546 * @version 1.0 547 */ 548 typedef struct OH_Drawing_Font_Metrics { 549 /** Indicating which metrics are valid */ 550 uint32_t flags; 551 /** storage for top in font metrics */ 552 float top; 553 /** storage for ascent in font metrics */ 554 float ascent; 555 /** storage for descent in font metrics */ 556 float descent; 557 /** storage for bottom in font metrics */ 558 float bottom; 559 /** storage for leading in font metrics */ 560 float leading; 561 /** Average character width, zero if unknown */ 562 float avgCharWidth; 563 /** Maximum character width, zero if unknown */ 564 float maxCharWidth; 565 /** Greatest extent to left of origin of any glyph bounding box, typically negative; deprecated with variable fonts */ 566 float xMin; 567 /** Greatest extent to right of origin of any glyph bounding box, typically positive; deprecated with variable fonts */ 568 float xMax; 569 /** Height of lower-case letter, zero if unknown, typically negative */ 570 float xHeight; 571 /** Height of an upper-case letter, zero if unknown, typically negative */ 572 float capHeight; 573 /** @brief Underline thickness */ 574 float underlineThickness; 575 /** Distance from baseline to top of stroke, typically positive */ 576 float underlinePosition; 577 /** Strikeout thickness */ 578 float strikeoutThickness; 579 /** Distance from baseline to bottom of stroke, typically negative */ 580 float strikeoutPosition; 581 } OH_Drawing_Font_Metrics; 582 583 /** 584 * @brief Obtains the metrics of a font. 585 * 586 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 587 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 588 * @param fontMetrics Indicates the pointer to an <b>OH_Drawing_Font_Metrics</b> object. 589 * @return Returns a float variable that recommended spacing between lines. 590 * @since 12 591 * @version 1.0 592 */ 593 float OH_Drawing_FontGetMetrics(OH_Drawing_Font* font, OH_Drawing_Font_Metrics* fontMetrics); 594 595 /** 596 * @brief Retrieves the bound rect for each glyph in glyph array. 597 * 598 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 599 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 600 * @param glyphs Indicates the array of glyph indices to be measured. 601 * @param count Indicates the number of glyphs. 602 * @param bounds The bound rect array for each glyph, returned to the caller. 603 * @return Returns the error code. 604 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 605 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of font, glyphs 606 * and bounds is nullptr or count is 0. 607 * @since 18 608 * @version 1.0 609 */ 610 OH_Drawing_ErrorCode OH_Drawing_FontGetBounds(const OH_Drawing_Font* font, const uint16_t* glyphs, uint32_t count, 611 OH_Drawing_Array* bounds); 612 613 /** 614 * @brief Retrieves the path for specified Glyph. 615 * 616 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 617 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 618 * @param glyph glyph index to be obtained. 619 * @param path The path object, returned to the caller. 620 * @return Returns the error code. 621 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 622 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of font, path 623 * is nullptr or glyph not exist. 624 * @since 18 625 * @version 1.0 626 */ 627 OH_Drawing_ErrorCode OH_Drawing_FontGetPathForGlyph(const OH_Drawing_Font* font, uint16_t glyph, 628 OH_Drawing_Path* path); 629 630 /** 631 * @brief Get the text outline path. 632 * 633 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 634 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 635 * @param text Indicates the character storage encoded with text encoding. 636 * @param byteLength Indicates to get the byte length of the corresponding text path. If this byte length is greater 637 * than the byte length of the text string, undefined behavior will occur. 638 * @param encoding <b>OH_Drawing_TextEncoding</b> Indicates the text encoding. 639 * @param x Indicates x coordinates of the text. 640 * @param y Indicates y coordinates of the text. 641 * @param path <b>OH_Drawing_Path</b> The path object, returned to the caller. 642 * @return Returns the error code. 643 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 644 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of font, text or path is nullptr. 645 * @since 18 646 */ 647 OH_Drawing_ErrorCode OH_Drawing_FontGetTextPath(const OH_Drawing_Font* font, const void* text, size_t byteLength, 648 OH_Drawing_TextEncoding encoding, float x, float y, OH_Drawing_Path* path); 649 650 /** 651 * @brief Creates an <b>OH_Drawing_FontFeatures</b> object. 652 * 653 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 654 * @return Returns the pointer to the <b>OH_Drawing_FontFeatures</b> object created. 655 * If nullptr is returned, the creation fails. 656 * The possible cause of the failure is that the available memory is empty. 657 * @since 20 658 * @version 1.0 659 */ 660 OH_Drawing_FontFeatures* OH_Drawing_FontFeaturesCreate(void); 661 662 /** 663 * @brief Adds a font feature for an <b>OH_Drawing_FontFeatures</b> object. 664 * 665 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 666 * @param fontFeatures Indicates the pointer to an <b>OH_Drawing_FontFeatures</b> object. 667 * @param name Indicates the feature name. 668 * @param value Indicates the value of the feature. 669 * @return Returns the error code. 670 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 671 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if either fontFeatures or name is nullptr. 672 * @since 20 673 * @version 1.0 674 */ 675 OH_Drawing_ErrorCode OH_Drawing_FontFeaturesAddFeature(OH_Drawing_FontFeatures* fontFeatures, 676 const char* name, float value); 677 678 /** 679 * @brief Destroys an <b>OH_Drawing_FontFeatures</b> object and reclaims the memory occupied by the object. 680 * 681 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 682 * @param fontFeatures Indicates the pointer to an <b>OH_Drawing_FontFeatures</b> object. 683 * @return Returns the error code. 684 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 685 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if fontFeatures is nullptr. 686 * @since 20 687 * @version 1.0 688 */ 689 OH_Drawing_ErrorCode OH_Drawing_FontFeaturesDestroy(OH_Drawing_FontFeatures* fontFeatures); 690 691 /** 692 * @brief Sets whether to follow the theme font. If the value is true, the theme font is used when typeface is not set. 693 * 694 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 695 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 696 * @param followed Indicates whether to follow the theme font. 697 * @return Returns the error code. 698 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 699 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if font is nullptr. 700 * @since 15 701 */ 702 OH_Drawing_ErrorCode OH_Drawing_FontSetThemeFontFollowed(OH_Drawing_Font* font, bool followed); 703 704 /** 705 * @brief Gets whether to follow the theme font. 706 * 707 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 708 * @param font Indicates the pointer to an <b>OH_Drawing_Font</b> object. 709 * @param followed Indicates whether to follow the theme font. 710 * @return Returns the error code. 711 * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. 712 * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if font or followed is nullptr. 713 * @since 15 714 */ 715 OH_Drawing_ErrorCode OH_Drawing_FontIsThemeFontFollowed(const OH_Drawing_Font* font, bool* followed); 716 717 #ifdef __cplusplus 718 } 719 #endif 720 /** @} */ 721 #endif 722