Paragraph

interface Paragraph
androidx.ui.text.Paragraph

A paragraph of text that is laid out.

Paragraphs can be displayed on a Canvas using the paint method.

Summary

Public methods

abstract TextDirection

Get the text direction of the character at the given offset.

abstract Rect

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

abstract Rect
getCursorRect(offset: Int)

Returns rectangle of the cursor area.

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

Compute the horizontal position where a newly inserted character at offset would be.

abstract Float
getLineBottom(lineIndex: Int)

Returns the bottom y coordinate of the given line.

abstract Int

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

abstract Float
getLineHeight(lineIndex: Int)

Returns the height of the given line.

abstract Float
getLineLeft(lineIndex: Int)

Returns the left x Coordinate of the given line.

abstract Float
getLineRight(lineIndex: Int)

Returns the right x Coordinate of the given line.

abstract Float
getLineWidth(lineIndex: Int)

Returns the width of the given line.

abstract Int

Returns the character offset closest to the given graphical position.

abstract TextDirection

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

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

Returns path that enclose the given text range.

abstract TextRange

Returns the TextRange of the word at the given character offset.

abstract Unit
paint(canvas: Canvas)

Paint the paragraph to canvas

Properties

abstract Boolean

True if there is more vertical content, but the text was truncated, either because we reached maxLines lines of text or because the maxLines was null, ellipsis was not null, and one of the lines exceeded the width constraint.

abstract Float

The distance from the top of the paragraph to the alphabetic baseline of the first line, in logical pixels.

abstract Float

The amount of vertical space this paragraph occupies.

abstract Float

The distance from the top of the paragraph to the alphabetic baseline of the last line, in logical pixels.

abstract Int

The total number of lines in the text.

abstract Float

Returns the smallest width beyond which increasing the width never decreases the height.

abstract Float

The width for text if all soft wrap opportunities were taken.

abstract Float

The amount of horizontal space this paragraph occupies.

Public methods

getBidiRunDirection

abstract fun getBidiRunDirection(offset: Int): TextDirection

Get the text direction of the character at the given offset.

getBoundingBox

abstract fun getBoundingBox(offset: Int): Rect

Returns the bounding box as Rect of the character for given character offset. Rect includes the top, bottom, left and right of a character.

getCursorRect

abstract fun getCursorRect(offset: Int): Rect

Returns rectangle of the cursor area.

getHorizontalPosition

abstract fun getHorizontalPosition(
    offset: Int,
    usePrimaryDirection: Boolean
): Float

Compute the horizontal position where a newly inserted character at offset would be.

If the inserted character at offset is within a LTR/RTL run, the returned position will be the left(right) edge of the character.

For example:
    Paragraph's direction is LTR.
    Text in logic order:               L0 L1 L2 R3 R4 R5
    Text in visual order:              L0 L1 L2 R5 R4 R3
        position of the offset(2):          |
        position of the offset(4):                   |

However, when the offset is at the BiDi transition offset, there will be two possible visual positions, which depends on the direction of the inserted character.

For example:
    Paragraph's direction is LTR.
    Text in logic order:               L0 L1 L2 R3 R4 R5
    Text in visual order:              L0 L1 L2 R5 R4 R3
        position of the offset(3):             |           (The inserted character is LTR)
                                                        |  (The inserted character is RTL)

In this case, usePrimaryDirection will be used to resolve the ambiguity. If true, the inserted character's direction is assumed to be the same as Paragraph's direction. Otherwise, the inserted character's direction is assumed to be the opposite of the Paragraph's direction.

For example:
    Paragraph's direction is LTR.
    Text in logic order:               L0 L1 L2 R3 R4 R5
    Text in visual order:              L0 L1 L2 R5 R4 R3
        position of the offset(3):             |           (usePrimaryDirection is true)
                                                        |  (usePrimaryDirection is false)

This method is useful to compute cursor position.

Parameters
offset: Int the offset of the character, in the range of 0,length.
usePrimaryDirection: Boolean whether the paragraph direction is respected when offset points to a BiDi transition point.
Return
a float number representing the horizontal position in the unit of pixel.

getLineBottom

abstract fun getLineBottom(lineIndex: Int): Float

Returns the bottom y coordinate of the given line.

getLineForOffset

abstract 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.

getLineHeight

abstract fun getLineHeight(lineIndex: Int): Float

Returns the height of the given line.

getLineLeft

abstract fun getLineLeft(lineIndex: Int): Float

Returns the left x Coordinate of the given line.

getLineRight

abstract fun getLineRight(lineIndex: Int): Float

Returns the right x Coordinate of the given line.

getLineWidth

abstract fun getLineWidth(lineIndex: Int): Float

Returns the width of the given line.

getOffsetForPosition

abstract fun getOffsetForPosition(position: PxPosition): Int

Returns the character offset closest to the given graphical position.

getParagraphDirection

abstract fun getParagraphDirection(offset: Int): TextDirection

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

getPathForRange

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

Returns path that enclose the given text range.

getWordBoundary

abstract fun getWordBoundary(offset: Int): TextRange

Returns the TextRange 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 TextRange(offset, offset+1). Word boundaries are defined more precisely in Unicode Standard Annex #29 http://www.unicode.org/reports/tr29/#Word_Boundaries

paint

abstract fun paint(canvas: Canvas): Unit

Paint the paragraph to canvas

Properties

didExceedMaxLines

abstract val didExceedMaxLines: Boolean

True if there is more vertical content, but the text was truncated, either because we reached maxLines lines of text or because the maxLines was null, ellipsis was not null, and one of the lines exceeded the width constraint.

See the discussion of the maxLines and ellipsis arguments at ParagraphStyle.

Should be called after layout has been called.

firstBaseline

abstract val firstBaseline: Float

The distance from the top of the paragraph to the alphabetic baseline of the first line, in logical pixels.

Should be called after layout has been called.

height

abstract val height: Float

The amount of vertical space this paragraph occupies.

Should be called after layout has been called.

lastBaseline

abstract val lastBaseline: Float

The distance from the top of the paragraph to the alphabetic baseline of the last line, in logical pixels.

Should be called after layout has been called.

lineCount

abstract val lineCount: Int

The total number of lines in the text.

Should be called after layout has been called.

maxIntrinsicWidth

abstract val maxIntrinsicWidth: Float

Returns the smallest width beyond which increasing the width never decreases the height.

minIntrinsicWidth

abstract val minIntrinsicWidth: Float

The width for text if all soft wrap opportunities were taken.

width

abstract val width: Float

The amount of horizontal space this paragraph occupies.

Should be called after layout has been called.