{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

TextLayoutResult

public final class TextLayoutResult


The data class which holds text layout result.

Summary

Public constructors

TextLayoutResult(
    @NonNull TextLayoutInput layoutInput,
    @NonNull MultiParagraph multiParagraph,
    @NonNull IntSize size
)

Public methods

final @NonNull TextLayoutResult
copy(@NonNull TextLayoutInput layoutInput, @NonNull IntSize size)
boolean
equals(Object other)
final @NonNull ResolvedTextDirection
getBidiRunDirection(int offset)

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

final @NonNull Rect
getBoundingBox(int offset)

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

final @NonNull Rect
getCursorRect(int offset)

Returns the rectangle of the cursor area

final boolean

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

final boolean

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

final float

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

final boolean

Returns true if either vertical overflow or horizontal overflow happens.

final float
getHorizontalPosition(int offset, boolean usePrimaryDirection)

Get the horizontal position for the specified text offset.

final float

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

final @NonNull TextLayoutInput

The parameters used for computing this text layout result.

final float
getLineBottom(int lineIndex)

Returns the bottom y coordinate of the given line.

final int

Returns a number of lines of this text layout

final int
getLineEnd(int lineIndex, boolean visibleEnd)

Returns the end offset of the given line.

final int
getLineForOffset(int offset)

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

final int

Returns line number closest to the given graphical vertical position.

final float
getLineLeft(int lineIndex)

Returns the left x coordinate of the given line.

final float
getLineRight(int lineIndex)

Returns the right x coordinate of the given line.

final int
getLineStart(int lineIndex)

Returns the start offset of the given line, inclusive.

final float
getLineTop(int lineIndex)

Returns the top y coordinate of the given line.

final @NonNull MultiParagraph

The multi paragraph object.

final int

Returns the character offset closest to the given graphical position.

final @NonNull ResolvedTextDirection

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

final @NonNull Path
getPathForRange(int start, int end)

Returns path that enclose the given text range.

final @NonNull List<Rect>

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

final @NonNull IntSize

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

final @NonNull TextRange
getWordBoundary(int offset)

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

int
final boolean
isLineEllipsized(int lineIndex)

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

@NonNull String

Public constructors

TextLayoutResult

public TextLayoutResult(
    @NonNull TextLayoutInput layoutInput,
    @NonNull MultiParagraph multiParagraph,
    @NonNull IntSize size
)

Public methods

copy

public final @NonNull TextLayoutResult copy(@NonNull TextLayoutInput layoutInput, @NonNull IntSize size)

equals

public boolean equals(Object other)

getBidiRunDirection

public final @NonNull ResolvedTextDirection getBidiRunDirection(int offset)

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

Parameters
int offset

a character offset

Returns
@NonNull ResolvedTextDirection

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

getBoundingBox

public final @NonNull Rect getBoundingBox(int offset)

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

Parameters
int offset

a character offset

Returns
@NonNull Rect

a bounding box for the character in pixels.

getCursorRect

public final @NonNull Rect getCursorRect(int offset)

Returns the rectangle of the cursor area

Parameters
int offset

An character offset of the cursor

Returns
@NonNull Rect

a rectangle of cursor region

getDidOverflowHeight

public final boolean getDidOverflowHeight()

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

getDidOverflowWidth

public final boolean getDidOverflowWidth()

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

getFirstBaseline

public final float getFirstBaseline()

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

getHasVisualOverflow

public final boolean getHasVisualOverflow()

Returns true if either vertical overflow or horizontal overflow happens.

getHorizontalPosition

public final float getHorizontalPosition(int offset, boolean usePrimaryDirection)

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
int offset

a character offset

boolean usePrimaryDirection

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.

getLastBaseline

public final float getLastBaseline()

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

getLayoutInput

public final @NonNull TextLayoutInput getLayoutInput()

The parameters used for computing this text layout result.

getLineBottom

public final float getLineBottom(int lineIndex)

Returns the bottom y coordinate of the given line.

Parameters
int lineIndex

the line number

Returns
float

the line bottom y coordinate

getLineCount

public final int getLineCount()

Returns a number of lines of this text layout

getLineEnd

public final int getLineEnd(int lineIndex, boolean visibleEnd)

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
int lineIndex

the line number

boolean 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
int

an exclusive end offset of the line.

getLineForOffset

public final int getLineForOffset(int offset)

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
int offset

a character offset

Returns
int

the 0 origin line number.

getLineForVerticalPosition

public final int getLineForVerticalPosition(float vertical)

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
float vertical

the vertical position

Returns
int

the 0 origin line number.

getLineLeft

public final float getLineLeft(int lineIndex)

Returns the left x coordinate of the given line.

Parameters
int lineIndex

the line number

Returns
float

the line left x coordinate

getLineRight

public final float getLineRight(int lineIndex)

Returns the right x coordinate of the given line.

Parameters
int lineIndex

the line number

Returns
float

the line right x coordinate

getLineStart

public final int getLineStart(int lineIndex)

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
int lineIndex

the line number

Returns
int

the start offset of the line

getLineTop

public final float getLineTop(int lineIndex)

Returns the top y coordinate of the given line.

Parameters
int lineIndex

the line number

Returns
float

the line top y coordinate

getMultiParagraph

public final @NonNull MultiParagraph getMultiParagraph()

The multi paragraph object.

This is the result of the text layout computation.

getOffsetForPosition

public final int getOffsetForPosition(@NonNull Offset position)

Returns the character offset closest to the given graphical position.

Parameters
@NonNull Offset position

a graphical position in this text layout

Returns
int

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

getParagraphDirection

public final @NonNull ResolvedTextDirection getParagraphDirection(int offset)

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

Parameters
int offset

a character offset

Returns
@NonNull ResolvedTextDirection

the paragraph direction

getPathForRange

public final @NonNull Path getPathForRange(int start, int end)

Returns path that enclose the given text range.

Parameters
int start

an inclusive start character offset

int end

an exclusive end character offset

Returns
@NonNull Path

a drawing path

getPlaceholderRects

public final @NonNull List<RectgetPlaceholderRects()

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.

getSize

public final @NonNull IntSize getSize()

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

getWordBoundary

public final @NonNull TextRange getWordBoundary(int offset)

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

public int hashCode()

isLineEllipsized

public final boolean isLineEllipsized(int lineIndex)

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

Parameters
int lineIndex

a 0 based line index

Returns
boolean

true if the given line is ellipsized, otherwise false

toString

public @NonNull String toString()