• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 package com.google.android.exoplayer2.text.span;
18 
19 import static java.lang.annotation.RetentionPolicy.SOURCE;
20 
21 import androidx.annotation.IntDef;
22 import java.lang.annotation.Documented;
23 import java.lang.annotation.Retention;
24 
25 /**
26  * A styling span for ruby text.
27  *
28  * <p>The text covered by this span is known as the "base text", and the ruby text is stored in
29  * {@link #rubyText}.
30  *
31  * <p>More information on <a href="https://en.wikipedia.org/wiki/Ruby_character">ruby characters</a>
32  * and <a href="https://developer.android.com/guide/topics/text/spans">span styling</a>.
33  */
34 // NOTE: There's no Android layout support for rubies, so this span currently doesn't extend any
35 // styling superclasses (e.g. MetricAffectingSpan). The only way to render these rubies is to
36 // extract the spans and do the layout manually.
37 // TODO: Consider adding support for parenthetical text to be used when rendering doesn't support
38 // rubies (e.g. HTML <rp> tag).
39 public final class RubySpan {
40 
41   /** The ruby position is unknown. */
42   public static final int POSITION_UNKNOWN = -1;
43 
44   /**
45    * The ruby text should be positioned above the base text.
46    *
47    * <p>For vertical text it should be positioned to the right, same as CSS's <a
48    * href="https://developer.mozilla.org/en-US/docs/Web/CSS/ruby-position">ruby-position</a>.
49    */
50   public static final int POSITION_OVER = 1;
51 
52   /**
53    * The ruby text should be positioned below the base text.
54    *
55    * <p>For vertical text it should be positioned to the left, same as CSS's <a
56    * href="https://developer.mozilla.org/en-US/docs/Web/CSS/ruby-position">ruby-position</a>.
57    */
58   public static final int POSITION_UNDER = 2;
59 
60   /**
61    * The possible positions of the ruby text relative to the base text.
62    *
63    * <p>One of:
64    *
65    * <ul>
66    *   <li>{@link #POSITION_UNKNOWN}
67    *   <li>{@link #POSITION_OVER}
68    *   <li>{@link #POSITION_UNDER}
69    * </ul>
70    */
71   @Documented
72   @Retention(SOURCE)
73   @IntDef({POSITION_UNKNOWN, POSITION_OVER, POSITION_UNDER})
74   public @interface Position {}
75 
76   /** The ruby text, i.e. the smaller explanatory characters. */
77   public final String rubyText;
78 
79   /** The position of the ruby text relative to the base text. */
80   @Position public final int position;
81 
RubySpan(String rubyText, @Position int position)82   public RubySpan(String rubyText, @Position int position) {
83     this.rubyText = rubyText;
84     this.position = position;
85   }
86 }
87