---
title: "TextLayoutResult"
description: "The data class which holds text layout result."
type: "class"
---

<div class='type'>Class</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
class TextLayoutResult
constructor(
    /** The parameters used for computing this text layout result. */
    val layoutInput: TextLayoutInput,

    /**
     * The multi paragraph object.
     *
     * This is the result of the text layout computation.
     */
    val multiParagraph: MultiParagraph,

    /** The amount of space required to paint this text in Int. */
    val size: IntSize,
)
```


The data class which holds text layout result.


## Properties

<div class='sourceset sourceset-common'>Common</div>


```kotlin
val firstBaseline: Float
```


The distance from the top to the alphabetic baseline of the first line.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
val lastBaseline: Float
```


The distance from the top to the alphabetic baseline of the last line.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
val didOverflowHeight: Boolean
```


Returns true if the text is too tall and couldn't fit with given height.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
val didOverflowWidth: Boolean
```


Returns true if the text is too wide and couldn't fit with given width.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
val hasVisualOverflow: Boolean
```


Returns true if either vertical overflow or horizontal overflow happens.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
val placeholderRects: List<Rect?>
```


Returns a list of bounding boxes that is reserved for `TextLayoutInput.placeholders`. Each
`Rect` in this list corresponds to the `Placeholder` passed to `TextLayoutInput.placeholders`
and it will have the height and width specified in the `Placeholder`. It's guaranteed that
`TextLayoutInput.placeholders` and `TextLayoutResult.placeholderRects` will have same length
and order.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
val lineCount: Int
```


Returns a number of lines of this text layout



## Functions

```kotlin
fun getLineStart(lineIndex: Int): Int
```


Returns the start offset of the given line, inclusive.

The start offset represents a position in text before the first character in the given line.
For example, `getLineStart(1)` will return 4 for the text below
<pre>
┌────┐
│abcd│
│efg │
└────┘
</pre>

#### Parameters

| | |
| --- | --- |
| lineIndex | the line number |


#### Returns

| | |
| --- | --- |
|  | the start offset of the line |



```kotlin
fun getLineEnd(lineIndex: Int, visibleEnd: Boolean = false): Int
```


Returns the end offset of the given line.

The end offset represents a position in text after the last character in the given line. For
example, `getLineEnd(0)` will return 4 for the text below
<pre>
┌────┐
│abcd│
│efg │
└────┘
</pre>

Characters being ellipsized are treated as invisible characters. So that if visibleEnd is
false, it will return line end including the ellipsized characters and vice versa.

#### Parameters

| | |
| --- | --- |
| lineIndex | the line number |
| visibleEnd | if true, the returned line end will not count trailing whitespaces or linefeed characters. Otherwise, this function will return the logical line end. By default it's false. |


#### Returns

| | |
| --- | --- |
|  | an exclusive end offset of the line. |



```kotlin
fun isLineEllipsized(lineIndex: Int): Boolean
```


Returns true if the given line is ellipsized, otherwise returns false.

#### Parameters

| | |
| --- | --- |
| lineIndex | a 0 based line index |


#### Returns

| | |
| --- | --- |
|  | true if the given line is ellipsized, otherwise false |



```kotlin
fun getLineTop(lineIndex: Int): Float
```


Returns the top y coordinate of the given line.

#### Parameters

| | |
| --- | --- |
| lineIndex | the line number |


#### Returns

| | |
| --- | --- |
|  | the line top y coordinate |



```kotlin
fun getLineBaseline(lineIndex: Int): Float
```


Returns the distance in pixels from the top of the text layout to the alphabetic baseline of
the line at index `lineIndex`.


```kotlin
fun getLineBottom(lineIndex: Int): Float
```


Returns the bottom y coordinate of the given line.

#### Parameters

| | |
| --- | --- |
| lineIndex | the line number |


#### Returns

| | |
| --- | --- |
|  | the line bottom y coordinate |



```kotlin
fun getLineLeft(lineIndex: Int): Float
```


Returns the left x coordinate of the given line.

#### Parameters

| | |
| --- | --- |
| lineIndex | the line number |


#### Returns

| | |
| --- | --- |
|  | the line left x coordinate |



```kotlin
fun getLineRight(lineIndex: Int): Float
```


Returns the right x coordinate of the given line.

#### Parameters

| | |
| --- | --- |
| lineIndex | the line number |


#### Returns

| | |
| --- | --- |
|  | the line right x coordinate |



```kotlin
fun getLineForOffset(offset: Int): Int
```


Returns the line number on which the specified text offset appears.

If you ask for a position before 0, you get 0; if you ask for a position beyond the end of
the text, you get the last line.

#### Parameters

| | |
| --- | --- |
| offset | a character offset |


#### Returns

| | |
| --- | --- |
|  | the 0 origin line number. |



```kotlin
fun getLineForVerticalPosition(vertical: Float): Int
```


Returns line number closest to the given graphical vertical position.

If you ask for a vertical position before 0, you get 0; if you ask for a vertical position
beyond the last line, you get the last line.

#### Parameters

| | |
| --- | --- |
| vertical | the vertical position |


#### Returns

| | |
| --- | --- |
|  | the 0 origin line number. |



```kotlin
fun getHorizontalPosition(offset: Int, usePrimaryDirection: Boolean): Float
```


Get the horizontal position for the specified text `offset`.

Returns the relative distance from the text starting offset. For example, if the paragraph
direction is Left-to-Right, this function returns positive value as a distance from the
left-most edge. If the paragraph direction is Right-to-Left, this function returns negative
value as a distance from the right-most edge.

`usePrimaryDirection` argument is taken into account only when the offset is in the BiDi
directional transition point. `usePrimaryDirection` is true means use the primary direction
run's coordinate, and use the secondary direction's run's coordinate if false.

#### Parameters

| | |
| --- | --- |
| offset | a character offset |
| usePrimaryDirection | true for using the primary run's coordinate if the given offset is in the BiDi directional transition point. |


#### Returns

| | |
| --- | --- |
|  | the relative distance from the text starting edge. |



```kotlin
fun getParagraphDirection(offset: Int): ResolvedTextDirection
```


Get the text direction of the paragraph containing the given offset.

#### Parameters

| | |
| --- | --- |
| offset | a character offset |


#### Returns

| | |
| --- | --- |
|  | the paragraph direction |



```kotlin
fun getBidiRunDirection(offset: Int): ResolvedTextDirection
```


Get the text direction of the resolved BiDi run that the character at the given offset
associated with.

#### Parameters

| | |
| --- | --- |
| offset | a character offset |


#### Returns

| | |
| --- | --- |
|  | the direction of the BiDi run of the given character offset. |



```kotlin
fun getOffsetForPosition(position: Offset): Int
```


Returns the character offset closest to the given graphical position.

#### Parameters

| | |
| --- | --- |
| position | a graphical position in this text layout |


#### Returns

| | |
| --- | --- |
|  | a character offset that is closest to the given graphical position. |



```kotlin
fun getBoundingBox(offset: Int): Rect
```


Returns the bounding box of the character for given character offset.

#### Parameters

| | |
| --- | --- |
| offset | a character offset |


#### Returns

| | |
| --- | --- |
|  | a bounding box for the character in pixels. |



```kotlin
fun getWordBoundary(offset: Int): TextRange
```


Returns the text range of the word at the given character offset.

Characters not part of a word, such as spaces, symbols, and punctuation, have word breaks on
both sides. In such cases, this method will return a text range that contains the given
character offset.

Word boundaries are defined more precisely in Unicode Standard Annex #29
<http://www.unicode.org/reports/tr29/#Word_Boundaries>.


```kotlin
fun getCursorRect(offset: Int): Rect
```


Returns the rectangle of the cursor area

#### Parameters

| | |
| --- | --- |
| offset | An character offset of the cursor |


#### Returns

| | |
| --- | --- |
|  | a rectangle of cursor region |



```kotlin
fun getPathForRange(start: Int, end: Int): Path
```


Returns path that enclose the given text range.

#### Parameters

| | |
| --- | --- |
| start | an inclusive start character offset |
| end | an exclusive end character offset |


#### Returns

| | |
| --- | --- |
|  | a drawing path |



```kotlin
fun copy(
        layoutInput: TextLayoutInput = this.layoutInput,
        size: IntSize = this.size,
    ): TextLayoutResult
```


