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     * Load font.
860     * @param { string } name - The font name.
861     * @param { string | Resource } path - The path of the font file.
862     * @returns { Promise<void> } The promise returned by the function.
863     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
864     * <br>2. Incorrect parameter types.
865     * @syscap SystemCapability.Graphics.Drawing
866     * @since 14
867     */
868    loadFont(name: string, path: string | Resource): Promise<void>;
869
870    /**
871     * Clear font caches.
872     * @syscap SystemCapability.Graphics.Drawing
873     * @since 12
874     */
875     clearCaches(): void;
876  }
877
878  /**
879   * Describes strut style.
880   * @typedef StrutStyle
881   * @syscap SystemCapability.Graphics.Drawing
882   * @since 12
883   */
884  interface StrutStyle {
885    /**
886     * The families of the font to use when calculating the strut.
887     * @type { ?Array<string> } fontfamily gather
888     * @syscap SystemCapability.Graphics.Drawing
889     * @since 12
890     */
891    fontFamilies?: Array<string>;
892
893    /**
894     * The font style to use when calculating the strut.
895     * @type { ?FontStyle } it is uint32_t type data
896     * @syscap SystemCapability.Graphics.Drawing
897     * @since 12
898     */
899    fontStyle?: FontStyle;
900
901    /**
902     * The font width to use when calculating the strut.
903     * @type { ?FontWidth } it is uint32_t type data
904     * @syscap SystemCapability.Graphics.Drawing
905     * @since 12
906     */
907    fontWidth?: FontWidth;
908
909    /**
910     * The font weight to use when calculating the strut.
911     * @type { ?FontWeight } it is uint32_t type data
912     * @syscap SystemCapability.Graphics.Drawing
913     * @since 12
914     */
915    fontWeight?: FontWeight;
916
917    /**
918     * The size of the ascent plus descent in logical pixels.
919     * @type { ?number } it is double type data
920     * @syscap SystemCapability.Graphics.Drawing
921     * @since 12
922     */
923    fontSize?: number;
924
925    /**
926     * The minimum height of the strut, as a multiple of fontSize.
927     * @type { ?number } it is double type data
928     * @syscap SystemCapability.Graphics.Drawing
929     * @since 12
930     */
931    height?: number;
932
933    /**
934     * The additional leading to apply to the strut as a multiple of Size.
935     * @type { ?number } it is double type data
936     * @syscap SystemCapability.Graphics.Drawing
937     * @since 12
938     */
939    leading?: number;
940
941    /**
942     * Whether the strut height should be forced.
943     * @type { ?boolean } it is boolean type data
944     * @syscap SystemCapability.Graphics.Drawing
945     * @since 12
946     */
947    forceHeight?: boolean;
948
949    /**
950     * Whether the strut style should be enable.
951     * @type { ?boolean } it is boolean type data
952     * @syscap SystemCapability.Graphics.Drawing
953     * @since 12
954     */
955    enabled?: boolean;
956
957    /**
958     * Whether the height is override.
959     * @type { ?boolean } it is boolean type data
960     * @syscap SystemCapability.Graphics.Drawing
961     * @since 12
962     */
963    heightOverride?: boolean;
964
965    /**
966     * Whether the half leading is enable.
967     * @type { ?boolean } it is boolean type data
968     * @syscap SystemCapability.Graphics.Drawing
969     * @since 12
970     */
971    halfLeading?: boolean;
972  }
973
974  /**
975   * Determines the configuration used by ParagraphBuilder to position lines within a Paragraph of text.
976   * @typedef ParagraphStyle
977   * @syscap SystemCapability.Graphics.Drawing
978   * @since 12
979   */
980  interface ParagraphStyle {
981    /**
982     * Text style of paragraph.
983     * @type { ?TextStyle }
984     * @syscap SystemCapability.Graphics.Drawing
985     * @since 12
986     */
987    textStyle?: TextStyle;
988
989    /**
990     * Text runs direction.
991     * @type { ?TextDirection }
992     * @syscap SystemCapability.Graphics.Drawing
993     * @since 12
994     */
995    textDirection?: TextDirection;
996
997    /**
998     * Refers to how to align the horizontal position of text when displaying text.
999     * @type { ?TextAlign }
1000     * @syscap SystemCapability.Graphics.Drawing
1001     * @since 12
1002     */
1003    align?: TextAlign;
1004
1005    /**
1006     * Word break strategy.
1007     * @type { ?WordBreak }
1008     * @syscap SystemCapability.Graphics.Drawing
1009     * @since 12
1010     */
1011    wordBreak?: WordBreak;
1012
1013    /**
1014     * Maximum number of lines.
1015     * @type { ?number }
1016     * @syscap SystemCapability.Graphics.Drawing
1017     * @since 12
1018     */
1019    maxLines?: number;
1020
1021    /**
1022     * text segmentation strategy.
1023     * @type { ?BreakStrategy }
1024     * @syscap SystemCapability.Graphics.Drawing
1025     * @since 12
1026     */
1027    breakStrategy?: BreakStrategy;
1028
1029    /**
1030     * Strut style of paragraph.
1031     * @type { ?StrutStyle }
1032     * @syscap SystemCapability.Graphics.Drawing
1033     * @since 12
1034     */
1035    strutStyle?: StrutStyle;
1036
1037    /**
1038     * Text height behavior of paragraph.
1039     * @type { ?TextHeightBehavior }
1040     * @syscap SystemCapability.Graphics.Drawing
1041     * @since 12
1042     */
1043    textHeightBehavior?: TextHeightBehavior;
1044
1045    /**
1046     * Text tab of paragraph. Tab alignment does not take effect when text alignment is also set, Or when the ellipsis
1047     * style is configured. When the tab is not set or the tab's location property is less than or equal to 0,
1048     * it is the default space effect. And all tabs in the paragraph after the setting are aligned
1049     * according to this tab effect.
1050     * @type { ?TextTab }
1051     * @syscap SystemCapability.Graphics.Drawing
1052     * @since 14
1053     */
1054    tab?: TextTab;
1055  }
1056
1057  /**
1058   * Where to vertically align the placeholder relative to the surrounding text.
1059   * @enum { number }
1060   * @syscap SystemCapability.Graphics.Drawing
1061   * @since 12
1062   */
1063  enum PlaceholderAlignment {
1064    /**
1065     * Match the baseline of the placeholder with the baseline.
1066     * @syscap SystemCapability.Graphics.Drawing
1067     * @since 12
1068     */
1069    OFFSET_AT_BASELINE,
1070
1071    /**
1072     * Align the bottom edge of the placeholder with the baseline such that the placeholder
1073     * sits on top of the baseline.
1074     * @syscap SystemCapability.Graphics.Drawing
1075     * @since 12
1076     */
1077    ABOVE_BASELINE,
1078
1079    /**
1080     * Align the top edge of the placeholder with the baseline specified in such that the placeholder
1081     * hangs below the baseline.
1082     * @syscap SystemCapability.Graphics.Drawing
1083     * @since 12
1084     */
1085    BELOW_BASELINE,
1086
1087    /**
1088     * Align the top edge of the placeholder with the top edge of the font. When the placeholder is very tall,
1089     * the extra space will hang from the top and extend through the bottom of the line.
1090     * @syscap SystemCapability.Graphics.Drawing
1091     * @since 12
1092     */
1093    TOP_OF_ROW_BOX,
1094
1095    /**
1096     * Align the bottom edge of the placeholder with the bottom edge of the text. When the placeholder is very tall,
1097     * the extra space will rise from the bottom and extend through the top of the line.
1098     * @syscap SystemCapability.Graphics.Drawing
1099     * @since 12
1100     */
1101    BOTTOM_OF_ROW_BOX,
1102
1103    /**
1104     * Align the middle of the placeholder with the middle of the text.When the placeholder is very tall,
1105     * the extra space will grow equally from the top and bottom of the line.
1106     * @syscap SystemCapability.Graphics.Drawing
1107     * @since 12
1108     */
1109    CENTER_OF_ROW_BOX,
1110  }
1111
1112  /**
1113   * Provide a description of placeholder scope in creating typography.
1114   * @typedef PlaceholderSpan
1115   * @syscap SystemCapability.Graphics.Drawing
1116   * @since 12
1117   */
1118  interface PlaceholderSpan {
1119    /**
1120     * The width of the placeholder.
1121     * @type { number }
1122     * @syscap SystemCapability.Graphics.Drawing
1123     * @since 12
1124     */
1125    width: number;
1126
1127    /**
1128     * The height of the placeholder.
1129     * @type { number }
1130     * @syscap SystemCapability.Graphics.Drawing
1131     * @since 12
1132     */
1133    height: number;
1134
1135    /**
1136     * Alignment mode of placeholder.
1137     * @type { PlaceholderAlignment }
1138     * @syscap SystemCapability.Graphics.Drawing
1139     * @since 12
1140     */
1141    align: PlaceholderAlignment;
1142
1143    /**
1144     * Baseline of placeholder.
1145     * @type { TextBaseline }
1146     * @syscap SystemCapability.Graphics.Drawing
1147     * @since 12
1148     */
1149    baseline: TextBaseline;
1150
1151    /**
1152     * Baseline offset of placeholder.
1153     * @type { number }
1154     * @syscap SystemCapability.Graphics.Drawing
1155     * @since 12
1156     */
1157    baselineOffset: number;
1158  }
1159
1160  /**
1161   * Provides the definition of the range.
1162   * @typedef Range
1163   * @syscap SystemCapability.Graphics.Drawing
1164   * @since 12
1165   */
1166  interface Range {
1167    /**
1168     * Left index.
1169     * @type { number }
1170     * @syscap SystemCapability.Graphics.Drawing
1171     * @since 12
1172     */
1173    start: number;
1174
1175    /**
1176     * Right index.
1177     * @type { number }
1178     * @syscap SystemCapability.Graphics.Drawing
1179     * @since 12
1180     */
1181    end: number;
1182  }
1183
1184  /**
1185   * An enumeration of system font types.
1186   * @enum { number }
1187   * @syscap SystemCapability.Graphics.Drawing
1188   * @since 14
1189   */
1190  enum SystemFontType {
1191    /**
1192     * All font types.
1193     * @syscap SystemCapability.Graphics.Drawing
1194     * @since 14
1195     */
1196    ALL = 1 << 0,
1197
1198    /**
1199     * System generic font type.
1200     * @syscap SystemCapability.Graphics.Drawing
1201     * @since 14
1202     */
1203    GENERIC = 1 << 1,
1204
1205    /**
1206     * Stylish font type.
1207     * @syscap SystemCapability.Graphics.Drawing
1208     * @since 14
1209     */
1210    STYLISH = 1 << 2,
1211
1212    /**
1213     * Installed font types.
1214     * @syscap SystemCapability.Graphics.Drawing
1215     * @since 14
1216     */
1217    INSTALLED = 1 << 3,
1218  }
1219
1220  /**
1221   * Font descriptor
1222   * @typedef FontDescriptor
1223   * @syscap SystemCapability.Graphics.Drawing
1224   * @since 14
1225   */
1226  interface FontDescriptor {
1227    /**
1228     * Font file path
1229     * @type { ?string }
1230     * @syscap SystemCapability.Graphics.Drawing
1231     * @since 14
1232     */
1233    path?: string;
1234
1235    /**
1236     * Font postScript name
1237     * @type { ?string }
1238     * @syscap SystemCapability.Graphics.Drawing
1239     * @since 14
1240     */
1241    postScriptName?: string;
1242
1243    /**
1244     * Full font name
1245     * @type { ?string }
1246     * @syscap SystemCapability.Graphics.Drawing
1247     * @since 14
1248     */
1249    fullName?: string;
1250
1251    /**
1252     * Font family name
1253     * @type { ?string }
1254     * @syscap SystemCapability.Graphics.Drawing
1255     * @since 14
1256     */
1257    fontFamily?: string;
1258
1259    /**
1260     * Font subfamily name
1261     * @type { ?string }
1262     * @syscap SystemCapability.Graphics.Drawing
1263     * @since 14
1264     */
1265    fontSubfamily?: string;
1266
1267    /**
1268     * Font weight
1269     * @type { ?FontWeight }
1270     * @syscap SystemCapability.Graphics.Drawing
1271     * @since 14
1272     */
1273    weight?: FontWeight;
1274
1275    /**
1276     * Font width
1277     * @type { ?number }
1278     * @syscap SystemCapability.Graphics.Drawing
1279     * @since 14
1280     */
1281    width?: number;
1282
1283    /**
1284     * Font slant, non-0 means italic.
1285     * @type { ?number }
1286     * @syscap SystemCapability.Graphics.Drawing
1287     * @since 14
1288     */
1289    italic?: number;
1290
1291    /**
1292     * Whether the font is monospaced
1293     * @type { ?boolean }
1294     * @syscap SystemCapability.Graphics.Drawing
1295     * @since 14
1296     */
1297    monoSpace?: boolean;
1298
1299    /**
1300     * Whether to support symbols
1301     * @type { ?boolean }
1302     * @syscap SystemCapability.Graphics.Drawing
1303     * @since 14
1304     */
1305    symbolic?: boolean;
1306  }
1307
1308  /**
1309   * A paragraph retains the size and position of each glyph in the text and can be efficiently resized and painted.
1310   * @syscap SystemCapability.Graphics.Drawing
1311   * @since 12
1312   */
1313  class Paragraph {
1314    /**
1315     * Calculates the positioning of all the glyphs.
1316     * @param { number } width - Control how wide the text is allowed to be.
1317     * @syscap SystemCapability.Graphics.Drawing
1318     * @since 12
1319     */
1320    layoutSync(width: number): void;
1321
1322    /**
1323     * Calculates the positioning of all the glyphs.
1324     * @param { number } width - Control how wide the text is allowed to be.
1325     * @returns { Promise<void> } The promise returned by the function.
1326     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
1327     * <br>2. Incorrect parameter types.
1328     * @syscap SystemCapability.Graphics.Drawing
1329     * @since 14
1330     */
1331    layout(width: number): Promise<void>;
1332
1333    /**
1334     * Paint the laid out text onto the supplied canvas at (x, y).
1335     * @param { drawing.Canvas } canvas - Object
1336     * @param { number } x - Represents the X-axis position on the canvas.
1337     * @param { number } y - Represents the Y-axis position on the canvas.
1338     * @syscap SystemCapability.Graphics.Drawing
1339     * @since 12
1340     */
1341    paint(canvas: drawing.Canvas, x: number, y: number): void;
1342
1343    /**
1344     * Draw the laid out text onto the supplied canvas along the path and offset.
1345     * @param { drawing.Canvas } canvas - Canvas used to carry the drawn content and drawing status.
1346     * @param { drawing.Path } path - Path used to determine the position of the text.
1347     * @param { number } hOffset - Horizontal offset along the path.
1348     * @param { number } vOffset - Vertical offset along the path.
1349     * @syscap SystemCapability.Graphics.Drawing
1350     * @since 12
1351     */
1352    paintOnPath(canvas: drawing.Canvas, path: drawing.Path, hOffset: number, vOffset: number): void;
1353
1354    /**
1355     * Get max width of horizontal space this paragraph occupied.
1356     * @returns { number } Max width of horizontal space.
1357     * @syscap SystemCapability.Graphics.Drawing
1358     * @since 12
1359     */
1360    getMaxWidth(): number;
1361
1362    /**
1363     * Get height of horizontal space this paragraph occupies.
1364     * @returns { number } Height of horizontal space this paragraph occupies.
1365     * @syscap SystemCapability.Graphics.Drawing
1366     * @since 12
1367     */
1368    getHeight(): number;
1369
1370    /**
1371     * Get the longest line of horizontal space this paragraph occupies.
1372     * @returns { number } The longest line of horizontal space this paragraph occupies.
1373     * @syscap SystemCapability.Graphics.Drawing
1374     * @since 12
1375     */
1376    getLongestLine(): number;
1377
1378    /**
1379     * Get the longest line of horizontal space this paragraph occupies, and this horizontal space contains the width
1380     * of indent.
1381     * @returns { number } The longest line with indent of horizontal space this paragraph occupies.
1382     * @syscap SystemCapability.Graphics.Drawing
1383     * @since 13
1384     */
1385    getLongestLineWithIndent(): number;
1386
1387    /**
1388     * Get the min intrinsic width of horizontal space this paragraph occupies.
1389     * @returns { number } The min intrinsic width of horizontal space this paragraph occupies.
1390     * @syscap SystemCapability.Graphics.Drawing
1391     * @since 12
1392     */
1393    getMinIntrinsicWidth(): number;
1394
1395    /**
1396     * Get the max intrinsic width.
1397     * @returns { number } Intrinsic Width.
1398     * @syscap SystemCapability.Graphics.Drawing
1399     * @since 12
1400     */
1401    getMaxIntrinsicWidth(): number;
1402
1403    /**
1404     * Get the alphabetic baseline.
1405     * @returns { number } Alphabetic Baseline.
1406     * @syscap SystemCapability.Graphics.Drawing
1407     * @since 12
1408     */
1409    getAlphabeticBaseline(): number;
1410
1411    /**
1412     * Get the ideographic baseline.
1413     * @returns { number } Ideographic Baseline.
1414     * @syscap SystemCapability.Graphics.Drawing
1415     * @since 12
1416     */
1417    getIdeographicBaseline(): number;
1418
1419    /**
1420     * Get the rects for range.
1421     * @param { Range } range - The range to set.
1422     * @param { RectWidthStyle } widthStyle - Width style to set.
1423     * @param { RectHeightStyle } heightStyle - Height style to set.
1424     * @returns { Array<TextBox> } The rects for range.
1425     * @syscap SystemCapability.Graphics.Drawing
1426     * @since 12
1427     */
1428    getRectsForRange(range: Range, widthStyle: RectWidthStyle, heightStyle: RectHeightStyle): Array<TextBox>;
1429
1430    /**
1431     * Get the rects for placeholders.
1432     * @returns { Array<TextBox> } The rects for placeholders.
1433     * @syscap SystemCapability.Graphics.Drawing
1434     * @since 12
1435     */
1436    getRectsForPlaceholders(): Array<TextBox>;
1437
1438    /**
1439     * Get the glyph position at coordinate.
1440     * @param { number } x - the positionX of typography to set.
1441     * @param { number } y - the positionY of typography to set.
1442     * @returns { PositionWithAffinity } TextBlob object.
1443     * @syscap SystemCapability.Graphics.Drawing
1444     * @since 12
1445     */
1446    getGlyphPositionAtCoordinate(x: number, y: number): PositionWithAffinity;
1447
1448    /**
1449     * Find the start and end position of the word containing the glyphs of the given offset.
1450     * @param { number } offset - offset value
1451     * @returns { Range } The range value returned to the caller.
1452     * @syscap SystemCapability.Graphics.Drawing
1453     * @since 12
1454     */
1455    getWordBoundary(offset: number): Range;
1456
1457    /**
1458     * Get line count.
1459     * @returns { number } The line count value returned to the caller.
1460     * @syscap SystemCapability.Graphics.Drawing
1461     * @since 12
1462     */
1463    getLineCount(): number;
1464
1465    /**
1466     * Get the line height of the specified line.
1467     * @param { number } line - line number
1468     * @returns { number } The line height value returned to the caller.
1469     * @syscap SystemCapability.Graphics.Drawing
1470     * @since 12
1471     */
1472    getLineHeight(line: number): number;
1473
1474    /**
1475     * Get the line width of the specified line.
1476     * @param { number } line - line number
1477     * @returns { number } The line width value returned to the caller.
1478     * @syscap SystemCapability.Graphics.Drawing
1479     * @since 12
1480     */
1481    getLineWidth(line: number): number;
1482
1483    /**
1484     * Return whether it exceed the maximum lines of typography.
1485     * @returns { boolean } The true indicates exceeding, the false indicates not exceeding.
1486     * @syscap SystemCapability.Graphics.Drawing
1487     * @since 12
1488     */
1489    didExceedMaxLines(): boolean;
1490
1491    /**
1492     * Get the text lines of paragraph.
1493     * @returns { Array<TextLine> } the tuple of TextLine.
1494     * @syscap SystemCapability.Graphics.Drawing
1495     * @since 12
1496     */
1497    getTextLines(): Array<TextLine>;
1498
1499    /**
1500     * Returns the visible text on the line (excluding a possible ellipsis).
1501     * @param { number } lineNumber - a line number
1502     * @param { boolean } includeSpaces - indicates if the whitespaces should be included
1503     * @returns { Range } The range of text.
1504     * @syscap SystemCapability.Graphics.Drawing
1505     * @since 12
1506     */
1507    getActualTextRange(lineNumber: number, includeSpaces: boolean): Range;
1508
1509    /**
1510     * Returns the array of line metrics for a line of text.
1511     * @returns { Array<LineMetrics> } Array of line metrics.
1512     * @syscap SystemCapability.Graphics.Drawing
1513     * @since 12
1514     */
1515    getLineMetrics(): Array<LineMetrics>;
1516
1517    /**
1518     * Returns line metrics info for the line.
1519     * @param { number } lineNumber - a line number
1520     * @returns { LineMetrics | undefined } line metrics.
1521     * @syscap SystemCapability.Graphics.Drawing
1522     * @since 12
1523     */
1524    getLineMetrics(lineNumber: number): LineMetrics | undefined;
1525  }
1526
1527  /**
1528   * Provides the abilities to typeset by line.
1529   * @syscap SystemCapability.Graphics.Drawing
1530   * @since 14
1531   */
1532  class LineTypeset {
1533    /**
1534     * Calculate the line breakpoint based on the width provided.
1535     * @param { number } startIndex - The starting point for the line-break calculations.
1536     * @param { number } width - The requested line-break width.
1537     * @returns { number } A count of the characters from startIndex that would cause the line break.
1538     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
1539     * <br>2. Incorrect parameter types.
1540     * @syscap SystemCapability.Graphics.Drawing
1541     * @since 14
1542     */
1543    getLineBreak(startIndex: number, width: number): number;
1544
1545    /**
1546     * Creates a text line object based on the text range provided.
1547     * @param { number } startIndex - The starting index of the text range.
1548     * @param { number } count - The characters count of the text range.
1549     * @returns { TextLine } Text line object.
1550     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
1551     * <br>2. Incorrect parameter types.
1552     * @syscap SystemCapability.Graphics.Drawing
1553     * @since 14
1554     */
1555    createLine(startIndex: number, count: number): TextLine;
1556  }
1557
1558  /**
1559   * Box that contain text.
1560   * @typedef TextBox
1561   * @syscap SystemCapability.Graphics.Drawing
1562   * @since 12
1563   */
1564  interface TextBox{
1565    /**
1566     * Rect of text box.
1567     * @type { common2D.Rect }
1568     * @syscap SystemCapability.Graphics.Drawing
1569     * @since 12
1570     */
1571    rect: common2D.Rect;
1572
1573    /**
1574     * Text direction.
1575     * @type { TextDirection }
1576     * @syscap SystemCapability.Graphics.Drawing
1577     * @since 12
1578     */
1579    direction: TextDirection;
1580  }
1581
1582  /**
1583   * Position and affinity.
1584   * @typedef PositionWithAffinity
1585   * @syscap SystemCapability.Graphics.Drawing
1586   * @since 12
1587   */
1588  interface PositionWithAffinity {
1589    /**
1590     * Position of text.
1591     * @type { number }
1592     * @syscap SystemCapability.Graphics.Drawing
1593     * @since 12
1594     */
1595    position: number;
1596
1597    /**
1598     * Affinity of text.
1599     * @type { Affinity }
1600     * @syscap SystemCapability.Graphics.Drawing
1601     * @since 12
1602     */
1603    affinity: Affinity;
1604  }
1605
1606  /**
1607   * Enumerates rect width style.
1608   * @enum { number }
1609   * @syscap SystemCapability.Graphics.Drawing
1610   * @since 12
1611   */
1612  enum RectWidthStyle {
1613    /**
1614     * Tight width.
1615     * @syscap SystemCapability.Graphics.Drawing
1616     * @since 12
1617     */
1618    TIGHT,
1619
1620    /**
1621     * Max width.
1622     * @syscap SystemCapability.Graphics.Drawing
1623     * @since 12
1624     */
1625    MAX,
1626  }
1627
1628  /**
1629   * Enumerates rect height style.
1630   * @enum { number }
1631   * @syscap SystemCapability.Graphics.Drawing
1632   * @since 12
1633   */
1634  enum RectHeightStyle {
1635    /**
1636     * Provide tight bounding boxes that fit heights per run.
1637     * @syscap SystemCapability.Graphics.Drawing
1638     * @since 12
1639     */
1640    TIGHT,
1641
1642    /**
1643     * The height of the boxes will be the maximum height of all runs in the line. All rects in the same
1644     * line will be the same height.
1645     * @syscap SystemCapability.Graphics.Drawing
1646     * @since 12
1647     */
1648    MAX,
1649
1650    /**
1651     * The top and bottom of each rect will cover half of the space above and half of the space below the line.
1652     * @syscap SystemCapability.Graphics.Drawing
1653     * @since 12
1654     */
1655    INCLUDE_LINE_SPACE_MIDDLE,
1656
1657    /**
1658     * The line spacing will be added to the top of the rect.
1659     * @syscap SystemCapability.Graphics.Drawing
1660     * @since 12
1661     */
1662    INCLUDE_LINE_SPACE_TOP,
1663
1664    /**
1665     * The line spacing will be added to the bottom of the rect.
1666     * @syscap SystemCapability.Graphics.Drawing
1667     * @since 12
1668     */
1669    INCLUDE_LINE_SPACE_BOTTOM,
1670
1671    /**
1672     * The height of the boxes will be calculated by text strut.
1673     * @syscap SystemCapability.Graphics.Drawing
1674     * @since 12
1675     */
1676    STRUT,
1677  }
1678
1679  /**
1680   * Enumerates text affinity.When a selection range involves line breaks or other special characters, the
1681   * affinity determines which side of the characters the start and end of the selection range should be
1682   * closer to.
1683   * @enum { number }
1684   * @syscap SystemCapability.Graphics.Drawing
1685   * @since 12
1686   */
1687  enum Affinity {
1688    /**
1689     * The position has affinity for the upstream side of the text position.
1690     * @syscap SystemCapability.Graphics.Drawing
1691     * @since 12
1692     */
1693
1694    UPSTREAM,
1695    /**
1696     * The position has affinity for the downstream side of the text position.
1697     * @syscap SystemCapability.Graphics.Drawing
1698     * @since 12
1699     */
1700    DOWNSTREAM,
1701  }
1702
1703  /**
1704   * Builds a Paragraph containing text with the given styling information.
1705   * @syscap SystemCapability.Graphics.Drawing
1706   * @since 12
1707   */
1708  class ParagraphBuilder {
1709    /**
1710     * Constructor ParagraphBuilder.
1711     * @param { ParagraphStyle } paragraphStyle - Paragraph style {@link ParagraphStyle}
1712     * @param { FontCollection } fontCollection - Font collection {@link FontCollection}
1713     * @syscap SystemCapability.Graphics.Drawing
1714     * @since 12
1715     */
1716    constructor(paragraphStyle: ParagraphStyle, fontCollection: FontCollection);
1717
1718    /**
1719     * Push a style to the stack.
1720     * @param { TextStyle } textStyle - Text style {@link TextStyle}
1721     * @syscap SystemCapability.Graphics.Drawing
1722     * @since 12
1723     */
1724    pushStyle(textStyle: TextStyle): void;
1725
1726    /**
1727     * Remove a style from the stack.
1728     * @syscap SystemCapability.Graphics.Drawing
1729     * @since 12
1730     */
1731    popStyle(): void;
1732
1733    /**
1734     * Adds text to the builder.
1735     * @param { string } text - Text string
1736     * @syscap SystemCapability.Graphics.Drawing
1737     * @since 12
1738     */
1739    addText(text: string): void;
1740
1741    /**
1742     * Add placeholder.
1743     * @param { PlaceholderSpan } placeholderSpan - Placeholder Span {@link PlaceholderSpan}
1744     * @syscap SystemCapability.Graphics.Drawing
1745     * @since 12
1746     */
1747    addPlaceholder(placeholderSpan: PlaceholderSpan): void;
1748
1749    /**
1750     * Create paragraph object.
1751     * @returns { Paragraph } The paragraph value returned to the caller.
1752     * @syscap SystemCapability.Graphics.Drawing
1753     * @since 12
1754     */
1755    build(): Paragraph;
1756
1757    /**
1758     * Create LineTypeset object.
1759     * @returns { LineTypeset } The LineTypeset value returned to the caller.
1760     * @syscap SystemCapability.Graphics.Drawing
1761     * @since 14
1762     */
1763    buildLineTypeset(): LineTypeset;
1764
1765    /**
1766     * Add symbolId.
1767     * @param { number } symbolId - Symbol Id
1768     * @syscap SystemCapability.Graphics.Drawing
1769     * @since 12
1770     */
1771    addSymbol(symbolId: number): void;
1772  }
1773
1774  /**
1775   * Provides the definition of the typographic bounds.
1776   * @typedef TypographicBounds
1777   * @syscap SystemCapability.Graphics.Drawing
1778   * @since 14
1779   */
1780  interface TypographicBounds {
1781    /**
1782     * Distance Retained Above Baseline.
1783     * @type { number }
1784     * @syscap SystemCapability.Graphics.Drawing
1785     * @since 14
1786     */
1787    ascent: number;
1788
1789    /**
1790     * The distance that remains below the baseline.
1791     * @type { number }
1792     * @syscap SystemCapability.Graphics.Drawing
1793     * @since 14
1794     */
1795    descent: number;
1796
1797    /**
1798     * Line Spacing.
1799     * @type { number }
1800     * @syscap SystemCapability.Graphics.Drawing
1801     * @since 14
1802     */
1803    leading: number;
1804
1805    /**
1806     * The total width of the typesetting border.
1807     * @type { number }
1808     * @syscap SystemCapability.Graphics.Drawing
1809     * @since 14
1810     */
1811    width: number;
1812  }
1813
1814  /**
1815   * Offset callback function of caret.
1816   *
1817   * @typedef { function } CaretOffsetsCallback
1818   * @param { number } offset - Character offset is traversed as an argument to the callback function.
1819   * @param { number } index - Character index is traversed as an argument to the callback function.
1820   * @param { boolean } leadingEdge - Whether the current offset is at the character front, as an argument to the
1821   * callback function.
1822   * @returns { boolean } The return value of the user-defined callback function. If false is returned, the traversal
1823   * continues. If true is returned, the traversal stops.
1824   * @syscap SystemCapability.Graphics.Drawing
1825   * @since 14
1826   */
1827  type CaretOffsetsCallback = (offset: number, index: number, leadingEdge: boolean) => boolean;
1828
1829  /**
1830   * The structure of text line that provides the basis of paragraph for graphics.
1831   * @syscap SystemCapability.Graphics.Drawing
1832   * @since 12
1833   */
1834  class TextLine {
1835    /**
1836     * Get the count of glyphs.
1837     * @returns { number } The counts of glyphs.
1838     * @syscap SystemCapability.Graphics.Drawing
1839     * @since 12
1840     */
1841    getGlyphCount(): number;
1842
1843    /**
1844     * Get the range of text line.
1845     * @returns { Range } The range of text.
1846     * @syscap SystemCapability.Graphics.Drawing
1847     * @since 12
1848     */
1849    getTextRange(): Range;
1850
1851    /**
1852     * Get the glyph runs of text line.
1853     * @returns { Array<Run> } The tuple of glyph runs of text.
1854     * @syscap SystemCapability.Graphics.Drawing
1855     * @since 12
1856     */
1857    getGlyphRuns(): Array<Run>;
1858
1859    /**
1860     * Paint the range of text line.
1861     * @param { drawing.Canvas } canvas - Canvas.
1862     * @param { number } x - Represents the X-axis position on the canvas.
1863     * @param { number } y - Represents the Y-axis position on the canvas.
1864     * @syscap SystemCapability.Graphics.Drawing
1865     * @since 12
1866     */
1867    paint(canvas: drawing.Canvas, x: number, y: number): void;
1868
1869    /**
1870     * Creates a truncated text line object.
1871     * @param { number } width - The width of the truncated line.
1872     * @param { EllipsisMode } ellipsisMode - Text ellipsis mode, EllipsisMode:MIDDLE is not supported.
1873     * @param { string } ellipsis - Text ellipsis.
1874     * @returns { TextLine } Truncated text line object.
1875     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
1876     * <br>2. Incorrect parameter types.
1877     * @syscap SystemCapability.Graphics.Drawing
1878     * @since 14
1879     */
1880    createTruncatedLine(width: number, ellipsisMode: EllipsisMode, ellipsis: string): TextLine;
1881
1882    /**
1883     * Gets the text line typographic bounds.
1884     * @returns { TypographicBounds } The text line of typographic bounds.
1885     * @syscap SystemCapability.Graphics.Drawing
1886     * @since 14
1887     */
1888    getTypographicBounds(): TypographicBounds;
1889
1890    /**
1891     * Gets the text line image bounds.
1892     * @returns { common2D.Rect } Rect of text line.
1893     * @syscap SystemCapability.Graphics.Drawing
1894     * @since 14
1895     */
1896    getImageBounds(): common2D.Rect;
1897
1898    /**
1899     * Gets the tail space width.
1900     * @returns { number } The tail space width.
1901     * @syscap SystemCapability.Graphics.Drawing
1902     * @since 14
1903     */
1904    getTrailingSpaceWidth(): number;
1905
1906    /**
1907     * Gets the string index of the given position.
1908     * @param { common2D.Point } point - The given position.
1909     * @returns { number } The string index for a given position.
1910     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
1911     * <br>2. Incorrect parameter types.
1912     * @syscap SystemCapability.Graphics.Drawing
1913     * @since 14
1914     */
1915    getStringIndexForPosition(point: common2D.Point): number;
1916
1917    /**
1918     * Gets the offset of the given string index.
1919     * @param { number } index - The given string index.
1920     * @returns { number } The offset for a given string index.
1921     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
1922     * <br>2. Incorrect parameter types.
1923     * @syscap SystemCapability.Graphics.Drawing
1924     * @since 14
1925     */
1926    getOffsetForStringIndex(index: number): number;
1927
1928    /**
1929     * Enumerate caret offset and index in text lines.
1930     * @param { CaretOffsetsCallback } callback - User-defined callback functions.
1931     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
1932     * <br>2. Incorrect parameter types.
1933     * @syscap SystemCapability.Graphics.Drawing
1934     * @since 14
1935     */
1936    enumerateCaretOffsets(callback: CaretOffsetsCallback): void;
1937
1938    /**
1939     * Gets the text offset based on the given alignment factor and alignment width.
1940     * @param { number } alignmentFactor - The coefficients that text needs to be aligned.
1941     *                                     Less than or equal to 0 is left justified, 0.5 is center justified,
1942     *                                     and greater than or equal to 1 is right justified.
1943     * @param { number } alignmentWidth - The width of the text to be aligned.
1944     *                                    Returns 0 if it is less than the actual width of the text.
1945     * @returns { number } The offset of the aligned text.
1946     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
1947     * <br>2. Incorrect parameter types.
1948     * @syscap SystemCapability.Graphics.Drawing
1949     * @since 14
1950     */
1951    getAlignmentOffset(alignmentFactor: number, alignmentWidth: number): number;
1952  }
1953
1954  /**
1955   * Independent rendering of text layout.
1956   * @syscap SystemCapability.Graphics.Drawing
1957   * @since 12
1958   */
1959  class Run {
1960    /**
1961     * Gets the number of glyph.
1962     * @returns { number } The number of glyph.
1963     * @syscap SystemCapability.Graphics.Drawing
1964     * @since 12
1965     */
1966    getGlyphCount(): number;
1967
1968    /**
1969     * Gets the glyph identifier for each character.
1970     * @returns { Array<number> } Glyph identifier.
1971     * @syscap SystemCapability.Graphics.Drawing
1972     * @since 12
1973     */
1974    getGlyphs(): Array<number>;
1975
1976    /**
1977     * Gets the range glyph identifier for each character.
1978     * @param { Range } range of run, range.start is the starting index of the run block, starting from 0.
1979     * range.end is run length, if range.start and range.end are set to 0, then get all of the current run.
1980     * @returns { Array<number> } Glyph identifier or undefined.
1981     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
1982     * <br>2. Incorrect parameter types.
1983     * @syscap SystemCapability.Graphics.Drawing
1984     * @since 14
1985     */
1986    getGlyphs(range: Range): Array<number>;
1987
1988    /**
1989     * Gets the font position offset.
1990     * @returns { Array<common2D.Point> } The position of the font in the layout.
1991     * @syscap SystemCapability.Graphics.Drawing
1992     * @since 12
1993     */
1994    getPositions(): Array<common2D.Point>;
1995
1996    /**
1997     * Gets the range font position offset.
1998     * @param { Range } range of run, range.start is the starting index of the run block, starting from 0.
1999     * range.end is run length, if range.start and range.end are set to 0, then get all of the current run.
2000     * @returns { Array<common2D.Point> } The position of the font in the layout or undefined.
2001     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
2002     * <br>2. Incorrect parameter types.
2003     * @syscap SystemCapability.Graphics.Drawing
2004     * @since 14
2005     */
2006    getPositions(range: Range): Array<common2D.Point>;
2007
2008	  /**
2009     * Gets the font position offset array.
2010     * @returns { Array<common2D.Point> } The position offset of the font in the layout.
2011     * @syscap SystemCapability.Graphics.Drawing
2012     * @since 12
2013     */
2014    getOffsets(): Array<common2D.Point>;
2015
2016    /**
2017     * Gets the font object instance.
2018     * @returns { drawing.Font } The font object instance.
2019     * @syscap SystemCapability.Graphics.Drawing
2020     * @since 12
2021     */
2022    getFont(): drawing.Font;
2023
2024    /**
2025     * Paint the laid out text onto the supplied canvas at (x, y).
2026     * @param { drawing.Canvas } canvas - Object.
2027     * @param { number } x - Represents the X-axis position on the canvas.
2028     * @param { number } y - Represents the Y-axis position on the canvas.
2029     * @syscap SystemCapability.Graphics.Drawing
2030     * @since 12
2031     */
2032    paint(canvas: drawing.Canvas, x: number, y: number): void;
2033
2034    /**
2035     * Gets the range of run glyph indices, the offset of the indices relative to the entire paragraph.
2036     * @param { Range } range of run, range.start is the starting index of the run block, starting from 0.
2037     * range.end is run length, if range.start range.and end are set to 0, then get all of the current run.
2038     * @returns { Array<number> } The glyph indices or undefined.
2039     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
2040     * <br>2. Incorrect parameter types.
2041     * @syscap SystemCapability.Graphics.Drawing
2042     * @since 14
2043     */
2044    getStringIndices(range?: Range): Array<number>;
2045
2046    /**
2047     * Gets the run glyph location and length.
2048     * @returns { Range } The run of glyph location and length, Range.start is location, Range.end is length.
2049     * @syscap SystemCapability.Graphics.Drawing
2050     * @since 14
2051     */
2052    getStringRange(): Range;
2053
2054    /**
2055     * Gets the run typographic bounds.
2056     * @returns { TypographicBounds } The run of typographic bounds.
2057     * @syscap SystemCapability.Graphics.Drawing
2058     * @since 14
2059     */
2060    getTypographicBounds(): TypographicBounds;
2061
2062    /**
2063     * Gets the run image bounds.
2064     * @returns { common2D.Rect } The run rect bounds.
2065     * @syscap SystemCapability.Graphics.Drawing
2066     * @since 14
2067     */
2068    getImageBounds(): common2D.Rect;
2069  }
2070
2071  /**
2072   * Describes the layout information and metrics for a continuous piece of text (a run) in a line of text.
2073   * @typedef RunMetrics
2074   * @syscap SystemCapability.Graphics.Drawing
2075   * @since 12
2076   */
2077  interface RunMetrics {
2078    /**
2079     * The metrics of an Font.
2080     * @type { TextStyle }
2081     * @syscap SystemCapability.Graphics.Drawing
2082     * @since 12
2083     */
2084    textStyle: TextStyle;
2085
2086    /**
2087     * Describes text style.
2088     * @type { drawing.FontMetrics }
2089     * @syscap SystemCapability.Graphics.Drawing
2090     * @since 12
2091     */
2092    fontMetrics: drawing.FontMetrics;
2093  }
2094
2095  /**
2096   * Describes the metric information for a line of text in a text layout.
2097   * @typedef LineMetrics
2098   * @syscap SystemCapability.Graphics.Drawing
2099   * @since 12
2100   */
2101  interface LineMetrics {
2102    /**
2103     * The indexes in the text buffer the line begins.
2104     * @type { number }
2105     * @syscap SystemCapability.Graphics.Drawing
2106     * @since 12
2107     */
2108    startIndex: number;
2109
2110    /**
2111     * The indexes in the text buffer the line ends.
2112     * @type { number }
2113     * @syscap SystemCapability.Graphics.Drawing
2114     * @since 12
2115     */
2116    endIndex: number;
2117
2118    /**
2119     * The height of the text rise, the distance from the baseline to the top of the character.
2120     * @type { number }
2121     * @syscap SystemCapability.Graphics.Drawing
2122     * @since 12
2123     */
2124    ascent: number;
2125
2126    /**
2127     * The height of the text drop, the distance from the baseline to the bottom of the character.
2128     * @type { number }
2129     * @syscap SystemCapability.Graphics.Drawing
2130     * @since 12
2131     */
2132    descent: number;
2133
2134    /**
2135     * The height of the current line is `round(ascent + descent)`.
2136     * @type { number }
2137     * @syscap SystemCapability.Graphics.Drawing
2138     * @since 12
2139     */
2140    height: number;
2141
2142    /**
2143     * Width of the line.
2144     * @type { number }
2145     * @syscap SystemCapability.Graphics.Drawing
2146     * @since 12
2147     */
2148    width: number;
2149
2150    /**
2151     * The left edge of the line. The right edge can be obtained with `left + width`.
2152     * @type { number }
2153     * @syscap SystemCapability.Graphics.Drawing
2154     * @since 12
2155     */
2156    left: number;
2157
2158    /**
2159     * The y position of the baseline for this line from the top of the paragraph.
2160     * @type { number }
2161     * @syscap SystemCapability.Graphics.Drawing
2162     * @since 12
2163     */
2164    baseline: number;
2165
2166    /**
2167     * Zero indexed line number.
2168     * @type { number }
2169     * @syscap SystemCapability.Graphics.Drawing
2170     * @since 12
2171     */
2172    lineNumber: number;
2173
2174    /**
2175     * Height from the top.
2176     * @type { number }
2177     * @syscap SystemCapability.Graphics.Drawing
2178     * @since 12
2179     */
2180    topHeight: number;
2181
2182    /**
2183     * Mapping between text index ranges and the FontMetrics associated with
2184     * them. The first run will be keyed under start_index. The metrics here.
2185     * are before layout and are the base values we calculate from.
2186     * @type { Map<number, RunMetrics> }
2187     * @syscap SystemCapability.Graphics.Drawing
2188     * @since 12
2189     */
2190    runMetrics: Map<number, RunMetrics>;
2191  }
2192
2193  /**
2194   * Obtain the corresponding font full names array based on the font type.
2195   * @param { SystemFontType } fontType - System font type.
2196   * @returns { Promise<Array<string>> } An array of font full names.
2197   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
2198   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
2199   * @syscap SystemCapability.Graphics.Drawing
2200   * @since 14
2201   */
2202  function getSystemFontFullNamesByType(fontType: SystemFontType): Promise<Array<string>>;
2203
2204  /**
2205   * Get font details according to the font full name and the font type, supporting generic fonts, stylish fonts, and
2206   * installed fonts.
2207   * @param { string } fullName - Font full name.
2208   * @param { SystemFontType } fontType - System font type.
2209   * @returns { Promise<FontDescriptor> } Returns the font descriptor.
2210   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
2211   * <br>2. Incorrect parameter types.
2212   * @syscap SystemCapability.Graphics.Drawing
2213   * @since 14
2214   */
2215  function getFontDescriptorByFullName(fullName: string, fontType: SystemFontType): Promise<FontDescriptor>;
2216
2217  /**
2218   * Obtain all system font descriptive symbols that match the specified font descriptor.
2219   * @param { FontDescriptor } desc - Custom font descriptor, where the 'path' fields are not
2220   * considered as valid matching values. If all fields are default values, get all font descriptors.
2221   * @returns { Promise<Array<FontDescriptor>> } List of font descriptors, and an empty array will be returned
2222   * if the matching fails.
2223   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
2224   * <br>2. Incorrect parameter types.
2225   * @syscap SystemCapability.Graphics.Drawing
2226   * @since 14
2227   */
2228  function matchFontDescriptors(desc: FontDescriptor): Promise<Array<FontDescriptor>>;
2229
2230  /**
2231   * Text tab contains alignment type and location in paragraph style.
2232   * @typedef TextTab
2233   * @syscap SystemCapability.Graphics.Drawing
2234   * @since 14
2235   */
2236  interface TextTab {
2237    /**
2238     * The alignment of tab. Support left alignment right alignment center alignment,
2239     * other enumeration values are left alignment effect.
2240     * @type { TextAlign }
2241     * @syscap SystemCapability.Graphics.Drawing
2242     * @since 14
2243     */
2244    alignment: TextAlign;
2245    
2246    /**
2247     * The position of the tab relative to the start of the line.
2248     * @type { number }
2249     * @syscap SystemCapability.Graphics.Drawing
2250     * @since 14
2251     */
2252    location: number;
2253  }
2254}
2255
2256export default text;
2257