• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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 { BusinessError } from '@ohos.base';
21import type drawing from '@ohos.graphics.drawing';
22import type common2D from '@ohos.graphics.common2D';
23import { Resource } from 'global.resource';
24
25/**
26 * Provides functions such as 2D graphics text paragraphs, text styles.
27 *
28 * @namespace text
29 * @syscap SystemCapability.Graphics.Drawing
30 * @since 12
31 */
32namespace text {
33  class Cleaner {
34    static { loadLibrary('text_engine_ani.z') }
35    private ptr: long = 0;
36    private className: string;
37    constructor(className: string, ptr: long) {
38      this.ptr = ptr;
39      this.className = className;
40    }
41    native clean(): void;
42  }
43
44  let destroyRegister = new FinalizationRegistry<Cleaner>((cleaner: Cleaner)=>{
45    cleaner.clean();
46  });
47  let unregisterToken = new object();
48
49  /**
50   * Provides the basis for graphics.
51   * @syscap SystemCapability.Graphics.Drawing
52   * @since 12
53   */
54  export class FontCollection {
55    static { loadLibrary('text_engine_ani.z') }
56    private nativeObj : long = 0;
57    private cleaner: Cleaner | null = null;
58
59    constructor() {
60      this.constructorNative();
61      this.registerCleaner(this.nativeObj);
62    };
63    native constructorNative(): void;
64    registerCleaner(ptr: long): void {
65      this.cleaner = new Cleaner("FontCollection", ptr);
66      destroyRegister.register(this, this.cleaner!, unregisterToken);
67    }
68
69    /**
70     * Get global FontCollection instance of the application.
71     * @returns { FontCollection } The FontCollection object.
72     * @syscap SystemCapability.Graphics.Drawing
73     * @since 12
74     */
75    native static getGlobalInstance(): FontCollection;
76
77    /**
78     * Load font.
79     * @param { string } name - the font name.
80     * @param { string | Resource } path - the path of the font file.
81     * @syscap SystemCapability.Graphics.Drawing
82     * @since 12
83     */
84    native loadFontSync(name: string, path: Resource | string): void;
85
86    /**
87     * Load font.
88     * @param { string } name - The font name.
89     * @param { string | Resource } path - The path of the font file.
90     * @returns { Promise<void> } The promise returned by the function.
91     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
92     * <br>2. Incorrect parameter types.
93     * @syscap SystemCapability.Graphics.Drawing
94     * @since 14
95     */
96    async loadFont(name: string, path: string | Resource): Promise<void> {
97      await new Promise<void>((resolve, reject) => {
98        try {
99          taskpool.execute((): void => {
100            this.loadFontSync(name, path);
101          }).then(() => {
102            resolve(undefined);
103          })
104        } catch (err) {
105          reject(err as BusinessError);
106        }
107      });
108    }
109
110    /**
111     * Clear font caches.
112     * @syscap SystemCapability.Graphics.Drawing
113     * @since 12
114     */
115    native clearCaches(): void;
116  }
117
118  /**
119   * Builds a Paragraph containing text with the given styling information.
120   * @syscap SystemCapability.Graphics.Drawing
121   * @since 12
122   */
123  export class ParagraphBuilder {
124    static { loadLibrary('text_engine_ani.z') }
125    private nativeObj : long = 0;
126    private cleaner: Cleaner | null = null;
127
128    /**
129     * Constructor ParagraphBuilder.
130     * @param { ParagraphStyle } paragraphStyle - Paragraph style {@link ParagraphStyle}
131     * @param { FontCollection } fontCollection - Font collection {@link FontCollection}
132     * @syscap SystemCapability.Graphics.Drawing
133     * @since 12
134     */
135    constructor(paragraphStyle: ParagraphStyle, fontCollection: FontCollection) {
136      this.constructorNative(paragraphStyle, fontCollection);
137      this.registerCleaner(this.nativeObj);
138    };
139    native constructorNative(paragraphStyle: ParagraphStyle, fontCollection: FontCollection): void;
140    registerCleaner(ptr: long): void {
141      this.cleaner = new Cleaner("ParagraphBuilder", ptr);
142      destroyRegister.register(this, this.cleaner!, unregisterToken);
143    }
144
145    /**
146     * Push a style to the stack.
147     * @param { TextStyle } textStyle - Text style {@link TextStyle}
148     * @syscap SystemCapability.Graphics.Drawing
149     * @since 12
150     */
151    native pushStyle(textStyle: TextStyle): void;
152
153    /**
154     * Remove a style from the stack.
155     * @syscap SystemCapability.Graphics.Drawing
156     * @since 12
157     */
158    native popStyle(): void;
159
160    /**
161     * Adds text to the builder.
162     * @param { string } text - Text string
163     * @syscap SystemCapability.Graphics.Drawing
164     * @since 12
165     */
166    native addText(text: string): void;
167
168    /**
169     * Create paragraph object.
170     * @returns { Paragraph } The paragraph value returned to the caller.
171     * @syscap SystemCapability.Graphics.Drawing
172     * @since 12
173     */
174    native build(): Paragraph;
175  }
176
177  /**
178   * A paragraph retains the size and position of each glyph in the text and can be efficiently resized and painted.
179   * @syscap SystemCapability.Graphics.Drawing
180   * @since 12
181   */
182  export class Paragraph {
183    static { loadLibrary('text_engine_ani.z') }
184    public nativeObj : long = 0;
185    private cleaner: Cleaner | null = null;
186
187    constructor() {
188      this.registerCleaner(this.nativeObj);
189    };
190    registerCleaner(ptr: long): void {
191      this.cleaner = new Cleaner("Paragraph", ptr);
192      destroyRegister.register(this, this.cleaner!, unregisterToken);
193    }
194
195    /**
196     * Calculates the positioning of all the glyphs.
197     * @param { number } width - Control how wide the text is allowed to be.
198     * @syscap SystemCapability.Graphics.Drawing
199     * @since 12
200     */
201    native layoutSync(width: number): void;
202
203    /**
204     * Paint the laid out text onto the supplied canvas at (x, y).
205     * @param { drawing.Canvas } canvas - Object
206     * @param { number } x - Represents the X-axis position on the canvas.
207     * @param { number } y - Represents the Y-axis position on the canvas.
208     * @syscap SystemCapability.Graphics.Drawing
209     * @since 12
210     */
211    native paint(canvas: drawing.Canvas, x: number, y: number): void;
212
213    /**
214     * Draw the laid out text onto the supplied canvas along the path and offset.
215     * @param { drawing.Canvas } canvas - Canvas used to carry the drawn content and drawing status.
216     * @param { drawing.Path } path - Path used to determine the position of the text.
217     * @param { number } hOffset - Horizontal offset along the path.
218     * @param { number } vOffset - Vertical offset along the path.
219     * @syscap SystemCapability.Graphics.Drawing
220     * @since 12
221     */
222    native paintOnPath(canvas: drawing.Canvas, path: drawing.Path, hOffset: number, vOffset: number): void;
223
224    /**
225     * Get the longest line of horizontal space this paragraph occupies.
226     * @returns { number } The longest line of horizontal space this paragraph occupies.
227     * @syscap SystemCapability.Graphics.Drawing
228     * @since 12
229     */
230    native getLongestLine(): number;
231
232    /**
233     * Returns the array of line metrics for a line of text.
234     * @returns { Array<LineMetrics> } Array of line metrics.
235     * @syscap SystemCapability.Graphics.Drawing
236     * @since 12
237     */
238    native getLineMetrics(): Array<LineMetrics>;
239
240    /**
241     * Returns line metrics info for the line.
242     * @param { number } lineNumber - a line number
243     * @returns { LineMetrics | undefined } line metrics.
244     * @syscap SystemCapability.Graphics.Drawing
245     * @since 12
246     */
247    getLineMetrics(lineNumber: number): LineMetrics | undefined {
248        return this.nativeGetLineMetricsAt(lineNumber);
249    };
250
251    private native nativeGetLineMetricsAt(lineNumber: number): LineMetrics | undefined;
252  }
253
254  /**
255   * Enumeration of font width of text.
256   * @enum { number }
257   * @syscap SystemCapability.Graphics.Drawing
258   * @since 12
259   */
260  enum FontWidth {
261    /**
262     * Ultra condensed font width.
263     * @syscap SystemCapability.Graphics.Drawing
264     * @since 12
265     */
266    ULTRA_CONDENSED = 1,
267
268    /**
269     * Extra condensed font width.
270     * @syscap SystemCapability.Graphics.Drawing
271     * @since 12
272     */
273    EXTRA_CONDENSED = 2,
274
275    /**
276     * Condensed font width.
277     * @syscap SystemCapability.Graphics.Drawing
278     * @since 12
279     */
280    CONDENSED = 3,
281
282    /**
283     * Semi condensed font width.
284     * @syscap SystemCapability.Graphics.Drawing
285     * @since 12
286     */
287    SEMI_CONDENSED = 4,
288
289    /**
290     * Normal font width.
291     * @syscap SystemCapability.Graphics.Drawing
292     * @since 12
293     */
294    NORMAL = 5,
295
296    /**
297     * Semi expanded font width.
298     * @syscap SystemCapability.Graphics.Drawing
299     * @since 12
300     */
301    SEMI_EXPANDED = 6,
302
303    /**
304     * Expanded font width.
305     * @syscap SystemCapability.Graphics.Drawing
306     * @since 12
307     */
308    EXPANDED = 7,
309
310    /**
311     * Extra expanded font width.
312     * @syscap SystemCapability.Graphics.Drawing
313     * @since 12
314     */
315    EXTRA_EXPANDED = 8,
316
317    /**
318     * Ultra expanded font width.
319     * @syscap SystemCapability.Graphics.Drawing
320     * @since 12
321     */
322    ULTRA_EXPANDED = 9,
323  }
324
325
326  /**
327   * Enumerates of height mode of text.
328   * @enum { number }
329   * @syscap SystemCapability.Graphics.Drawing
330   * @since 12
331   */
332  enum TextHeightBehavior {
333    /**
334     * Both ascend of first row and last row style.
335     * @syscap SystemCapability.Graphics.Drawing
336     * @since 12
337     */
338    ALL = 0x0,
339
340    /**
341     * Forbidding ascend of first row style.
342     * @syscap SystemCapability.Graphics.Drawing
343     * @since 12
344     */
345    DISABLE_FIRST_ASCENT = 0x1,
346
347    /**
348     * Forbidding ascend of last row style.
349     * @syscap SystemCapability.Graphics.Drawing
350     * @since 12
351     */
352    DISABLE_LAST_ASCENT = 0x2,
353
354    /**
355     * Neither ascend of first row nor last row style.
356     * @syscap SystemCapability.Graphics.Drawing
357     * @since 12
358     */
359    DISABLE_ALL = 0x1 | 0x2,
360  }
361
362  /**
363   * Refers to how to align the horizontal position of text when displaying text.
364   * @enum { number }
365   * @syscap SystemCapability.Graphics.Drawing
366   * @since 12
367   */
368  enum TextAlign {
369    /**
370     * Use the left side of the text as a reference line for alignment.
371     * @syscap SystemCapability.Graphics.Drawing
372     * @since 12
373     */
374    LEFT = 0,
375
376    /**
377     * Use the right side of the text as a reference line for alignment.
378     * @syscap SystemCapability.Graphics.Drawing
379     * @since 12
380     */
381    RIGHT = 1,
382
383    /**
384     * Use the midpoint line the text as a reference line for alignment.
385     * @syscap SystemCapability.Graphics.Drawing
386     * @since 12
387     */
388    CENTER = 2,
389
390    /**
391     * Align the text at the start and end of the line.
392     * @syscap SystemCapability.Graphics.Drawing
393     * @since 12
394     */
395    JUSTIFY = 3,
396
397    /**
398     * Align text from start, based on the direction of text, such as left-to-right or right-to-left.
399     * @syscap SystemCapability.Graphics.Drawing
400     * @since 12
401     */
402    START = 4,
403
404    /**
405     * Align text from end, based on the direction of text, such as left-to-right or right-to-left, opposite to START.
406     * @syscap SystemCapability.Graphics.Drawing
407     * @since 12
408     */
409    END = 5,
410  }
411
412  /**
413   * Enumerate text runs direction.
414   * @enum { number }
415   * @syscap SystemCapability.Graphics.Drawing
416   * @since 12
417   */
418  enum TextDirection {
419    /**
420     * The text is oriented from right to left.
421     * @syscap SystemCapability.Graphics.Drawing
422     * @since 12
423     */
424    RTL,
425
426    /**
427     * The text is oriented from left to right.
428     * @syscap SystemCapability.Graphics.Drawing
429     * @since 12
430     */
431    LTR,
432  }
433
434  /**
435   * Enumerate text segmentation strategy.
436   * @enum { number }
437   * @syscap SystemCapability.Graphics.Drawing
438   * @since 12
439   */
440  enum BreakStrategy {
441    /**
442     * The segmentation strategy is greedy.
443     * @syscap SystemCapability.Graphics.Drawing
444     * @since 12
445     */
446    GREEDY,
447
448    /**
449     * The segmentation strategy is high quality.
450     * @syscap SystemCapability.Graphics.Drawing
451     * @since 12
452     */
453    HIGH_QUALITY,
454
455    /**
456     * The segmentation strategy is balanced.
457     * @syscap SystemCapability.Graphics.Drawing
458     * @since 12
459     */
460    BALANCED,
461  }
462
463  /**
464   * Enumerate word break strategy.
465   * @enum { number }
466   * @syscap SystemCapability.Graphics.Drawing
467   * @since 12
468   */
469  enum WordBreak {
470    /**
471     * Normal word break strategy.
472     * @syscap SystemCapability.Graphics.Drawing
473     * @since 12
474     */
475    NORMAL,
476
477    /**
478     * Breaks word by character.
479     * @syscap SystemCapability.Graphics.Drawing
480     * @since 12
481     */
482    BREAK_ALL,
483
484    /**
485     * Breaks word by phrase.
486     * @syscap SystemCapability.Graphics.Drawing
487     * @since 12
488     */
489    BREAK_WORD,
490
491    /**
492     * Breaks word by hyphen.
493     * @syscap SystemCapability.Graphics.Drawing
494     * @since 18
495     */
496    BREAK_HYPHEN,
497  }
498
499  /**
500   * Describes strut style.
501   * @typedef StrutStyle
502   * @syscap SystemCapability.Graphics.Drawing
503   * @since 12
504   */
505  interface StrutStyle {
506    /**
507     * The families of the font to use when calculating the strut.
508     * @type { ?Array<string> } fontfamily gather
509     * @syscap SystemCapability.Graphics.Drawing
510     * @since 12
511     */
512    fontFamilies?: Array<string>;
513
514    /**
515     * The font style to use when calculating the strut.
516     * @type { ?FontStyle } it is uint32_t type data
517     * @syscap SystemCapability.Graphics.Drawing
518     * @since 12
519     */
520    fontStyle?: FontStyle;
521
522    /**
523     * The font width to use when calculating the strut.
524     * @type { ?FontWidth } it is uint32_t type data
525     * @syscap SystemCapability.Graphics.Drawing
526     * @since 12
527     */
528    fontWidth?: FontWidth;
529
530    /**
531     * The font weight to use when calculating the strut.
532     * @type { ?FontWeight } it is uint32_t type data
533     * @syscap SystemCapability.Graphics.Drawing
534     * @since 12
535     */
536    fontWeight?: FontWeight;
537
538    /**
539     * The size of the ascent plus descent in logical pixels.
540     * @type { ?number } it is double type data
541     * @syscap SystemCapability.Graphics.Drawing
542     * @since 12
543     */
544    fontSize?: number;
545
546    /**
547     * The minimum height of the strut, as a multiple of fontSize.
548     * @type { ?number } it is double type data
549     * @syscap SystemCapability.Graphics.Drawing
550     * @since 12
551     */
552    height?: number;
553
554    /**
555     * The additional leading to apply to the strut as a multiple of Size.
556     * @type { ?number } it is double type data
557     * @syscap SystemCapability.Graphics.Drawing
558     * @since 12
559     */
560    leading?: number;
561
562    /**
563     * Whether the strut height should be forced.
564     * @type { ?boolean } it is boolean type data
565     * @syscap SystemCapability.Graphics.Drawing
566     * @since 12
567     */
568    forceHeight?: boolean;
569
570    /**
571     * Whether the strut style should be enable.
572     * @type { ?boolean } it is boolean type data
573     * @syscap SystemCapability.Graphics.Drawing
574     * @since 12
575     */
576    enabled?: boolean;
577
578    /**
579     * Whether the height is override.
580     * @type { ?boolean } it is boolean type data
581     * @syscap SystemCapability.Graphics.Drawing
582     * @since 12
583     */
584    heightOverride?: boolean;
585
586    /**
587     * Whether the half leading is enable.
588     * @type { ?boolean } it is boolean type data
589     * @syscap SystemCapability.Graphics.Drawing
590     * @since 12
591     */
592    halfLeading?: boolean;
593  }
594
595  /**
596   * Text tab contains alignment type and location in paragraph style.
597   * @typedef TextTab
598   * @syscap SystemCapability.Graphics.Drawing
599   * @since 18
600   */
601  interface TextTab {
602    /**
603     * The alignment of tab. Support left alignment right alignment center alignment,
604     * other enumeration values are left alignment effect.
605     * @type { TextAlign }
606     * @syscap SystemCapability.Graphics.Drawing
607     * @since 18
608     */
609    alignment: TextAlign;
610
611    /**
612     * The position of the tab relative to the start of the line.
613     * @type { number }
614     * @syscap SystemCapability.Graphics.Drawing
615     * @since 18
616     */
617    location: number;
618  }
619
620  /**
621   * Determines the configuration used by ParagraphBuilder to position lines within a Paragraph of text.
622   * @typedef ParagraphStyle
623   * @syscap SystemCapability.Graphics.Drawing
624   * @since 12
625   */
626  export interface ParagraphStyle {
627    /**
628     * Text style of paragraph.
629     * @type { ?TextStyle }
630     * @syscap SystemCapability.Graphics.Drawing
631     * @since 12
632     */
633    textStyle?: TextStyle;
634
635    /**
636     * Text runs direction.
637     * @type { ?TextDirection }
638     * @syscap SystemCapability.Graphics.Drawing
639     * @since 12
640     */
641    textDirection?: TextDirection;
642
643    /**
644     * Refers to how to align the horizontal position of text when displaying text.
645     * @type { ?TextAlign }
646     * @syscap SystemCapability.Graphics.Drawing
647     * @since 12
648     */
649    align?: TextAlign;
650
651    /**
652     * Word break strategy.
653     * @type { ?WordBreak }
654     * @syscap SystemCapability.Graphics.Drawing
655     * @since 12
656     */
657    wordBreak?: WordBreak;
658
659    /**
660     * Maximum number of lines.
661     * @type { ?number }
662     * @syscap SystemCapability.Graphics.Drawing
663     * @since 12
664     */
665    maxLines?: number;
666
667    /**
668     * text segmentation strategy.
669     * @type { ?BreakStrategy }
670     * @syscap SystemCapability.Graphics.Drawing
671     * @since 12
672     */
673    breakStrategy?: BreakStrategy;
674
675    /**
676     * Strut style of paragraph.
677     * @type { ?StrutStyle }
678     * @syscap SystemCapability.Graphics.Drawing
679     * @since 12
680     */
681    strutStyle?: StrutStyle;
682
683    /**
684     * Text height behavior of paragraph.
685     * @type { ?TextHeightBehavior }
686     * @syscap SystemCapability.Graphics.Drawing
687     * @since 12
688     */
689    textHeightBehavior?: TextHeightBehavior;
690
691    /**
692     * Text tab of paragraph. Tab alignment does not take effect when text alignment is also set, Or when the ellipsis
693     * style is configured. When the tab is not set or the tab's location property is less than or equal to 0,
694     * it is the default space effect. And all tabs in the paragraph after the setting are aligned
695     * according to this tab effect.
696     * @type { ?TextTab }
697     * @syscap SystemCapability.Graphics.Drawing
698     * @since 18
699     */
700    tab?: TextTab;
701  }
702
703  /**
704   * Describes shadow of text.
705   * @typedef TextShadow
706   * @syscap SystemCapability.Graphics.Drawing
707   * @since 12
708   */
709  interface TextShadow {
710    /**
711     * The color of text shadow.
712     * @type { ?common2D.Color } The color of text shadow
713     * @syscap SystemCapability.Graphics.Drawing
714     * @since 12
715     */
716    color?: common2D.Color;
717
718    /**
719     * The value sets offset of text shadow that based on the original text.
720     * @type { ?common2D.Point } The point of shadow
721     * @syscap SystemCapability.Graphics.Drawing
722     * @since 12
723     */
724    point?: common2D.Point;
725
726    /**
727     * The value sets special effect radius of blurring text, it default is 0.
728     * @type { ?number } The value about radius of blur, it type is "double"
729     * @syscap SystemCapability.Graphics.Drawing
730     * @since 12
731     */
732    blurRadius?: number;
733  }
734
735  export class TextShadowInternal implements TextShadow {
736    color?: common2D.Color;
737    point?: common2D.Point;
738    blurRadius?: number;
739  }
740
741  /**
742   * Describes text style.
743   * @typedef TextStyle
744   * @syscap SystemCapability.Graphics.Drawing
745   * @since 12
746   */
747  export interface TextStyle {
748    /**
749     * Decoration of text.
750     * @type { ?Decoration } decoration for text
751     * @syscap SystemCapability.Graphics.Drawing
752     * @since 12
753     */
754    decoration?: Decoration;
755
756    /**
757     * Color of text.
758     * @type { ?common2D.Color } it is uint32_t type data
759     * @syscap SystemCapability.Graphics.Drawing
760     * @since 12
761     */
762    color?: common2D.Color;
763
764    /**
765     * Font weight of text.
766     * @type { ?FontWeight } it is uint32_t type data
767     * @syscap SystemCapability.Graphics.Drawing
768     * @since 12
769     */
770    fontWeight?: FontWeight;
771
772    /**
773     * Font style of text.
774     * @type { ?FontStyle } it is uint32_t type data
775     * @syscap SystemCapability.Graphics.Drawing
776     * @since 12
777     */
778    fontStyle?: FontStyle;
779
780    /**
781     * Base line of text.
782     * @type { ?TextBaseline } it is uint32_t type data
783     * @syscap SystemCapability.Graphics.Drawing
784     * @since 12
785     */
786    baseline?: TextBaseline;
787
788    /**
789     * Font Families of text.
790     * @type { ?Array<string> } fontfamily gather
791     * @syscap SystemCapability.Graphics.Drawing
792     * @since 12
793     */
794    fontFamilies?: Array<string>;
795
796    /**
797     * Font size of text.
798     * @type { ?number } it is double type data
799     * @syscap SystemCapability.Graphics.Drawing
800     * @since 12
801     */
802    fontSize?: number;
803
804    /**
805     * Letter spacing of text.
806     * @type { ?number } it is double type data
807     * @syscap SystemCapability.Graphics.Drawing
808     * @since 12
809     */
810    letterSpacing?: number;
811
812    /**
813     * Word spacing of text.
814     * @type { ?number } it is double type data
815     * @syscap SystemCapability.Graphics.Drawing
816     * @since 12
817     */
818    wordSpacing?: number;
819
820    /**
821     * Height scale of text.
822     * @type { ?number } it is double type data
823     * @syscap SystemCapability.Graphics.Drawing
824     * @since 12
825     */
826    heightScale?: number;
827
828    /**
829     * Half leading of text.
830     * @type { ?boolean } it is boolean type data
831     * @syscap SystemCapability.Graphics.Drawing
832     * @since 12
833     */
834    halfLeading?: boolean;
835
836    /**
837     * Control the height calculation method of font blob, true means calculate the height of the blob by
838     * the font size, false means by the line height and leading.
839     * @type { ?boolean } it is boolean type data
840     * @syscap SystemCapability.Graphics.Drawing
841     * @since 12
842     */
843    heightOnly?: boolean;
844
845    /**
846     * Text ellipsis.
847     * @type { ?string } it is u16string type data.
848     * @syscap SystemCapability.Graphics.Drawing
849     * @since 12
850     */
851    ellipsis?: string;
852
853    /**
854     * Text ellipsis mode.
855     * @type { ?EllipsisMode } Ellipsis mode.
856     * @syscap SystemCapability.Graphics.Drawing
857     * @since 12
858     */
859    ellipsisMode?: EllipsisMode;
860
861    /**
862     * Text locale.
863     * @type { ?string } it is string type data.
864     * @syscap SystemCapability.Graphics.Drawing
865     * @since 12
866     */
867    locale?: string;
868
869    /**
870     * The offset distance that the underline of text.
871     * @type { ?number } it is double type data.
872     * @syscap SystemCapability.Graphics.Drawing
873     * @since 12
874     */
875    baselineShift?: number;
876
877    /**
878     * Text Style available font features.
879     * @type { ?Array<FontFeature> } A collection of font features.
880     * @syscap SystemCapability.Graphics.Drawing
881     * @since 12
882     */
883    fontFeatures?: Array<FontFeature>;
884
885    /**
886     * Text shadows of text.
887     * @type { ?Array<TextShadow> } textShadow gather.
888     * @syscap SystemCapability.Graphics.Drawing
889     * @since 12
890     */
891    textShadows?: Array<TextShadow>;
892
893    /**
894     * Rect style of text.
895     * @type { ?RectStyle } rect style for text.
896     * @syscap SystemCapability.Graphics.Drawing
897     * @since 12
898     */
899    backgroundRect?: RectStyle;
900
901    /**
902     * Text Style available font variations.
903     * @type { ?Array<FontVariation> } A collection of font variations.
904     * @syscap SystemCapability.Graphics.Drawing
905     * @since 12
906     */
907    fontVariations?: Array<FontVariation>;
908  }
909
910  export class TextStyleInternal implements TextStyle {
911    decoration?: Decoration;
912    color?: common2D.Color;
913    fontWeight?: FontWeight;
914    fontStyle?: FontStyle;
915    baseline?: TextBaseline;
916    fontFamilies?: Array<string>;
917    fontSize?: number;
918    letterSpacing?: number;
919    wordSpacing?: number;
920    heightScale?: number;
921    halfLeading?: boolean;
922    heightOnly?: boolean;
923    ellipsis?: string;
924    ellipsisMode?: EllipsisMode;
925    locale?: string;
926    baselineShift?: number;
927    fontFeatures?: Array<FontFeature>;
928    textShadows?: Array<TextShadow>;
929    backgroundRect?: RectStyle;
930    fontVariations?: Array<FontVariation>;
931  }
932
933
934  /**
935   * Describes the metric information for a line of text in a text layout.
936   * @typedef LineMetrics
937   * @syscap SystemCapability.Graphics.Drawing
938   * @since 12
939   */
940  interface LineMetrics {
941    /**
942     * The indexes in the text buffer the line begins.
943     * @type { number }
944     * @syscap SystemCapability.Graphics.Drawing
945     * @since 12
946     */
947    startIndex: number;
948
949    /**
950     * The indexes in the text buffer the line ends.
951     * @type { number }
952     * @syscap SystemCapability.Graphics.Drawing
953     * @since 12
954     */
955    endIndex: number;
956
957    /**
958     * The height of the text rise, the distance from the baseline to the top of the character.
959     * @type { number }
960     * @syscap SystemCapability.Graphics.Drawing
961     * @since 12
962     */
963    ascent: number;
964
965    /**
966     * The height of the text drop, the distance from the baseline to the bottom of the character.
967     * @type { number }
968     * @syscap SystemCapability.Graphics.Drawing
969     * @since 12
970     */
971    descent: number;
972
973    /**
974     * The height of the current line is `round(ascent + descent)`.
975     * @type { number }
976     * @syscap SystemCapability.Graphics.Drawing
977     * @since 12
978     */
979    height: number;
980
981    /**
982     * Width of the line.
983     * @type { number }
984     * @syscap SystemCapability.Graphics.Drawing
985     * @since 12
986     */
987    width: number;
988
989    /**
990     * The left edge of the line. The right edge can be obtained with `left + width`.
991     * @type { number }
992     * @syscap SystemCapability.Graphics.Drawing
993     * @since 12
994     */
995    left: number;
996
997    /**
998     * The y position of the baseline for this line from the top of the paragraph.
999     * @type { number }
1000     * @syscap SystemCapability.Graphics.Drawing
1001     * @since 12
1002     */
1003    baseline: number;
1004
1005    /**
1006     * Zero indexed line number.
1007     * @type { number }
1008     * @syscap SystemCapability.Graphics.Drawing
1009     * @since 12
1010     */
1011    lineNumber: number;
1012
1013    /**
1014     * Height from the top.
1015     * @type { number }
1016     * @syscap SystemCapability.Graphics.Drawing
1017     * @since 12
1018     */
1019    topHeight: number;
1020
1021    /**
1022     * Mapping between text index ranges and the FontMetrics associated with
1023     * them. The first run will be keyed under start_index. The metrics here.
1024     * are before layout and are the base values we calculate from.
1025     * @type { Map<number, RunMetrics> }
1026     * @syscap SystemCapability.Graphics.Drawing
1027     * @since 12
1028     */
1029    runMetrics: Map<number, RunMetrics>;
1030  }
1031
1032  export class LineMetricsInternal implements LineMetrics {
1033    startIndex: number;
1034    endIndex: number;
1035    ascent: number;
1036    descent: number;
1037    height: number;
1038    width: number;
1039    left: number;
1040    baseline: number;
1041    lineNumber: number;
1042    topHeight: number;
1043    runMetrics: Map<number, RunMetrics>;
1044  }
1045
1046  /**
1047   * Enumeration of font weight of text.
1048   * @enum { number }
1049   * @syscap SystemCapability.Graphics.Drawing
1050   * @since 12
1051   */
1052  export enum FontWeight {
1053    /**
1054     * Thin
1055     * @syscap SystemCapability.Graphics.Drawing
1056     * @since 12
1057     */
1058    W100,
1059
1060    /**
1061     * Extra-light
1062     * @syscap SystemCapability.Graphics.Drawing
1063     * @since 12
1064     */
1065    W200,
1066
1067    /**
1068     * Light
1069     * @syscap SystemCapability.Graphics.Drawing
1070     * @since 12
1071     */
1072    W300,
1073
1074    /**
1075     * Normal/Regular
1076     * @syscap SystemCapability.Graphics.Drawing
1077     * @since 12
1078     */
1079    W400,
1080
1081    /**
1082     * Medium
1083     * @syscap SystemCapability.Graphics.Drawing
1084     * @since 12
1085     */
1086    W500,
1087
1088    /**
1089     * Semi-bold
1090     * @syscap SystemCapability.Graphics.Drawing
1091     * @since 12
1092     */
1093    W600,
1094
1095    /**
1096     * Bold
1097     * @syscap SystemCapability.Graphics.Drawing
1098     * @since 12
1099     */
1100    W700,
1101
1102    /**
1103     * Extra-bold
1104     * @syscap SystemCapability.Graphics.Drawing
1105     * @since 12
1106     */
1107    W800,
1108
1109    /**
1110     * Black
1111     * @syscap SystemCapability.Graphics.Drawing
1112     * @since 12
1113     */
1114    W900,
1115  }
1116
1117  /**
1118   * Enumeration of font style of text.
1119   * @enum { number }
1120   * @syscap SystemCapability.Graphics.Drawing
1121   * @since 12
1122   */
1123  export enum FontStyle {
1124    /**
1125     * Upright font type.
1126     * @syscap SystemCapability.Graphics.Drawing
1127     * @since 12
1128     */
1129    NORMAL,
1130
1131    /**
1132     * Slant font.
1133     * @syscap SystemCapability.Graphics.Drawing
1134     * @since 12
1135     */
1136    ITALIC,
1137
1138    /**
1139     * Oblique font.
1140     * @syscap SystemCapability.Graphics.Drawing
1141     * @since 12
1142     */
1143    OBLIQUE,
1144  }
1145
1146  /**
1147   * Enumeration the type of text baseline.
1148   * @enum { number }
1149   * @syscap SystemCapability.Graphics.Drawing
1150   * @since 12
1151   */
1152  export enum TextBaseline {
1153    /**
1154     * The alphabetic baseline, typically used for Latin-based scripts where the baseline aligns
1155     * with the base of lowercase letters.
1156     * @syscap SystemCapability.Graphics.Drawing
1157     * @since 12
1158     */
1159    ALPHABETIC,
1160
1161    /**
1162     * The ideographic baseline, commonly used for ideographic scripts such as Chinese, Japanese, and Korean,
1163     * where the baseline aligns with the center of characters.
1164     * @syscap SystemCapability.Graphics.Drawing
1165     * @since 12
1166     */
1167    IDEOGRAPHIC,
1168  }
1169
1170  /**
1171   * Enumerates of ellipsis mode.
1172   * @enum { number }
1173   * @syscap SystemCapability.Graphics.Drawing
1174   * @since 12
1175   */
1176  export enum EllipsisMode {
1177    /**
1178     * The ellipsis is shown in the start of text.
1179     * @syscap SystemCapability.Graphics.Drawing
1180     * @since 12
1181     */
1182    START,
1183
1184    /**
1185     * The ellipsis is shown in the middle of text.
1186     * @syscap SystemCapability.Graphics.Drawing
1187     * @since 12
1188     */
1189    MIDDLE,
1190
1191    /**
1192     * The ellipsis is shown in the end of text.
1193     * @syscap SystemCapability.Graphics.Drawing
1194     * @since 12
1195     */
1196    END,
1197  }
1198
1199  /**
1200   * Decoration for text.
1201   * @typedef Decoration
1202   * @syscap SystemCapability.Graphics.Drawing
1203   * @since 12
1204   */
1205  export interface Decoration {
1206    /**
1207     * Decorates text by line.
1208     * @type { ?TextDecorationType }
1209     * @syscap SystemCapability.Graphics.Drawing
1210     * @since 12
1211     */
1212    textDecoration?: TextDecorationType;
1213
1214    /**
1215     * Text color.
1216     * @type { ?common2D.Color }
1217     * @syscap SystemCapability.Graphics.Drawing
1218     * @since 12
1219     */
1220    color?: common2D.Color;
1221
1222    /**
1223     * Text decoration style.
1224     * @type { ?TextDecorationStyle }
1225     * @syscap SystemCapability.Graphics.Drawing
1226     * @since 12
1227     */
1228    decorationStyle?: TextDecorationStyle;
1229
1230    /**
1231     * The thickness scale of decoration line.
1232     * @type { ?number }
1233     * @syscap SystemCapability.Graphics.Drawing
1234     * @since 12
1235     */
1236    decorationThicknessScale?: number;
1237  }
1238
1239  export class DecorationInternal implements Decoration {
1240    textDecoration?: TextDecorationType;
1241    color?: common2D.Color;
1242    decorationStyle?: TextDecorationStyle;
1243    decorationThicknessScale?: number;
1244  }
1245
1246  /**
1247   * Describes font feature of text.
1248   * @typedef FontFeature
1249   * @syscap SystemCapability.Graphics.Drawing
1250   * @since 12
1251   */
1252  export interface FontFeature {
1253    /**
1254     * The name of font feature.
1255     * @type { string } feature name
1256     * @syscap SystemCapability.Graphics.Drawing
1257     * @since 12
1258     */
1259    name: string;
1260
1261    /**
1262     * The value of font feature.
1263     * @type { number } feature value
1264     * @syscap SystemCapability.Graphics.Drawing
1265     * @since 12
1266     */
1267    value: number;
1268  }
1269
1270  export class FontFeatureInternal implements FontFeature {
1271    name: string;
1272    value: number;
1273  }
1274
1275  /**
1276   * Enumerates decoration line for text.
1277   * @enum { number }
1278   * @syscap SystemCapability.Graphics.Drawing
1279   * @since 12
1280   */
1281  export enum TextDecorationType {
1282    /**
1283     * There are no text decoration.
1284     * @syscap SystemCapability.Graphics.Drawing
1285     * @since 12
1286     */
1287    NONE = 0x0,
1288
1289    /**
1290     * There is a decoration line below the text.
1291     * @syscap SystemCapability.Graphics.Drawing
1292     * @since 12
1293     */
1294    UNDERLINE = 0x1,
1295
1296    /**
1297     * There is a decoration line above the text.
1298     * @syscap SystemCapability.Graphics.Drawing
1299     * @since 12
1300     */
1301    OVERLINE = 0x2,
1302
1303    /**
1304     * There is a decoration line through the middle of the text.
1305     * @syscap SystemCapability.Graphics.Drawing
1306     * @since 12
1307     */
1308    LINE_THROUGH = 0x4,
1309  }
1310
1311  /**
1312   * Enumerates decoration line style.
1313   * @enum { number }
1314   * @syscap SystemCapability.Graphics.Drawing
1315   * @since 12
1316   */
1317  export enum TextDecorationStyle {
1318    /**
1319     * Decoration line is solid line.
1320     * @syscap SystemCapability.Graphics.Drawing
1321     * @since 12
1322     */
1323    SOLID,
1324
1325    /**
1326     * Decoration line is double line.
1327     * @syscap SystemCapability.Graphics.Drawing
1328     * @since 12
1329     */
1330    DOUBLE,
1331
1332    /**
1333     * Decoration line is dotted line.
1334     * @syscap SystemCapability.Graphics.Drawing
1335     * @since 12
1336     */
1337    DOTTED,
1338
1339    /**
1340     * Decoration line is dashed line.
1341     * @syscap SystemCapability.Graphics.Drawing
1342     * @since 12
1343     */
1344    DASHED,
1345
1346    /**
1347     * Decoration line is wavy line.
1348     * @syscap SystemCapability.Graphics.Drawing
1349     * @since 12
1350     */
1351    WAVY,
1352  }
1353
1354  /**
1355   * Describes the layout information and metrics for a continuous piece of text (a run) in a line of text.
1356   * @typedef RunMetrics
1357   * @syscap SystemCapability.Graphics.Drawing
1358   * @since 12
1359   */
1360  export interface RunMetrics {
1361    /**
1362     * The metrics of an Font.
1363     * @type { TextStyle }
1364     * @syscap SystemCapability.Graphics.Drawing
1365     * @since 12
1366     */
1367    textStyle: TextStyle;
1368
1369    /**
1370     * Describes text style.
1371     * @type { drawing.FontMetrics }
1372     * @syscap SystemCapability.Graphics.Drawing
1373     * @since 12
1374     */
1375    fontMetrics: drawing.FontMetrics;
1376  }
1377
1378  export class RunMetricsInternal implements RunMetrics {
1379    textStyle: TextStyle;
1380    fontMetrics: drawing.FontMetrics;
1381  }
1382
1383  /**
1384   * Describes rect style of text.
1385   * @typedef RectStyle
1386   * @syscap SystemCapability.Graphics.Drawing
1387   * @since 12
1388   */
1389  export interface RectStyle {
1390    /**
1391     * The color of rect style.
1392     * @type { common2D.Color } The color of rect style
1393     * @syscap SystemCapability.Graphics.Drawing
1394     * @since 12
1395     */
1396    color: common2D.Color;
1397
1398    /**
1399     * Radius in left top of rect style.
1400     * @type { number } it is double type data
1401     * @syscap SystemCapability.Graphics.Drawing
1402     * @since 12
1403     */
1404    leftTopRadius: number;
1405
1406    /**
1407     * Radius in right top of rect style.
1408     * @type { number } it is double type data
1409     * @syscap SystemCapability.Graphics.Drawing
1410     * @since 12
1411     */
1412    rightTopRadius: number;
1413
1414    /**
1415     * Radius in right bottom of rect style.
1416     * @type { number } it is double type data
1417     * @syscap SystemCapability.Graphics.Drawing
1418     * @since 12
1419     */
1420    rightBottomRadius: number;
1421
1422    /**
1423     * Radius in left bottom of rect style.
1424     * @type { number } it is double type data
1425     * @syscap SystemCapability.Graphics.Drawing
1426     * @since 12
1427     */
1428    leftBottomRadius: number;
1429  }
1430
1431  export class RectStyleInternal implements RectStyle {
1432    color: common2D.Color;
1433    leftTopRadius: number;
1434    rightTopRadius: number;
1435    rightBottomRadius: number;
1436    leftBottomRadius: number;
1437  }
1438
1439  /**
1440   * Describes font variation of text.
1441   * @typedef FontVariation
1442   * @syscap SystemCapability.Graphics.Drawing
1443   * @since 12
1444   */
1445  export interface FontVariation {
1446    /**
1447     * The axis of font variation.
1448     * @type { string } variation axis
1449     * @syscap SystemCapability.Graphics.Drawing
1450     * @since 12
1451     */
1452    axis: string;
1453
1454    /**
1455     * The value of font variation.
1456     * @type { number } variation value
1457     * @syscap SystemCapability.Graphics.Drawing
1458     * @since 12
1459     */
1460    value: number;
1461  }
1462
1463  export class FontVariationInternal implements FontVariation {
1464    axis: string;
1465    value: number;
1466  }
1467}