public final class RubySpan extends ReplacementSpan


A span used to specify ruby text for a portion of the text.

The text covered by this span is known as the "base text", and the ruby text is stored in text.

Ruby text cannot be nested (i.e., ruby text cannot contain further ruby text). Ruby spans also cannot overlap each other.

More information on ruby characters and span styling.

This span is designed for use with VerticalTextLayout, media3-ui library, and a bit more general use cases.

Summary

Constants

static final float

Public constructors

RubySpan(
    @NonNull CharSequence text,
    @NonNull AnnotationPosition position,
    @NonNull TextOrientation orientation,
    float textScale
)

Public methods

void
draw(
    @NonNull Canvas canvas,
    CharSequence text,
    int start,
    int end,
    float x,
    int top,
    int y,
    int bottom,
    @NonNull Paint paint
)
final @NonNull TextOrientation

The text orientation of the ruby text.

final @NonNull AnnotationPosition

The position of ruby text relative to the base text.

int
getSize(
    @NonNull Paint paint,
    CharSequence text,
    int start,
    int end,
    Paint.FontMetricsInt fm
)
final @NonNull CharSequence

The ruby text to be displayed adjacent to the base text.

final float

The text scale ratio of the ruby text relative to the base text.

Constants

DEFAULT_TEXT_SCALE

public static final float DEFAULT_TEXT_SCALE = 0.5f

Public fields

DEFAULT_ORIENTATION

public static final @NonNull TextOrientation DEFAULT_ORIENTATION

DEFAULT_POSITION

public static final @NonNull AnnotationPosition DEFAULT_POSITION

Public constructors

RubySpan

Added in 1.0.0-alpha04
public RubySpan(
    @NonNull CharSequence text,
    @NonNull AnnotationPosition position,
    @NonNull TextOrientation orientation,
    float textScale
)

Public methods

draw

Added in 1.0.0-alpha04
public void draw(
    @NonNull Canvas canvas,
    CharSequence text,
    int start,
    int end,
    float x,
    int top,
    int y,
    int bottom,
    @NonNull Paint paint
)

getOrientation

Added in 1.0.0-alpha04
public final @NonNull TextOrientation getOrientation()

The text orientation of the ruby text. Defaults to TextOrientation.Mixed.

getPosition

Added in 1.0.0-alpha04
public final @NonNull AnnotationPosition getPosition()

The position of ruby text relative to the base text. Defaults to AnnotationPosition.Before.

getSize

Added in 1.0.0-alpha04
public int getSize(
    @NonNull Paint paint,
    CharSequence text,
    int start,
    int end,
    Paint.FontMetricsInt fm
)

getText

Added in 1.0.0-alpha04
public final @NonNull CharSequence getText()

The ruby text to be displayed adjacent to the base text.

getTextScale

Added in 1.0.0-alpha04
public final float getTextScale()

The text scale ratio of the ruby text relative to the base text. Defaults to 0.5f.