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