Builder
class Builder
The builder class to create a TextBoundsInfo
object.
Summary
Public constructors
Builder
Builder(
start: Int,
end: Int)
Create a builder for TextBoundsInfo
.
Exceptions |
java.lang.IllegalArgumentException |
if the given start or end is negative, or end is smaller than the start . |
Public methods
build
fun build(): TextBoundsInfo
Create the TextBoundsInfo
using the parameters in this Builder
.
Exceptions |
java.lang.IllegalStateException |
in the following conditions:
- if the
start or end is not set.
- if the
matrix is not set.
- if
characterBounds is not set or its length doesn't equal to 4 * (end - start ).
- if the
characterFlags is not set or its length doesn't equal to (end - start ).
- if
graphemeSegmentFinder , wordSegmentFinder or lineSegmentFinder is not set.
- if characters in the same line has inconsistent
FLAG_LINE_IS_RTL flag.
|
setCharacterBidiLevel
fun setCharacterBidiLevel(characterBidiLevels: IntArray): TextBoundsInfo.Builder
Set the BiDi levels for the character. The bidiLevel of the i-th character in the editor is stored at index (i - start). The length of the given array must equal to (end - start).
BiDi level is defined by the unicode bidirectional algorithm . One can determine whether a character's direction is right-to-left (RTL) or left-to-right (LTR) by checking the last bit of the BiDi level. If it's 1, the character is RTL, otherwise the character is LTR. The BiDi level of a character must be in the range of [0, 125].
Parameters |
characterBidiLevels |
IntArray: the array of the character's BiDi level. This value cannot be null . |
Exceptions |
java.lang.NullPointerException |
if the given characterBidiLevels is null . |
java.lang.IllegalArgumentException |
if the given characterBidiLevels contains an element that's out of the range [0, 125]. |
setCharacterBounds
fun setCharacterBounds(characterBounds: FloatArray): TextBoundsInfo.Builder
Set the characters bounds, in the coordinates of the editor.
The given array should be divided into groups of four where each element represents left, top, right and bottom of the character bounds respectively. The bounds of the i-th character in the editor should be stored at index 4 * (i - start). The length of the given array must equal to 4 * (end - start).
Sometimes multiple characters in a single grapheme are rendered as one symbol on the screen. So those characters only have one shared bounds. In this case, we recommend the editor to assign all the width to the bounds of the first character in the grapheme, and make the rest characters' bounds zero-width.
For example, the string "'0xD83D' '0xDE00'" is rendered as one grapheme - a grinning face emoji. If the bounds of the grapheme is: Rect(5, 10, 15, 20), the character bounds of the string should be: [ Rect(5, 10, 15, 20), Rect(15, 10, 15, 20) ].
Parameters |
characterBounds |
FloatArray: the array of the flattened character bounds. This value cannot be null . |
Exceptions |
java.lang.NullPointerException |
if the given characterBounds is null . |
setCharacterFlags
fun setCharacterFlags(characterFlags: IntArray): TextBoundsInfo.Builder
Set the flags of the characters. The flags of the i-th character in the editor is stored at index (i - start). The length of the given array must equal to (end - start). The flags contain the following information:
Parameters |
characterFlags |
IntArray: the array of the character's flags. This value cannot be null . |
Exceptions |
java.lang.NullPointerException |
if the given characterFlags is null . |
java.lang.IllegalArgumentException |
if the given characterFlags contains invalid flags. |
setGraphemeSegmentFinder
fun setGraphemeSegmentFinder(graphemeSegmentFinder: SegmentFinder): TextBoundsInfo.Builder
Set the SegmentFinder
that locates the grapheme cluster boundaries. Grapheme is defined in the unicode annex #29: unicode text segmentation. It's a user-perspective character. And it's usually the minimal unit for selection, backspace, deletion etc.
Please note that only the grapheme segments within the range from start to end will be available to the IME. The remaining information will be discarded during serialization for better performance.
Parameters |
graphemeSegmentFinder |
SegmentFinder: the SegmentFinder that locates the grapheme cluster boundaries. This value cannot be null . |
Exceptions |
java.lang.NullPointerException |
if the given graphemeSegmentFinder is null . |
setLineSegmentFinder
fun setLineSegmentFinder(lineSegmentFinder: SegmentFinder): TextBoundsInfo.Builder
Set the SegmentFinder
that locates the line boundaries. Aside from the hard breaks in the text, it should also locate the soft line breaks added by the editor. It is expected that the characters within the same line is rendered on the same baseline. (Except for some text formatted as subscript and superscript.)
Please note that only the line segments within the range from start to end will be available to the IME. The remaining information will be discarded during serialization for better performance.
Exceptions |
java.lang.NullPointerException |
if the given lineSegmentFinder is null . |
setMatrix
fun setMatrix(matrix: Matrix): TextBoundsInfo.Builder
Sets the matrix that transforms local coordinates into screen coordinates.
Parameters |
matrix |
Matrix: transformation matrix from local coordinates into screen coordinates. This value cannot be null . |
Exceptions |
java.lang.NullPointerException |
if the given matrix is null . |
setStartAndEnd
fun setStartAndEnd(
start: Int,
end: Int
): TextBoundsInfo.Builder
Set the start and end index of the TextBoundsInfo
. It's the range of the characters whose information is available in the TextBoundsInfo
.
Parameters |
start |
Int: the start index of the TextBoundsInfo , inclusive. Value is 0 or greater |
end |
Int: the end index of the TextBoundsInfo , exclusive. Value is 0 or greater |
Exceptions |
java.lang.IllegalArgumentException |
if the given start or end is negative, or end is smaller than the start . |
setWordSegmentFinder
fun setWordSegmentFinder(wordSegmentFinder: SegmentFinder): TextBoundsInfo.Builder
Set the SegmentFinder
that locates the word boundaries.
Please note that only the word segments within the range from start to end will be available to the IME. The remaining information will be discarded during serialization for better performance.
Exceptions |
java.lang.NullPointerException |
if the given wordSegmentFinder is null . |