The second Android 11 Developer Preview is now available, test it out and share your feedback.

TextLayoutResult

data class TextLayoutResult
kotlin.Any
   ↳ androidx.ui.text.TextLayoutResult

The data class which holds text layout result.

Summary

Public methods

TextDirection

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

Rect

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

Rect
getCursorRect(offset: Int)

Returns the rectangle of the cursor area

Px
getHorizontalPosition(offset: Int, usePrimaryDirection: Boolean)

Get the horizontal position for the specified text offset.

Px
getLineBottom(lineIndex: Int)

Returns the bottom y coordinate of the given line.

Int

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

Int

Returns the character offset closest to the given graphical position.

TextDirection

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

Path
getPathForRange(start: Int, end: Int)

Returns path that enclose the given text range.

TextRange

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

Properties

Boolean

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

Boolean

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

Px

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

Boolean

Returns true if either vertical overflow or horizontal overflow happens.

Px

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

TextLayoutInput

The parameters used for computing this text layout result.

IntPxSize

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

Public methods

getBidiRunDirection

fun getBidiRunDirection(offset: Int): TextDirection

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

Parameters
offset: Int a character offset
Return
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
Return
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
Return
a rectangle of cursor region

getHorizontalPosition

fun getHorizontalPosition(
    offset: Int,
    usePrimaryDirection: Boolean
): Px

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.
Return
the relative distance from the text starting edge.

getLineBottom

fun getLineBottom(lineIndex: Int): Px

Returns the bottom y coordinate of the given line.

Parameters
lineIndex: Int the line number
Return
the line bottom y coordinate

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
Return
the 0 origin line number.

getOffsetForPosition

fun getOffsetForPosition(position: PxPosition): Int

Returns the character offset closest to the given graphical position.

Parameters
position: PxPosition a graphical position in this text layout
Return
a character offset that is closest to the given graphical position.

getParagraphDirection

fun getParagraphDirection(offset: Int): TextDirection

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

Parameters
offset: Int a character offset
Return
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
Return
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 <_>.

Properties

didOverflowHeight

val didOverflowHeight: Boolean

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

didOverflowWidth

val didOverflowWidth: Boolean

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

firstBaseline

val firstBaseline: Px

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

hasVisualOverflow

val hasVisualOverflow: Boolean

Returns true if either vertical overflow or horizontal overflow happens.

lastBaseline

val lastBaseline: Px

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

layoutInput

val layoutInput: TextLayoutInput

The parameters used for computing this text layout result.

size

val size: IntPxSize

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