TextLayoutResult


The data class which holds text layout result.

Summary

Public constructors

TextLayoutResult(
    layoutInput: TextLayoutInput,
    multiParagraph: MultiParagraph,
    size: IntSize
)
Cmn

Public functions

TextLayoutResult
copy(layoutInput: TextLayoutInput, size: IntSize)
Cmn
open operator Boolean
equals(other: Any?)
Cmn
ResolvedTextDirection

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

Cmn
Rect

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

Cmn
Rect
getCursorRect(offset: Int)

Returns the rectangle of the cursor area

Cmn
Float
getHorizontalPosition(offset: Int, usePrimaryDirection: Boolean)

Get the horizontal position for the specified text offset.

Cmn
Float
getLineBaseline(lineIndex: Int)

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

Cmn
Float
getLineBottom(lineIndex: Int)

Returns the bottom y coordinate of the given line.

Cmn
Int
getLineEnd(lineIndex: Int, visibleEnd: Boolean)

Returns the end offset of the given line.

Cmn
Int

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

Cmn
Int

Returns line number closest to the given graphical vertical position.

Cmn
Float
getLineLeft(lineIndex: Int)

Returns the left x coordinate of the given line.

Cmn
Float
getLineRight(lineIndex: Int)

Returns the right x coordinate of the given line.

Cmn
Int
getLineStart(lineIndex: Int)

Returns the start offset of the given line, inclusive.

Cmn
Float
getLineTop(lineIndex: Int)

Returns the top y coordinate of the given line.

Cmn
Int

Returns the character offset closest to the given graphical position.

Cmn
ResolvedTextDirection

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

Cmn
Path
getPathForRange(start: Int, end: Int)

Returns path that enclose the given text range.

Cmn
TextRange

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

Cmn
open Int
Cmn
Boolean
isLineEllipsized(lineIndex: Int)

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

Cmn
open String
Cmn

Public properties

Boolean

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

Cmn
Boolean

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

Cmn
Float

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

Cmn
Boolean

Returns true if either vertical overflow or horizontal overflow happens.

Cmn
Float

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

Cmn
TextLayoutInput

The parameters used for computing this text layout result.

Cmn
Int

Returns a number of lines of this text layout

Cmn
MultiParagraph

The multi paragraph object.

Cmn
List<Rect?>

Returns a list of bounding boxes that is reserved for TextLayoutInput.placeholders.

Cmn
IntSize

The amount of space required to paint this text in Int.

Cmn

Public constructors

TextLayoutResult

TextLayoutResult(
    layoutInput: TextLayoutInput,
    multiParagraph: MultiParagraph,
    size: IntSize
)

Public functions

copy

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

equals

open operator fun equals(other: Any?): Boolean

getBidiRunDirection

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: Int

a character offset

Returns
ResolvedTextDirection

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

getBoundingBox

fun getBoundingBox(offset: Int): Rect

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

Parameters
offset: Int

a character offset

Returns
Rect

a bounding box for the character in pixels.

getCursorRect

fun getCursorRect(offset: Int): Rect

Returns the rectangle of the cursor area

Parameters
offset: Int

An character offset of the cursor

Returns
Rect

a rectangle of cursor region

getHorizontalPosition

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: Int

a character offset

usePrimaryDirection: Boolean

true for using the primary run's coordinate if the given offset is in the BiDi directional transition point.

Returns
Float

the relative distance from the text starting edge.

getLineBaseline

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.

getLineBottom

fun getLineBottom(lineIndex: Int): Float

Returns the bottom y coordinate of the given line.

Parameters
lineIndex: Int

the line number

Returns
Float

the line bottom y coordinate

getLineEnd

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

┌────┐
│abcd│
│efg │
└────┘

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: Int

the line number

visibleEnd: Boolean = false

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
Int

an exclusive end offset of the line.

getLineForOffset

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: Int

a character offset

Returns
Int

the 0 origin line number.

getLineForVerticalPosition

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: Float

the vertical position

Returns
Int

the 0 origin line number.

getLineLeft

fun getLineLeft(lineIndex: Int): Float

Returns the left x coordinate of the given line.

Parameters
lineIndex: Int

the line number

Returns
Float

the line left x coordinate

getLineRight

fun getLineRight(lineIndex: Int): Float

Returns the right x coordinate of the given line.

Parameters
lineIndex: Int

the line number

Returns
Float

the line right x coordinate

getLineStart

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

┌────┐
│abcd│
│efg │
└────┘
Parameters
lineIndex: Int

the line number

Returns
Int

the start offset of the line

getLineTop

fun getLineTop(lineIndex: Int): Float

Returns the top y coordinate of the given line.

Parameters
lineIndex: Int

the line number

Returns
Float

the line top y coordinate

getOffsetForPosition

fun getOffsetForPosition(position: Offset): Int

Returns the character offset closest to the given graphical position.

Parameters
position: Offset

a graphical position in this text layout

Returns
Int

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

getParagraphDirection

fun getParagraphDirection(offset: Int): ResolvedTextDirection

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

Parameters
offset: Int

a character offset

Returns
ResolvedTextDirection

the paragraph direction

getPathForRange

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

Returns path that enclose the given text range.

Parameters
start: Int

an inclusive start character offset

end: Int

an exclusive end character offset

Returns
Path

a drawing path

getWordBoundary

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.

hashCode

open fun hashCode(): Int

isLineEllipsized

fun isLineEllipsized(lineIndex: Int): Boolean

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

Parameters
lineIndex: Int

a 0 based line index

Returns
Boolean

true if the given line is ellipsized, otherwise false

toString

open fun toString(): String

Public properties

didOverflowHeight

val didOverflowHeightBoolean

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

didOverflowWidth

val didOverflowWidthBoolean

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

firstBaseline

val firstBaselineFloat

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

hasVisualOverflow

val hasVisualOverflowBoolean

Returns true if either vertical overflow or horizontal overflow happens.

lastBaseline

val lastBaselineFloat

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

layoutInput

val layoutInputTextLayoutInput

The parameters used for computing this text layout result.

lineCount

val lineCountInt

Returns a number of lines of this text layout

multiParagraph

val multiParagraphMultiParagraph

The multi paragraph object.

This is the result of the text layout computation.

placeholderRects

val placeholderRectsList<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.

size

val sizeIntSize

The amount of space required to paint this text in Int.