Commit f88fbaf6 by ibaker Committed by Oliver Woodman

Add Cue.verticalType field

Inspired by the `vertical` cue setting in WebVTT:
https://www.w3.org/TR/webvtt1/#webvtt-vertical-text-cue-setting

PiperOrigin-RevId: 286583621
parent da121a08
...@@ -49,9 +49,7 @@ public final class Cue { ...@@ -49,9 +49,7 @@ public final class Cue {
@IntDef({TYPE_UNSET, ANCHOR_TYPE_START, ANCHOR_TYPE_MIDDLE, ANCHOR_TYPE_END}) @IntDef({TYPE_UNSET, ANCHOR_TYPE_START, ANCHOR_TYPE_MIDDLE, ANCHOR_TYPE_END})
public @interface AnchorType {} public @interface AnchorType {}
/** /** An unset anchor, line, text size or vertical type value. */
* An unset anchor or line type value.
*/
public static final int TYPE_UNSET = Integer.MIN_VALUE; public static final int TYPE_UNSET = Integer.MIN_VALUE;
/** /**
...@@ -115,6 +113,25 @@ public final class Cue { ...@@ -115,6 +113,25 @@ public final class Cue {
public static final int TEXT_SIZE_TYPE_ABSOLUTE = 2; public static final int TEXT_SIZE_TYPE_ABSOLUTE = 2;
/** /**
* The type of vertical layout for this cue, which may be unset (i.e. horizontal). One of {@link
* #TYPE_UNSET}, {@link #VERTICAL_TYPE_RL} or {@link #VERTICAL_TYPE_LR}.
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@IntDef({
TYPE_UNSET,
VERTICAL_TYPE_RL,
VERTICAL_TYPE_LR,
})
public @interface VerticalType {}
/** Vertical right-to-left (e.g. for Japanese). */
public static final int VERTICAL_TYPE_RL = 1;
/** Vertical left-to-right (e.g. for Mongolian). */
public static final int VERTICAL_TYPE_LR = 2;
/**
* The cue text, or null if this is an image cue. Note the {@link CharSequence} may be decorated * The cue text, or null if this is an image cue. Note the {@link CharSequence} may be decorated
* with styling spans. * with styling spans.
*/ */
...@@ -242,6 +259,12 @@ public final class Cue { ...@@ -242,6 +259,12 @@ public final class Cue {
public final float textSize; public final float textSize;
/** /**
* The vertical formatting of this Cue, or {@link #TYPE_UNSET} if the cue has no vertical setting
* (and so should be horizontal).
*/
public final @VerticalType int verticalType;
/**
* Creates a text cue whose {@link #textAlignment} is null, whose type parameters are set to * Creates a text cue whose {@link #textAlignment} is null, whose type parameters are set to
* {@link #TYPE_UNSET} and whose dimension parameters are set to {@link #DIMEN_UNSET}. * {@link #TYPE_UNSET} and whose dimension parameters are set to {@link #DIMEN_UNSET}.
* *
...@@ -338,7 +361,8 @@ public final class Cue { ...@@ -338,7 +361,8 @@ public final class Cue {
size, size,
/* bitmapHeight= */ DIMEN_UNSET, /* bitmapHeight= */ DIMEN_UNSET,
/* windowColorSet= */ false, /* windowColorSet= */ false,
/* windowColor= */ Color.BLACK); /* windowColor= */ Color.BLACK,
/* verticalType= */ TYPE_UNSET);
} }
/** /**
...@@ -382,7 +406,8 @@ public final class Cue { ...@@ -382,7 +406,8 @@ public final class Cue {
size, size,
/* bitmapHeight= */ DIMEN_UNSET, /* bitmapHeight= */ DIMEN_UNSET,
windowColorSet, windowColorSet,
windowColor); windowColor,
/* verticalType= */ TYPE_UNSET);
} }
private Cue( private Cue(
...@@ -399,7 +424,8 @@ public final class Cue { ...@@ -399,7 +424,8 @@ public final class Cue {
float size, float size,
float bitmapHeight, float bitmapHeight,
boolean windowColorSet, boolean windowColorSet,
int windowColor) { int windowColor,
@VerticalType int verticalType) {
// Exactly one of text or bitmap should be set. // Exactly one of text or bitmap should be set.
if (text == null) { if (text == null) {
Assertions.checkNotNull(bitmap); Assertions.checkNotNull(bitmap);
...@@ -420,6 +446,7 @@ public final class Cue { ...@@ -420,6 +446,7 @@ public final class Cue {
this.windowColor = windowColor; this.windowColor = windowColor;
this.textSizeType = textSizeType; this.textSizeType = textSizeType;
this.textSize = textSize; this.textSize = textSize;
this.verticalType = verticalType;
} }
/** A builder for {@link Cue} objects. */ /** A builder for {@link Cue} objects. */
...@@ -438,6 +465,7 @@ public final class Cue { ...@@ -438,6 +465,7 @@ public final class Cue {
private float bitmapHeight; private float bitmapHeight;
private boolean windowColorSet; private boolean windowColorSet;
@ColorInt private int windowColor; @ColorInt private int windowColor;
@VerticalType private int verticalType;
public Builder() { public Builder() {
text = null; text = null;
...@@ -454,6 +482,7 @@ public final class Cue { ...@@ -454,6 +482,7 @@ public final class Cue {
bitmapHeight = DIMEN_UNSET; bitmapHeight = DIMEN_UNSET;
windowColorSet = false; windowColorSet = false;
windowColor = Color.BLACK; windowColor = Color.BLACK;
verticalType = TYPE_UNSET;
} }
/** /**
...@@ -624,6 +653,16 @@ public final class Cue { ...@@ -624,6 +653,16 @@ public final class Cue {
return this; return this;
} }
/**
* Sets the vertical formatting for this Cue.
*
* @see Cue#verticalType
*/
public Builder setVerticalType(@VerticalType int verticalType) {
this.verticalType = verticalType;
return this;
}
/** Build the cue. */ /** Build the cue. */
public Cue build() { public Cue build() {
return new Cue( return new Cue(
...@@ -640,7 +679,8 @@ public final class Cue { ...@@ -640,7 +679,8 @@ public final class Cue {
size, size,
bitmapHeight, bitmapHeight,
windowColorSet, windowColorSet,
windowColor); windowColor,
verticalType);
} }
} }
} }
...@@ -43,6 +43,7 @@ public class CueTest { ...@@ -43,6 +43,7 @@ public class CueTest {
.setTextSize(0.2f, Cue.TEXT_SIZE_TYPE_FRACTIONAL) .setTextSize(0.2f, Cue.TEXT_SIZE_TYPE_FRACTIONAL)
.setSize(0.8f) .setSize(0.8f)
.setWindowColor(Color.CYAN) .setWindowColor(Color.CYAN)
.setVerticalType(Cue.VERTICAL_TYPE_RL)
.build(); .build();
assertThat(cue.text).isEqualTo("text"); assertThat(cue.text).isEqualTo("text");
...@@ -56,6 +57,7 @@ public class CueTest { ...@@ -56,6 +57,7 @@ public class CueTest {
assertThat(cue.size).isEqualTo(0.8f); assertThat(cue.size).isEqualTo(0.8f);
assertThat(cue.windowColor).isEqualTo(Color.CYAN); assertThat(cue.windowColor).isEqualTo(Color.CYAN);
assertThat(cue.windowColorSet).isTrue(); assertThat(cue.windowColorSet).isTrue();
assertThat(cue.verticalType).isEqualTo(Cue.VERTICAL_TYPE_RL);
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment