# RubySpan

Artifact: [androidx.text:text-vertical](https://developer.android.com/jetpack/androidx/releases/text) [View Source](https://cs.android.com/search?q=file:androidx/text/vertical/RubySpan.kt+class:androidx.text.vertical.RubySpan) Added in [1.0.0-beta03](https://developer.android.com/jetpack/androidx/releases/text#1.0.0-beta03)

*** ** * ** ***


```
public final class RubySpan extends ReplacementSpan
```

<br />

|---|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||||
| ↳ | [android.text.style.CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html) ||||
|   | ↳ | [android.text.style.MetricAffectingSpan](https://developer.android.com/reference/android/text/style/MetricAffectingSpan.html) |||
|   |   | ↳ | [android.text.style.ReplacementSpan](https://developer.android.com/reference/android/text/style/ReplacementSpan.html) ||
|   |   |   | ↳ | [androidx.text.vertical.RubySpan](https://developer.android.com/reference/androidx/text/vertical/RubySpan) |

*** ** * ** ***

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 `https://developer.android.com/reference/androidx/text/vertical/RubySpan#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](https://en.wikipedia.org/wiki/Ruby_character) and [span styling](https://developer.android.com/guide/topics/text/spans).

This span is designed for use with `https://developer.android.com/reference/androidx/text/vertical/VerticalTextLayout` and also other general use cases.

## Summary

| ### Constants |
|---|---|
| `static final float` | `https://developer.android.com/reference/androidx/text/vertical/RubySpan#DEFAULT_TEXT_SCALE() = 0.5f` |

| ### Public fields |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/text/vertical/TextOrientation` | `https://developer.android.com/reference/androidx/text/vertical/RubySpan#DEFAULT_ORIENTATION()` |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/text/vertical/AnnotationPosition` | `https://developer.android.com/reference/androidx/text/vertical/RubySpan#DEFAULT_POSITION()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/text/vertical/RubySpan#RubySpan(kotlin.CharSequence,androidx.text.vertical.AnnotationPosition,androidx.text.vertical.TextOrientation,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html text, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/text/vertical/AnnotationPosition position, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/text/vertical/TextOrientation orientation, float textScale )` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/text/vertical/RubySpan#draw(android.graphics.Canvas,kotlin.CharSequence,kotlin.Int,kotlin.Int,kotlin.Float,kotlin.Int,kotlin.Int,kotlin.Int,android.graphics.Paint)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Canvas.html canvas, https://developer.android.com/reference/java/lang/CharSequence.html text, int start, int end, float x, int top, int y, int bottom, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Paint.html paint )` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/text/vertical/TextOrientation` | `https://developer.android.com/reference/androidx/text/vertical/RubySpan#getOrientation()()` The text orientation of the ruby text. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/text/vertical/AnnotationPosition` | `https://developer.android.com/reference/androidx/text/vertical/RubySpan#getPosition()()` The position of ruby text relative to the base text. |
| `int` | `https://developer.android.com/reference/androidx/text/vertical/RubySpan#getSize(android.graphics.Paint,kotlin.CharSequence,kotlin.Int,kotlin.Int,android.graphics.Paint.FontMetricsInt)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Paint.html paint, https://developer.android.com/reference/java/lang/CharSequence.html text, int start, int end, https://developer.android.com/reference/android/graphics/Paint.FontMetricsInt.html fm )` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html` | `https://developer.android.com/reference/androidx/text/vertical/RubySpan#getText()()` The ruby text to be displayed adjacent to the base text. |
| `final float` | `https://developer.android.com/reference/androidx/text/vertical/RubySpan#getTextScale()()` The text scale ratio of the ruby text relative to the base text. |

### Inherited methods

From [android.text.style.MetricAffectingSpan](https://developer.android.com/reference/android/text/style/MetricAffectingSpan.html) `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/text/style/MetricAffectingSpan.html` `https://developer.android.com/reference/android/text/style/MetricAffectingSpan.html#getUnderlying()()` From [android.text.style.ReplacementSpan](https://developer.android.com/reference/android/text/style/ReplacementSpan.html) `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/CharSequence.html` `https://developer.android.com/reference/android/text/style/ReplacementSpan.html#getContentDescription()()` `void` `https://developer.android.com/reference/android/text/style/ReplacementSpan.html#setContentDescription(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence.html contentDescription)` `void` `https://developer.android.com/reference/android/text/style/ReplacementSpan.html#updateDrawState(android.text.TextPaint)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/text/TextPaint.html ds)` `void` `https://developer.android.com/reference/android/text/style/ReplacementSpan.html#updateMeasureState(android.text.TextPaint)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/text/TextPaint.html p)`

## 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-beta03](https://developer.android.com/jetpack/androidx/releases/text#1.0.0-beta03)

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

## Public methods

### draw

Added in [1.0.0-beta03](https://developer.android.com/jetpack/androidx/releases/text#1.0.0-beta03)

```
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-beta03](https://developer.android.com/jetpack/androidx/releases/text#1.0.0-beta03)

```
public final @NonNull TextOrientation getOrientation()
```

The text orientation of the ruby text. Defaults to `https://developer.android.com/reference/androidx/text/vertical/TextOrientation#Mixed`.

### getPosition

Added in [1.0.0-beta03](https://developer.android.com/jetpack/androidx/releases/text#1.0.0-beta03)

```
public final @NonNull AnnotationPosition getPosition()
```

The position of ruby text relative to the base text. Defaults to `https://developer.android.com/reference/androidx/text/vertical/AnnotationPosition#Before()`.

### getSize

Added in [1.0.0-beta03](https://developer.android.com/jetpack/androidx/releases/text#1.0.0-beta03)

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

### getText

Added in [1.0.0-beta03](https://developer.android.com/jetpack/androidx/releases/text#1.0.0-beta03)

```
public final @NonNull CharSequence getText()
```

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

### getTextScale

Added in [1.0.0-beta03](https://developer.android.com/jetpack/androidx/releases/text#1.0.0-beta03)

```
public final float getTextScale()
```

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