1e41f4b71Sopenharmony_ci# @ohos.graphics.text (Text)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe Text module allows you to create complex text paragraphs, with various text styles, paragraph styles, and line break rules. It then converts the information into layout data that can be efficiently rendered on the screen. This module uses the physical pixel unit, px.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciThis module provides the following classes:
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci- [TextStyle](#textstyle): text style, which controls the font type, size, and spacing of the text.
8e41f4b71Sopenharmony_ci- [FontCollection](#fontcollection): font manager, which controls various fonts.
9e41f4b71Sopenharmony_ci- [ParagraphStyle](#paragraphstyle): paragraph style, which controls the display style of a paragraph.
10e41f4b71Sopenharmony_ci- [Paragraph](#paragraph): paragraph, which is constructed by calling [build()](#build) in the **ParagraphBuilder** class.
11e41f4b71Sopenharmony_ci- [ParagraphBuilder](#paragraphbuilder): paragraph builder, which controls the generation of different paragraph objects.
12e41f4b71Sopenharmony_ci- [TextLine](#textline): carrier of the paragraph text in lines. It is obtained by calling [getTextLines()](#gettextlines) in the **Paragraph** class.
13e41f4b71Sopenharmony_ci- [Run](#run): rendering unit used for text typesetting. It is obtained by calling [getGlyphRuns()](#getglyphruns) in the **TextLine** class.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci> **NOTE**
16e41f4b71Sopenharmony_ci>
17e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci## Modules to Import
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci```ts
22e41f4b71Sopenharmony_ciimport { text } from '@kit.ArkGraphics2D';
23e41f4b71Sopenharmony_ci```
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci## TextAlign
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ciEnumerates the text alignment modes.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci| Name       | Value  | Description                                         |
32e41f4b71Sopenharmony_ci| --------- | ---- | ---------------------------------------------- |
33e41f4b71Sopenharmony_ci| LEFT      | 0    | Left-aligned.                                 |
34e41f4b71Sopenharmony_ci| RIGHT     | 1    | Right-aligned.                                 |
35e41f4b71Sopenharmony_ci| CENTER    | 2    | Center-aligned.                                 |
36e41f4b71Sopenharmony_ci| JUSTIFY   | 3    | Justified, which means that each line (except the last line) is stretched so that every line has equal width, and the left and right margins are straight.                   |
37e41f4b71Sopenharmony_ci| START     | 4    | Aligned with the start position, which depends on [TextDirection](#textdirection).|
38e41f4b71Sopenharmony_ci| END       | 5    | Aligned with the end position, which depends on [TextDirection](#textdirection).|
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci## TextDirection
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ciEnumerates the text directions.
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci| Name    | Value  | Description             |
47e41f4b71Sopenharmony_ci| -------- | ---- | ---------------- |
48e41f4b71Sopenharmony_ci| RTL      | 0    | Right to left (RTL).|
49e41f4b71Sopenharmony_ci| LTR      | 1    | Left to right (LTR).|
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci## BreakStrategy
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ciEnumerates the text break strategies.
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci| Name         | Value  | Description                                           |
58e41f4b71Sopenharmony_ci| ------------- | ---- | ---------------------------------------------- |
59e41f4b71Sopenharmony_ci| GREEDY        | 0    | Each line is filled as much as possible during line break. No hyphen is automatically added.          |
60e41f4b71Sopenharmony_ci| HIGH_QUALITY  | 1    | Text continuity is preferentially considered during line break. If necessary, hyphens are automatically added.               |
61e41f4b71Sopenharmony_ci| BALANCED      | 2    | Each line of a paragraph has the same width. If necessary, hyphens are automatically added.|
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci## WordBreak
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ciEnumerates the word break types.
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci| Name       | Value  | Description                                                                                                                 |
70e41f4b71Sopenharmony_ci| ----------- | ---- | -------------------------------------------------------------------------------------------------------------------- |
71e41f4b71Sopenharmony_ci| NORMAL      | 0    | Default mode. Word breaks are allowed between words as appropriate to the relevant language writing systems.                                                                 |
72e41f4b71Sopenharmony_ci| BREAK_ALL   | 1    | Word breaks are allowed between any characters for non-CJK text. (CJK means Chinese, Japanese, and Korean.) This value is suitable for Asian text that contains some non-Asian text. For example, it can be used to break consecutive English characters.|
73e41f4b71Sopenharmony_ci| BREAK_WORD  | 2    | Works in the same way as **BREAK_ALL**, except that it does not break unbreakable words.                                  |
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci## Decoration
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ciDescribes a text decoration.
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci| Name                     | Type                                                 | Read Only| Optional| Description                                        |
82e41f4b71Sopenharmony_ci| ------------------------- | --------------------------------------------------- | ---- | ---- | -------------------------------------------- |
83e41f4b71Sopenharmony_ci| textDecoration            | [TextDecorationType](#textdecorationtype)           | Yes  | Yes  | Type of the decoration. The default value is **NONE**.                      |
84e41f4b71Sopenharmony_ci| color                     | [common2D.Color](js-apis-graphics-common2D.md#color)| Yes  | Yes  | Color of the decoration. The default value is transparent.                      |
85e41f4b71Sopenharmony_ci| decorationStyle           | [TextDecorationStyle](#textdecorationstyle)         | Yes  | Yes  | Style of the decoration. The default value is **SOLID**.                     |
86e41f4b71Sopenharmony_ci| decorationThicknessScale  | number                                              | Yes  | Yes  | Ratio of the decoration thickness to the default value. The value is a floating point number. The default value is 1.0.|
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci## TextDecorationType
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ciEnumerates the text decoration types.
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci| Name          | Value| Description       |
95e41f4b71Sopenharmony_ci| -------------- | - | ----------- |
96e41f4b71Sopenharmony_ci| NONE           | 0 | No decoration is used.|
97e41f4b71Sopenharmony_ci| UNDERLINE      | 1 | An underline is used for decoration.     |
98e41f4b71Sopenharmony_ci| OVERLINE       | 2 | An overline is used for decoration.    |
99e41f4b71Sopenharmony_ci| LINE_THROUGH   | 3 | A strikethrough is used for decoration.     |
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci## TextDecorationStyle
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ciEnumerates the text decoration styles.
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci| Name  | Value| Description  |
108e41f4b71Sopenharmony_ci| ------ | - | ------ |
109e41f4b71Sopenharmony_ci| SOLID  | 0 | Solid style. |
110e41f4b71Sopenharmony_ci| DOUBLE | 1 | Double style.|
111e41f4b71Sopenharmony_ci| DOTTED | 2 | Dotted style.|
112e41f4b71Sopenharmony_ci| DASHED | 3 | Dashed style. |
113e41f4b71Sopenharmony_ci| WAVY   | 4 | Wavy style.|
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci## FontWeight
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ciEnumerates the font weights.
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci| Name | Value| Description  |
122e41f4b71Sopenharmony_ci| ----- | - | ------- |
123e41f4b71Sopenharmony_ci| W100  | 0 | Font weight W100.|
124e41f4b71Sopenharmony_ci| W200  | 1 | Font weight W200.|
125e41f4b71Sopenharmony_ci| W300  | 2 | Font weight W300.|
126e41f4b71Sopenharmony_ci| W400  | 3 | Font weight W400.|
127e41f4b71Sopenharmony_ci| W500  | 4 | Font weight W500.|
128e41f4b71Sopenharmony_ci| W600  | 5 | Font weight W600.|
129e41f4b71Sopenharmony_ci| W700  | 6 | Font weight W700.|
130e41f4b71Sopenharmony_ci| W800  | 7 | Font weight W800.|
131e41f4b71Sopenharmony_ci| W900  | 8 | Font weight W900.|
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci## FontWidth
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ciEnumerates the font widths.
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci| Name            | Value| Description      |
140e41f4b71Sopenharmony_ci| ---------------- | - | ---------- |
141e41f4b71Sopenharmony_ci| ULTRA_CONDENSED  | 1 | Ultra condensed. |
142e41f4b71Sopenharmony_ci| EXTRA_CONDENSED  | 2 | Extra condensed. |
143e41f4b71Sopenharmony_ci| CONDENSED        | 3 | Condensed. |
144e41f4b71Sopenharmony_ci| SEMI_CONDENSED   | 4 | Semi condensed. |
145e41f4b71Sopenharmony_ci| NORMAL           | 5 | Normal. |
146e41f4b71Sopenharmony_ci| SEMI_EXPANDED    | 6 | Semi expanded. |
147e41f4b71Sopenharmony_ci| EXPANDED         | 7 | Expanded. |
148e41f4b71Sopenharmony_ci| EXTRA_EXPANDED   | 8 | Extra expanded. |
149e41f4b71Sopenharmony_ci| ULTRA_EXPANDED   | 9 | Ultra expanded.|
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci## FontStyle
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ciEnumerates the font styles.
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci| Name   | Value| Description                                                |
158e41f4b71Sopenharmony_ci| ------- | - | ---------------------------------------------------- |
159e41f4b71Sopenharmony_ci| NORMAL  | 0 | Normal.                                           |
160e41f4b71Sopenharmony_ci| ITALIC  | 1 | Italic. If no italic version is available for the current font, the oblique version will be used instead. |
161e41f4b71Sopenharmony_ci| OBLIQUE | 2 | Oblique. If no oblique version is available for the current font, the italic version will be used instead.|
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci## TextHeightBehavior
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ciEnumerates the text height modifier patterns.
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ci| Name                 |  Value| Description                                                 |
170e41f4b71Sopenharmony_ci| --------------------- | --- | ---------------------------------------------------- |
171e41f4b71Sopenharmony_ci| ALL                   | 0x0 | Enables ascent for the first and last rows of a paragraph.           |
172e41f4b71Sopenharmony_ci| DISABLE_FIRST_ASCENT  | 0x1 | Disables ascent for the first row of a paragraph.                  |
173e41f4b71Sopenharmony_ci| DISABLE_LAST_ASCENT   | 0x2 | Disables ascent for the last row of a paragraph.                |
174e41f4b71Sopenharmony_ci| DISABLE_ALL           | 0x3 | Disables ascent for the first and last rows of a paragraph.         |
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci## TextBaseline
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ciEnumerates the text baseline types.
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci| Name       | Value| Description|
183e41f4b71Sopenharmony_ci| ----------- | - | ---- |
184e41f4b71Sopenharmony_ci| ALPHABETIC  | 0 | Alphabetic baseline, where the letters in Latin alphabets sit on.|
185e41f4b71Sopenharmony_ci| IDEOGRAPHIC | 1 | Ideographic baseline, where the baseline is at the bottom of the text area. It is usually used for CJK text.|
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci## EllipsisMode
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ciEnumerates the ellipsis styles.
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci**EllipsisMode.START** and **EllipsisMode.MIDDLE** take effect only when text overflows in a single line.
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci| Name  | Value| Description     |
196e41f4b71Sopenharmony_ci| ------ | - | --------- |
197e41f4b71Sopenharmony_ci| START  | 0 | Places the ellipsis in the text header.|
198e41f4b71Sopenharmony_ci| MIDDLE | 1 | Places the ellipsis in the middle of the text.|
199e41f4b71Sopenharmony_ci| END    | 2 | Places the ellipsis at the end of the text.|
200e41f4b71Sopenharmony_ci
201e41f4b71Sopenharmony_ci## TextShadow
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ciDescribes the text shadow.
204e41f4b71Sopenharmony_ci
205e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci| Name         | Type                                                | Read Only| Optional| Description                              |
208e41f4b71Sopenharmony_ci| ------------- | ---------------------------------------------------- | --  | ---  | --------------------------------- |
209e41f4b71Sopenharmony_ci| color         | [common2D.Color](js-apis-graphics-common2D.md#color) | Yes |  Yes  | Color of the text shadow. The default value is black (255, 0, 0, 0).       |
210e41f4b71Sopenharmony_ci| point         | [common2D.Point](js-apis-graphics-common2D.md#point12) | Yes |  Yes  | Position of the text shadow relative to the text. The horizontal and vertical coordinates must be greater than or equal to 0.   |
211e41f4b71Sopenharmony_ci| blurRadius    | number                                               | Yes |  Yes  | Blur radius. The value is a floating point number. The default value is **0.0px**.      |
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ci## RectStyle
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ciDescribes the style of a rectangle.
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ci| Name              | Type                                                | Read Only| Optional| Description                                     |
220e41f4b71Sopenharmony_ci| -----------------  | ---------------------------------------------------- | --  | ---  | ---------------------------------------- |
221e41f4b71Sopenharmony_ci| color              | [common2D.Color](js-apis-graphics-common2D.md#color) | Yes |  No  | Color of the rectangle.                |
222e41f4b71Sopenharmony_ci| leftTopRadius      | number                                               | Yes |  No  | Left top radius of the rectangle.      |
223e41f4b71Sopenharmony_ci| rightTopRadius     | number                                               | Yes |  No  | Right top radius of the rectangle.      |
224e41f4b71Sopenharmony_ci| rightBottomRadius  | number                                               | Yes |  No  | Right bottom radius of the rectangle.      |
225e41f4b71Sopenharmony_ci| leftBottomRadius   | number                                               | Yes |  No  | Left bottom radius of the rectangle.      |
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci## FontFeature
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ciDescribes a font feature.
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci| Name     | Type                                                | Read Only| Optional| Description                                      |
234e41f4b71Sopenharmony_ci| --------- | ---------------------------------------------------- | --  | ---  | ----------------------------------------- |
235e41f4b71Sopenharmony_ci| name      | string                                               | Yes |  No  | String identified by the keyword in the font feature key-value pair.      |
236e41f4b71Sopenharmony_ci| value     | number                                               | Yes |  No  | Value in the font feature key-value pair.                       |
237e41f4b71Sopenharmony_ci
238e41f4b71Sopenharmony_ci## FontVariation
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_ciDescribes a font variation.
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ci| Name     | Type                                                | Read Only| Optional| Description                                      |
245e41f4b71Sopenharmony_ci| --------- | ---------------------------------------------------- | --  | ---  | ----------------------------------------- |
246e41f4b71Sopenharmony_ci| axis      | string                                               | Yes |  No  | String identified by the keyword in the font variation key-value pair.      |
247e41f4b71Sopenharmony_ci| value     | number                                               | Yes |  No  | Value in the font variation key-value pair.                       |
248e41f4b71Sopenharmony_ci
249e41f4b71Sopenharmony_ci## TextStyle
250e41f4b71Sopenharmony_ci
251e41f4b71Sopenharmony_ciDescribes a text style.
252e41f4b71Sopenharmony_ci
253e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_ci| Name                     | Type                                    | Read Only| Optional| Description                                                  |
256e41f4b71Sopenharmony_ci| ------------- | ---------------------------------------------------- | -- | -- | --------------------------------------------------------- |
257e41f4b71Sopenharmony_ci| decoration    | [Decoration](#decoration)                            | Yes| Yes| Text decoration. The default value is the initial decoration.            |
258e41f4b71Sopenharmony_ci| color         | [common2D.Color](js-apis-graphics-common2D.md#color) | Yes| Yes| Font color. The default color is white.                        |
259e41f4b71Sopenharmony_ci| fontWeight    | [FontWeight](#fontweight)                            | Yes| Yes| Font weight. The default value is **W400**.                         |
260e41f4b71Sopenharmony_ci| fontStyle     | [FontStyle](#fontstyle)                              | Yes| Yes| Font style. The default value is **NORMAL**.                         |
261e41f4b71Sopenharmony_ci| baseline      | [TextBaseline](#textbaseline)                        | Yes| Yes| Text baseline type. The default value is **ALPHABETIC**.              |
262e41f4b71Sopenharmony_ci| fontFamilies  | Array\<string>                                       | Yes| Yes| List of font families. By default, the list corresponds to the system's default fonts.                   |
263e41f4b71Sopenharmony_ci| fontSize      | number                                               | Yes| Yes| Font size, in units of px. The value is a floating point number. The default value is **14.0**.  |
264e41f4b71Sopenharmony_ci| letterSpacing | number                                               | Yes| Yes| Letter spacing, in units of px. The value is a floating point number. The default value is **0.0**. A positive value causes characters to spread farther apart, and a negative value bring characters closer together.|
265e41f4b71Sopenharmony_ci| wordSpacing   | number                                               | Yes| Yes| Word spacing, in units of px. The value is a floating point number. The default value is **0.0**.                |
266e41f4b71Sopenharmony_ci| heightScale   | number                                               | Yes| Yes| Scale factor of the line height. The value is a floating point number. The default value is **1.0**. This parameter is valid only when **heightOnly** is set to** true**.              |
267e41f4b71Sopenharmony_ci| heightOnly    | boolean                                              | Yes| Yes| How the height of the text box is set. The value **true** means that the height of the text box is set based on the font size and the value of **heightScale**, and **false** means that the height is set based on the line height and line spacing. The default value is **false**.|
268e41f4b71Sopenharmony_ci| halfLeading   | boolean                                              | Yes| Yes| Whether half leading is enabled. Half leading is the leading split in half and applied equally to the top and bottom edges. The value **true** means that half leading is enabled, and **false** means the opposite. The default value is **false**.|
269e41f4b71Sopenharmony_ci| ellipsis      | string                                               | Yes| Yes| Ellipsis content, which will be used to replace the extra content.      |
270e41f4b71Sopenharmony_ci| ellipsisMode  | [EllipsisMode](#ellipsismode)                        | Yes| Yes| Ellipsis type. The default value is **END**, indicating that the ellipsis is at the end of a line.                       |
271e41f4b71Sopenharmony_ci| locale        | string                                               | Yes| Yes| Locale. For example, **'en'** indicates English, **'zh-Hans'** indicates Simplified Chinese, and **'zh-Hant'** indicates Traditional Chinese. For details, see ISO 639-1. The default value is an empty string.|
272e41f4b71Sopenharmony_ci| baselineShift | number                                               | Yes| Yes| Shift of the baseline. The value is a floating point number. The default value is **0.0px**.                |
273e41f4b71Sopenharmony_ci| fontFeatures  | Array\<[FontFeature](#fontfeature)>                  | Yes| Yes| Array of font features.|
274e41f4b71Sopenharmony_ci| fontVariations| Array\<[FontVariation](#fontvariation)>              | Yes| Yes| Array of font variations.|
275e41f4b71Sopenharmony_ci| textShadows   | Array\<[TextShadow](#textshadow)>                    | Yes| Yes| Array of text shadows.|
276e41f4b71Sopenharmony_ci| backgroundRect| [RectStyle](#rectstyle)                              | Yes| Yes| Rectangle style.|
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ci## StrutStyle
279e41f4b71Sopenharmony_ci
280e41f4b71Sopenharmony_ciDescribes the strut style, which determines the line spacing, baseline alignment mode, and other properties related to the line height when drawing texts. The strut style is disabled by default.
281e41f4b71Sopenharmony_ci
282e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
283e41f4b71Sopenharmony_ci
284e41f4b71Sopenharmony_ci| Name                     | Type                                      | Read Only| Optional| Description                                                                |
285e41f4b71Sopenharmony_ci| -------------  | ---------------------------------------------------- | ---- | -- | --------------------------------------------------------------------- |
286e41f4b71Sopenharmony_ci| fontFamilies   | Array\<string>                                       | Yes  | Yes| Font families. The default value is the system fonts.                                              |
287e41f4b71Sopenharmony_ci| fontStyle      | [FontStyle](#fontstyle)                              | Yes  | Yes| Font style. The default value is **NORMAL**.                                              |
288e41f4b71Sopenharmony_ci| fontWidth      | [FontWidth](#fontwidth)                              | Yes  | Yes| Font width. The default value is **NORMAL**.                                               |
289e41f4b71Sopenharmony_ci| fontWeight     | [FontWeight](#fontweight)                            | Yes  | Yes| Font weight. The default value is **W400**.                                                     |
290e41f4b71Sopenharmony_ci| fontSize       | number                                               | Yes  | Yes| Font size, in units of px. The value is a floating point number. The default value is **14.0**.                             |
291e41f4b71Sopenharmony_ci| height         | number                                               | Yes  | Yes| Scale factor of the line height. The value is a floating point number. The default value is **1.0**.                                        |
292e41f4b71Sopenharmony_ci| leading        | number                                               | Yes  | Yes| Custom leading to be applied to the strut. The value is a floating point number. The default value is **-1.0**.                         |
293e41f4b71Sopenharmony_ci| forceHeight    | boolean                                              | Yes  | Yes| Whether to forcibly use the strut height for all lines. The value **true** means to forcibly use the strut height for all lines, and **false** means the opposite. The default value is **false**.    |
294e41f4b71Sopenharmony_ci| enabled        | boolean                                              | Yes  | Yes| Whether to enable the strut style. The value **true** means to enable the strut style, and **false** means the opposite. The default value is **false**.             |
295e41f4b71Sopenharmony_ci| heightOverride | boolean                                              | Yes  | Yes| Whether to override the height. The value **true** means to override the height, and **false** means the opposite. The default value is **false**.                 |
296e41f4b71Sopenharmony_ci| halfLeading    | boolean                                              | Yes  | Yes| Whether half leading is enabled. Half leading is the leading split in half and applied equally to the top and bottom edges. The value **true** means that half leading is enabled, and **false** means the opposite. The default value is **false**.          |
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_ci## FontCollection
299e41f4b71Sopenharmony_ci
300e41f4b71Sopenharmony_ciImplements a font manager.
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ci### getGlobalInstance
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_cistatic getGlobalInstance(): FontCollection
305e41f4b71Sopenharmony_ci
306e41f4b71Sopenharmony_ciObtains a global **FontCollection** instance.
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ci**Return value**
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_ci| Type  | Description               |
313e41f4b71Sopenharmony_ci| ------ | ------------------ |
314e41f4b71Sopenharmony_ci| [FontCollection](#fontcollection) | **FontCollection** instance.|
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_ci**Example**
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_ci```ts
319e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
320e41f4b71Sopenharmony_ci
321e41f4b71Sopenharmony_cifunction textFunc() {
322e41f4b71Sopenharmony_ci  let fontCollection = text.FontCollection.getGlobalInstance();
323e41f4b71Sopenharmony_ci}
324e41f4b71Sopenharmony_ci
325e41f4b71Sopenharmony_ci@Entry
326e41f4b71Sopenharmony_ci@Component
327e41f4b71Sopenharmony_cistruct Index {
328e41f4b71Sopenharmony_ci  fun: Function = textFunc;
329e41f4b71Sopenharmony_ci  build() {
330e41f4b71Sopenharmony_ci    Column() {
331e41f4b71Sopenharmony_ci      Button().onClick(() => {
332e41f4b71Sopenharmony_ci        this.fun();
333e41f4b71Sopenharmony_ci      })
334e41f4b71Sopenharmony_ci    }
335e41f4b71Sopenharmony_ci  }
336e41f4b71Sopenharmony_ci}
337e41f4b71Sopenharmony_ci```
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ci### loadFontSync
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ciloadFontSync(name: string, path: string | Resource): void
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ciLoads a font from a file in the specified path. This API returns the result synchronously. In this API, **name** specifies the alias of the font, and the custom font effect can be displayed only when the value of **name** is set in **fontFamilies** in **[TextStyle](#textstyle)**. The supported font file formats are .ttf and .otf.
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
346e41f4b71Sopenharmony_ci
347e41f4b71Sopenharmony_ci**Parameters**
348e41f4b71Sopenharmony_ci
349e41f4b71Sopenharmony_ci| Name| Type              | Mandatory| Description                             |
350e41f4b71Sopenharmony_ci| ----- | ------------------ | ---- | --------------------------------------------------------------------------------- |
351e41f4b71Sopenharmony_ci| name  | string             | Yes  | Name of the font.                                               |
352e41f4b71Sopenharmony_ci| path  | string \| [Resource](../apis-arkui/arkui-ts/ts-types.md#resource) | Yes  | Path of the font file to import. The value must be **file://***absolute path of the font file* or **rawfile/***directory or file name*.|
353e41f4b71Sopenharmony_ci
354e41f4b71Sopenharmony_ci**Example**
355e41f4b71Sopenharmony_ci
356e41f4b71Sopenharmony_ci```ts
357e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_cilet fontCollection: text.FontCollection = new text.FontCollection();
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ci@Entry
362e41f4b71Sopenharmony_ci@Component
363e41f4b71Sopenharmony_cistruct RenderTest {
364e41f4b71Sopenharmony_ci  LoadFontSyncTest() {
365e41f4b71Sopenharmony_ci    fontCollection.loadFontSync('Clock_01', 'file:///system/fonts/HarmonyClock_01.ttf')
366e41f4b71Sopenharmony_ci    let fontFamilies: Array<string> = ["Clock_01"]
367e41f4b71Sopenharmony_ci    let myTextStyle: text.TextStyle = {
368e41f4b71Sopenharmony_ci      fontFamilies: fontFamilies
369e41f4b71Sopenharmony_ci    };
370e41f4b71Sopenharmony_ci    let myParagraphStyle: text.ParagraphStyle = {
371e41f4b71Sopenharmony_ci      textStyle: myTextStyle,
372e41f4b71Sopenharmony_ci    }
373e41f4b71Sopenharmony_ci    let paragraphBuilder: text.ParagraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection);
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ci    let textData = "Test loadFontSync to load the font HarmonyClock_01.ttf."
376e41f4b71Sopenharmony_ci    paragraphBuilder.addText(textData);
377e41f4b71Sopenharmony_ci    let paragraph: text.Paragraph = paragraphBuilder.build();
378e41f4b71Sopenharmony_ci    paragraph.layoutSync(600);
379e41f4b71Sopenharmony_ci  }
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ci  aboutToAppear() {
382e41f4b71Sopenharmony_ci    this.LoadFontSyncTest();
383e41f4b71Sopenharmony_ci  }
384e41f4b71Sopenharmony_ci
385e41f4b71Sopenharmony_ci  build() {
386e41f4b71Sopenharmony_ci  }
387e41f4b71Sopenharmony_ci}
388e41f4b71Sopenharmony_ci```
389e41f4b71Sopenharmony_ci
390e41f4b71Sopenharmony_ci### clearCaches
391e41f4b71Sopenharmony_ci
392e41f4b71Sopenharmony_ciclearCaches(): void
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_ciClears the font cache.
395e41f4b71Sopenharmony_ci
396e41f4b71Sopenharmony_ciThe font cache has a memory limit and a clearing mechanism. It occupies limited memory. You are not advised to clear it unless otherwise required.
397e41f4b71Sopenharmony_ci
398e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci**Example**
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ci```ts
403e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
404e41f4b71Sopenharmony_ci
405e41f4b71Sopenharmony_ci@Entry
406e41f4b71Sopenharmony_ci@Component
407e41f4b71Sopenharmony_cistruct Index {
408e41f4b71Sopenharmony_ci  build() {
409e41f4b71Sopenharmony_ci    Column() {
410e41f4b71Sopenharmony_ci      Button().onClick(() => {
411e41f4b71Sopenharmony_ci        text.FontCollection.getGlobalInstance().clearCaches();
412e41f4b71Sopenharmony_ci      })
413e41f4b71Sopenharmony_ci    }
414e41f4b71Sopenharmony_ci  }
415e41f4b71Sopenharmony_ci}
416e41f4b71Sopenharmony_ci```
417e41f4b71Sopenharmony_ci
418e41f4b71Sopenharmony_ci## ParagraphStyle
419e41f4b71Sopenharmony_ci
420e41f4b71Sopenharmony_ciDescribes a paragraph style.
421e41f4b71Sopenharmony_ci
422e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
423e41f4b71Sopenharmony_ci
424e41f4b71Sopenharmony_ci| Name                | Type                                       | Read Only| Optional| Description                                         |
425e41f4b71Sopenharmony_ci| -------------------- | ------------------------------------------ | ---- | ---- | -------------------------------------------- |
426e41f4b71Sopenharmony_ci| textStyle            | [TextStyle](#textstyle)                    | Yes  | Yes  | Text style applied to the paragraph. The default value is the initial text style.|
427e41f4b71Sopenharmony_ci| textDirection        | [TextDirection](#textdirection)            | Yes  | Yes  | Text direction. The default value is **LTR**.                         |
428e41f4b71Sopenharmony_ci| align                | [TextAlign](#textalign)                    | Yes  | Yes  | Text alignment mode. The default value is **START**.                    |
429e41f4b71Sopenharmony_ci| wordBreak            | [WordBreak](#wordbreak)                    | Yes  | Yes  | Word break type. The default value is **BREAK_WORD**.                   |
430e41f4b71Sopenharmony_ci| maxLines             | number                                     | Yes  | Yes  | Maximum number of lines. The value is an integer. The default value is **1e9**.                 |
431e41f4b71Sopenharmony_ci| breakStrategy        | [BreakStrategy](#breakstrategy)            | Yes  | Yes  | Text break strategy. The default value is **GREEDY**.                       |
432e41f4b71Sopenharmony_ci| strutStyle           | [StrutStyle](#strutstyle)                  | Yes  | Yes  | Strut style. The default value is the initial **StrutStyle** object.              |
433e41f4b71Sopenharmony_ci| textHeightBehavior   | [TextHeightBehavior](#textheightbehavior)  | Yes  | Yes  | Text height modifier pattern. The default value is **ALL**.                             |
434e41f4b71Sopenharmony_ci
435e41f4b71Sopenharmony_ci
436e41f4b71Sopenharmony_ci## PlaceholderAlignment
437e41f4b71Sopenharmony_ci
438e41f4b71Sopenharmony_ciEnumerates the vertical alignment modes of a placeholder relative to the surrounding text.
439e41f4b71Sopenharmony_ci
440e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
441e41f4b71Sopenharmony_ci
442e41f4b71Sopenharmony_ci| Name               | Value| Description                  |
443e41f4b71Sopenharmony_ci| ------------------- | - | ---------------------- |
444e41f4b71Sopenharmony_ci| OFFSET_AT_BASELINE  | 0 | Aligns the baseline of the placeholder to the baseline of the text.    |
445e41f4b71Sopenharmony_ci| ABOVE_BASELINE      | 1 | Aligns the bottom edge of the placeholder to the baseline of the text.  |
446e41f4b71Sopenharmony_ci| BELOW_BASELINE      | 2 | Aligns the top edge of the placeholder to the baseline of the text.  |
447e41f4b71Sopenharmony_ci| TOP_OF_ROW_BOX      | 3 | Aligns the top edge of the placeholder to the bottom edge of the text.  |
448e41f4b71Sopenharmony_ci| BOTTOM_OF_ROW_BOX   | 4 | Aligns the bottom edge of the placeholder to the bottom edge of the text.  |
449e41f4b71Sopenharmony_ci| CENTER_OF_ROW_BOX   | 5 | Aligns the middle of the placeholder to the middle of the text.|
450e41f4b71Sopenharmony_ci
451e41f4b71Sopenharmony_ci![image_PlaceholderAlignment.png](figures/image_PlaceholderAlignment.png)
452e41f4b71Sopenharmony_ci
453e41f4b71Sopenharmony_ci> **NOTE**
454e41f4b71Sopenharmony_ci>
455e41f4b71Sopenharmony_ci> The preceding figure shows only the last three alignment modes. The first three alignment modes are similar. The only difference is that the comparison position changes to the text baseline, which is the green line shown below.
456e41f4b71Sopenharmony_ci>
457e41f4b71Sopenharmony_ci>![image_Baseline.png](figures/image_Baseline.png)
458e41f4b71Sopenharmony_ci
459e41f4b71Sopenharmony_ci## PlaceholderSpan
460e41f4b71Sopenharmony_ci
461e41f4b71Sopenharmony_ciDescribes the carrier of a placeholder style.
462e41f4b71Sopenharmony_ci
463e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
464e41f4b71Sopenharmony_ci
465e41f4b71Sopenharmony_ci| Name          | Type                                          | Read Only| Optional| Description                        |
466e41f4b71Sopenharmony_ci| -------------- | --------------------------------------------- | ---- | --- | --------------------------- |
467e41f4b71Sopenharmony_ci| width          | number                                        | Yes  | No  | Width of the placeholder, in units of px. The value is a floating point number.|
468e41f4b71Sopenharmony_ci| height         | number                                        | Yes  | No  | Height of the placeholder, in units of px. The value is a floating point number.|
469e41f4b71Sopenharmony_ci| align          | [PlaceholderAlignment](#placeholderalignment) | Yes  | No  | Vertical alignment of the placeholder relative to the surrounding text.|
470e41f4b71Sopenharmony_ci| baseline       | [TextBaseline](#textbaseline)                 | Yes  | No  | Type of the text baseline.                  |
471e41f4b71Sopenharmony_ci| baselineOffset | number                                        | Yes  | No  | Offset to the text baseline, in units of px. The value is a floating point number. |
472e41f4b71Sopenharmony_ci
473e41f4b71Sopenharmony_ci## Range
474e41f4b71Sopenharmony_ci
475e41f4b71Sopenharmony_ciDescribes a left-closed and right-open interval.
476e41f4b71Sopenharmony_ci
477e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
478e41f4b71Sopenharmony_ci
479e41f4b71Sopenharmony_ci| Name  | Type  | Read Only| Optional| Description           |
480e41f4b71Sopenharmony_ci| ----- | ------ | ---- | --- | --------------- |
481e41f4b71Sopenharmony_ci| start | number | Yes  | No  | Index of the leftmost point of the interval. The value is an integer.|
482e41f4b71Sopenharmony_ci| end   | number | Yes  | No  | Index of the rightmost point of the interval. The value is an integer.|
483e41f4b71Sopenharmony_ci
484e41f4b71Sopenharmony_ci## Paragraph
485e41f4b71Sopenharmony_ci
486e41f4b71Sopenharmony_ciImplements a carrier that stores the text content and style. You can perform operations such as typography and drawing.
487e41f4b71Sopenharmony_ci
488e41f4b71Sopenharmony_ciBefore calling any of the following APIs, you must use [build()](#build) of the [ParagraphBuilder](#paragraphbuilder) class to create a **Paragraph** object.
489e41f4b71Sopenharmony_ci
490e41f4b71Sopenharmony_ci### layoutSync
491e41f4b71Sopenharmony_ci
492e41f4b71Sopenharmony_cilayoutSync(width: number): void
493e41f4b71Sopenharmony_ci
494e41f4b71Sopenharmony_ciPerforms typography and calculates the positions of all glyphs.
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ci**Parameters**
499e41f4b71Sopenharmony_ci
500e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description          |
501e41f4b71Sopenharmony_ci| ----- | ------ | ---- | -------------- |
502e41f4b71Sopenharmony_ci| width | number | Yes  | Maximum width of a single line, in units of px. The value is a floating point number.|
503e41f4b71Sopenharmony_ci
504e41f4b71Sopenharmony_ci**Example**
505e41f4b71Sopenharmony_ci
506e41f4b71Sopenharmony_ci```ts
507e41f4b71Sopenharmony_ciparagraph.layoutSync(100);
508e41f4b71Sopenharmony_ci```
509e41f4b71Sopenharmony_ci
510e41f4b71Sopenharmony_ci### paint
511e41f4b71Sopenharmony_ci
512e41f4b71Sopenharmony_cipaint(canvas: drawing.Canvas, x: number, y: number): void
513e41f4b71Sopenharmony_ci
514e41f4b71Sopenharmony_ciPaints the text on the canvas with the coordinate point (x, y) as the upper left corner.
515e41f4b71Sopenharmony_ci
516e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
517e41f4b71Sopenharmony_ci
518e41f4b71Sopenharmony_ci**Parameters**
519e41f4b71Sopenharmony_ci
520e41f4b71Sopenharmony_ci| Name| Type                                                 | Mandatory| Description                   |
521e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ---------------------- |
522e41f4b71Sopenharmony_ci| canvas | [drawing.Canvas](js-apis-graphics-drawing.md#canvas) | Yes  | Target canvas.        |
523e41f4b71Sopenharmony_ci|    x   | number                                               | Yes  | X coordinate of the upper left corner. The value is a floating point number.|
524e41f4b71Sopenharmony_ci|    y   | number                                               | Yes  | Y coordinate of the upper left corner. The value is a floating point number.|
525e41f4b71Sopenharmony_ci
526e41f4b71Sopenharmony_ci**Example**
527e41f4b71Sopenharmony_ci
528e41f4b71Sopenharmony_ci```ts
529e41f4b71Sopenharmony_ciconst color: ArrayBuffer = new ArrayBuffer(160000);
530e41f4b71Sopenharmony_cilet opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 200, width: 200 } }
531e41f4b71Sopenharmony_cilet pixelMap: image.PixelMap = image.createPixelMapSync(color, opts);
532e41f4b71Sopenharmony_cilet canvas = new drawing.Canvas(pixelMap);
533e41f4b71Sopenharmony_ciparagraph.paint(canvas, 0, 0);
534e41f4b71Sopenharmony_ci```
535e41f4b71Sopenharmony_ci
536e41f4b71Sopenharmony_ci### paintOnPath
537e41f4b71Sopenharmony_ci
538e41f4b71Sopenharmony_cipaintOnPath(canvas: drawing.Canvas, path: drawing.Path, hOffset: number, vOffset: number): void
539e41f4b71Sopenharmony_ci
540e41f4b71Sopenharmony_ciDraws text along a path on the canvas.
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
543e41f4b71Sopenharmony_ci
544e41f4b71Sopenharmony_ci**Parameters**
545e41f4b71Sopenharmony_ci
546e41f4b71Sopenharmony_ci| Name| Type                                                 | Mandatory| Description                   |
547e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ---------------------- |
548e41f4b71Sopenharmony_ci| canvas | [drawing.Canvas](js-apis-graphics-drawing.md#canvas) | Yes  | Target canvas.        |
549e41f4b71Sopenharmony_ci| path | [drawing.Path](js-apis-graphics-drawing.md#path) | Yes  | Path along which the text is drawn.        |
550e41f4b71Sopenharmony_ci|    hOffset   | number                                               | Yes  | Horizontal offset along the path direction. A positive number indicates a position that is ahead along the path from its start point, and a negative number indicates a position that is behind from the start point.|
551e41f4b71Sopenharmony_ci|    vOffset   | number                                               | Yes  | Vertical offset along the path direction. A positive number indicates a position on the left side of the path, and a negative number indicates a position on the right side of the path.|
552e41f4b71Sopenharmony_ci
553e41f4b71Sopenharmony_ci**Example**
554e41f4b71Sopenharmony_ci
555e41f4b71Sopenharmony_ci```ts
556e41f4b71Sopenharmony_ciconst color: ArrayBuffer = new ArrayBuffer(160000);
557e41f4b71Sopenharmony_cilet opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 200, width: 200 } }
558e41f4b71Sopenharmony_cilet pixelMap: image.PixelMap = image.createPixelMapSync(color, opts);
559e41f4b71Sopenharmony_cilet canvas = new drawing.Canvas(pixelMap);
560e41f4b71Sopenharmony_cilet path = new drawing.Path();
561e41f4b71Sopenharmony_cipath.arcTo(20, 20, 180, 180, 180, 90);
562e41f4b71Sopenharmony_ciparagraph.paintOnPath(canvas, path, 0, 0);
563e41f4b71Sopenharmony_ci```
564e41f4b71Sopenharmony_ci
565e41f4b71Sopenharmony_ci### getMaxWidth
566e41f4b71Sopenharmony_ci
567e41f4b71Sopenharmony_cigetMaxWidth(): number
568e41f4b71Sopenharmony_ci
569e41f4b71Sopenharmony_ciObtains the maximum width of the line in the text.
570e41f4b71Sopenharmony_ci
571e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
572e41f4b71Sopenharmony_ci
573e41f4b71Sopenharmony_ci**Return value**
574e41f4b71Sopenharmony_ci
575e41f4b71Sopenharmony_ci| Type  | Description      |
576e41f4b71Sopenharmony_ci| ------ | --------- |
577e41f4b71Sopenharmony_ci| number | Maximum line width, in units of px. The value is a floating point number.|
578e41f4b71Sopenharmony_ci
579e41f4b71Sopenharmony_ci**Example**
580e41f4b71Sopenharmony_ci
581e41f4b71Sopenharmony_ci```ts
582e41f4b71Sopenharmony_cilet maxWidth = paragraph.getMaxWidth();
583e41f4b71Sopenharmony_ci```
584e41f4b71Sopenharmony_ci
585e41f4b71Sopenharmony_ci### getHeight
586e41f4b71Sopenharmony_ci
587e41f4b71Sopenharmony_cigetHeight(): number
588e41f4b71Sopenharmony_ci
589e41f4b71Sopenharmony_ciObtains the total height of the text.
590e41f4b71Sopenharmony_ci
591e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
592e41f4b71Sopenharmony_ci
593e41f4b71Sopenharmony_ci**Return value**
594e41f4b71Sopenharmony_ci
595e41f4b71Sopenharmony_ci| Type  | Description  |
596e41f4b71Sopenharmony_ci| ------ | ----- |
597e41f4b71Sopenharmony_ci| number | Total height, in units of px. The value is a floating point number.|
598e41f4b71Sopenharmony_ci
599e41f4b71Sopenharmony_ci**Example**
600e41f4b71Sopenharmony_ci
601e41f4b71Sopenharmony_ci```ts
602e41f4b71Sopenharmony_cilet height = paragraph.getHeight();
603e41f4b71Sopenharmony_ci```
604e41f4b71Sopenharmony_ci
605e41f4b71Sopenharmony_ci### getLongestLine
606e41f4b71Sopenharmony_ci
607e41f4b71Sopenharmony_cigetLongestLine(): number
608e41f4b71Sopenharmony_ci
609e41f4b71Sopenharmony_ciObtains the longest line in the text.
610e41f4b71Sopenharmony_ci
611e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
612e41f4b71Sopenharmony_ci
613e41f4b71Sopenharmony_ci**Return value**
614e41f4b71Sopenharmony_ci
615e41f4b71Sopenharmony_ci| Type  | Description          |
616e41f4b71Sopenharmony_ci| ------ | ------------- |
617e41f4b71Sopenharmony_ci| number | Longest line, in units of px. The value is a floating point number.|
618e41f4b71Sopenharmony_ci
619e41f4b71Sopenharmony_ci**Example**
620e41f4b71Sopenharmony_ci
621e41f4b71Sopenharmony_ci```ts
622e41f4b71Sopenharmony_cilet longestLine = paragraph.getLongestLine();
623e41f4b71Sopenharmony_ci```
624e41f4b71Sopenharmony_ci
625e41f4b71Sopenharmony_ci### getLongestLineWithIndent<sup>13+</sup>
626e41f4b71Sopenharmony_ci
627e41f4b71Sopenharmony_cigetLongestLineWithIndent(): number
628e41f4b71Sopenharmony_ci
629e41f4b71Sopenharmony_ciObtains the width of the longest line, including its indentation, in the text. You are advised to round up the return value in actual use. If the text content is empty, **0** is returned.
630e41f4b71Sopenharmony_ci
631e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
632e41f4b71Sopenharmony_ci
633e41f4b71Sopenharmony_ci**Return value**
634e41f4b71Sopenharmony_ci
635e41f4b71Sopenharmony_ci| Type  | Description          |
636e41f4b71Sopenharmony_ci| ------ | ------------- |
637e41f4b71Sopenharmony_ci| number | Width of the longest line, including its indentation. The value is a floating point number, in px.|
638e41f4b71Sopenharmony_ci
639e41f4b71Sopenharmony_ci**Example**
640e41f4b71Sopenharmony_ci
641e41f4b71Sopenharmony_ci```ts
642e41f4b71Sopenharmony_cilet longestLineWithIndent = paragraph.getLongestLineWithIndent();
643e41f4b71Sopenharmony_ci```
644e41f4b71Sopenharmony_ci
645e41f4b71Sopenharmony_ci### getMinIntrinsicWidth
646e41f4b71Sopenharmony_ci
647e41f4b71Sopenharmony_cigetMinIntrinsicWidth(): number
648e41f4b71Sopenharmony_ci
649e41f4b71Sopenharmony_ciObtains the minimum intrinsic width of the paragraph.
650e41f4b71Sopenharmony_ci
651e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
652e41f4b71Sopenharmony_ci
653e41f4b71Sopenharmony_ci**Return value**
654e41f4b71Sopenharmony_ci
655e41f4b71Sopenharmony_ci| Type  | Description                          |
656e41f4b71Sopenharmony_ci| ------ | ----------------------------- |
657e41f4b71Sopenharmony_ci| number | Minimum intrinsic width, in units of px. The value is a floating point number.|
658e41f4b71Sopenharmony_ci
659e41f4b71Sopenharmony_ci**Example**
660e41f4b71Sopenharmony_ci
661e41f4b71Sopenharmony_ci```ts
662e41f4b71Sopenharmony_cilet minIntrinsicWidth = paragraph.getMinIntrinsicWidth();
663e41f4b71Sopenharmony_ci```
664e41f4b71Sopenharmony_ci
665e41f4b71Sopenharmony_ci### getMaxIntrinsicWidth
666e41f4b71Sopenharmony_ci
667e41f4b71Sopenharmony_cigetMaxIntrinsicWidth(): number
668e41f4b71Sopenharmony_ci
669e41f4b71Sopenharmony_ciObtains the maximum intrinsic width of the paragraph.
670e41f4b71Sopenharmony_ci
671e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
672e41f4b71Sopenharmony_ci
673e41f4b71Sopenharmony_ci**Return value**
674e41f4b71Sopenharmony_ci
675e41f4b71Sopenharmony_ci| Type  | Description                          |
676e41f4b71Sopenharmony_ci| ------ | ----------------------------- |
677e41f4b71Sopenharmony_ci| number | Maximum intrinsic width, in units of px. The value is a floating point number.|
678e41f4b71Sopenharmony_ci
679e41f4b71Sopenharmony_ci**Example**
680e41f4b71Sopenharmony_ci
681e41f4b71Sopenharmony_ci```ts
682e41f4b71Sopenharmony_cilet maxIntrinsicWidth = paragraph.getMaxIntrinsicWidth();
683e41f4b71Sopenharmony_ci```
684e41f4b71Sopenharmony_ci
685e41f4b71Sopenharmony_ci### getAlphabeticBaseline
686e41f4b71Sopenharmony_ci
687e41f4b71Sopenharmony_cigetAlphabeticBaseline(): number
688e41f4b71Sopenharmony_ci
689e41f4b71Sopenharmony_ciObtains the alphabetic baseline.
690e41f4b71Sopenharmony_ci
691e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
692e41f4b71Sopenharmony_ci
693e41f4b71Sopenharmony_ci**Return value**
694e41f4b71Sopenharmony_ci
695e41f4b71Sopenharmony_ci| Type  | Description               |
696e41f4b71Sopenharmony_ci| ------ | ------------------ |
697e41f4b71Sopenharmony_ci| number | Alphabetic baseline, in units of px. The value is a floating point number.|
698e41f4b71Sopenharmony_ci
699e41f4b71Sopenharmony_ci**Example**
700e41f4b71Sopenharmony_ci
701e41f4b71Sopenharmony_ci```ts
702e41f4b71Sopenharmony_cilet alphabeticBaseline = paragraph.getAlphabeticBaseline();
703e41f4b71Sopenharmony_ci```
704e41f4b71Sopenharmony_ci
705e41f4b71Sopenharmony_ci### getIdeographicBaseline
706e41f4b71Sopenharmony_ci
707e41f4b71Sopenharmony_cigetIdeographicBaseline(): number
708e41f4b71Sopenharmony_ci
709e41f4b71Sopenharmony_ciObtains the ideographic baseline.
710e41f4b71Sopenharmony_ci
711e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
712e41f4b71Sopenharmony_ci
713e41f4b71Sopenharmony_ci**Return value**
714e41f4b71Sopenharmony_ci
715e41f4b71Sopenharmony_ci| Type  | Description                 |
716e41f4b71Sopenharmony_ci| ------ | -------------------- |
717e41f4b71Sopenharmony_ci| number | Ideographic baseline, in units of px. The value is a floating point number.|
718e41f4b71Sopenharmony_ci
719e41f4b71Sopenharmony_ci**Example**
720e41f4b71Sopenharmony_ci
721e41f4b71Sopenharmony_ci```ts
722e41f4b71Sopenharmony_cilet ideographicBaseline = paragraph.getIdeographicBaseline();
723e41f4b71Sopenharmony_ci```
724e41f4b71Sopenharmony_ci
725e41f4b71Sopenharmony_ci### getRectsForRange
726e41f4b71Sopenharmony_ci
727e41f4b71Sopenharmony_cigetRectsForRange(range: Range, widthStyle: RectWidthStyle, heightStyle: RectHeightStyle): Array\<TextBox>
728e41f4b71Sopenharmony_ci
729e41f4b71Sopenharmony_ciObtains the rectangles occupied by the characters in the range of the text under the given rectangle width and height.
730e41f4b71Sopenharmony_ci
731e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
732e41f4b71Sopenharmony_ci
733e41f4b71Sopenharmony_ci**Parameters**
734e41f4b71Sopenharmony_ci
735e41f4b71Sopenharmony_ci| Name     | Type                                | Mandatory| Description                    |
736e41f4b71Sopenharmony_ci| ----------- | ----------------------------------- | ---- | ------------------------ |
737e41f4b71Sopenharmony_ci| range       | [Range](#range)                     | Yes  | Range of the text. |
738e41f4b71Sopenharmony_ci| widthStyle  | [RectWidthStyle](#rectwidthstyle)   | Yes  | Width of the rectangle.|
739e41f4b71Sopenharmony_ci| heightStyle | [RectHeightStyle](#rectheightstyle) | Yes  | Height of the rectangle.|
740e41f4b71Sopenharmony_ci
741e41f4b71Sopenharmony_ci**Return value**
742e41f4b71Sopenharmony_ci
743e41f4b71Sopenharmony_ci| Type                        | Description       |
744e41f4b71Sopenharmony_ci| --------------------------- | ----------- |
745e41f4b71Sopenharmony_ci| Array\<[TextBox](#textbox)> | Array holding the rectangles obtained.|
746e41f4b71Sopenharmony_ci
747e41f4b71Sopenharmony_ci**Example**
748e41f4b71Sopenharmony_ci
749e41f4b71Sopenharmony_ci```ts
750e41f4b71Sopenharmony_cilet range: text.Range = { start: 0, end: 1};
751e41f4b71Sopenharmony_cilet rects = paragraph.getRectsForRange(range, text.RectWidthStyle.TIGHT, text.RectHeightStyle.TIGHT);
752e41f4b71Sopenharmony_ci```
753e41f4b71Sopenharmony_ci
754e41f4b71Sopenharmony_ci### getRectsForPlaceholders
755e41f4b71Sopenharmony_ci
756e41f4b71Sopenharmony_cigetRectsForPlaceholders(): Array\<TextBox>
757e41f4b71Sopenharmony_ci
758e41f4b71Sopenharmony_ciObtains the rectangles occupied by all placeholders in the text.
759e41f4b71Sopenharmony_ci
760e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
761e41f4b71Sopenharmony_ci
762e41f4b71Sopenharmony_ci**Return value**
763e41f4b71Sopenharmony_ci
764e41f4b71Sopenharmony_ci| Type                        | Description       |
765e41f4b71Sopenharmony_ci| --------------------------- | ----------- |
766e41f4b71Sopenharmony_ci| Array\<[TextBox](#textbox)> | Array holding the rectangles obtained.|
767e41f4b71Sopenharmony_ci
768e41f4b71Sopenharmony_ci**Example**
769e41f4b71Sopenharmony_ci
770e41f4b71Sopenharmony_ci```ts
771e41f4b71Sopenharmony_cilet placeholderRects = paragraph.getRectsForPlaceholders();
772e41f4b71Sopenharmony_ci```
773e41f4b71Sopenharmony_ci
774e41f4b71Sopenharmony_ci### getGlyphPositionAtCoordinate
775e41f4b71Sopenharmony_ci
776e41f4b71Sopenharmony_cigetGlyphPositionAtCoordinate(x: number, y: number): PositionWithAffinity
777e41f4b71Sopenharmony_ci
778e41f4b71Sopenharmony_ciObtains the position of a glyph close to a given coordinate.
779e41f4b71Sopenharmony_ci
780e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
781e41f4b71Sopenharmony_ci
782e41f4b71Sopenharmony_ci**Parameters**
783e41f4b71Sopenharmony_ci
784e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description  |
785e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ------ |
786e41f4b71Sopenharmony_ci| x     | number | Yes  | X coordinate. The value is a floating point number.|
787e41f4b71Sopenharmony_ci| y     | number | Yes  | Y coordinate. The value is a floating point number.|
788e41f4b71Sopenharmony_ci
789e41f4b71Sopenharmony_ci**Return value**
790e41f4b71Sopenharmony_ci
791e41f4b71Sopenharmony_ci| Type                                         | Description       |
792e41f4b71Sopenharmony_ci| --------------------------------------------- | ----------- |
793e41f4b71Sopenharmony_ci| [PositionWithAffinity](#positionwithaffinity) | Position of the glyph.|
794e41f4b71Sopenharmony_ci
795e41f4b71Sopenharmony_ci**Example**
796e41f4b71Sopenharmony_ci
797e41f4b71Sopenharmony_ci```ts
798e41f4b71Sopenharmony_cilet positionWithAffinity = paragraph.getGlyphPositionAtCoordinate(0, 0);
799e41f4b71Sopenharmony_ci```
800e41f4b71Sopenharmony_ci
801e41f4b71Sopenharmony_ci### getWordBoundary
802e41f4b71Sopenharmony_ci
803e41f4b71Sopenharmony_cigetWordBoundary(offset: number): Range
804e41f4b71Sopenharmony_ci
805e41f4b71Sopenharmony_ciObtains the range of the word where the glyph with a given offset is located.
806e41f4b71Sopenharmony_ci
807e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
808e41f4b71Sopenharmony_ci
809e41f4b71Sopenharmony_ci**Parameters**
810e41f4b71Sopenharmony_ci
811e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description       |
812e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------- |
813e41f4b71Sopenharmony_ci| offset | number | Yes  | Offset of the glyph. The value is an integer.|
814e41f4b71Sopenharmony_ci
815e41f4b71Sopenharmony_ci**Return value**
816e41f4b71Sopenharmony_ci
817e41f4b71Sopenharmony_ci| Type           | Description           |
818e41f4b71Sopenharmony_ci| --------------- | -------------- |
819e41f4b71Sopenharmony_ci| [Range](#range) | Range of the word.|
820e41f4b71Sopenharmony_ci
821e41f4b71Sopenharmony_ci**Example**
822e41f4b71Sopenharmony_ci
823e41f4b71Sopenharmony_ci```ts
824e41f4b71Sopenharmony_cilet wordRange = paragraph.getWordBoundary(0);
825e41f4b71Sopenharmony_ci```
826e41f4b71Sopenharmony_ci
827e41f4b71Sopenharmony_ci### getLineCount
828e41f4b71Sopenharmony_ci
829e41f4b71Sopenharmony_cigetLineCount(): number
830e41f4b71Sopenharmony_ci
831e41f4b71Sopenharmony_ciObtains the number of text lines.
832e41f4b71Sopenharmony_ci
833e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
834e41f4b71Sopenharmony_ci
835e41f4b71Sopenharmony_ci**Return value**
836e41f4b71Sopenharmony_ci
837e41f4b71Sopenharmony_ci| Type  | Description      |
838e41f4b71Sopenharmony_ci| ------ | --------- |
839e41f4b71Sopenharmony_ci| number | Number of text lines. The value is an integer.|
840e41f4b71Sopenharmony_ci
841e41f4b71Sopenharmony_ci**Example**
842e41f4b71Sopenharmony_ci
843e41f4b71Sopenharmony_ci```ts
844e41f4b71Sopenharmony_cilet lineCount = paragraph.getLineCount();
845e41f4b71Sopenharmony_ci```
846e41f4b71Sopenharmony_ci
847e41f4b71Sopenharmony_ci### getLineHeight
848e41f4b71Sopenharmony_ci
849e41f4b71Sopenharmony_cigetLineHeight(line: number): number
850e41f4b71Sopenharmony_ci
851e41f4b71Sopenharmony_ciObtains the height of a given line.
852e41f4b71Sopenharmony_ci
853e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
854e41f4b71Sopenharmony_ci
855e41f4b71Sopenharmony_ci**Parameters**
856e41f4b71Sopenharmony_ci
857e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description     |
858e41f4b71Sopenharmony_ci| ----- | ------ | ---- | --------- |
859e41f4b71Sopenharmony_ci| line  | number | Yes  | Index of the line. The value is an integer.|
860e41f4b71Sopenharmony_ci
861e41f4b71Sopenharmony_ci**Return value**
862e41f4b71Sopenharmony_ci
863e41f4b71Sopenharmony_ci| Type  | Description |
864e41f4b71Sopenharmony_ci| ------ | ---- |
865e41f4b71Sopenharmony_ci| number | Line height.|
866e41f4b71Sopenharmony_ci
867e41f4b71Sopenharmony_ci**Example**
868e41f4b71Sopenharmony_ci
869e41f4b71Sopenharmony_ci```ts
870e41f4b71Sopenharmony_cilet lineHeight = paragraph.getLineHeight(0);
871e41f4b71Sopenharmony_ci```
872e41f4b71Sopenharmony_ci
873e41f4b71Sopenharmony_ci### getLineWidth
874e41f4b71Sopenharmony_ci
875e41f4b71Sopenharmony_cigetLineWidth(line: number): number
876e41f4b71Sopenharmony_ci
877e41f4b71Sopenharmony_ciObtains the width of a given line.
878e41f4b71Sopenharmony_ci
879e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
880e41f4b71Sopenharmony_ci
881e41f4b71Sopenharmony_ci**Parameters**
882e41f4b71Sopenharmony_ci
883e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description     |
884e41f4b71Sopenharmony_ci| ----- | ------ | ---- | --------- |
885e41f4b71Sopenharmony_ci| line  | number | Yes  | Index of the line. The value is an integer.|
886e41f4b71Sopenharmony_ci
887e41f4b71Sopenharmony_ci**Return value**
888e41f4b71Sopenharmony_ci
889e41f4b71Sopenharmony_ci| Type  | Description |
890e41f4b71Sopenharmony_ci| ------ | ---- |
891e41f4b71Sopenharmony_ci| number | Line width.|
892e41f4b71Sopenharmony_ci
893e41f4b71Sopenharmony_ci**Example**
894e41f4b71Sopenharmony_ci
895e41f4b71Sopenharmony_ci```ts
896e41f4b71Sopenharmony_cilet lineWidth = paragraph.getLineWidth(0);
897e41f4b71Sopenharmony_ci```
898e41f4b71Sopenharmony_ci
899e41f4b71Sopenharmony_ci### didExceedMaxLines
900e41f4b71Sopenharmony_ci
901e41f4b71Sopenharmony_cididExceedMaxLines(): boolean
902e41f4b71Sopenharmony_ci
903e41f4b71Sopenharmony_ciChecks whether the number of lines in the paragraph exceeds the maximum.
904e41f4b71Sopenharmony_ci
905e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
906e41f4b71Sopenharmony_ci
907e41f4b71Sopenharmony_ci**Return value**
908e41f4b71Sopenharmony_ci
909e41f4b71Sopenharmony_ci| Type   | Description                                                     |
910e41f4b71Sopenharmony_ci| ------- | -------------------------------------------------------- |
911e41f4b71Sopenharmony_ci| boolean | **true**: The number of lines exceeds the maximum.<br>**false**: The number of lines does not exceed the maximum.|
912e41f4b71Sopenharmony_ci
913e41f4b71Sopenharmony_ci**Example**
914e41f4b71Sopenharmony_ci
915e41f4b71Sopenharmony_ci```ts
916e41f4b71Sopenharmony_cilet didExceed = paragraph.didExceedMaxLines();
917e41f4b71Sopenharmony_ci```
918e41f4b71Sopenharmony_ci
919e41f4b71Sopenharmony_ci### getTextLines
920e41f4b71Sopenharmony_ci
921e41f4b71Sopenharmony_cigetTextLines(): Array\<TextLine>
922e41f4b71Sopenharmony_ci
923e41f4b71Sopenharmony_ciObtains all the text lines.
924e41f4b71Sopenharmony_ci
925e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
926e41f4b71Sopenharmony_ci
927e41f4b71Sopenharmony_ci**Return value**
928e41f4b71Sopenharmony_ci
929e41f4b71Sopenharmony_ci| Type                         | Description         |
930e41f4b71Sopenharmony_ci| ----------------------------- | ------------- |
931e41f4b71Sopenharmony_ci| Array\<[TextLine](#textline)> | Array of text lines.|
932e41f4b71Sopenharmony_ci
933e41f4b71Sopenharmony_ci**Example**
934e41f4b71Sopenharmony_ci
935e41f4b71Sopenharmony_ci```ts
936e41f4b71Sopenharmony_cilet lines = paragraph.getTextLines();
937e41f4b71Sopenharmony_ci```
938e41f4b71Sopenharmony_ci
939e41f4b71Sopenharmony_ci### getActualTextRange
940e41f4b71Sopenharmony_ci
941e41f4b71Sopenharmony_cigetActualTextRange(lineNumber: number, includeSpaces: boolean): Range
942e41f4b71Sopenharmony_ci
943e41f4b71Sopenharmony_ciObtains the actually visible text range in the specified line, excluding the ellipsis displayed due to text overflow.
944e41f4b71Sopenharmony_ci
945e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
946e41f4b71Sopenharmony_ci
947e41f4b71Sopenharmony_ci**Parameters**
948e41f4b71Sopenharmony_ci
949e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description     |
950e41f4b71Sopenharmony_ci| ----- | ------ | ---- | --------- |
951e41f4b71Sopenharmony_ci| lineNumber  | number | Yes  | Line number of the text range, starting from 0.|
952e41f4b71Sopenharmony_ci| includeSpaces  | boolean | Yes  | Whether spaces are included. The value **true** means that spaces are contained, and **false** means the opposite.|
953e41f4b71Sopenharmony_ci
954e41f4b71Sopenharmony_ci**Return value**
955e41f4b71Sopenharmony_ci
956e41f4b71Sopenharmony_ci| Type            | Description                                             |
957e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------ |
958e41f4b71Sopenharmony_ci| [Range](#range)  | Text range obtained.                              |
959e41f4b71Sopenharmony_ci
960e41f4b71Sopenharmony_ci**Example**
961e41f4b71Sopenharmony_ci
962e41f4b71Sopenharmony_ci```ts
963e41f4b71Sopenharmony_cilet rang = paragraph.getActualTextRange(0, true);
964e41f4b71Sopenharmony_ci```
965e41f4b71Sopenharmony_ci
966e41f4b71Sopenharmony_ci
967e41f4b71Sopenharmony_ci### getLineMetrics
968e41f4b71Sopenharmony_ci
969e41f4b71Sopenharmony_cigetLineMetrics(): Array\<LineMetrics>
970e41f4b71Sopenharmony_ci
971e41f4b71Sopenharmony_ciObtains an array of line measurement information.
972e41f4b71Sopenharmony_ci
973e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
974e41f4b71Sopenharmony_ci
975e41f4b71Sopenharmony_ci**Return value**
976e41f4b71Sopenharmony_ci
977e41f4b71Sopenharmony_ci| Type                         | Description         |
978e41f4b71Sopenharmony_ci| ----------------------------- | ------------- |
979e41f4b71Sopenharmony_ci| Array\<[LineMetrics](#linemetrics)> | Array of line measurement information.|
980e41f4b71Sopenharmony_ci
981e41f4b71Sopenharmony_ci**Example**
982e41f4b71Sopenharmony_ci
983e41f4b71Sopenharmony_ci```ts
984e41f4b71Sopenharmony_cilet arrLineMetrc =  paragraph.getLineMetrics();
985e41f4b71Sopenharmony_ci```
986e41f4b71Sopenharmony_ci
987e41f4b71Sopenharmony_ci### getLineMetrics
988e41f4b71Sopenharmony_ci
989e41f4b71Sopenharmony_cigetLineMetrics(lineNumber: number): LineMetrics | undefined
990e41f4b71Sopenharmony_ci
991e41f4b71Sopenharmony_ciObtains the line measurement information of a line.
992e41f4b71Sopenharmony_ci
993e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
994e41f4b71Sopenharmony_ci
995e41f4b71Sopenharmony_ci**Parameters**
996e41f4b71Sopenharmony_ci
997e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description     |
998e41f4b71Sopenharmony_ci| ----- | ------ | ---- | --------- |
999e41f4b71Sopenharmony_ci| lineNumber  | number | Yes  | Line number, starting from 0.|
1000e41f4b71Sopenharmony_ci
1001e41f4b71Sopenharmony_ci**Return value**
1002e41f4b71Sopenharmony_ci
1003e41f4b71Sopenharmony_ci| Type            | Description                                             |
1004e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------ |
1005e41f4b71Sopenharmony_ci| [LineMetrics](#linemetrics) | **LineMetrics** object containing the measurement information if the specified line number is valid and the measurement information exists. If the line number is invalid or the measurement information cannot be obtained, **undefined** is returned.                 |
1006e41f4b71Sopenharmony_ci
1007e41f4b71Sopenharmony_ci**Example**
1008e41f4b71Sopenharmony_ci
1009e41f4b71Sopenharmony_ci```ts
1010e41f4b71Sopenharmony_cilet lineMetrics =  paragraph.getLineMetrics(0);
1011e41f4b71Sopenharmony_ci```
1012e41f4b71Sopenharmony_ci
1013e41f4b71Sopenharmony_ci## RunMetrics
1014e41f4b71Sopenharmony_ci
1015e41f4b71Sopenharmony_ciDescribes the layout information and measurement information of a run of text in a text line.
1016e41f4b71Sopenharmony_ci
1017e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1018e41f4b71Sopenharmony_ci
1019e41f4b71Sopenharmony_ci| Name     | Type                                               | Read Only| Optional| Description       |
1020e41f4b71Sopenharmony_ci| --------- | -------------------------------------------------- | ---- | ---- | ----------- |
1021e41f4b71Sopenharmony_ci| textStyle | [TextStyle](#textstyle)                             | Yes  | No  | Text style.|
1022e41f4b71Sopenharmony_ci| fontMetrics | [drawing.FontMetrics](js-apis-graphics-drawing.md#fontmetrics)| Yes  | No  | Font measurement information.   |
1023e41f4b71Sopenharmony_ci
1024e41f4b71Sopenharmony_ci## LineMetrics
1025e41f4b71Sopenharmony_ci
1026e41f4b71Sopenharmony_ciDescribes the measurement information of a single line of text in the text layout.
1027e41f4b71Sopenharmony_ci
1028e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1029e41f4b71Sopenharmony_ci
1030e41f4b71Sopenharmony_ci| Name     | Type                                               | Read Only| Optional| Description       |
1031e41f4b71Sopenharmony_ci| --------- | -------------------------------------------------- | ---- | ---- | ----------- |
1032e41f4b71Sopenharmony_ci| startIndex | number                                            | Yes  | No  | Start index of the line in the text buffer.|
1033e41f4b71Sopenharmony_ci| endIndex   | number                                            | Yes  | No  | End index of the line in the text buffer.|
1034e41f4b71Sopenharmony_ci| ascent     | number                                            | Yes  | No  | Ascent, that is, the distance from the baseline to the top of the character.|
1035e41f4b71Sopenharmony_ci| descent    | number                                            | Yes  | No  | Descent, that is, the distance from the baseline to the bottom of the character.|
1036e41f4b71Sopenharmony_ci| height     | number                                            | Yes  | No  | Height of the line, which is Math.round(ascent + descent).|
1037e41f4b71Sopenharmony_ci| width      | number                                            | Yes  | No  | Width of the line.                     |
1038e41f4b71Sopenharmony_ci| left       | number                        | Yes  | No  | Left edge of the line. The right edge is the value of **left** plus the value of **width**.|
1039e41f4b71Sopenharmony_ci| baseline   | number                        | Yes  | No  | Y coordinate of the baseline in the line relative to the top of the paragraph.|
1040e41f4b71Sopenharmony_ci| lineNumber   | number                        | Yes  | No  | Line number, starting from 0.|
1041e41f4b71Sopenharmony_ci| topHeight   | number                        | Yes  | No  | Height from the top to the current line.|
1042e41f4b71Sopenharmony_ci| runMetrics   | Map<number, [RunMetrics](#runmetrics)>                        | Yes  | No  | Mapping between the text index range and the associated font measurement information.|
1043e41f4b71Sopenharmony_ci
1044e41f4b71Sopenharmony_ci## TextBox
1045e41f4b71Sopenharmony_ci
1046e41f4b71Sopenharmony_ciDescribes the rectangle that holds the text.
1047e41f4b71Sopenharmony_ci
1048e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1049e41f4b71Sopenharmony_ci
1050e41f4b71Sopenharmony_ci| Name     | Type                                               | Read Only| Optional| Description       |
1051e41f4b71Sopenharmony_ci| --------- | -------------------------------------------------- | ---- | ---- | ----------- |
1052e41f4b71Sopenharmony_ci| rect      | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | No  | Information about the rectangle.|
1053e41f4b71Sopenharmony_ci| direction | [TextDirection](#textdirection)                    | Yes  | No  | Text direction.   |
1054e41f4b71Sopenharmony_ci
1055e41f4b71Sopenharmony_ci## PositionWithAffinity
1056e41f4b71Sopenharmony_ci
1057e41f4b71Sopenharmony_ciDescribes the position and affinity of a glyph.
1058e41f4b71Sopenharmony_ci
1059e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1060e41f4b71Sopenharmony_ci
1061e41f4b71Sopenharmony_ci| Name     | Type                  | Read Only| Optional| Description                     |
1062e41f4b71Sopenharmony_ci| --------- | --------------------- | ---- | ---- | ------------------------ |
1063e41f4b71Sopenharmony_ci| position  | number                | Yes  | No  | Index of the glyph relative to the paragraph. The value is an integer. |
1064e41f4b71Sopenharmony_ci| affinity  | [Affinity](#affinity) | Yes  | No  | Affinity of the position.              |
1065e41f4b71Sopenharmony_ci
1066e41f4b71Sopenharmony_ci## RectWidthStyle
1067e41f4b71Sopenharmony_ci
1068e41f4b71Sopenharmony_ciEnumerates the rectangle width styles.
1069e41f4b71Sopenharmony_ci
1070e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1071e41f4b71Sopenharmony_ci
1072e41f4b71Sopenharmony_ci| Name | Value| Description                                  |
1073e41f4b71Sopenharmony_ci| ----- | - | -------------------------------------- |
1074e41f4b71Sopenharmony_ci| TIGHT | 0 | If **letterSpacing** is not set, the rectangle conforms tightly to the text it contains. However, if **letterSpacing** is set, a gap is introduced between the rectangle and text.                           |
1075e41f4b71Sopenharmony_ci| MAX   | 1 | The rectangle's width is extended to align with the widest rectangle across all lines.  |
1076e41f4b71Sopenharmony_ci
1077e41f4b71Sopenharmony_ci## RectHeightStyle
1078e41f4b71Sopenharmony_ci
1079e41f4b71Sopenharmony_ciEnumerates the rectangle height styles.
1080e41f4b71Sopenharmony_ci
1081e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1082e41f4b71Sopenharmony_ci
1083e41f4b71Sopenharmony_ci| Name                     | Value| Description                                          |
1084e41f4b71Sopenharmony_ci| ------------------------- | - | ---------------------------------------------- |
1085e41f4b71Sopenharmony_ci| TIGHT                     | 0 | Tight style.                                   |
1086e41f4b71Sopenharmony_ci| MAX                       | 1 | Extends the height to match the highest rectangle in all lines.          |
1087e41f4b71Sopenharmony_ci| INCLUDE_LINE_SPACE_MIDDLE | 2 | Includes half of the line spacing to both the top and bottom of the rectangle.|
1088e41f4b71Sopenharmony_ci| INCLUDE_LINE_SPACE_TOP    | 3 | Includes the line spacing to the top of the rectangle.                     |
1089e41f4b71Sopenharmony_ci| INCLUDE_LINE_SPACE_BOTTOM | 4 | Includes the line spacing to the bottom of the rectangle.                     |
1090e41f4b71Sopenharmony_ci| STRUT                     | 5 | Sets the height according to the strut style.                         |
1091e41f4b71Sopenharmony_ci
1092e41f4b71Sopenharmony_ci## Affinity
1093e41f4b71Sopenharmony_ci
1094e41f4b71Sopenharmony_ciEnumerates the affinity modes.
1095e41f4b71Sopenharmony_ci
1096e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1097e41f4b71Sopenharmony_ci
1098e41f4b71Sopenharmony_ci| Name      | Value| Description                         |
1099e41f4b71Sopenharmony_ci| ---------- | - | ----------------------------- |
1100e41f4b71Sopenharmony_ci| UPSTREAM   | 0 | The position has affinity for the upstream side of the text position.|
1101e41f4b71Sopenharmony_ci| DOWNSTREAM | 1 | The position has affinity for the downstream side of the text position.|
1102e41f4b71Sopenharmony_ci
1103e41f4b71Sopenharmony_ci## ParagraphBuilder
1104e41f4b71Sopenharmony_ci
1105e41f4b71Sopenharmony_ciImplements a paragraph builder.
1106e41f4b71Sopenharmony_ci
1107e41f4b71Sopenharmony_ci### constructor
1108e41f4b71Sopenharmony_ci
1109e41f4b71Sopenharmony_ciconstructor(paragraphStyle: ParagraphStyle, fontCollection: FontCollection)
1110e41f4b71Sopenharmony_ci
1111e41f4b71Sopenharmony_ciA constructor used to create a **ParagraphBuilder** object.
1112e41f4b71Sopenharmony_ci
1113e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1114e41f4b71Sopenharmony_ci
1115e41f4b71Sopenharmony_ci**Parameters**
1116e41f4b71Sopenharmony_ci
1117e41f4b71Sopenharmony_ci| Name        | Type                              | Mandatory| Description       |
1118e41f4b71Sopenharmony_ci| -------------- | --------------------------------- | ---- | ----------- |
1119e41f4b71Sopenharmony_ci| paragraphStyle | [ParagraphStyle](#paragraphstyle) | Yes  | Paragraph style.  |
1120e41f4b71Sopenharmony_ci| fontCollection | [FontCollection](#fontcollection) | Yes  | Font manager.|
1121e41f4b71Sopenharmony_ci
1122e41f4b71Sopenharmony_ci**Example**
1123e41f4b71Sopenharmony_ci
1124e41f4b71Sopenharmony_ci```ts
1125e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D";
1126e41f4b71Sopenharmony_ci
1127e41f4b71Sopenharmony_cifunction textFunc() {
1128e41f4b71Sopenharmony_ci  let myTextStyle: text.TextStyle = {
1129e41f4b71Sopenharmony_ci    color: { alpha: 255, red: 255, green: 0, blue: 0 },
1130e41f4b71Sopenharmony_ci    fontSize: 33,
1131e41f4b71Sopenharmony_ci  };
1132e41f4b71Sopenharmony_ci  let myParagraphStyle: text.ParagraphStyle = {
1133e41f4b71Sopenharmony_ci    textStyle: myTextStyle,
1134e41f4b71Sopenharmony_ci    align: text.TextAlign.END,
1135e41f4b71Sopenharmony_ci  };
1136e41f4b71Sopenharmony_ci  let fontCollection = new text.FontCollection();
1137e41f4b71Sopenharmony_ci  let ParagraphGraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection);
1138e41f4b71Sopenharmony_ci}
1139e41f4b71Sopenharmony_ci
1140e41f4b71Sopenharmony_ci@Entry
1141e41f4b71Sopenharmony_ci@Component
1142e41f4b71Sopenharmony_cistruct Index {
1143e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1144e41f4b71Sopenharmony_ci  build() {
1145e41f4b71Sopenharmony_ci    Column() {
1146e41f4b71Sopenharmony_ci      Button().onClick(() => {
1147e41f4b71Sopenharmony_ci        this.fun();
1148e41f4b71Sopenharmony_ci      })
1149e41f4b71Sopenharmony_ci    }
1150e41f4b71Sopenharmony_ci  }
1151e41f4b71Sopenharmony_ci}
1152e41f4b71Sopenharmony_ci```
1153e41f4b71Sopenharmony_ci
1154e41f4b71Sopenharmony_ci### pushStyle
1155e41f4b71Sopenharmony_ci
1156e41f4b71Sopenharmony_ci pushStyle(textStyle: TextStyle): void
1157e41f4b71Sopenharmony_ci
1158e41f4b71Sopenharmony_ciPushes a text style.
1159e41f4b71Sopenharmony_ci
1160e41f4b71Sopenharmony_ci> **NOTE**
1161e41f4b71Sopenharmony_ci>
1162e41f4b71Sopenharmony_ci> This API pushes the style of the current text blob until [popStyle](#popstyle), which restores to the previous text style, is called.
1163e41f4b71Sopenharmony_ci
1164e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1165e41f4b71Sopenharmony_ci
1166e41f4b71Sopenharmony_ci**Parameters**
1167e41f4b71Sopenharmony_ci
1168e41f4b71Sopenharmony_ci| Name   | Type      | Mandatory| Description                                                                                                  |
1169e41f4b71Sopenharmony_ci| --------- | --------- | ---- | ------------------------------------------------------------------------------------------------------ |
1170e41f4b71Sopenharmony_ci| textStyle | [TextStyle](#textstyle) | Yes  | Text style, which describes various visual attributes of text, such as font, font size, color, font weight, word spacing, line spacing, decoration (such as underline and strikethrough), and text shadow.|
1171e41f4b71Sopenharmony_ci
1172e41f4b71Sopenharmony_ci**Example**
1173e41f4b71Sopenharmony_ci
1174e41f4b71Sopenharmony_ci```ts
1175e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D'
1176e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
1177e41f4b71Sopenharmony_ciimport { common2D } from "@kit.ArkGraphics2D"
1178e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
1179e41f4b71Sopenharmony_ci
1180e41f4b71Sopenharmony_cifunction textFunc() {
1181e41f4b71Sopenharmony_ci  let myTextStyle: text.TextStyle = {
1182e41f4b71Sopenharmony_ci    color: { alpha: 255, red: 255, green: 0, blue: 0 },
1183e41f4b71Sopenharmony_ci    fontSize: 33,
1184e41f4b71Sopenharmony_ci  };
1185e41f4b71Sopenharmony_ci  let myParagraphStyle: text.ParagraphStyle = {
1186e41f4b71Sopenharmony_ci    textStyle: myTextStyle,
1187e41f4b71Sopenharmony_ci    align: text.TextAlign.CENTER,
1188e41f4b71Sopenharmony_ci  };
1189e41f4b71Sopenharmony_ci  let fontCollection = new text.FontCollection();
1190e41f4b71Sopenharmony_ci  let ParagraphGraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection);
1191e41f4b71Sopenharmony_ci  ParagraphGraphBuilder.pushStyle(myTextStyle);
1192e41f4b71Sopenharmony_ci}
1193e41f4b71Sopenharmony_ci
1194e41f4b71Sopenharmony_ci@Entry
1195e41f4b71Sopenharmony_ci@Component
1196e41f4b71Sopenharmony_cistruct Index {
1197e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1198e41f4b71Sopenharmony_ci  build() {
1199e41f4b71Sopenharmony_ci    Column() {
1200e41f4b71Sopenharmony_ci      Button().onClick(() => {
1201e41f4b71Sopenharmony_ci        this.fun();
1202e41f4b71Sopenharmony_ci      })
1203e41f4b71Sopenharmony_ci    }
1204e41f4b71Sopenharmony_ci  }
1205e41f4b71Sopenharmony_ci}
1206e41f4b71Sopenharmony_ci```
1207e41f4b71Sopenharmony_ci
1208e41f4b71Sopenharmony_ci### popStyle
1209e41f4b71Sopenharmony_ci
1210e41f4b71Sopenharmony_cipopStyle(): void
1211e41f4b71Sopenharmony_ci
1212e41f4b71Sopenharmony_ciRestores to the previous text style.
1213e41f4b71Sopenharmony_ci
1214e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1215e41f4b71Sopenharmony_ci
1216e41f4b71Sopenharmony_ci**Example**
1217e41f4b71Sopenharmony_ci
1218e41f4b71Sopenharmony_ci```ts
1219e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D'
1220e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
1221e41f4b71Sopenharmony_ciimport { common2D } from "@kit.ArkGraphics2D"
1222e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
1223e41f4b71Sopenharmony_ci
1224e41f4b71Sopenharmony_cifunction textFunc() {
1225e41f4b71Sopenharmony_ci  let myTextStyle: text.TextStyle = {
1226e41f4b71Sopenharmony_ci    color: { alpha: 255, red: 255, green: 0, blue: 0 },
1227e41f4b71Sopenharmony_ci    fontSize: 33,
1228e41f4b71Sopenharmony_ci  };
1229e41f4b71Sopenharmony_ci  let myParagraphStyle: text.ParagraphStyle = {
1230e41f4b71Sopenharmony_ci    textStyle: myTextStyle,
1231e41f4b71Sopenharmony_ci    align: text.TextAlign.END,
1232e41f4b71Sopenharmony_ci  };
1233e41f4b71Sopenharmony_ci  let fontCollection = new text.FontCollection();
1234e41f4b71Sopenharmony_ci  let ParagraphGraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection);
1235e41f4b71Sopenharmony_ci  ParagraphGraphBuilder.pushStyle(myTextStyle);
1236e41f4b71Sopenharmony_ci  ParagraphGraphBuilder.popStyle();
1237e41f4b71Sopenharmony_ci}
1238e41f4b71Sopenharmony_ci
1239e41f4b71Sopenharmony_ci@Entry
1240e41f4b71Sopenharmony_ci@Component
1241e41f4b71Sopenharmony_cistruct Index {
1242e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1243e41f4b71Sopenharmony_ci  build() {
1244e41f4b71Sopenharmony_ci    Column() {
1245e41f4b71Sopenharmony_ci      Button().onClick(() => {
1246e41f4b71Sopenharmony_ci        this.fun();
1247e41f4b71Sopenharmony_ci      })
1248e41f4b71Sopenharmony_ci    }
1249e41f4b71Sopenharmony_ci  }
1250e41f4b71Sopenharmony_ci}
1251e41f4b71Sopenharmony_ci```
1252e41f4b71Sopenharmony_ci
1253e41f4b71Sopenharmony_ci### addText
1254e41f4b71Sopenharmony_ci
1255e41f4b71Sopenharmony_ciaddText(text: string): void
1256e41f4b71Sopenharmony_ci
1257e41f4b71Sopenharmony_ciInserts a text string into the paragraph being built.
1258e41f4b71Sopenharmony_ci
1259e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1260e41f4b71Sopenharmony_ci
1261e41f4b71Sopenharmony_ci**Parameters**
1262e41f4b71Sopenharmony_ci
1263e41f4b71Sopenharmony_ci| Name  | Type   | Mandatory| Description                      |
1264e41f4b71Sopenharmony_ci| ------- | ------- | ---- | -------------------------- |
1265e41f4b71Sopenharmony_ci| text    | string  | Yes  | Text string to insert.|
1266e41f4b71Sopenharmony_ci
1267e41f4b71Sopenharmony_ci**Example**
1268e41f4b71Sopenharmony_ci
1269e41f4b71Sopenharmony_ci```ts
1270e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D'
1271e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
1272e41f4b71Sopenharmony_ciimport { common2D } from "@kit.ArkGraphics2D"
1273e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
1274e41f4b71Sopenharmony_ci
1275e41f4b71Sopenharmony_cifunction textFunc() {
1276e41f4b71Sopenharmony_ci  let myTextStyle: text.TextStyle = {
1277e41f4b71Sopenharmony_ci    color: { alpha: 255, red: 255, green: 0, blue: 0 },
1278e41f4b71Sopenharmony_ci    fontSize: 33,
1279e41f4b71Sopenharmony_ci  };
1280e41f4b71Sopenharmony_ci  let myParagraphStyle: text.ParagraphStyle = {
1281e41f4b71Sopenharmony_ci    textStyle: myTextStyle,
1282e41f4b71Sopenharmony_ci    align: text.TextAlign.END,
1283e41f4b71Sopenharmony_ci  };
1284e41f4b71Sopenharmony_ci  let fontCollection = new text.FontCollection();
1285e41f4b71Sopenharmony_ci  let ParagraphGraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection);
1286e41f4b71Sopenharmony_ci  ParagraphGraphBuilder.addText("123666");
1287e41f4b71Sopenharmony_ci}
1288e41f4b71Sopenharmony_ci
1289e41f4b71Sopenharmony_ci@Entry
1290e41f4b71Sopenharmony_ci@Component
1291e41f4b71Sopenharmony_cistruct Index {
1292e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1293e41f4b71Sopenharmony_ci  build() {
1294e41f4b71Sopenharmony_ci    Column() {
1295e41f4b71Sopenharmony_ci      Button().onClick(() => {
1296e41f4b71Sopenharmony_ci        this.fun();
1297e41f4b71Sopenharmony_ci      })
1298e41f4b71Sopenharmony_ci    }
1299e41f4b71Sopenharmony_ci  }
1300e41f4b71Sopenharmony_ci}
1301e41f4b71Sopenharmony_ci```
1302e41f4b71Sopenharmony_ci
1303e41f4b71Sopenharmony_ci### addPlaceholder
1304e41f4b71Sopenharmony_ci
1305e41f4b71Sopenharmony_ciaddPlaceholder(placeholderSpan: PlaceholderSpan): void
1306e41f4b71Sopenharmony_ci
1307e41f4b71Sopenharmony_ciInserts a placeholder into the paragraph being built.
1308e41f4b71Sopenharmony_ci
1309e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1310e41f4b71Sopenharmony_ci
1311e41f4b71Sopenharmony_ci**Parameters**
1312e41f4b71Sopenharmony_ci
1313e41f4b71Sopenharmony_ci| Name         | Type                                | Mandatory| Description                                               |
1314e41f4b71Sopenharmony_ci| --------------- | ----------------------------------- | ---- | --------------------------------------------------- |
1315e41f4b71Sopenharmony_ci| placeholderSpan | [PlaceholderSpan](#placeholderspan) | Yes  | Placeholder span, which describes the size, alignment, baseline type, and baseline offset of the placeholder. |
1316e41f4b71Sopenharmony_ci
1317e41f4b71Sopenharmony_ci**Example**
1318e41f4b71Sopenharmony_ci
1319e41f4b71Sopenharmony_ci```ts
1320e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D'
1321e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
1322e41f4b71Sopenharmony_ciimport { common2D } from "@kit.ArkGraphics2D"
1323e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
1324e41f4b71Sopenharmony_ci
1325e41f4b71Sopenharmony_cifunction textFunc() {
1326e41f4b71Sopenharmony_ci  let myParagraphStyle: text.ParagraphStyle = {
1327e41f4b71Sopenharmony_ci    align: text.TextAlign.END,
1328e41f4b71Sopenharmony_ci  };
1329e41f4b71Sopenharmony_ci  let myPlaceholderSpan: text.PlaceholderSpan = {
1330e41f4b71Sopenharmony_ci    width: 10000,
1331e41f4b71Sopenharmony_ci    height: 10000000,
1332e41f4b71Sopenharmony_ci    align: text.PlaceholderAlignment.ABOVE_BASELINE,
1333e41f4b71Sopenharmony_ci    baseline: text.TextBaseline.ALPHABETIC,
1334e41f4b71Sopenharmony_ci    baselineOffset: 100000
1335e41f4b71Sopenharmony_ci  };
1336e41f4b71Sopenharmony_ci  let fontCollection = new text.FontCollection();
1337e41f4b71Sopenharmony_ci  let ParagraphGraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection);
1338e41f4b71Sopenharmony_ci  ParagraphGraphBuilder.addPlaceholder(myPlaceholderSpan);
1339e41f4b71Sopenharmony_ci}
1340e41f4b71Sopenharmony_ci
1341e41f4b71Sopenharmony_ci@Entry
1342e41f4b71Sopenharmony_ci@Component
1343e41f4b71Sopenharmony_cistruct Index {
1344e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1345e41f4b71Sopenharmony_ci  build() {
1346e41f4b71Sopenharmony_ci    Column() {
1347e41f4b71Sopenharmony_ci      Button().onClick(() => {
1348e41f4b71Sopenharmony_ci        this.fun();
1349e41f4b71Sopenharmony_ci      })
1350e41f4b71Sopenharmony_ci    }
1351e41f4b71Sopenharmony_ci  }
1352e41f4b71Sopenharmony_ci}
1353e41f4b71Sopenharmony_ci```
1354e41f4b71Sopenharmony_ci
1355e41f4b71Sopenharmony_ci### build
1356e41f4b71Sopenharmony_ci
1357e41f4b71Sopenharmony_cibuild(): Paragraph
1358e41f4b71Sopenharmony_ci
1359e41f4b71Sopenharmony_ciCreates a paragraph object that can be used for subsequent typography and rendering.
1360e41f4b71Sopenharmony_ci
1361e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1362e41f4b71Sopenharmony_ci
1363e41f4b71Sopenharmony_ci**Return value**
1364e41f4b71Sopenharmony_ci
1365e41f4b71Sopenharmony_ci| Type                    | Description                          |
1366e41f4b71Sopenharmony_ci| ------------------------ | ------------------------------ |
1367e41f4b71Sopenharmony_ci| [Paragraph](#paragraph)  | **Paragraph** object that can be used for subsequent typography and rendering.|
1368e41f4b71Sopenharmony_ci
1369e41f4b71Sopenharmony_ci**Example**
1370e41f4b71Sopenharmony_ci
1371e41f4b71Sopenharmony_ci```ts
1372e41f4b71Sopenharmony_ciimport { drawing, text, common2D } from '@kit.ArkGraphics2D'
1373e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
1374e41f4b71Sopenharmony_ci
1375e41f4b71Sopenharmony_cifunction textFunc() {
1376e41f4b71Sopenharmony_ci  let myParagraphStyle: text.ParagraphStyle = {
1377e41f4b71Sopenharmony_ci    align: text.TextAlign.END,
1378e41f4b71Sopenharmony_ci  };
1379e41f4b71Sopenharmony_ci  let fontCollection = new text.FontCollection();
1380e41f4b71Sopenharmony_ci  let ParagraphGraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection);
1381e41f4b71Sopenharmony_ci  let paragraph = ParagraphGraphBuilder.build();
1382e41f4b71Sopenharmony_ci}
1383e41f4b71Sopenharmony_ci
1384e41f4b71Sopenharmony_ci@Entry
1385e41f4b71Sopenharmony_ci@Component
1386e41f4b71Sopenharmony_cistruct Index {
1387e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1388e41f4b71Sopenharmony_ci  build() {
1389e41f4b71Sopenharmony_ci    Column() {
1390e41f4b71Sopenharmony_ci      Button().onClick(() => {
1391e41f4b71Sopenharmony_ci        this.fun();
1392e41f4b71Sopenharmony_ci      })
1393e41f4b71Sopenharmony_ci    }
1394e41f4b71Sopenharmony_ci  }
1395e41f4b71Sopenharmony_ci}
1396e41f4b71Sopenharmony_ci```
1397e41f4b71Sopenharmony_ci
1398e41f4b71Sopenharmony_ci### addSymbol
1399e41f4b71Sopenharmony_ci
1400e41f4b71Sopenharmony_ciaddSymbol(symbolId: number): void
1401e41f4b71Sopenharmony_ci
1402e41f4b71Sopenharmony_ciInserts a symbol into the paragraph being built.
1403e41f4b71Sopenharmony_ci
1404e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1405e41f4b71Sopenharmony_ci
1406e41f4b71Sopenharmony_ci**Parameters**
1407e41f4b71Sopenharmony_ci
1408e41f4b71Sopenharmony_ci| Name   | Type   | Mandatory| Description                                                       |
1409e41f4b71Sopenharmony_ci| -------- | ------- | ---- | ----------------------------------------------------------- |
1410e41f4b71Sopenharmony_ci| symbolId | number  | Yes  | Symbol code to insert. The value is a hexadecimal number in the range 0xF0000–0xF0C97. For details about the configurable symbol codes and symbol names, see the **value** and **name** fields in the [JSON file](https://gitee.com/openharmony/global_system_resources/blob/master/systemres/main/resources/base/element/symbol.json).|
1411e41f4b71Sopenharmony_ci
1412e41f4b71Sopenharmony_ci**Example**
1413e41f4b71Sopenharmony_ci
1414e41f4b71Sopenharmony_ci```ts
1415e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D";
1416e41f4b71Sopenharmony_ci
1417e41f4b71Sopenharmony_cifunction textFunc() {
1418e41f4b71Sopenharmony_ci  let myTextStyle: text.TextStyle = {
1419e41f4b71Sopenharmony_ci    color: { alpha: 255, red: 255, green: 0, blue: 0 },
1420e41f4b71Sopenharmony_ci    fontSize: 33,
1421e41f4b71Sopenharmony_ci  };
1422e41f4b71Sopenharmony_ci  let myParagraphStyle: text.ParagraphStyle = {
1423e41f4b71Sopenharmony_ci    textStyle: myTextStyle,
1424e41f4b71Sopenharmony_ci    align: text.TextAlign.END,
1425e41f4b71Sopenharmony_ci  };
1426e41f4b71Sopenharmony_ci  let fontCollection = new text.FontCollection();
1427e41f4b71Sopenharmony_ci  let ParagraphGraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection);
1428e41f4b71Sopenharmony_ci  ParagraphGraphBuilder.addSymbol(0xF0000);
1429e41f4b71Sopenharmony_ci  let paragraph = ParagraphGraphBuilder.build();
1430e41f4b71Sopenharmony_ci}
1431e41f4b71Sopenharmony_ci
1432e41f4b71Sopenharmony_ci@Entry
1433e41f4b71Sopenharmony_ci@Component
1434e41f4b71Sopenharmony_cistruct Index {
1435e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1436e41f4b71Sopenharmony_ci  build() {
1437e41f4b71Sopenharmony_ci    Column() {
1438e41f4b71Sopenharmony_ci      Button().onClick(() => {
1439e41f4b71Sopenharmony_ci        this.fun();
1440e41f4b71Sopenharmony_ci      })
1441e41f4b71Sopenharmony_ci    }
1442e41f4b71Sopenharmony_ci  }
1443e41f4b71Sopenharmony_ci}
1444e41f4b71Sopenharmony_ci```
1445e41f4b71Sopenharmony_ci
1446e41f4b71Sopenharmony_ci## TextLine
1447e41f4b71Sopenharmony_ci
1448e41f4b71Sopenharmony_ciImplements a carrier that describes the basic text line structure of a paragraph.
1449e41f4b71Sopenharmony_ci
1450e41f4b71Sopenharmony_ciBefore calling any of the following APIs, you must use [getTextLines()](#gettextlines) of the [Paragraph](#paragraph) class to create a **TextLine** object.
1451e41f4b71Sopenharmony_ci
1452e41f4b71Sopenharmony_ci### getGlyphCount
1453e41f4b71Sopenharmony_ci
1454e41f4b71Sopenharmony_cigetGlyphCount(): number
1455e41f4b71Sopenharmony_ci
1456e41f4b71Sopenharmony_ciObtains the number of glyphs in this text line.
1457e41f4b71Sopenharmony_ci
1458e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1459e41f4b71Sopenharmony_ci
1460e41f4b71Sopenharmony_ci**Return value**
1461e41f4b71Sopenharmony_ci
1462e41f4b71Sopenharmony_ci| Type   | Description              |
1463e41f4b71Sopenharmony_ci| ------- | ------------------ |
1464e41f4b71Sopenharmony_ci| number  | Number of glyphs. The value is an integer.|
1465e41f4b71Sopenharmony_ci
1466e41f4b71Sopenharmony_ci**Example**
1467e41f4b71Sopenharmony_ci
1468e41f4b71Sopenharmony_ci```ts
1469e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
1470e41f4b71Sopenharmony_ci
1471e41f4b71Sopenharmony_cifunction textFunc() {
1472e41f4b71Sopenharmony_ci  let GlyphCount = lines[0].getGlyphCount();
1473e41f4b71Sopenharmony_ci}
1474e41f4b71Sopenharmony_ci
1475e41f4b71Sopenharmony_ci@Entry
1476e41f4b71Sopenharmony_ci@Component
1477e41f4b71Sopenharmony_cistruct Index {
1478e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1479e41f4b71Sopenharmony_ci  build() {
1480e41f4b71Sopenharmony_ci    Column() {
1481e41f4b71Sopenharmony_ci      Button().onClick(() => {
1482e41f4b71Sopenharmony_ci        this.fun();
1483e41f4b71Sopenharmony_ci      })
1484e41f4b71Sopenharmony_ci    }
1485e41f4b71Sopenharmony_ci  }
1486e41f4b71Sopenharmony_ci}
1487e41f4b71Sopenharmony_ci```
1488e41f4b71Sopenharmony_ci
1489e41f4b71Sopenharmony_ci### getTextRange
1490e41f4b71Sopenharmony_ci
1491e41f4b71Sopenharmony_cigetTextRange(): Range
1492e41f4b71Sopenharmony_ci
1493e41f4b71Sopenharmony_ciObtains the range of the text in this text line in the entire paragraph.
1494e41f4b71Sopenharmony_ci
1495e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1496e41f4b71Sopenharmony_ci
1497e41f4b71Sopenharmony_ci**Return value**
1498e41f4b71Sopenharmony_ci
1499e41f4b71Sopenharmony_ci| Type            | Description                                             |
1500e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------ |
1501e41f4b71Sopenharmony_ci| [Range](#range)  | Range of the text in this text line in the entire paragraph.|
1502e41f4b71Sopenharmony_ci
1503e41f4b71Sopenharmony_ci**Example**
1504e41f4b71Sopenharmony_ci
1505e41f4b71Sopenharmony_ci```ts
1506e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
1507e41f4b71Sopenharmony_ci
1508e41f4b71Sopenharmony_cifunction textFunc() {
1509e41f4b71Sopenharmony_ci  let textRange = lines[0].getTextRange();
1510e41f4b71Sopenharmony_ci}
1511e41f4b71Sopenharmony_ci
1512e41f4b71Sopenharmony_ci@Entry
1513e41f4b71Sopenharmony_ci@Component
1514e41f4b71Sopenharmony_cistruct Index {
1515e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1516e41f4b71Sopenharmony_ci  build() {
1517e41f4b71Sopenharmony_ci    Column() {
1518e41f4b71Sopenharmony_ci      Button().onClick(() => {
1519e41f4b71Sopenharmony_ci        this.fun();
1520e41f4b71Sopenharmony_ci      })
1521e41f4b71Sopenharmony_ci    }
1522e41f4b71Sopenharmony_ci  }
1523e41f4b71Sopenharmony_ci}
1524e41f4b71Sopenharmony_ci```
1525e41f4b71Sopenharmony_ci
1526e41f4b71Sopenharmony_ci### getGlyphRuns
1527e41f4b71Sopenharmony_ci
1528e41f4b71Sopenharmony_cigetGlyphRuns(): Array\<Run>
1529e41f4b71Sopenharmony_ci
1530e41f4b71Sopenharmony_ciObtains the glyph runs in this text line.
1531e41f4b71Sopenharmony_ci
1532e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1533e41f4b71Sopenharmony_ci
1534e41f4b71Sopenharmony_ci**Return value**
1535e41f4b71Sopenharmony_ci
1536e41f4b71Sopenharmony_ci| Type        | Description                        |
1537e41f4b71Sopenharmony_ci| ------------ | --------------------------- |
1538e41f4b71Sopenharmony_ci| Array\<[Run](#run)>  | Array of the glyph runs obtained.|
1539e41f4b71Sopenharmony_ci
1540e41f4b71Sopenharmony_ci**Example**
1541e41f4b71Sopenharmony_ci
1542e41f4b71Sopenharmony_ci```ts
1543e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
1544e41f4b71Sopenharmony_ci
1545e41f4b71Sopenharmony_cifunction textFunc() {
1546e41f4b71Sopenharmony_ci  let runs = lines[0].getGlyphRuns();
1547e41f4b71Sopenharmony_ci}
1548e41f4b71Sopenharmony_ci
1549e41f4b71Sopenharmony_ci@Entry
1550e41f4b71Sopenharmony_ci@Component
1551e41f4b71Sopenharmony_cistruct Index {
1552e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1553e41f4b71Sopenharmony_ci  build() {
1554e41f4b71Sopenharmony_ci    Column() {
1555e41f4b71Sopenharmony_ci      Button().onClick(() => {
1556e41f4b71Sopenharmony_ci        this.fun();
1557e41f4b71Sopenharmony_ci      })
1558e41f4b71Sopenharmony_ci    }
1559e41f4b71Sopenharmony_ci  }
1560e41f4b71Sopenharmony_ci}
1561e41f4b71Sopenharmony_ci```
1562e41f4b71Sopenharmony_ci
1563e41f4b71Sopenharmony_ci### paint
1564e41f4b71Sopenharmony_ci
1565e41f4b71Sopenharmony_cipaint(canvas: drawing.Canvas, x: number, y: number): void
1566e41f4b71Sopenharmony_ci
1567e41f4b71Sopenharmony_ciPaints this text line on the canvas with the coordinate point (x, y) as the upper left corner.
1568e41f4b71Sopenharmony_ci
1569e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1570e41f4b71Sopenharmony_ci
1571e41f4b71Sopenharmony_ci**Parameters**
1572e41f4b71Sopenharmony_ci
1573e41f4b71Sopenharmony_ci| Name| Type                                                 | Mandatory| Description                   |
1574e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ---------------------- |
1575e41f4b71Sopenharmony_ci| canvas | [drawing.Canvas](js-apis-graphics-drawing.md#canvas) | Yes  | Target canvas.     |
1576e41f4b71Sopenharmony_ci|    x   | number                                               | Yes  | X coordinate of the upper left corner. The value is a floating point number.|
1577e41f4b71Sopenharmony_ci|    y   | number                                               | Yes  | Y coordinate of the upper left corner. The value is a floating point number.|
1578e41f4b71Sopenharmony_ci
1579e41f4b71Sopenharmony_ci**Example**
1580e41f4b71Sopenharmony_ci
1581e41f4b71Sopenharmony_ci```ts
1582e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D'
1583e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
1584e41f4b71Sopenharmony_ciimport { common2D } from "@kit.ArkGraphics2D"
1585e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
1586e41f4b71Sopenharmony_ci
1587e41f4b71Sopenharmony_cifunction textFunc() {
1588e41f4b71Sopenharmony_ci  const color: ArrayBuffer = new ArrayBuffer(160000);
1589e41f4b71Sopenharmony_ci  let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 200, width: 200 } }
1590e41f4b71Sopenharmony_ci  let pixelMap: image.PixelMap = image.createPixelMapSync(color, opts);
1591e41f4b71Sopenharmony_ci  let canvas = new drawing.Canvas(pixelMap);
1592e41f4b71Sopenharmony_ci  lines[0].paint(canvas, 0, 0);
1593e41f4b71Sopenharmony_ci}
1594e41f4b71Sopenharmony_ci
1595e41f4b71Sopenharmony_ci@Entry
1596e41f4b71Sopenharmony_ci@Component
1597e41f4b71Sopenharmony_cistruct Index {
1598e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1599e41f4b71Sopenharmony_ci  build() {
1600e41f4b71Sopenharmony_ci    Column() {
1601e41f4b71Sopenharmony_ci      Button().onClick(() => {
1602e41f4b71Sopenharmony_ci        this.fun();
1603e41f4b71Sopenharmony_ci      })
1604e41f4b71Sopenharmony_ci    }
1605e41f4b71Sopenharmony_ci  }
1606e41f4b71Sopenharmony_ci}
1607e41f4b71Sopenharmony_ci```
1608e41f4b71Sopenharmony_ci
1609e41f4b71Sopenharmony_ci## Run
1610e41f4b71Sopenharmony_ci
1611e41f4b71Sopenharmony_ciImplements a rendering unit for text typesetting.
1612e41f4b71Sopenharmony_ci
1613e41f4b71Sopenharmony_ciBefore calling any of the following APIs, you must use [getGlyphRuns()](#getglyphruns) of the [TextLine](#textline) class to create a **Run** object.
1614e41f4b71Sopenharmony_ci
1615e41f4b71Sopenharmony_ci### getGlyphCount
1616e41f4b71Sopenharmony_ci
1617e41f4b71Sopenharmony_cigetGlyphCount(): number
1618e41f4b71Sopenharmony_ci
1619e41f4b71Sopenharmony_ciObtains the number of glyphs in this glyph run.
1620e41f4b71Sopenharmony_ci
1621e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1622e41f4b71Sopenharmony_ci
1623e41f4b71Sopenharmony_ci**Return value**
1624e41f4b71Sopenharmony_ci
1625e41f4b71Sopenharmony_ci| Type    | Description               |
1626e41f4b71Sopenharmony_ci| ------- | -------------------- |
1627e41f4b71Sopenharmony_ci| number  | Number of glyphs. The value is an integer.|
1628e41f4b71Sopenharmony_ci
1629e41f4b71Sopenharmony_ci**Example**
1630e41f4b71Sopenharmony_ci
1631e41f4b71Sopenharmony_ci```ts
1632e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
1633e41f4b71Sopenharmony_ci
1634e41f4b71Sopenharmony_cifunction textFunc() {
1635e41f4b71Sopenharmony_ci  let glyphs = runs[0].getGlyphCount();
1636e41f4b71Sopenharmony_ci}
1637e41f4b71Sopenharmony_ci
1638e41f4b71Sopenharmony_ci@Entry
1639e41f4b71Sopenharmony_ci@Component
1640e41f4b71Sopenharmony_cistruct Index {
1641e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1642e41f4b71Sopenharmony_ci  build() {
1643e41f4b71Sopenharmony_ci    Column() {
1644e41f4b71Sopenharmony_ci      Button().onClick(() => {
1645e41f4b71Sopenharmony_ci        this.fun();
1646e41f4b71Sopenharmony_ci      })
1647e41f4b71Sopenharmony_ci    }
1648e41f4b71Sopenharmony_ci  }
1649e41f4b71Sopenharmony_ci}
1650e41f4b71Sopenharmony_ci```
1651e41f4b71Sopenharmony_ci
1652e41f4b71Sopenharmony_ci### getGlyphs
1653e41f4b71Sopenharmony_ci
1654e41f4b71Sopenharmony_cigetGlyphs(): Array\<number>
1655e41f4b71Sopenharmony_ci
1656e41f4b71Sopenharmony_ciObtains the index of each glyph in this glyph run.
1657e41f4b71Sopenharmony_ci
1658e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1659e41f4b71Sopenharmony_ci
1660e41f4b71Sopenharmony_ci**Return value**
1661e41f4b71Sopenharmony_ci
1662e41f4b71Sopenharmony_ci| Type           | Description                            |
1663e41f4b71Sopenharmony_ci| --------------- | -------------------------------- |
1664e41f4b71Sopenharmony_ci| Array\<number>  | Array holding the index of each glyph in this glyph run.|
1665e41f4b71Sopenharmony_ci
1666e41f4b71Sopenharmony_ci**Example**
1667e41f4b71Sopenharmony_ci
1668e41f4b71Sopenharmony_ci```ts
1669e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
1670e41f4b71Sopenharmony_ci
1671e41f4b71Sopenharmony_cifunction textFunc() {
1672e41f4b71Sopenharmony_ci  let glyph = runs[0].getGlyphs();
1673e41f4b71Sopenharmony_ci}
1674e41f4b71Sopenharmony_ci
1675e41f4b71Sopenharmony_ci@Entry
1676e41f4b71Sopenharmony_ci@Component
1677e41f4b71Sopenharmony_cistruct Index {
1678e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1679e41f4b71Sopenharmony_ci  build() {
1680e41f4b71Sopenharmony_ci    Column() {
1681e41f4b71Sopenharmony_ci      Button().onClick(() => {
1682e41f4b71Sopenharmony_ci        this.fun();
1683e41f4b71Sopenharmony_ci      })
1684e41f4b71Sopenharmony_ci    }
1685e41f4b71Sopenharmony_ci  }
1686e41f4b71Sopenharmony_ci}
1687e41f4b71Sopenharmony_ci```
1688e41f4b71Sopenharmony_ci
1689e41f4b71Sopenharmony_ci### getPositions
1690e41f4b71Sopenharmony_ci
1691e41f4b71Sopenharmony_cigetPositions(): Array<common2D.Point>
1692e41f4b71Sopenharmony_ci
1693e41f4b71Sopenharmony_ciObtains the index of each glyph relative to the respective line in this glyph run.
1694e41f4b71Sopenharmony_ci
1695e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1696e41f4b71Sopenharmony_ci
1697e41f4b71Sopenharmony_ci**Return value**
1698e41f4b71Sopenharmony_ci
1699e41f4b71Sopenharmony_ci| Type                  | Description                                  |
1700e41f4b71Sopenharmony_ci| ---------------------- | ------------------------------------- |
1701e41f4b71Sopenharmony_ci| Array<[common2D.Point](js-apis-graphics-common2D.md#point12)>  | Array holding the index of each glyph relative to the respective line in this glyph run.|
1702e41f4b71Sopenharmony_ci
1703e41f4b71Sopenharmony_ci**Example**
1704e41f4b71Sopenharmony_ci
1705e41f4b71Sopenharmony_ci```ts
1706e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D";
1707e41f4b71Sopenharmony_ci
1708e41f4b71Sopenharmony_cifunction textFunc() {
1709e41f4b71Sopenharmony_ci  let positions = runs[0].getPositions();
1710e41f4b71Sopenharmony_ci}
1711e41f4b71Sopenharmony_ci
1712e41f4b71Sopenharmony_ci@Entry
1713e41f4b71Sopenharmony_ci@Component
1714e41f4b71Sopenharmony_cistruct Index {
1715e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1716e41f4b71Sopenharmony_ci  build() {
1717e41f4b71Sopenharmony_ci    Column() {
1718e41f4b71Sopenharmony_ci      Button().onClick(() => {
1719e41f4b71Sopenharmony_ci        this.fun();
1720e41f4b71Sopenharmony_ci      })
1721e41f4b71Sopenharmony_ci    }
1722e41f4b71Sopenharmony_ci  }
1723e41f4b71Sopenharmony_ci}
1724e41f4b71Sopenharmony_ci```
1725e41f4b71Sopenharmony_ci
1726e41f4b71Sopenharmony_ci### getOffsets
1727e41f4b71Sopenharmony_ci
1728e41f4b71Sopenharmony_cigetOffsets(): Array<common2D.Point>
1729e41f4b71Sopenharmony_ci
1730e41f4b71Sopenharmony_ciObtains the offset of each glyph in this glyph run relative to its index.
1731e41f4b71Sopenharmony_ci
1732e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1733e41f4b71Sopenharmony_ci
1734e41f4b71Sopenharmony_ci**Return value**
1735e41f4b71Sopenharmony_ci
1736e41f4b71Sopenharmony_ci| Type                  | Description          |
1737e41f4b71Sopenharmony_ci| ---------------------- | -------------- |
1738e41f4b71Sopenharmony_ci| Array<[common2D.Point](js-apis-graphics-common2D.md#point12)>  | Array holding the offset of each glyph in this glyph run relative to its index.|
1739e41f4b71Sopenharmony_ci
1740e41f4b71Sopenharmony_ci**Example**
1741e41f4b71Sopenharmony_ci
1742e41f4b71Sopenharmony_ci```ts
1743e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D";
1744e41f4b71Sopenharmony_ci
1745e41f4b71Sopenharmony_cifunction textFunc() {
1746e41f4b71Sopenharmony_ci  let offsets = runs[0].getOffsets();
1747e41f4b71Sopenharmony_ci}
1748e41f4b71Sopenharmony_ci
1749e41f4b71Sopenharmony_ci@Entry
1750e41f4b71Sopenharmony_ci@Component
1751e41f4b71Sopenharmony_cistruct Index {
1752e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1753e41f4b71Sopenharmony_ci  build() {
1754e41f4b71Sopenharmony_ci    Column() {
1755e41f4b71Sopenharmony_ci      Button().onClick(() => {
1756e41f4b71Sopenharmony_ci        this.fun();
1757e41f4b71Sopenharmony_ci      })
1758e41f4b71Sopenharmony_ci    }
1759e41f4b71Sopenharmony_ci  }
1760e41f4b71Sopenharmony_ci}
1761e41f4b71Sopenharmony_ci```
1762e41f4b71Sopenharmony_ci
1763e41f4b71Sopenharmony_ci### getFont
1764e41f4b71Sopenharmony_ci
1765e41f4b71Sopenharmony_cigetFont(): drawing.Font
1766e41f4b71Sopenharmony_ci
1767e41f4b71Sopenharmony_ciObtains the **Font** object of this glyph run.
1768e41f4b71Sopenharmony_ci
1769e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1770e41f4b71Sopenharmony_ci
1771e41f4b71Sopenharmony_ci**Return value**
1772e41f4b71Sopenharmony_ci
1773e41f4b71Sopenharmony_ci| Type                  | Description          |
1774e41f4b71Sopenharmony_ci| ------------------------------------------------- | -------------------------- |
1775e41f4b71Sopenharmony_ci| [drawing.Font](js-apis-graphics-drawing.md#font)  | **Font** object of this glyph run.|
1776e41f4b71Sopenharmony_ci
1777e41f4b71Sopenharmony_ci**Example**
1778e41f4b71Sopenharmony_ci
1779e41f4b71Sopenharmony_ci```ts
1780e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D'
1781e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D";
1782e41f4b71Sopenharmony_ci
1783e41f4b71Sopenharmony_cifunction textFunc() {
1784e41f4b71Sopenharmony_ci  let font = runs[0].getFont();
1785e41f4b71Sopenharmony_ci}
1786e41f4b71Sopenharmony_ci
1787e41f4b71Sopenharmony_ci@Entry
1788e41f4b71Sopenharmony_ci@Component
1789e41f4b71Sopenharmony_cistruct Index {
1790e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1791e41f4b71Sopenharmony_ci  build() {
1792e41f4b71Sopenharmony_ci    Column() {
1793e41f4b71Sopenharmony_ci      Button().onClick(() => {
1794e41f4b71Sopenharmony_ci        this.fun();
1795e41f4b71Sopenharmony_ci      })
1796e41f4b71Sopenharmony_ci    }
1797e41f4b71Sopenharmony_ci  }
1798e41f4b71Sopenharmony_ci}
1799e41f4b71Sopenharmony_ci```
1800e41f4b71Sopenharmony_ci
1801e41f4b71Sopenharmony_ci### paint
1802e41f4b71Sopenharmony_ci
1803e41f4b71Sopenharmony_cipaint(canvas: drawing.Canvas, x: number, y: number): void
1804e41f4b71Sopenharmony_ci
1805e41f4b71Sopenharmony_ciPaints this glyph run on the canvas with the coordinate point (x, y) as the upper left corner.
1806e41f4b71Sopenharmony_ci
1807e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1808e41f4b71Sopenharmony_ci
1809e41f4b71Sopenharmony_ci**Parameters**
1810e41f4b71Sopenharmony_ci
1811e41f4b71Sopenharmony_ci| Name| Type                                                 | Mandatory| Description                   |
1812e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ---------------------- |
1813e41f4b71Sopenharmony_ci| canvas | [drawing.Canvas](js-apis-graphics-drawing.md#canvas) | Yes  | Target canvas.     |
1814e41f4b71Sopenharmony_ci|    x   | number                                               | Yes  | X coordinate of the upper left corner. The value is a floating point number.|
1815e41f4b71Sopenharmony_ci|    y   | number                                               | Yes  | Y coordinate of the upper left corner. The value is a floating point number.|
1816e41f4b71Sopenharmony_ci
1817e41f4b71Sopenharmony_ci**Example**
1818e41f4b71Sopenharmony_ci
1819e41f4b71Sopenharmony_ci```ts
1820e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D'
1821e41f4b71Sopenharmony_ciimport { text } from "@kit.ArkGraphics2D"
1822e41f4b71Sopenharmony_ciimport { common2D } from "@kit.ArkGraphics2D"
1823e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
1824e41f4b71Sopenharmony_ci
1825e41f4b71Sopenharmony_cifunction textFunc() {
1826e41f4b71Sopenharmony_ci  const color: ArrayBuffer = new ArrayBuffer(160000);
1827e41f4b71Sopenharmony_ci  let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 200, width: 200 } }
1828e41f4b71Sopenharmony_ci  let pixelMap: image.PixelMap = image.createPixelMapSync(color, opts);
1829e41f4b71Sopenharmony_ci  let canvas = new drawing.Canvas(pixelMap);
1830e41f4b71Sopenharmony_ci  runs[0].paint(canvas, 0, 0);
1831e41f4b71Sopenharmony_ci}
1832e41f4b71Sopenharmony_ci
1833e41f4b71Sopenharmony_ci@Entry
1834e41f4b71Sopenharmony_ci@Component
1835e41f4b71Sopenharmony_cistruct Index {
1836e41f4b71Sopenharmony_ci  fun: Function = textFunc;
1837e41f4b71Sopenharmony_ci  build() {
1838e41f4b71Sopenharmony_ci    Column() {
1839e41f4b71Sopenharmony_ci      Button().onClick(() => {
1840e41f4b71Sopenharmony_ci        this.fun();
1841e41f4b71Sopenharmony_ci      })
1842e41f4b71Sopenharmony_ci    }
1843e41f4b71Sopenharmony_ci  }
1844e41f4b71Sopenharmony_ci}
1845e41f4b71Sopenharmony_ci```
1846