1/* 2 * Copyright (c) 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 * @file 18 * @kit ArkGraphics2D 19 */ 20import type drawing from './@ohos.graphics.drawing'; 21import type common2D from './@ohos.graphics.common2D'; 22 23/** 24 * Provides functions such as 2D graphics text paragraphs, text styles. 25 * 26 * @namespace text 27 * @syscap SystemCapability.Graphics.Drawing 28 * @since 12 29 */ 30declare namespace text { 31 32 /** 33 * Refers to how to align the horizontal position of text when displaying text. 34 * @enum { number } 35 * @syscap SystemCapability.Graphics.Drawing 36 * @since 12 37 */ 38 enum TextAlign { 39 /** 40 * Use the left side of the text as a reference line for alignment. 41 * @syscap SystemCapability.Graphics.Drawing 42 * @since 12 43 */ 44 LEFT = 0, 45 46 /** 47 * Use the right side of the text as a reference line for alignment. 48 * @syscap SystemCapability.Graphics.Drawing 49 * @since 12 50 */ 51 RIGHT = 1, 52 53 /** 54 * Use the midpoint line the text as a reference line for alignment. 55 * @syscap SystemCapability.Graphics.Drawing 56 * @since 12 57 */ 58 CENTER = 2, 59 60 /** 61 * Align the text at the start and end of the line. 62 * @syscap SystemCapability.Graphics.Drawing 63 * @since 12 64 */ 65 JUSTIFY = 3, 66 67 /** 68 * Align text from start, based on the direction of text, such as left-to-right or right-to-left. 69 * @syscap SystemCapability.Graphics.Drawing 70 * @since 12 71 */ 72 START = 4, 73 74 /** 75 * Align text from end, based on the direction of text, such as left-to-right or right-to-left, opposite to START. 76 * @syscap SystemCapability.Graphics.Drawing 77 * @since 12 78 */ 79 END = 5, 80 } 81 82 /** 83 * Enumerate text runs direction. 84 * @enum { number } 85 * @syscap SystemCapability.Graphics.Drawing 86 * @since 12 87 */ 88 enum TextDirection { 89 /** 90 * The text is oriented from right to left. 91 * @syscap SystemCapability.Graphics.Drawing 92 * @since 12 93 */ 94 RTL, 95 96 /** 97 * The text is oriented from left to right. 98 * @syscap SystemCapability.Graphics.Drawing 99 * @since 12 100 */ 101 LTR, 102 } 103 104 /** 105 * Enumerate text segmentation strategy. 106 * @enum { number } 107 * @syscap SystemCapability.Graphics.Drawing 108 * @since 12 109 */ 110 enum BreakStrategy { 111 /** 112 * The segmentation strategy is greedy. 113 * @syscap SystemCapability.Graphics.Drawing 114 * @since 12 115 */ 116 GREEDY, 117 118 /** 119 * The segmentation strategy is high quality. 120 * @syscap SystemCapability.Graphics.Drawing 121 * @since 12 122 */ 123 HIGH_QUALITY, 124 125 /** 126 * The segmentation strategy is balanced. 127 * @syscap SystemCapability.Graphics.Drawing 128 * @since 12 129 */ 130 BALANCED, 131 } 132 133 /** 134 * Enumerate word break strategy. 135 * @enum { number } 136 * @syscap SystemCapability.Graphics.Drawing 137 * @since 12 138 */ 139 enum WordBreak { 140 /** 141 * Normal word break strategy. 142 * @syscap SystemCapability.Graphics.Drawing 143 * @since 12 144 */ 145 NORMAL, 146 147 /** 148 * Breaks word by character. 149 * @syscap SystemCapability.Graphics.Drawing 150 * @since 12 151 */ 152 BREAK_ALL, 153 154 /** 155 * Breaks word by phrase. 156 * @syscap SystemCapability.Graphics.Drawing 157 * @since 12 158 */ 159 BREAK_WORD, 160 } 161 162 /** 163 * Decoration for text. 164 * @typedef Decoration 165 * @syscap SystemCapability.Graphics.Drawing 166 * @since 12 167 */ 168 interface Decoration { 169 /** 170 * Decorates text by line. 171 * @type { ?TextDecorationType } 172 * @syscap SystemCapability.Graphics.Drawing 173 * @since 12 174 */ 175 textDecoration?: TextDecorationType; 176 177 /** 178 * Text color. 179 * @type { ?common2D.Color } 180 * @syscap SystemCapability.Graphics.Drawing 181 * @since 12 182 */ 183 color?: common2D.Color; 184 185 /** 186 * Text decoration style. 187 * @type { ?TextDecorationStyle } 188 * @syscap SystemCapability.Graphics.Drawing 189 * @since 12 190 */ 191 decorationStyle?: TextDecorationStyle; 192 193 /** 194 * The thickness scale of decoration line. 195 * @type { ?number } 196 * @syscap SystemCapability.Graphics.Drawing 197 * @since 12 198 */ 199 decorationThicknessScale?: number; 200 } 201 202 /** 203 * Enumerates decoration line for text. 204 * @enum { number } 205 * @syscap SystemCapability.Graphics.Drawing 206 * @since 12 207 */ 208 enum TextDecorationType { 209 /** 210 * There are no text decoration. 211 * @syscap SystemCapability.Graphics.Drawing 212 * @since 12 213 */ 214 NONE, 215 216 /** 217 * There is a decoration line below the text. 218 * @syscap SystemCapability.Graphics.Drawing 219 * @since 12 220 */ 221 UNDERLINE, 222 223 /** 224 * There is a decoration line above the text. 225 * @syscap SystemCapability.Graphics.Drawing 226 * @since 12 227 */ 228 OVERLINE, 229 230 /** 231 * There is a decoration line through the middle of the text. 232 * @syscap SystemCapability.Graphics.Drawing 233 * @since 12 234 */ 235 LINE_THROUGH, 236 } 237 238 /** 239 * Enumerates decoration line style. 240 * @enum { number } 241 * @syscap SystemCapability.Graphics.Drawing 242 * @since 12 243 */ 244 enum TextDecorationStyle { 245 /** 246 * Decoration line is solid line. 247 * @syscap SystemCapability.Graphics.Drawing 248 * @since 12 249 */ 250 SOLID, 251 252 /** 253 * Decoration line is double line. 254 * @syscap SystemCapability.Graphics.Drawing 255 * @since 12 256 */ 257 DOUBLE, 258 259 /** 260 * Decoration line is dotted line. 261 * @syscap SystemCapability.Graphics.Drawing 262 * @since 12 263 */ 264 DOTTED, 265 266 /** 267 * Decoration line is dashed line. 268 * @syscap SystemCapability.Graphics.Drawing 269 * @since 12 270 */ 271 DASHED, 272 273 /** 274 * Decoration line is wavy line. 275 * @syscap SystemCapability.Graphics.Drawing 276 * @since 12 277 */ 278 WAVY, 279 } 280 281 /** 282 * Enumeration of font weight of text. 283 * @enum { number } 284 * @syscap SystemCapability.Graphics.Drawing 285 * @since 12 286 */ 287 enum FontWeight { 288 /** 289 * Thin 290 * @syscap SystemCapability.Graphics.Drawing 291 * @since 12 292 */ 293 W100, 294 295 /** 296 * Extra-light 297 * @syscap SystemCapability.Graphics.Drawing 298 * @since 12 299 */ 300 W200, 301 302 /** 303 * Light 304 * @syscap SystemCapability.Graphics.Drawing 305 * @since 12 306 */ 307 W300, 308 309 /** 310 * Normal/Regular 311 * @syscap SystemCapability.Graphics.Drawing 312 * @since 12 313 */ 314 W400, 315 316 /** 317 * Medium 318 * @syscap SystemCapability.Graphics.Drawing 319 * @since 12 320 */ 321 W500, 322 323 /** 324 * Semi-bold 325 * @syscap SystemCapability.Graphics.Drawing 326 * @since 12 327 */ 328 W600, 329 330 /** 331 * Bold 332 * @syscap SystemCapability.Graphics.Drawing 333 * @since 12 334 */ 335 W700, 336 337 /** 338 * Extra-bold 339 * @syscap SystemCapability.Graphics.Drawing 340 * @since 12 341 */ 342 W800, 343 344 /** 345 * Black 346 * @syscap SystemCapability.Graphics.Drawing 347 * @since 12 348 */ 349 W900, 350 } 351 352 /** 353 * Enumeration of font style of text. 354 * @enum { number } 355 * @syscap SystemCapability.Graphics.Drawing 356 * @since 12 357 */ 358 enum FontStyle { 359 /** 360 * Upright font type. 361 * @syscap SystemCapability.Graphics.Drawing 362 * @since 12 363 */ 364 NORMAL, 365 366 /** 367 * Slant font. 368 * @syscap SystemCapability.Graphics.Drawing 369 * @since 12 370 */ 371 ITALIC, 372 373 /** 374 * Oblique font. 375 * @syscap SystemCapability.Graphics.Drawing 376 * @since 12 377 */ 378 OBLIQUE, 379 } 380 381 /** 382 * Enumeration of font width of text. 383 * @enum { number } 384 * @syscap SystemCapability.Graphics.Drawing 385 * @since 12 386 */ 387 enum FontWidth { 388 /** 389 * Ultra condensed font width. 390 * @syscap SystemCapability.Graphics.Drawing 391 * @since 12 392 */ 393 ULTRA_CONDENSED = 1, 394 395 /** 396 * Extra condensed font width. 397 * @syscap SystemCapability.Graphics.Drawing 398 * @since 12 399 */ 400 EXTRA_CONDENSED = 2, 401 402 /** 403 * Condensed font width. 404 * @syscap SystemCapability.Graphics.Drawing 405 * @since 12 406 */ 407 CONDENSED = 3, 408 409 /** 410 * Semi condensed font width. 411 * @syscap SystemCapability.Graphics.Drawing 412 * @since 12 413 */ 414 SEMI_CONDENSED = 4, 415 416 /** 417 * Normal font width. 418 * @syscap SystemCapability.Graphics.Drawing 419 * @since 12 420 */ 421 NORMAL = 5, 422 423 /** 424 * Semi expanded font width. 425 * @syscap SystemCapability.Graphics.Drawing 426 * @since 12 427 */ 428 SEMI_EXPANDED = 6, 429 430 /** 431 * Expanded font width. 432 * @syscap SystemCapability.Graphics.Drawing 433 * @since 12 434 */ 435 EXPANDED = 7, 436 437 /** 438 * Extra expanded font width. 439 * @syscap SystemCapability.Graphics.Drawing 440 * @since 12 441 */ 442 EXTRA_EXPANDED = 8, 443 444 /** 445 * Ultra expanded font width. 446 * @syscap SystemCapability.Graphics.Drawing 447 * @since 12 448 */ 449 ULTRA_EXPANDED = 9, 450 } 451 452 /** 453 * Enumerates of height mode of text. 454 * @enum { number } 455 * @syscap SystemCapability.Graphics.Drawing 456 * @since 12 457 */ 458 enum TextHeightBehavior { 459 /** 460 * Both ascend of first row and last row style. 461 * @syscap SystemCapability.Graphics.Drawing 462 * @since 12 463 */ 464 ALL = 0x0, 465 466 /** 467 * Forbidding ascend of first row style. 468 * @syscap SystemCapability.Graphics.Drawing 469 * @since 12 470 */ 471 DISABLE_FIRST_ASCENT = 0x1, 472 473 /** 474 * Forbidding ascend of last row style. 475 * @syscap SystemCapability.Graphics.Drawing 476 * @since 12 477 */ 478 DISABLE_LAST_ASCENT = 0x2, 479 480 /** 481 * Neither ascend of first row nor last row style. 482 * @syscap SystemCapability.Graphics.Drawing 483 * @since 12 484 */ 485 DISABLE_ALL = 0x1 | 0x2, 486 } 487 488 /** 489 * Enumeration the type of text baseline. 490 * @enum { number } 491 * @syscap SystemCapability.Graphics.Drawing 492 * @since 12 493 */ 494 enum TextBaseline { 495 /** 496 * The alphabetic baseline, typically used for Latin-based scripts where the baseline aligns 497 * with the base of lowercase letters. 498 * @syscap SystemCapability.Graphics.Drawing 499 * @since 12 500 */ 501 ALPHABETIC, 502 503 /** 504 * The ideographic baseline, commonly used for ideographic scripts such as Chinese, Japanese, and Korean, 505 * where the baseline aligns with the center of characters. 506 * @syscap SystemCapability.Graphics.Drawing 507 * @since 12 508 */ 509 IDEOGRAPHIC, 510 } 511 512 /** 513 * Enumerates of ellipsis mode. 514 * @enum { number } 515 * @syscap SystemCapability.Graphics.Drawing 516 * @since 12 517 */ 518 enum EllipsisMode { 519 /** 520 * The ellipsis is shown in the start of text. 521 * @syscap SystemCapability.Graphics.Drawing 522 * @since 12 523 */ 524 START, 525 526 /** 527 * The ellipsis is shown in the middle of text. 528 * @syscap SystemCapability.Graphics.Drawing 529 * @since 12 530 */ 531 MIDDLE, 532 533 /** 534 * The ellipsis is shown in the end of text. 535 * @syscap SystemCapability.Graphics.Drawing 536 * @since 12 537 */ 538 END, 539 } 540 541 /** 542 * Describes shadow of text. 543 * @typedef TextShadow 544 * @syscap SystemCapability.Graphics.Drawing 545 * @since 12 546 */ 547 interface TextShadow { 548 /** 549 * The color of text shadow. 550 * @type { ?common2D.Color } The color of text shadow 551 * @syscap SystemCapability.Graphics.Drawing 552 * @since 12 553 */ 554 color?: common2D.Color; 555 /** 556 * The value sets offset of text shadow that based on the original text. 557 * @type { ?common2D.Point } The point of shadow 558 * @syscap SystemCapability.Graphics.Drawing 559 * @since 12 560 */ 561 point?: common2D.Point; 562 /** 563 * The value sets special effect radius of blurring text, it default is 0. 564 * @type { ?number } The value about radius of blur, it type is "double" 565 * @syscap SystemCapability.Graphics.Drawing 566 * @since 12 567 */ 568 blurRadius?: number; 569 } 570 571 /** 572 * Describes rect style of text. 573 * @typedef RectStyle 574 * @syscap SystemCapability.Graphics.Drawing 575 * @since 12 576 */ 577 interface RectStyle { 578 /** 579 * The color of rect style. 580 * @type { common2D.Color } The color of rect style 581 * @syscap SystemCapability.Graphics.Drawing 582 * @since 12 583 */ 584 color: common2D.Color; 585 586 /** 587 * Radius in left top of rect style. 588 * @type { number } it is double type data 589 * @syscap SystemCapability.Graphics.Drawing 590 * @since 12 591 */ 592 leftTopRadius: number; 593 594 /** 595 * Radius in right top of rect style. 596 * @type { number } it is double type data 597 * @syscap SystemCapability.Graphics.Drawing 598 * @since 12 599 */ 600 rightTopRadius: number; 601 602 /** 603 * Radius in right bottom of rect style. 604 * @type { number } it is double type data 605 * @syscap SystemCapability.Graphics.Drawing 606 * @since 12 607 */ 608 rightBottomRadius: number; 609 610 /** 611 * Radius in left bottom of rect style. 612 * @type { number } it is double type data 613 * @syscap SystemCapability.Graphics.Drawing 614 * @since 12 615 */ 616 leftBottomRadius: number; 617 } 618 619 /** 620 * Describes font feature of text. 621 * @typedef FontFeature 622 * @syscap SystemCapability.Graphics.Drawing 623 * @since 12 624 */ 625 interface FontFeature { 626 /** 627 * The name of font feature. 628 * @type { string } feature name 629 * @syscap SystemCapability.Graphics.Drawing 630 * @since 12 631 */ 632 name: string; 633 /** 634 * The value of font feature. 635 * @type { number } feature value 636 * @syscap SystemCapability.Graphics.Drawing 637 * @since 12 638 */ 639 value: number; 640 } 641 642 /** 643 * Describes font variation of text. 644 * @typedef FontVariation 645 * @syscap SystemCapability.Graphics.Drawing 646 * @since 12 647 */ 648 interface FontVariation { 649 /** 650 * The axis of font variation. 651 * @type { string } variation axis 652 * @syscap SystemCapability.Graphics.Drawing 653 * @since 12 654 */ 655 axis: string; 656 /** 657 * The value of font variation. 658 * @type { number } variation value 659 * @syscap SystemCapability.Graphics.Drawing 660 * @since 12 661 */ 662 value: number; 663 } 664 665 /** 666 * Describes text style. 667 * @typedef TextStyle 668 * @syscap SystemCapability.Graphics.Drawing 669 * @since 12 670 */ 671 interface TextStyle { 672 673 /** 674 * Decoration of text. 675 * @type { ?Decoration } decoration for text 676 * @syscap SystemCapability.Graphics.Drawing 677 * @since 12 678 */ 679 decoration?: Decoration; 680 681 /** 682 * Color of text. 683 * @type { ?common2D.Color } it is uint32_t type data 684 * @syscap SystemCapability.Graphics.Drawing 685 * @since 12 686 */ 687 color?: common2D.Color; 688 689 /** 690 * Font weight of text. 691 * @type { ?FontWeight } it is uint32_t type data 692 * @syscap SystemCapability.Graphics.Drawing 693 * @since 12 694 */ 695 fontWeight?: FontWeight; 696 697 /** 698 * Font style of text. 699 * @type { ?FontStyle } it is uint32_t type data 700 * @syscap SystemCapability.Graphics.Drawing 701 * @since 12 702 */ 703 fontStyle?: FontStyle; 704 705 /** 706 * Base line of text. 707 * @type { ?TextBaseline } it is uint32_t type data 708 * @syscap SystemCapability.Graphics.Drawing 709 * @since 12 710 */ 711 baseline?: TextBaseline; 712 713 /** 714 * Font Families of text. 715 * @type { ?Array<string> } fontfamily gather 716 * @syscap SystemCapability.Graphics.Drawing 717 * @since 12 718 */ 719 fontFamilies?: Array<string>; 720 721 /** 722 * Font size of text. 723 * @type { ?number } it is double type data 724 * @syscap SystemCapability.Graphics.Drawing 725 * @since 12 726 */ 727 fontSize?: number; 728 729 /** 730 * Letter spacing of text. 731 * @type { ?number } it is double type data 732 * @syscap SystemCapability.Graphics.Drawing 733 * @since 12 734 */ 735 letterSpacing?: number; 736 737 /** 738 * Word spacing of text. 739 * @type { ?number } it is double type data 740 * @syscap SystemCapability.Graphics.Drawing 741 * @since 12 742 */ 743 wordSpacing?: number; 744 745 /** 746 * Height scale of text. 747 * @type { ?number } it is double type data 748 * @syscap SystemCapability.Graphics.Drawing 749 * @since 12 750 */ 751 heightScale?: number; 752 753 /** 754 * Half leading of text. 755 * @type { ?boolean } it is boolean type data 756 * @syscap SystemCapability.Graphics.Drawing 757 * @since 12 758 */ 759 halfLeading?: boolean; 760 761 /** 762 * Control the height calculation method of font blob, true means calculate the height of the blob by 763 * the font size, false means by the line height and leading. 764 * @type { ?boolean } it is boolean type data 765 * @syscap SystemCapability.Graphics.Drawing 766 * @since 12 767 */ 768 heightOnly?: boolean; 769 770 /** 771 * Text ellipsis. 772 * @type { ?string } it is u16string type data. 773 * @syscap SystemCapability.Graphics.Drawing 774 * @since 12 775 */ 776 ellipsis?: string; 777 778 /** 779 * Text ellipsis mode. 780 * @type { ?EllipsisMode } Ellipsis mode. 781 * @syscap SystemCapability.Graphics.Drawing 782 * @since 12 783 */ 784 ellipsisMode?: EllipsisMode; 785 786 /** 787 * Text locale. 788 * @type { ?string } it is string type data. 789 * @syscap SystemCapability.Graphics.Drawing 790 * @since 12 791 */ 792 locale?: string; 793 794 /** 795 * The offset distance that the underline of text. 796 * @type { ?number } it is double type data. 797 * @syscap SystemCapability.Graphics.Drawing 798 * @since 12 799 */ 800 baselineShift?: number; 801 802 /** 803 * Text Style available font features. 804 * @type { ?Array<FontFeature> } A collection of font features. 805 * @syscap SystemCapability.Graphics.Drawing 806 * @since 12 807 */ 808 fontFeatures?: Array<FontFeature>; 809 810 /** 811 * Text shadows of text. 812 * @type { ?Array<TextShadow> } textShadow gather. 813 * @syscap SystemCapability.Graphics.Drawing 814 * @since 12 815 */ 816 textShadows?: Array<TextShadow>; 817 818 /** 819 * Rect style of text. 820 * @type { ?RectStyle } rect style for text. 821 * @syscap SystemCapability.Graphics.Drawing 822 * @since 12 823 */ 824 backgroundRect?: RectStyle; 825 826 /** 827 * Text Style available font variations. 828 * @type { ?Array<FontVariation> } A collection of font variations. 829 * @syscap SystemCapability.Graphics.Drawing 830 * @since 12 831 */ 832 fontVariations?: Array<FontVariation>; 833 } 834 835 /** 836 * Provides the basis for graphics. 837 * @syscap SystemCapability.Graphics.Drawing 838 * @since 12 839 */ 840 class FontCollection { 841 /** 842 * Get global FontCollection instance of the application. 843 * @returns { FontCollection } The FontCollection object. 844 * @syscap SystemCapability.Graphics.Drawing 845 * @since 12 846 */ 847 static getGlobalInstance(): FontCollection; 848 849 /** 850 * Load font. 851 * @param { string } name - the font name. 852 * @param { string | Resource } path - the path of the font file. 853 * @syscap SystemCapability.Graphics.Drawing 854 * @since 12 855 */ 856 loadFontSync(name: string, path: string | Resource): void; 857 858 /** 859 * Clear font caches. 860 * @syscap SystemCapability.Graphics.Drawing 861 * @since 12 862 */ 863 clearCaches(): void; 864 } 865 866 /** 867 * Describes strut style. 868 * @typedef StrutStyle 869 * @syscap SystemCapability.Graphics.Drawing 870 * @since 12 871 */ 872 interface StrutStyle { 873 /** 874 * The families of the font to use when calculating the strut. 875 * @type { ?Array<string> } fontfamily gather 876 * @syscap SystemCapability.Graphics.Drawing 877 * @since 12 878 */ 879 fontFamilies?: Array<string>; 880 881 /** 882 * The font style to use when calculating the strut. 883 * @type { ?FontStyle } it is uint32_t type data 884 * @syscap SystemCapability.Graphics.Drawing 885 * @since 12 886 */ 887 fontStyle?: FontStyle; 888 889 /** 890 * The font width to use when calculating the strut. 891 * @type { ?FontWidth } it is uint32_t type data 892 * @syscap SystemCapability.Graphics.Drawing 893 * @since 12 894 */ 895 fontWidth?: FontWidth; 896 897 /** 898 * The font weight to use when calculating the strut. 899 * @type { ?FontWeight } it is uint32_t type data 900 * @syscap SystemCapability.Graphics.Drawing 901 * @since 12 902 */ 903 fontWeight?: FontWeight; 904 905 /** 906 * The size of the ascent plus descent in logical pixels. 907 * @type { ?number } it is double type data 908 * @syscap SystemCapability.Graphics.Drawing 909 * @since 12 910 */ 911 fontSize?: number; 912 913 /** 914 * The minimum height of the strut, as a multiple of fontSize. 915 * @type { ?number } it is double type data 916 * @syscap SystemCapability.Graphics.Drawing 917 * @since 12 918 */ 919 height?: number; 920 921 /** 922 * The additional leading to apply to the strut as a multiple of Size. 923 * @type { ?number } it is double type data 924 * @syscap SystemCapability.Graphics.Drawing 925 * @since 12 926 */ 927 leading?: number; 928 929 /** 930 * Whether the strut height should be forced. 931 * @type { ?boolean } it is boolean type data 932 * @syscap SystemCapability.Graphics.Drawing 933 * @since 12 934 */ 935 forceHeight?: boolean; 936 937 /** 938 * Whether the strut style should be enable. 939 * @type { ?boolean } it is boolean type data 940 * @syscap SystemCapability.Graphics.Drawing 941 * @since 12 942 */ 943 enabled?: boolean; 944 945 /** 946 * Whether the height is override. 947 * @type { ?boolean } it is boolean type data 948 * @syscap SystemCapability.Graphics.Drawing 949 * @since 12 950 */ 951 heightOverride?: boolean; 952 953 /** 954 * Whether the half leading is enable. 955 * @type { ?boolean } it is boolean type data 956 * @syscap SystemCapability.Graphics.Drawing 957 * @since 12 958 */ 959 halfLeading?: boolean; 960 } 961 962 /** 963 * Determines the configuration used by ParagraphBuilder to position lines within a Paragraph of text. 964 * @typedef ParagraphStyle 965 * @syscap SystemCapability.Graphics.Drawing 966 * @since 12 967 */ 968 interface ParagraphStyle { 969 /** 970 * Text style of paragraph. 971 * @type { ?TextStyle } 972 * @syscap SystemCapability.Graphics.Drawing 973 * @since 12 974 */ 975 textStyle?: TextStyle; 976 977 /** 978 * Text runs direction. 979 * @type { ?TextDirection } 980 * @syscap SystemCapability.Graphics.Drawing 981 * @since 12 982 */ 983 textDirection?: TextDirection; 984 985 /** 986 * Refers to how to align the horizontal position of text when displaying text. 987 * @type { ?TextAlign } 988 * @syscap SystemCapability.Graphics.Drawing 989 * @since 12 990 */ 991 align?: TextAlign; 992 993 /** 994 * Word break strategy. 995 * @type { ?WordBreak } 996 * @syscap SystemCapability.Graphics.Drawing 997 * @since 12 998 */ 999 wordBreak?: WordBreak; 1000 1001 /** 1002 * Maximum number of lines. 1003 * @type { ?number } 1004 * @syscap SystemCapability.Graphics.Drawing 1005 * @since 12 1006 */ 1007 maxLines?: number; 1008 1009 /** 1010 * text segmentation strategy. 1011 * @type { ?BreakStrategy } 1012 * @syscap SystemCapability.Graphics.Drawing 1013 * @since 12 1014 */ 1015 breakStrategy?: BreakStrategy; 1016 1017 /** 1018 * Strut style of paragraph. 1019 * @type { ?StrutStyle } 1020 * @syscap SystemCapability.Graphics.Drawing 1021 * @since 12 1022 */ 1023 strutStyle?: StrutStyle; 1024 1025 /** 1026 * Text height behavior of paragraph. 1027 * @type { ?TextHeightBehavior } 1028 * @syscap SystemCapability.Graphics.Drawing 1029 * @since 12 1030 */ 1031 textHeightBehavior?: TextHeightBehavior; 1032 } 1033 1034 /** 1035 * Where to vertically align the placeholder relative to the surrounding text. 1036 * @enum { number } 1037 * @syscap SystemCapability.Graphics.Drawing 1038 * @since 12 1039 */ 1040 enum PlaceholderAlignment { 1041 /** 1042 * Match the baseline of the placeholder with the baseline. 1043 * @syscap SystemCapability.Graphics.Drawing 1044 * @since 12 1045 */ 1046 OFFSET_AT_BASELINE, 1047 1048 /** 1049 * Align the bottom edge of the placeholder with the baseline such that the placeholder 1050 * sits on top of the baseline. 1051 * @syscap SystemCapability.Graphics.Drawing 1052 * @since 12 1053 */ 1054 ABOVE_BASELINE, 1055 1056 /** 1057 * Align the top edge of the placeholder with the baseline specified in such that the placeholder 1058 * hangs below the baseline. 1059 * @syscap SystemCapability.Graphics.Drawing 1060 * @since 12 1061 */ 1062 BELOW_BASELINE, 1063 1064 /** 1065 * Align the top edge of the placeholder with the top edge of the font. When the placeholder is very tall, 1066 * the extra space will hang from the top and extend through the bottom of the line. 1067 * @syscap SystemCapability.Graphics.Drawing 1068 * @since 12 1069 */ 1070 TOP_OF_ROW_BOX, 1071 1072 /** 1073 * Align the bottom edge of the placeholder with the bottom edge of the text. When the placeholder is very tall, 1074 * the extra space will rise from the bottom and extend through the top of the line. 1075 * @syscap SystemCapability.Graphics.Drawing 1076 * @since 12 1077 */ 1078 BOTTOM_OF_ROW_BOX, 1079 1080 /** 1081 * Align the middle of the placeholder with the middle of the text.When the placeholder is very tall, 1082 * the extra space will grow equally from the top and bottom of the line. 1083 * @syscap SystemCapability.Graphics.Drawing 1084 * @since 12 1085 */ 1086 CENTER_OF_ROW_BOX, 1087 } 1088 1089 /** 1090 * Provide a description of placeholder scope in creating typography. 1091 * @typedef PlaceholderSpan 1092 * @syscap SystemCapability.Graphics.Drawing 1093 * @since 12 1094 */ 1095 interface PlaceholderSpan { 1096 /** 1097 * The width of the placeholder. 1098 * @type { number } 1099 * @syscap SystemCapability.Graphics.Drawing 1100 * @since 12 1101 */ 1102 width: number; 1103 1104 /** 1105 * The height of the placeholder. 1106 * @type { number } 1107 * @syscap SystemCapability.Graphics.Drawing 1108 * @since 12 1109 */ 1110 height: number; 1111 1112 /** 1113 * Alignment mode of placeholder. 1114 * @type { PlaceholderAlignment } 1115 * @syscap SystemCapability.Graphics.Drawing 1116 * @since 12 1117 */ 1118 align: PlaceholderAlignment; 1119 1120 /** 1121 * Baseline of placeholder. 1122 * @type { TextBaseline } 1123 * @syscap SystemCapability.Graphics.Drawing 1124 * @since 12 1125 */ 1126 baseline: TextBaseline; 1127 1128 /** 1129 * Baseline offset of placeholder. 1130 * @type { number } 1131 * @syscap SystemCapability.Graphics.Drawing 1132 * @since 12 1133 */ 1134 baselineOffset: number; 1135 } 1136 1137 /** 1138 * Provides the definition of the range. 1139 * @typedef Range 1140 * @syscap SystemCapability.Graphics.Drawing 1141 * @since 12 1142 */ 1143 interface Range { 1144 /** 1145 * Left index. 1146 * @type { number } 1147 * @syscap SystemCapability.Graphics.Drawing 1148 * @since 12 1149 */ 1150 start: number; 1151 1152 /** 1153 * Right index. 1154 * @type { number } 1155 * @syscap SystemCapability.Graphics.Drawing 1156 * @since 12 1157 */ 1158 end: number; 1159 } 1160 1161 /** 1162 * An enumeration of system font types. 1163 * @enum { number } 1164 * @syscap SystemCapability.Graphics.Drawing 1165 * @since 14 1166 */ 1167 enum SystemFontType { 1168 /** 1169 * All font types. 1170 * @syscap SystemCapability.Graphics.Drawing 1171 * @since 14 1172 */ 1173 ALL = 1 << 0, 1174 1175 /** 1176 * System generic font type. 1177 * @syscap SystemCapability.Graphics.Drawing 1178 * @since 14 1179 */ 1180 GENERIC = 1 << 1, 1181 1182 /** 1183 * Stylish font type. 1184 * @syscap SystemCapability.Graphics.Drawing 1185 * @since 14 1186 */ 1187 STYLISH = 1 << 2, 1188 1189 /** 1190 * Installed font types. 1191 * @syscap SystemCapability.Graphics.Drawing 1192 * @since 14 1193 */ 1194 INSTALLED = 1 << 3, 1195 } 1196 1197 /** 1198 * Font descriptor 1199 * @typedef FontDescriptor 1200 * @syscap SystemCapability.Graphics.Drawing 1201 * @since 14 1202 */ 1203 interface FontDescriptor { 1204 /** 1205 * Font file path 1206 * @type { ?string } 1207 * @syscap SystemCapability.Graphics.Drawing 1208 * @since 14 1209 */ 1210 path?: string; 1211 1212 /** 1213 * Font postScript name 1214 * @type { ?string } 1215 * @syscap SystemCapability.Graphics.Drawing 1216 * @since 14 1217 */ 1218 postScriptName?: string; 1219 1220 /** 1221 * Full font name 1222 * @type { ?string } 1223 * @syscap SystemCapability.Graphics.Drawing 1224 * @since 14 1225 */ 1226 fullName?: string; 1227 1228 /** 1229 * Font family name 1230 * @type { ?string } 1231 * @syscap SystemCapability.Graphics.Drawing 1232 * @since 14 1233 */ 1234 fontFamily?: string; 1235 1236 /** 1237 * Font subfamily name 1238 * @type { ?string } 1239 * @syscap SystemCapability.Graphics.Drawing 1240 * @since 14 1241 */ 1242 fontSubfamily?: string; 1243 1244 /** 1245 * Font weight 1246 * @type { ?FontWeight } 1247 * @syscap SystemCapability.Graphics.Drawing 1248 * @since 14 1249 */ 1250 weight?: FontWeight; 1251 1252 /** 1253 * Font width 1254 * @type { ?number } 1255 * @syscap SystemCapability.Graphics.Drawing 1256 * @since 14 1257 */ 1258 width?: number; 1259 1260 /** 1261 * Font slant, non-0 means italic. 1262 * @type { ?number } 1263 * @syscap SystemCapability.Graphics.Drawing 1264 * @since 14 1265 */ 1266 italic?: number; 1267 1268 /** 1269 * Whether the font is monospaced 1270 * @type { ?boolean } 1271 * @syscap SystemCapability.Graphics.Drawing 1272 * @since 14 1273 */ 1274 monoSpace?: boolean; 1275 1276 /** 1277 * Whether to support symbols 1278 * @type { ?boolean } 1279 * @syscap SystemCapability.Graphics.Drawing 1280 * @since 14 1281 */ 1282 symbolic?: boolean; 1283 } 1284 1285 /** 1286 * A paragraph retains the size and position of each glyph in the text and can be efficiently resized and painted. 1287 * @syscap SystemCapability.Graphics.Drawing 1288 * @since 12 1289 */ 1290 class Paragraph { 1291 /** 1292 * Calculates the positioning of all the glyphs. 1293 * @param { number } width - Control how wide the text is allowed to be. 1294 * @syscap SystemCapability.Graphics.Drawing 1295 * @since 12 1296 */ 1297 layoutSync(width: number): void; 1298 1299 /** 1300 * Paint the laid out text onto the supplied canvas at (x, y). 1301 * @param { drawing.Canvas } canvas - Object 1302 * @param { number } x - Represents the X-axis position on the canvas. 1303 * @param { number } y - Represents the Y-axis position on the canvas. 1304 * @syscap SystemCapability.Graphics.Drawing 1305 * @since 12 1306 */ 1307 paint(canvas: drawing.Canvas, x: number, y: number): void; 1308 1309 /** 1310 * Draw the laid out text onto the supplied canvas along the path and offset. 1311 * @param { drawing.Canvas } canvas - Canvas used to carry the drawn content and drawing status. 1312 * @param { drawing.Path } path - Path used to determine the position of the text. 1313 * @param { number } hOffset - Horizontal offset along the path. 1314 * @param { number } vOffset - Vertical offset along the path. 1315 * @syscap SystemCapability.Graphics.Drawing 1316 * @since 12 1317 */ 1318 paintOnPath(canvas: drawing.Canvas, path: drawing.Path, hOffset: number, vOffset: number): void; 1319 1320 /** 1321 * Get max width of horizontal space this paragraph occupied. 1322 * @returns { number } Max width of horizontal space. 1323 * @syscap SystemCapability.Graphics.Drawing 1324 * @since 12 1325 */ 1326 getMaxWidth(): number; 1327 1328 /** 1329 * Get height of horizontal space this paragraph occupies. 1330 * @returns { number } Height of horizontal space this paragraph occupies. 1331 * @syscap SystemCapability.Graphics.Drawing 1332 * @since 12 1333 */ 1334 getHeight(): number; 1335 1336 /** 1337 * Get the longest line of horizontal space this paragraph occupies. 1338 * @returns { number } The longest line of horizontal space this paragraph occupies. 1339 * @syscap SystemCapability.Graphics.Drawing 1340 * @since 12 1341 */ 1342 getLongestLine(): number; 1343 1344 /** 1345 * Get the longest line of horizontal space this paragraph occupies, and this horizontal space contains the width 1346 * of indent. 1347 * @returns { number } The longest line with indent of horizontal space this paragraph occupies. 1348 * @syscap SystemCapability.Graphics.Drawing 1349 * @since 13 1350 */ 1351 getLongestLineWithIndent(): number; 1352 1353 /** 1354 * Get the min intrinsic width of horizontal space this paragraph occupies. 1355 * @returns { number } The min intrinsic width of horizontal space this paragraph occupies. 1356 * @syscap SystemCapability.Graphics.Drawing 1357 * @since 12 1358 */ 1359 getMinIntrinsicWidth(): number; 1360 1361 /** 1362 * Get the max intrinsic width. 1363 * @returns { number } Intrinsic Width. 1364 * @syscap SystemCapability.Graphics.Drawing 1365 * @since 12 1366 */ 1367 getMaxIntrinsicWidth(): number; 1368 1369 /** 1370 * Get the alphabetic baseline. 1371 * @returns { number } Alphabetic Baseline. 1372 * @syscap SystemCapability.Graphics.Drawing 1373 * @since 12 1374 */ 1375 getAlphabeticBaseline(): number; 1376 1377 /** 1378 * Get the ideographic baseline. 1379 * @returns { number } Ideographic Baseline. 1380 * @syscap SystemCapability.Graphics.Drawing 1381 * @since 12 1382 */ 1383 getIdeographicBaseline(): number; 1384 1385 /** 1386 * Get the rects for range. 1387 * @param { Range } range - The range to set. 1388 * @param { RectWidthStyle } widthStyle - Width style to set. 1389 * @param { RectHeightStyle } heightStyle - Height style to set. 1390 * @returns { Array<TextBox> } The rects for range. 1391 * @syscap SystemCapability.Graphics.Drawing 1392 * @since 12 1393 */ 1394 getRectsForRange(range: Range, widthStyle: RectWidthStyle, heightStyle: RectHeightStyle): Array<TextBox>; 1395 1396 /** 1397 * Get the rects for placeholders. 1398 * @returns { Array<TextBox> } The rects for placeholders. 1399 * @syscap SystemCapability.Graphics.Drawing 1400 * @since 12 1401 */ 1402 getRectsForPlaceholders(): Array<TextBox>; 1403 1404 /** 1405 * Get the glyph position at coordinate. 1406 * @param { number } x - the positionX of typography to set. 1407 * @param { number } y - the positionY of typography to set. 1408 * @returns { PositionWithAffinity } TextBlob object. 1409 * @syscap SystemCapability.Graphics.Drawing 1410 * @since 12 1411 */ 1412 getGlyphPositionAtCoordinate(x: number, y: number): PositionWithAffinity; 1413 1414 /** 1415 * Find the start and end position of the word containing the glyphs of the given offset. 1416 * @param { number } offset - offset value 1417 * @returns { Range } The range value returned to the caller. 1418 * @syscap SystemCapability.Graphics.Drawing 1419 * @since 12 1420 */ 1421 getWordBoundary(offset: number): Range; 1422 1423 /** 1424 * Get line count. 1425 * @returns { number } The line count value returned to the caller. 1426 * @syscap SystemCapability.Graphics.Drawing 1427 * @since 12 1428 */ 1429 getLineCount(): number; 1430 1431 /** 1432 * Get the line height of the specified line. 1433 * @param { number } line - line number 1434 * @returns { number } The line height value returned to the caller. 1435 * @syscap SystemCapability.Graphics.Drawing 1436 * @since 12 1437 */ 1438 getLineHeight(line: number): number; 1439 1440 /** 1441 * Get the line width of the specified line. 1442 * @param { number } line - line number 1443 * @returns { number } The line width value returned to the caller. 1444 * @syscap SystemCapability.Graphics.Drawing 1445 * @since 12 1446 */ 1447 getLineWidth(line: number): number; 1448 1449 /** 1450 * Return whether it exceed the maximum lines of typography. 1451 * @returns { boolean } The true indicates exceeding, the false indicates not exceeding. 1452 * @syscap SystemCapability.Graphics.Drawing 1453 * @since 12 1454 */ 1455 didExceedMaxLines(): boolean; 1456 1457 /** 1458 * Get the text lines of paragraph. 1459 * @returns { Array<TextLine> } the tuple of TextLine. 1460 * @syscap SystemCapability.Graphics.Drawing 1461 * @since 12 1462 */ 1463 getTextLines(): Array<TextLine>; 1464 1465 /** 1466 * Returns the visible text on the line (excluding a possible ellipsis). 1467 * @param { number } lineNumber - a line number 1468 * @param { boolean } includeSpaces - indicates if the whitespaces should be included 1469 * @returns { Range } The range of text. 1470 * @syscap SystemCapability.Graphics.Drawing 1471 * @since 12 1472 */ 1473 getActualTextRange(lineNumber: number, includeSpaces: boolean): Range; 1474 1475 /** 1476 * Returns the array of line metrics for a line of text. 1477 * @returns { Array<LineMetrics> } Array of line metrics. 1478 * @syscap SystemCapability.Graphics.Drawing 1479 * @since 12 1480 */ 1481 getLineMetrics(): Array<LineMetrics>; 1482 1483 /** 1484 * Returns line metrics info for the line. 1485 * @param { number } lineNumber - a line number 1486 * @returns { LineMetrics | undefined } line metrics. 1487 * @syscap SystemCapability.Graphics.Drawing 1488 * @since 12 1489 */ 1490 getLineMetrics(lineNumber: number): LineMetrics | undefined; 1491 } 1492 1493 /** 1494 * Box that contain text. 1495 * @typedef TextBox 1496 * @syscap SystemCapability.Graphics.Drawing 1497 * @since 12 1498 */ 1499 interface TextBox{ 1500 /** 1501 * Rect of text box. 1502 * @type { common2D.Rect } 1503 * @syscap SystemCapability.Graphics.Drawing 1504 * @since 12 1505 */ 1506 rect: common2D.Rect; 1507 1508 /** 1509 * Text direction. 1510 * @type { TextDirection } 1511 * @syscap SystemCapability.Graphics.Drawing 1512 * @since 12 1513 */ 1514 direction: TextDirection; 1515 } 1516 1517 /** 1518 * Position and affinity. 1519 * @typedef PositionWithAffinity 1520 * @syscap SystemCapability.Graphics.Drawing 1521 * @since 12 1522 */ 1523 interface PositionWithAffinity { 1524 /** 1525 * Position of text. 1526 * @type { number } 1527 * @syscap SystemCapability.Graphics.Drawing 1528 * @since 12 1529 */ 1530 position: number; 1531 1532 /** 1533 * Affinity of text. 1534 * @type { Affinity } 1535 * @syscap SystemCapability.Graphics.Drawing 1536 * @since 12 1537 */ 1538 affinity: Affinity; 1539 } 1540 1541 /** 1542 * Enumerates rect width style. 1543 * @enum { number } 1544 * @syscap SystemCapability.Graphics.Drawing 1545 * @since 12 1546 */ 1547 enum RectWidthStyle { 1548 /** 1549 * Tight width. 1550 * @syscap SystemCapability.Graphics.Drawing 1551 * @since 12 1552 */ 1553 TIGHT, 1554 1555 /** 1556 * Max width. 1557 * @syscap SystemCapability.Graphics.Drawing 1558 * @since 12 1559 */ 1560 MAX, 1561 } 1562 1563 /** 1564 * Enumerates rect height style. 1565 * @enum { number } 1566 * @syscap SystemCapability.Graphics.Drawing 1567 * @since 12 1568 */ 1569 enum RectHeightStyle { 1570 /** 1571 * Provide tight bounding boxes that fit heights per run. 1572 * @syscap SystemCapability.Graphics.Drawing 1573 * @since 12 1574 */ 1575 TIGHT, 1576 1577 /** 1578 * The height of the boxes will be the maximum height of all runs in the line. All rects in the same 1579 * line will be the same height. 1580 * @syscap SystemCapability.Graphics.Drawing 1581 * @since 12 1582 */ 1583 MAX, 1584 1585 /** 1586 * The top and bottom of each rect will cover half of the space above and half of the space below the line. 1587 * @syscap SystemCapability.Graphics.Drawing 1588 * @since 12 1589 */ 1590 INCLUDE_LINE_SPACE_MIDDLE, 1591 1592 /** 1593 * The line spacing will be added to the top of the rect. 1594 * @syscap SystemCapability.Graphics.Drawing 1595 * @since 12 1596 */ 1597 INCLUDE_LINE_SPACE_TOP, 1598 1599 /** 1600 * The line spacing will be added to the bottom of the rect. 1601 * @syscap SystemCapability.Graphics.Drawing 1602 * @since 12 1603 */ 1604 INCLUDE_LINE_SPACE_BOTTOM, 1605 1606 /** 1607 * The height of the boxes will be calculated by text strut. 1608 * @syscap SystemCapability.Graphics.Drawing 1609 * @since 12 1610 */ 1611 STRUT, 1612 } 1613 1614 /** 1615 * Enumerates text affinity.When a selection range involves line breaks or other special characters, the 1616 * affinity determines which side of the characters the start and end of the selection range should be 1617 * closer to. 1618 * @enum { number } 1619 * @syscap SystemCapability.Graphics.Drawing 1620 * @since 12 1621 */ 1622 enum Affinity { 1623 /** 1624 * The position has affinity for the upstream side of the text position. 1625 * @syscap SystemCapability.Graphics.Drawing 1626 * @since 12 1627 */ 1628 1629 UPSTREAM, 1630 /** 1631 * The position has affinity for the downstream side of the text position. 1632 * @syscap SystemCapability.Graphics.Drawing 1633 * @since 12 1634 */ 1635 DOWNSTREAM, 1636 } 1637 1638 /** 1639 * Builds a Paragraph containing text with the given styling information. 1640 * @syscap SystemCapability.Graphics.Drawing 1641 * @since 12 1642 */ 1643 class ParagraphBuilder { 1644 /** 1645 * Constructor ParagraphBuilder. 1646 * @param { ParagraphStyle } paragraphStyle - Paragraph style {@link ParagraphStyle} 1647 * @param { FontCollection } fontCollection - Font collection {@link FontCollection} 1648 * @syscap SystemCapability.Graphics.Drawing 1649 * @since 12 1650 */ 1651 constructor(paragraphStyle: ParagraphStyle, fontCollection: FontCollection); 1652 1653 /** 1654 * Push a style to the stack. 1655 * @param { TextStyle } textStyle - Text style {@link TextStyle} 1656 * @syscap SystemCapability.Graphics.Drawing 1657 * @since 12 1658 */ 1659 pushStyle(textStyle: TextStyle): void; 1660 1661 /** 1662 * Remove a style from the stack. 1663 * @syscap SystemCapability.Graphics.Drawing 1664 * @since 12 1665 */ 1666 popStyle(): void; 1667 1668 /** 1669 * Adds text to the builder. 1670 * @param { string } text - Text string 1671 * @syscap SystemCapability.Graphics.Drawing 1672 * @since 12 1673 */ 1674 addText(text: string): void; 1675 1676 /** 1677 * Add placeholder. 1678 * @param { PlaceholderSpan } placeholderSpan - Placeholder Span {@link PlaceholderSpan} 1679 * @syscap SystemCapability.Graphics.Drawing 1680 * @since 12 1681 */ 1682 addPlaceholder(placeholderSpan: PlaceholderSpan): void; 1683 1684 /** 1685 * Create paragraph object. 1686 * @returns { Paragraph } The paragraph value returned to the caller. 1687 * @syscap SystemCapability.Graphics.Drawing 1688 * @since 12 1689 */ 1690 build(): Paragraph; 1691 1692 /** 1693 * Add symbolId. 1694 * @param { number } symbolId - Symbol Id 1695 * @syscap SystemCapability.Graphics.Drawing 1696 * @since 12 1697 */ 1698 addSymbol(symbolId: number): void; 1699 } 1700 1701 /** 1702 * The structure of text line that provides the basis of paragraph for graphics. 1703 * @syscap SystemCapability.Graphics.Drawing 1704 * @since 12 1705 */ 1706 class TextLine { 1707 /** 1708 * Get the count of glyphs. 1709 * @returns { number } The counts of glyphs. 1710 * @syscap SystemCapability.Graphics.Drawing 1711 * @since 12 1712 */ 1713 getGlyphCount(): number; 1714 1715 /** 1716 * Get the range of text line. 1717 * @returns { Range } The range of text. 1718 * @syscap SystemCapability.Graphics.Drawing 1719 * @since 12 1720 */ 1721 getTextRange(): Range; 1722 1723 /** 1724 * Get the glyph runs of text line. 1725 * @returns { Array<Run> } The tuple of glyph runs of text. 1726 * @syscap SystemCapability.Graphics.Drawing 1727 * @since 12 1728 */ 1729 getGlyphRuns(): Array<Run>; 1730 1731 /** 1732 * Paint the range of text line. 1733 * @param { drawing.Canvas } canvas - Canvas. 1734 * @param { number } x - Represents the X-axis position on the canvas. 1735 * @param { number } y - Represents the Y-axis position on the canvas. 1736 * @syscap SystemCapability.Graphics.Drawing 1737 * @since 12 1738 */ 1739 paint(canvas: drawing.Canvas, x: number, y: number): void; 1740 } 1741 1742 /** 1743 * Independent rendering of text layout. 1744 * @syscap SystemCapability.Graphics.Drawing 1745 * @since 12 1746 */ 1747 class Run { 1748 /** 1749 * Gets the number of glyph. 1750 * @returns { number } The number of glyph. 1751 * @syscap SystemCapability.Graphics.Drawing 1752 * @since 12 1753 */ 1754 getGlyphCount(): number; 1755 1756 /** 1757 * Gets the glyph identifier for each character. 1758 * @returns { Array<number> } Glyph identifier. 1759 * @syscap SystemCapability.Graphics.Drawing 1760 * @since 12 1761 */ 1762 getGlyphs(): Array<number>; 1763 1764 /** 1765 * Gets the font position offset. 1766 * @returns { Array<common2D.Point> } The position of the font in the layout. 1767 * @syscap SystemCapability.Graphics.Drawing 1768 * @since 12 1769 */ 1770 getPositions(): Array<common2D.Point>; 1771 1772 /** 1773 * Gets the font position offset array. 1774 * @returns { Array<common2D.Point> } The position offset of the font in the layout. 1775 * @syscap SystemCapability.Graphics.Drawing 1776 * @since 12 1777 */ 1778 getOffsets(): Array<common2D.Point>; 1779 1780 /** 1781 * Gets the font object instance. 1782 * @returns { drawing.Font } The font object instance. 1783 * @syscap SystemCapability.Graphics.Drawing 1784 * @since 12 1785 */ 1786 getFont(): drawing.Font; 1787 1788 /** 1789 * Paint the laid out text onto the supplied canvas at (x, y). 1790 * @param { drawing.Canvas } canvas - Object. 1791 * @param { number } x - Represents the X-axis position on the canvas. 1792 * @param { number } y - Represents the Y-axis position on the canvas. 1793 * @syscap SystemCapability.Graphics.Drawing 1794 * @since 12 1795 */ 1796 paint(canvas: drawing.Canvas, x: number, y: number): void; 1797 } 1798 1799 /** 1800 * Describes the layout information and metrics for a continuous piece of text (a run) in a line of text. 1801 * @typedef RunMetrics 1802 * @syscap SystemCapability.Graphics.Drawing 1803 * @since 12 1804 */ 1805 interface RunMetrics { 1806 /** 1807 * The metrics of an Font. 1808 * @type { TextStyle } 1809 * @syscap SystemCapability.Graphics.Drawing 1810 * @since 12 1811 */ 1812 textStyle: TextStyle; 1813 1814 /** 1815 * Describes text style. 1816 * @type { drawing.FontMetrics } 1817 * @syscap SystemCapability.Graphics.Drawing 1818 * @since 12 1819 */ 1820 fontMetrics: drawing.FontMetrics; 1821 } 1822 1823 /** 1824 * Describes the metric information for a line of text in a text layout. 1825 * @typedef LineMetrics 1826 * @syscap SystemCapability.Graphics.Drawing 1827 * @since 12 1828 */ 1829 interface LineMetrics { 1830 /** 1831 * The indexes in the text buffer the line begins. 1832 * @type { number } 1833 * @syscap SystemCapability.Graphics.Drawing 1834 * @since 12 1835 */ 1836 startIndex: number; 1837 1838 /** 1839 * The indexes in the text buffer the line ends. 1840 * @type { number } 1841 * @syscap SystemCapability.Graphics.Drawing 1842 * @since 12 1843 */ 1844 endIndex: number; 1845 1846 /** 1847 * The height of the text rise, the distance from the baseline to the top of the character. 1848 * @type { number } 1849 * @syscap SystemCapability.Graphics.Drawing 1850 * @since 12 1851 */ 1852 ascent: number; 1853 1854 /** 1855 * The height of the text drop, the distance from the baseline to the bottom of the character. 1856 * @type { number } 1857 * @syscap SystemCapability.Graphics.Drawing 1858 * @since 12 1859 */ 1860 descent: number; 1861 1862 /** 1863 * The height of the current line is `round(ascent + descent)`. 1864 * @type { number } 1865 * @syscap SystemCapability.Graphics.Drawing 1866 * @since 12 1867 */ 1868 height: number; 1869 1870 /** 1871 * Width of the line. 1872 * @type { number } 1873 * @syscap SystemCapability.Graphics.Drawing 1874 * @since 12 1875 */ 1876 width: number; 1877 1878 /** 1879 * The left edge of the line. The right edge can be obtained with `left + width`. 1880 * @type { number } 1881 * @syscap SystemCapability.Graphics.Drawing 1882 * @since 12 1883 */ 1884 left: number; 1885 1886 /** 1887 * The y position of the baseline for this line from the top of the paragraph. 1888 * @type { number } 1889 * @syscap SystemCapability.Graphics.Drawing 1890 * @since 12 1891 */ 1892 baseline: number; 1893 1894 /** 1895 * Zero indexed line number. 1896 * @type { number } 1897 * @syscap SystemCapability.Graphics.Drawing 1898 * @since 12 1899 */ 1900 lineNumber: number; 1901 1902 /** 1903 * Height from the top. 1904 * @type { number } 1905 * @syscap SystemCapability.Graphics.Drawing 1906 * @since 12 1907 */ 1908 topHeight: number; 1909 1910 /** 1911 * Mapping between text index ranges and the FontMetrics associated with 1912 * them. The first run will be keyed under start_index. The metrics here. 1913 * are before layout and are the base values we calculate from. 1914 * @type { Map<number, RunMetrics> } 1915 * @syscap SystemCapability.Graphics.Drawing 1916 * @since 12 1917 */ 1918 runMetrics: Map<number, RunMetrics>; 1919 } 1920 1921 /** 1922 * Obtain the corresponding font full names array based on the font type. 1923 * @param { SystemFontType } fontType - System font type. 1924 * @returns { Promise<Array<string>> } An array of font full names. 1925 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1926 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 1927 * @syscap SystemCapability.Graphics.Drawing 1928 * @since 14 1929 */ 1930 function getSystemFontFullNamesByType(fontType: SystemFontType): Promise<Array<string>>; 1931 1932 /** 1933 * Get font details according to the font full name and the font type, supporting generic fonts, stylish fonts, and 1934 * installed fonts. 1935 * @param { string } fullName - Font full name. 1936 * @param { SystemFontType } fontType - System font type. 1937 * @returns { Promise<FontDescriptor> } Returns the font descriptor. 1938 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 1939 * <br>2. Incorrect parameter types. 1940 * @syscap SystemCapability.Graphics.Drawing 1941 * @since 14 1942 */ 1943 function getFontDescriptorByFullName(fullName: string, fontType: SystemFontType): Promise<FontDescriptor>; 1944} 1945 1946export default text; 1947