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 * A paragraph retains the size and position of each glyph in the text and can be efficiently resized and painted. 1163 * @syscap SystemCapability.Graphics.Drawing 1164 * @since 12 1165 */ 1166 class Paragraph { 1167 /** 1168 * Calculates the positioning of all the glyphs. 1169 * @param { number } width - Control how wide the text is allowed to be. 1170 * @syscap SystemCapability.Graphics.Drawing 1171 * @since 12 1172 */ 1173 layoutSync(width: number): void; 1174 1175 /** 1176 * Paint the laid out text onto the supplied canvas at (x, y). 1177 * @param { drawing.Canvas } canvas - Object 1178 * @param { number } x - Represents the X-axis position on the canvas. 1179 * @param { number } y - Represents the Y-axis position on the canvas. 1180 * @syscap SystemCapability.Graphics.Drawing 1181 * @since 12 1182 */ 1183 paint(canvas: drawing.Canvas, x: number, y: number): void; 1184 1185 /** 1186 * Draw the laid out text onto the supplied canvas along the path and offset. 1187 * @param { drawing.Canvas } canvas - Canvas used to carry the drawn content and drawing status. 1188 * @param { drawing.Path } path - Path used to determine the position of the text. 1189 * @param { number } hOffset - Horizontal offset along the path. 1190 * @param { number } vOffset - Vertical offset along the path. 1191 * @syscap SystemCapability.Graphics.Drawing 1192 * @since 12 1193 */ 1194 paintOnPath(canvas: drawing.Canvas, path: drawing.Path, hOffset: number, vOffset: number): void; 1195 1196 /** 1197 * Get max width of horizontal space this paragraph occupied. 1198 * @returns { number } Max width of horizontal space. 1199 * @syscap SystemCapability.Graphics.Drawing 1200 * @since 12 1201 */ 1202 getMaxWidth(): number; 1203 1204 /** 1205 * Get height of horizontal space this paragraph occupies. 1206 * @returns { number } Height of horizontal space this paragraph occupies. 1207 * @syscap SystemCapability.Graphics.Drawing 1208 * @since 12 1209 */ 1210 getHeight(): number; 1211 1212 /** 1213 * Get the longest line of horizontal space this paragraph occupies. 1214 * @returns { number } The longest line of horizontal space this paragraph occupies. 1215 * @syscap SystemCapability.Graphics.Drawing 1216 * @since 12 1217 */ 1218 getLongestLine(): number; 1219 1220 /** 1221 * Get the longest line of horizontal space this paragraph occupies, and this horizontal space contains the width 1222 * of indent. 1223 * @returns { number } The longest line with indent of horizontal space this paragraph occupies. 1224 * @syscap SystemCapability.Graphics.Drawing 1225 * @since 13 1226 */ 1227 getLongestLineWithIndent(): number; 1228 1229 /** 1230 * Get the min intrinsic width of horizontal space this paragraph occupies. 1231 * @returns { number } The min intrinsic width of horizontal space this paragraph occupies. 1232 * @syscap SystemCapability.Graphics.Drawing 1233 * @since 12 1234 */ 1235 getMinIntrinsicWidth(): number; 1236 1237 /** 1238 * Get the max intrinsic width. 1239 * @returns { number } Intrinsic Width. 1240 * @syscap SystemCapability.Graphics.Drawing 1241 * @since 12 1242 */ 1243 getMaxIntrinsicWidth(): number; 1244 1245 /** 1246 * Get the alphabetic baseline. 1247 * @returns { number } Alphabetic Baseline. 1248 * @syscap SystemCapability.Graphics.Drawing 1249 * @since 12 1250 */ 1251 getAlphabeticBaseline(): number; 1252 1253 /** 1254 * Get the ideographic baseline. 1255 * @returns { number } Ideographic Baseline. 1256 * @syscap SystemCapability.Graphics.Drawing 1257 * @since 12 1258 */ 1259 getIdeographicBaseline(): number; 1260 1261 /** 1262 * Get the rects for range. 1263 * @param { Range } range - The range to set. 1264 * @param { RectWidthStyle } widthStyle - Width style to set. 1265 * @param { RectHeightStyle } heightStyle - Height style to set. 1266 * @returns { Array<TextBox> } The rects for range. 1267 * @syscap SystemCapability.Graphics.Drawing 1268 * @since 12 1269 */ 1270 getRectsForRange(range: Range, widthStyle: RectWidthStyle, heightStyle: RectHeightStyle): Array<TextBox>; 1271 1272 /** 1273 * Get the rects for placeholders. 1274 * @returns { Array<TextBox> } The rects for placeholders. 1275 * @syscap SystemCapability.Graphics.Drawing 1276 * @since 12 1277 */ 1278 getRectsForPlaceholders(): Array<TextBox>; 1279 1280 /** 1281 * Get the glyph position at coordinate. 1282 * @param { number } x - the positionX of typography to set. 1283 * @param { number } y - the positionY of typography to set. 1284 * @returns { PositionWithAffinity } TextBlob object. 1285 * @syscap SystemCapability.Graphics.Drawing 1286 * @since 12 1287 */ 1288 getGlyphPositionAtCoordinate(x: number, y: number): PositionWithAffinity; 1289 1290 /** 1291 * Find the start and end position of the word containing the glyphs of the given offset. 1292 * @param { number } offset - offset value 1293 * @returns { Range } The range value returned to the caller. 1294 * @syscap SystemCapability.Graphics.Drawing 1295 * @since 12 1296 */ 1297 getWordBoundary(offset: number): Range; 1298 1299 /** 1300 * Get line count. 1301 * @returns { number } The line count value returned to the caller. 1302 * @syscap SystemCapability.Graphics.Drawing 1303 * @since 12 1304 */ 1305 getLineCount(): number; 1306 1307 /** 1308 * Get the line height of the specified line. 1309 * @param { number } line - line number 1310 * @returns { number } The line height value returned to the caller. 1311 * @syscap SystemCapability.Graphics.Drawing 1312 * @since 12 1313 */ 1314 getLineHeight(line: number): number; 1315 1316 /** 1317 * Get the line width of the specified line. 1318 * @param { number } line - line number 1319 * @returns { number } The line width value returned to the caller. 1320 * @syscap SystemCapability.Graphics.Drawing 1321 * @since 12 1322 */ 1323 getLineWidth(line: number): number; 1324 1325 /** 1326 * Return whether it exceed the maximum lines of typography. 1327 * @returns { boolean } The true indicates exceeding, the false indicates not exceeding. 1328 * @syscap SystemCapability.Graphics.Drawing 1329 * @since 12 1330 */ 1331 didExceedMaxLines(): boolean; 1332 1333 /** 1334 * Get the text lines of paragraph. 1335 * @returns { Array<TextLine> } the tuple of TextLine. 1336 * @syscap SystemCapability.Graphics.Drawing 1337 * @since 12 1338 */ 1339 getTextLines(): Array<TextLine>; 1340 1341 /** 1342 * Returns the visible text on the line (excluding a possible ellipsis). 1343 * @param { number } lineNumber - a line number 1344 * @param { boolean } includeSpaces - indicates if the whitespaces should be included 1345 * @returns { Range } The range of text. 1346 * @syscap SystemCapability.Graphics.Drawing 1347 * @since 12 1348 */ 1349 getActualTextRange(lineNumber: number, includeSpaces: boolean): Range; 1350 1351 /** 1352 * Returns the array of line metrics for a line of text. 1353 * @returns { Array<LineMetrics> } Array of line metrics. 1354 * @syscap SystemCapability.Graphics.Drawing 1355 * @since 12 1356 */ 1357 getLineMetrics(): Array<LineMetrics>; 1358 1359 /** 1360 * Returns line metrics info for the line. 1361 * @param { number } lineNumber - a line number 1362 * @returns { LineMetrics | undefined } line metrics. 1363 * @syscap SystemCapability.Graphics.Drawing 1364 * @since 12 1365 */ 1366 getLineMetrics(lineNumber: number): LineMetrics | undefined; 1367 } 1368 1369 /** 1370 * Box that contain text. 1371 * @typedef TextBox 1372 * @syscap SystemCapability.Graphics.Drawing 1373 * @since 12 1374 */ 1375 interface TextBox{ 1376 /** 1377 * Rect of text box. 1378 * @type { common2D.Rect } 1379 * @syscap SystemCapability.Graphics.Drawing 1380 * @since 12 1381 */ 1382 rect: common2D.Rect; 1383 1384 /** 1385 * Text direction. 1386 * @type { TextDirection } 1387 * @syscap SystemCapability.Graphics.Drawing 1388 * @since 12 1389 */ 1390 direction: TextDirection; 1391 } 1392 1393 /** 1394 * Position and affinity. 1395 * @typedef PositionWithAffinity 1396 * @syscap SystemCapability.Graphics.Drawing 1397 * @since 12 1398 */ 1399 interface PositionWithAffinity { 1400 /** 1401 * Position of text. 1402 * @type { number } 1403 * @syscap SystemCapability.Graphics.Drawing 1404 * @since 12 1405 */ 1406 position: number; 1407 1408 /** 1409 * Affinity of text. 1410 * @type { Affinity } 1411 * @syscap SystemCapability.Graphics.Drawing 1412 * @since 12 1413 */ 1414 affinity: Affinity; 1415 } 1416 1417 /** 1418 * Enumerates rect width style. 1419 * @enum { number } 1420 * @syscap SystemCapability.Graphics.Drawing 1421 * @since 12 1422 */ 1423 enum RectWidthStyle { 1424 /** 1425 * Tight width. 1426 * @syscap SystemCapability.Graphics.Drawing 1427 * @since 12 1428 */ 1429 TIGHT, 1430 1431 /** 1432 * Max width. 1433 * @syscap SystemCapability.Graphics.Drawing 1434 * @since 12 1435 */ 1436 MAX, 1437 } 1438 1439 /** 1440 * Enumerates rect height style. 1441 * @enum { number } 1442 * @syscap SystemCapability.Graphics.Drawing 1443 * @since 12 1444 */ 1445 enum RectHeightStyle { 1446 /** 1447 * Provide tight bounding boxes that fit heights per run. 1448 * @syscap SystemCapability.Graphics.Drawing 1449 * @since 12 1450 */ 1451 TIGHT, 1452 1453 /** 1454 * The height of the boxes will be the maximum height of all runs in the line. All rects in the same 1455 * line will be the same height. 1456 * @syscap SystemCapability.Graphics.Drawing 1457 * @since 12 1458 */ 1459 MAX, 1460 1461 /** 1462 * The top and bottom of each rect will cover half of the space above and half of the space below the line. 1463 * @syscap SystemCapability.Graphics.Drawing 1464 * @since 12 1465 */ 1466 INCLUDE_LINE_SPACE_MIDDLE, 1467 1468 /** 1469 * The line spacing will be added to the top of the rect. 1470 * @syscap SystemCapability.Graphics.Drawing 1471 * @since 12 1472 */ 1473 INCLUDE_LINE_SPACE_TOP, 1474 1475 /** 1476 * The line spacing will be added to the bottom of the rect. 1477 * @syscap SystemCapability.Graphics.Drawing 1478 * @since 12 1479 */ 1480 INCLUDE_LINE_SPACE_BOTTOM, 1481 1482 /** 1483 * The height of the boxes will be calculated by text strut. 1484 * @syscap SystemCapability.Graphics.Drawing 1485 * @since 12 1486 */ 1487 STRUT, 1488 } 1489 1490 /** 1491 * Enumerates text affinity.When a selection range involves line breaks or other special characters, the 1492 * affinity determines which side of the characters the start and end of the selection range should be 1493 * closer to. 1494 * @enum { number } 1495 * @syscap SystemCapability.Graphics.Drawing 1496 * @since 12 1497 */ 1498 enum Affinity { 1499 /** 1500 * The position has affinity for the upstream side of the text position. 1501 * @syscap SystemCapability.Graphics.Drawing 1502 * @since 12 1503 */ 1504 1505 UPSTREAM, 1506 /** 1507 * The position has affinity for the downstream side of the text position. 1508 * @syscap SystemCapability.Graphics.Drawing 1509 * @since 12 1510 */ 1511 DOWNSTREAM, 1512 } 1513 1514 /** 1515 * Builds a Paragraph containing text with the given styling information. 1516 * @syscap SystemCapability.Graphics.Drawing 1517 * @since 12 1518 */ 1519 class ParagraphBuilder { 1520 /** 1521 * Constructor ParagraphBuilder. 1522 * @param { ParagraphStyle } paragraphStyle - Paragraph style {@link ParagraphStyle} 1523 * @param { FontCollection } fontCollection - Font collection {@link FontCollection} 1524 * @syscap SystemCapability.Graphics.Drawing 1525 * @since 12 1526 */ 1527 constructor(paragraphStyle: ParagraphStyle, fontCollection: FontCollection); 1528 1529 /** 1530 * Push a style to the stack. 1531 * @param { TextStyle } textStyle - Text style {@link TextStyle} 1532 * @syscap SystemCapability.Graphics.Drawing 1533 * @since 12 1534 */ 1535 pushStyle(textStyle: TextStyle): void; 1536 1537 /** 1538 * Remove a style from the stack. 1539 * @syscap SystemCapability.Graphics.Drawing 1540 * @since 12 1541 */ 1542 popStyle(): void; 1543 1544 /** 1545 * Adds text to the builder. 1546 * @param { string } text - Text string 1547 * @syscap SystemCapability.Graphics.Drawing 1548 * @since 12 1549 */ 1550 addText(text: string): void; 1551 1552 /** 1553 * Add placeholder. 1554 * @param { PlaceholderSpan } placeholderSpan - Placeholder Span {@link PlaceholderSpan} 1555 * @syscap SystemCapability.Graphics.Drawing 1556 * @since 12 1557 */ 1558 addPlaceholder(placeholderSpan: PlaceholderSpan): void; 1559 1560 /** 1561 * Create paragraph object. 1562 * @returns { Paragraph } The paragraph value returned to the caller. 1563 * @syscap SystemCapability.Graphics.Drawing 1564 * @since 12 1565 */ 1566 build(): Paragraph; 1567 1568 /** 1569 * Add symbolId. 1570 * @param { number } symbolId - Symbol Id 1571 * @syscap SystemCapability.Graphics.Drawing 1572 * @since 12 1573 */ 1574 addSymbol(symbolId: number): void; 1575 } 1576 1577 /** 1578 * The structure of text line that provides the basis of paragraph for graphics. 1579 * @syscap SystemCapability.Graphics.Drawing 1580 * @since 12 1581 */ 1582 class TextLine { 1583 /** 1584 * Get the count of glyphs. 1585 * @returns { number } The counts of glyphs. 1586 * @syscap SystemCapability.Graphics.Drawing 1587 * @since 12 1588 */ 1589 getGlyphCount(): number; 1590 1591 /** 1592 * Get the range of text line. 1593 * @returns { Range } The range of text. 1594 * @syscap SystemCapability.Graphics.Drawing 1595 * @since 12 1596 */ 1597 getTextRange(): Range; 1598 1599 /** 1600 * Get the glyph runs of text line. 1601 * @returns { Array<Run> } The tuple of glyph runs of text. 1602 * @syscap SystemCapability.Graphics.Drawing 1603 * @since 12 1604 */ 1605 getGlyphRuns(): Array<Run>; 1606 1607 /** 1608 * Paint the range of text line. 1609 * @param { drawing.Canvas } canvas - Canvas. 1610 * @param { number } x - Represents the X-axis position on the canvas. 1611 * @param { number } y - Represents the Y-axis position on the canvas. 1612 * @syscap SystemCapability.Graphics.Drawing 1613 * @since 12 1614 */ 1615 paint(canvas: drawing.Canvas, x: number, y: number): void; 1616 } 1617 1618 /** 1619 * Independent rendering of text layout. 1620 * @syscap SystemCapability.Graphics.Drawing 1621 * @since 12 1622 */ 1623 class Run { 1624 /** 1625 * Gets the number of glyph. 1626 * @returns { number } The number of glyph. 1627 * @syscap SystemCapability.Graphics.Drawing 1628 * @since 12 1629 */ 1630 getGlyphCount(): number; 1631 1632 /** 1633 * Gets the glyph identifier for each character. 1634 * @returns { Array<number> } Glyph identifier. 1635 * @syscap SystemCapability.Graphics.Drawing 1636 * @since 12 1637 */ 1638 getGlyphs(): Array<number>; 1639 1640 /** 1641 * Gets the font position offset. 1642 * @returns { Array<common2D.Point> } The position of the font in the layout. 1643 * @syscap SystemCapability.Graphics.Drawing 1644 * @since 12 1645 */ 1646 getPositions(): Array<common2D.Point>; 1647 1648 /** 1649 * Gets the font position offset array. 1650 * @returns { Array<common2D.Point> } The position offset of the font in the layout. 1651 * @syscap SystemCapability.Graphics.Drawing 1652 * @since 12 1653 */ 1654 getOffsets(): Array<common2D.Point>; 1655 1656 /** 1657 * Gets the font object instance. 1658 * @returns { drawing.Font } The font object instance. 1659 * @syscap SystemCapability.Graphics.Drawing 1660 * @since 12 1661 */ 1662 getFont(): drawing.Font; 1663 1664 /** 1665 * Paint the laid out text onto the supplied canvas at (x, y). 1666 * @param { drawing.Canvas } canvas - Object. 1667 * @param { number } x - Represents the X-axis position on the canvas. 1668 * @param { number } y - Represents the Y-axis position on the canvas. 1669 * @syscap SystemCapability.Graphics.Drawing 1670 * @since 12 1671 */ 1672 paint(canvas: drawing.Canvas, x: number, y: number): void; 1673 } 1674 1675 /** 1676 * Describes the layout information and metrics for a continuous piece of text (a run) in a line of text. 1677 * @typedef RunMetrics 1678 * @syscap SystemCapability.Graphics.Drawing 1679 * @since 12 1680 */ 1681 interface RunMetrics { 1682 /** 1683 * The metrics of an Font. 1684 * @type { TextStyle } 1685 * @syscap SystemCapability.Graphics.Drawing 1686 * @since 12 1687 */ 1688 textStyle: TextStyle; 1689 1690 /** 1691 * Describes text style. 1692 * @type { drawing.FontMetrics } 1693 * @syscap SystemCapability.Graphics.Drawing 1694 * @since 12 1695 */ 1696 fontMetrics: drawing.FontMetrics; 1697 } 1698 1699 /** 1700 * Describes the metric information for a line of text in a text layout. 1701 * @typedef LineMetrics 1702 * @syscap SystemCapability.Graphics.Drawing 1703 * @since 12 1704 */ 1705 interface LineMetrics { 1706 /** 1707 * The indexes in the text buffer the line begins. 1708 * @type { number } 1709 * @syscap SystemCapability.Graphics.Drawing 1710 * @since 12 1711 */ 1712 startIndex: number; 1713 1714 /** 1715 * The indexes in the text buffer the line ends. 1716 * @type { number } 1717 * @syscap SystemCapability.Graphics.Drawing 1718 * @since 12 1719 */ 1720 endIndex: number; 1721 1722 /** 1723 * The height of the text rise, the distance from the baseline to the top of the character. 1724 * @type { number } 1725 * @syscap SystemCapability.Graphics.Drawing 1726 * @since 12 1727 */ 1728 ascent: number; 1729 1730 /** 1731 * The height of the text drop, the distance from the baseline to the bottom of the character. 1732 * @type { number } 1733 * @syscap SystemCapability.Graphics.Drawing 1734 * @since 12 1735 */ 1736 descent: number; 1737 1738 /** 1739 * The height of the current line is `round(ascent + descent)`. 1740 * @type { number } 1741 * @syscap SystemCapability.Graphics.Drawing 1742 * @since 12 1743 */ 1744 height: number; 1745 1746 /** 1747 * Width of the line. 1748 * @type { number } 1749 * @syscap SystemCapability.Graphics.Drawing 1750 * @since 12 1751 */ 1752 width: number; 1753 1754 /** 1755 * The left edge of the line. The right edge can be obtained with `left + width`. 1756 * @type { number } 1757 * @syscap SystemCapability.Graphics.Drawing 1758 * @since 12 1759 */ 1760 left: number; 1761 1762 /** 1763 * The y position of the baseline for this line from the top of the paragraph. 1764 * @type { number } 1765 * @syscap SystemCapability.Graphics.Drawing 1766 * @since 12 1767 */ 1768 baseline: number; 1769 1770 /** 1771 * Zero indexed line number. 1772 * @type { number } 1773 * @syscap SystemCapability.Graphics.Drawing 1774 * @since 12 1775 */ 1776 lineNumber: number; 1777 1778 /** 1779 * Height from the top. 1780 * @type { number } 1781 * @syscap SystemCapability.Graphics.Drawing 1782 * @since 12 1783 */ 1784 topHeight: number; 1785 1786 /** 1787 * Mapping between text index ranges and the FontMetrics associated with 1788 * them. The first run will be keyed under start_index. The metrics here. 1789 * are before layout and are the base values we calculate from. 1790 * @type { Map<number, RunMetrics> } 1791 * @syscap SystemCapability.Graphics.Drawing 1792 * @since 12 1793 */ 1794 runMetrics: Map<number, RunMetrics>; 1795 } 1796} 1797 1798export default text;