1e41f4b71Sopenharmony_ci# @ohos.measure (Text Measurement)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **measure** module provides APIs for measuring text metrics, such as text height and width.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci> 
9e41f4b71Sopenharmony_ci> Since API version 12, you can use the **getMeasureUtils** API in **UIContext** to obtain the [MeasureUtils](js-apis-arkui-UIContext.md#measureutils12)r object associated with the current UI context.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## Modules to Import
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci```ts
14e41f4b71Sopenharmony_ciimport { MeasureText } from '@kit.ArkUI'
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## MeasureText.measureText
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_cimeasureText(options: MeasureOptions): number
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciMeasures the width of the given single-line text.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**Parameters**
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci| Name    | Type                             | Mandatory  | Description       |
30e41f4b71Sopenharmony_ci| ------- | ------------------------------- | ---- | --------- |
31e41f4b71Sopenharmony_ci| options | [MeasureOptions](#measureoptions) | Yes   | Information about the measured text. |
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**Return value**
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci| Type         | Description      |
36e41f4b71Sopenharmony_ci| ------------  | --------- |
37e41f4b71Sopenharmony_ci| number        | Text width.<br>Unit: px |
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**Example**
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci```ts
43e41f4b71Sopenharmony_ciimport { MeasureText } from '@kit.ArkUI'
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci@Entry
46e41f4b71Sopenharmony_ci@Component
47e41f4b71Sopenharmony_cistruct Index {
48e41f4b71Sopenharmony_ci  @State textWidth: number = MeasureText.measureText({
49e41f4b71Sopenharmony_ci    textContent: "Hello word",
50e41f4b71Sopenharmony_ci    fontSize: '50px'
51e41f4b71Sopenharmony_ci  })
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci  build() {
54e41f4b71Sopenharmony_ci    Row() {
55e41f4b71Sopenharmony_ci      Column() {
56e41f4b71Sopenharmony_ci        Text(`The width of 'Hello World': ${this.textWidth}`)
57e41f4b71Sopenharmony_ci      }
58e41f4b71Sopenharmony_ci      .width('100%')
59e41f4b71Sopenharmony_ci    }
60e41f4b71Sopenharmony_ci    .height('100%')
61e41f4b71Sopenharmony_ci  }
62e41f4b71Sopenharmony_ci}
63e41f4b71Sopenharmony_ci```
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci## MeasureText.measureTextSize<sup>10+</sup>
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_cimeasureTextSize(options: MeasureOptions): SizeOptions
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ciMeasures the width and height of the given single-line text.
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci**Parameters**
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci| Name    | Type                             | Mandatory  | Description       |
78e41f4b71Sopenharmony_ci| ------- | ------------------------------- | ---- | --------- |
79e41f4b71Sopenharmony_ci| options | [MeasureOptions](#measureoptions) | Yes   | Information about the measured text. |
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci**Return value**
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci| Type         | Description      |
84e41f4b71Sopenharmony_ci| ------------  | --------- |
85e41f4b71Sopenharmony_ci| [SizeOptions](arkui-ts/ts-types.md#sizeoptions)  | Layout width and height occupied by the text.<br>**NOTE**<br>The return values for text width and height are both in px. |
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**Example**
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci```ts
91e41f4b71Sopenharmony_ciimport { MeasureText } from '@kit.ArkUI'
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci@Entry
94e41f4b71Sopenharmony_ci@Component
95e41f4b71Sopenharmony_cistruct Index {
96e41f4b71Sopenharmony_ci  textSize : SizeOptions = MeasureText.measureTextSize({
97e41f4b71Sopenharmony_ci    textContent: "Hello word",
98e41f4b71Sopenharmony_ci    fontSize: '50px'
99e41f4b71Sopenharmony_ci  })
100e41f4b71Sopenharmony_ci  build() {
101e41f4b71Sopenharmony_ci    Row() {
102e41f4b71Sopenharmony_ci      Column() {
103e41f4b71Sopenharmony_ci        Text(`The width of 'Hello World': ${this.textSize.width}`)
104e41f4b71Sopenharmony_ci        Text(`The height of 'Hello World': ${this.textSize.height}`)
105e41f4b71Sopenharmony_ci      }
106e41f4b71Sopenharmony_ci      .width('100%')
107e41f4b71Sopenharmony_ci    }
108e41f4b71Sopenharmony_ci    .height('100%')
109e41f4b71Sopenharmony_ci  }
110e41f4b71Sopenharmony_ci}
111e41f4b71Sopenharmony_ci```
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci## MeasureOptions
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ciProvides attributes of the measured text.
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci| Name          | Type                                                                                               | Mandatory | Description                     |
122e41f4b71Sopenharmony_ci| -------------- | -------------------------------------------------------------------------------------------------- | ---- | ----------------------------------------------- |
123e41f4b71Sopenharmony_ci| textContent | string \| [Resource](arkui-ts/ts-types.md#resource)                                                                                             | Yes  | Content of the measured text.                                 |
124e41f4b71Sopenharmony_ci| constraintWidth<sup>10+</sup> | number \| string \| [Resource](arkui-ts/ts-types.md#resource)   | No  | Layout width of the measured text.<br>**NOTE**<br>The default unit is vp. The value cannot be a percentage. If this parameter is not set, the value of **SizeOption** is the maximum width allowed for the single-line text.                            |
125e41f4b71Sopenharmony_ci| fontSize       | number \| string \| [Resource](arkui-ts/ts-types.md#resource)               | No  | Font size of the text to be measured. When **fontSize** is of the number type, the unit is vp.<br>Default value: **16**<br>**NOTE**<br>The value cannot be a percentage.<br>Since API version 12, the fp unit is used when **fontSize** is of the number type.   |
126e41f4b71Sopenharmony_ci| fontStyle      | number \| [FontStyle](arkui-ts/ts-appendix-enums.md#fontstyle)                        | No  | Font style of the measured text.<br>Default value: **FontStyle.Normal**           |
127e41f4b71Sopenharmony_ci| fontWeight     | number \| string \| [FontWeight](arkui-ts/ts-appendix-enums.md#fontweight)  | No  | Font width of the measured text. For the number type, the value ranges from 100 to 900, at an interval of 100. A larger value indicates a heavier font weight. The default value is **400**. For the string type, only strings of the number type are supported, for example, **400**, **"bold"**, **"bolder"**, **"lighter"**, **"regular"**, and **"medium"**, which correspond to the enumerated values in **FontWeight**.<br>Default value: **FontWeight.Normal**|
128e41f4b71Sopenharmony_ci| fontFamily     | string \| [Resource](arkui-ts/ts-types.md#resource)                                   | No  | Font family of the measured text. Default value: **'HarmonyOS Sans'**<br>Only the default font is supported.|
129e41f4b71Sopenharmony_ci| letterSpacing  | number \| string                                                                         | No  | Letter spacing of the measured text.|
130e41f4b71Sopenharmony_ci| textAlign<sup>10+</sup>  | number \| [TextAlign](arkui-ts/ts-appendix-enums.md#textalign)              | No  | Horizontal alignment mode of the measured text.<br>Default value: **TextAlign.Start**|
131e41f4b71Sopenharmony_ci| overflow<sup>10+</sup>  | number \| [TextOverflow](arkui-ts/ts-appendix-enums.md#textoverflow)         | No  | Display mode when the measured text is too long.|
132e41f4b71Sopenharmony_ci| maxLines<sup>10+</sup>  | number                                                                                    | No  | Maximum number of lines in the measured text.|
133e41f4b71Sopenharmony_ci| lineHeight<sup>10+</sup>  | number \| string \| [Resource](arkui-ts/ts-types.md#resource)    | No  | Line height of the measured text.|
134e41f4b71Sopenharmony_ci| baselineOffset<sup>10+</sup>  | number \| string                                                          | No  | Baseline offset of the measured text.<br>Default value: **0** |
135e41f4b71Sopenharmony_ci| textCase<sup>10+</sup>  | number \| [TextCase](arkui-ts/ts-appendix-enums.md#textcase)                 | No  | Case of the measured text.<br>Default value: **TextCase.Normal** |
136e41f4b71Sopenharmony_ci| textIndent<sup>11+</sup> | number \| string  | No | Indentation of the first line.<br>Default value: **0** |
137e41f4b71Sopenharmony_ci| wordBreak<sup>11+</sup> | [WordBreak](arkui-ts/ts-appendix-enums.md#wordbreak11) | No  | Line break rule.<br>Default value: **WordBreak.BREAK_WORD**<br>**NOTE**<br>When used with **{overflow: TextOverflow.Ellipsis}** and **maxLines**, **WordBreak.BREAK_ALL** can insert line breaks between letters when overflow occurs and display excess content with an ellipsis (...). |
138