Commit 4ad64547 by Denise LaFayette

Address code review comments

- Refactor TextEmphasis class to support different ordering of styles
- Merge RubySpan.Position and TextEmphasisSpan.Position
- Remove TTML constructs from Spanned classes
parent fcda8d47
Showing with 212 additions and 258 deletions
......@@ -16,12 +16,6 @@
*/
package com.google.android.exoplayer2.text.span;
import static java.lang.annotation.RetentionPolicy.SOURCE;
import androidx.annotation.IntDef;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
/**
* A styling span for ruby text.
*
......@@ -38,48 +32,14 @@ import java.lang.annotation.Retention;
// rubies (e.g. HTML <rp> tag).
public final class RubySpan {
/** The ruby position is unknown. */
public static final int POSITION_UNKNOWN = -1;
/**
* The ruby text should be positioned above the base text.
*
* <p>For vertical text it should be positioned to the right, same as CSS's <a
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/ruby-position">ruby-position</a>.
*/
public static final int POSITION_OVER = 1;
/**
* The ruby text should be positioned below the base text.
*
* <p>For vertical text it should be positioned to the left, same as CSS's <a
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/ruby-position">ruby-position</a>.
*/
public static final int POSITION_UNDER = 2;
/**
* The possible positions of the ruby text relative to the base text.
*
* <p>One of:
*
* <ul>
* <li>{@link #POSITION_UNKNOWN}
* <li>{@link #POSITION_OVER}
* <li>{@link #POSITION_UNDER}
* </ul>
*/
@Documented
@Retention(SOURCE)
@IntDef({POSITION_UNKNOWN, POSITION_OVER, POSITION_UNDER})
public @interface Position {}
/** The ruby text, i.e. the smaller explanatory characters. */
public final String rubyText;
/** The position of the ruby text relative to the base text. */
@Position public final int position;
@TextAnnotation.Position
public final int position;
public RubySpan(String rubyText, @Position int position) {
public RubySpan(String rubyText, @TextAnnotation.Position int position) {
this.rubyText = rubyText;
this.position = position;
}
......
package com.google.android.exoplayer2.text.span;
import static java.lang.annotation.RetentionPolicy.SOURCE;
import androidx.annotation.IntDef;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
/**
* Class used to describe properties of a text annotation (i.e. ruby, text emphasis marks)
*/
public class TextAnnotation {
/** The text annotation position is unknown. */
public static final int POSITION_UNKNOWN = -1;
/**
* For horizontal text, the text annotation should be positioned above the base text.
*
* <p>For vertical text it should be positioned to the right, same as CSS's <a
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/ruby-position">ruby-position</a>.
*/
public static final int POSITION_BEFORE = 1;
/**
* For horizontal text, the text annotation should be positioned below the base text.
*
* <p>For vertical text it should be positioned to the left, same as CSS's <a
* href="https://developer.mozilla.org/en-US/docs/Web/CSS/ruby-position">ruby-position</a>.
*/
public static final int POSITION_AFTER = 2;
/**
* The possible positions of the annotation text relative to the base text.
*
* <p>One of:
*
* <ul>
* <li>{@link #POSITION_UNKNOWN}
* <li>{@link #POSITION_BEFORE}
* <li>{@link #POSITION_AFTER}
* </ul>
*/
@Documented
@Retention(SOURCE)
@IntDef({POSITION_UNKNOWN, POSITION_BEFORE, POSITION_AFTER})
public @interface Position {}
}
......@@ -23,72 +23,22 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
public final class TextEmphasisSpan {
/**
* <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/text-emphasis-position">Text Emphasis Position</a>
*/
/**
* The text emphasis position is unknown. If an implementation does not recognize or otherwise
* distinguish an annotation position value, then it must be interpreted as if a position of
* before were specified; as such, an implementation that supports text annotation marks must
* minimally support the before value.
*/
public static final int POSITION_UNKNOWN = -1;
/**
* The emphasis marks should be positioned above the base text in horizontal writing mode The
* emphasis marks should be positioned to the right of the base text in vertical writing mode
*/
public static final int POSITION_BEFORE = 1;
/**
* The emphasis marks should be positioned below the base text in horizontal writing mode The
* emphasis marks should be positioned to the left of the base text in vertical writing mode
*/
public static final int POSITION_AFTER = 2;
/**
* The text emphasis should be positioned in following way:
*
* <ul>
* <li>Equivalent to {@link #POSITION_BEFORE} for (1) the only line area of or (2) the first line
* area of the last block area generated by a p element which contains annotated text
* <li>otherwise, equivalent to {@link #POSITION_AFTER}
* </ul>
*/
public static final int POSITION_OUTSIDE = 3;
/**
* The possible positions of the emphasis marks relative to the base text.
*
* <p>One of:
*
* <ul>
* <li>{@link #POSITION_UNKNOWN}
* <li>{@link #POSITION_BEFORE}
* <li>{@link #POSITION_AFTER}
* <li>{@link #POSITION_OUTSIDE}
* </ul>
*/
@Documented
@Retention(SOURCE)
@IntDef({POSITION_UNKNOWN, POSITION_BEFORE, POSITION_AFTER, POSITION_OUTSIDE})
public @interface Position {
}
/**
* The text emphasis position is unknown.
*/
public static final int MARK_UNKNOWN = -1;
public static final int MARK_AUTO = 1;
public static final int MARK_FILLED_CIRCLE = 2;
public static final int MARK_FILLED_DOT = 3;
public static final int MARK_FILLED_SESAME = 4;
public static final int MARK_OPEN_CIRCLE = 5;
public static final int MARK_OPEN_DOT = 6;
public static final int MARK_OPEN_SESAME = 7;
// Bits [1:0] are used for typical mark types
public static final int MARK_FLAG_CIRCLE = 1;
public static final int MARK_FLAG_DOT = 2;
public static final int MARK_FLAG_SESAME = 3;
// Bit 2 is used for filled/open
public static final int MARK_FLAG_FILLED = 0;
public static final int MARK_FLAG_OPEN = 4;
// Below are the mark style constants
public static final int MARK_FILLED_CIRCLE = MARK_FLAG_CIRCLE | MARK_FLAG_FILLED;
public static final int MARK_FILLED_DOT = MARK_FLAG_DOT | MARK_FLAG_FILLED;
public static final int MARK_FILLED_SESAME = MARK_FLAG_SESAME | MARK_FLAG_FILLED;
public static final int MARK_OPEN_CIRCLE = MARK_FLAG_CIRCLE | MARK_FLAG_OPEN;
public static final int MARK_OPEN_DOT = MARK_FLAG_DOT | MARK_FLAG_OPEN;
public static final int MARK_OPEN_SESAME = MARK_FLAG_SESAME | MARK_FLAG_OPEN;
/**
* The possible types of annotations used.
......@@ -96,8 +46,6 @@ public final class TextEmphasisSpan {
* <p>One of:
*
* <ul>
* <li>{@link #MARK_UNKNOWN}
* <li>{@link #MARK_AUTO}
* <li>{@link #MARK_FILLED_CIRCLE}
* <li>{@link #MARK_FILLED_DOT}
* <li>{@link #MARK_FILLED_SESAME}
......@@ -105,29 +53,31 @@ public final class TextEmphasisSpan {
* <li>{@link #MARK_OPEN_DOT}
* <li>{@link #MARK_OPEN_SESAME}
* </ul>
*
* Note: We are intentionally excluding MARK_AUTO here since the auto value should
* be resolved
*/
@Documented
@Retention(SOURCE)
@IntDef({MARK_UNKNOWN, MARK_AUTO, MARK_FILLED_CIRCLE, MARK_FILLED_DOT, MARK_FILLED_SESAME,
@IntDef({MARK_FILLED_CIRCLE, MARK_FILLED_DOT, MARK_FILLED_SESAME,
MARK_OPEN_CIRCLE, MARK_OPEN_DOT, MARK_OPEN_SESAME})
public @interface Mark {
}
/**
* The position of the text emphasis relative to the base text
* The mark used to emphasis text
*/
@TextEmphasisSpan.Position
public final int position;
public @TextEmphasisSpan.Mark int mark;
/**
* The text emphasis mark
* The position of the text emphasis relative to the base text
*/
@TextEmphasisSpan.Mark
public final int mark;
@TextAnnotation.Position
public final int position;
public TextEmphasisSpan(@TextEmphasisSpan.Mark int mark,
@TextEmphasisSpan.Position int position) {
@TextAnnotation.Position int position) {
this.mark = mark;
this.position = position;
}
......
......@@ -22,7 +22,7 @@ import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.SimpleSubtitleDecoder;
import com.google.android.exoplayer2.text.Subtitle;
import com.google.android.exoplayer2.text.SubtitleDecoderException;
import com.google.android.exoplayer2.text.span.RubySpan;
import com.google.android.exoplayer2.text.span.TextAnnotation;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ColorParser;
import com.google.android.exoplayer2.util.Log;
......@@ -583,10 +583,10 @@ public final class TtmlDecoder extends SimpleSubtitleDecoder {
case TtmlNode.ATTR_TTS_RUBY_POSITION:
switch (Util.toLowerInvariant(attributeValue)) {
case TtmlNode.RUBY_BEFORE:
style = createIfNull(style).setRubyPosition(RubySpan.POSITION_OVER);
style = createIfNull(style).setRubyPosition(TextAnnotation.POSITION_BEFORE);
break;
case TtmlNode.RUBY_AFTER:
style = createIfNull(style).setRubyPosition(RubySpan.POSITION_UNDER);
style = createIfNull(style).setRubyPosition(TextAnnotation.POSITION_AFTER);
break;
default:
// ignore
......
......@@ -31,6 +31,7 @@ import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan;
import com.google.android.exoplayer2.text.span.RubySpan;
import com.google.android.exoplayer2.text.span.SpanUtil;
import com.google.android.exoplayer2.text.span.TextAnnotation;
import com.google.android.exoplayer2.text.span.TextEmphasisSpan;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.Util;
......@@ -124,21 +125,36 @@ import java.util.Map;
}
if (style.getTextEmphasis() != null) {
TextEmphasis textEmphasis = style.getTextEmphasis();
// https://www.w3.org/TR/ttml2/#style-value-emphasis-style
// If an implementation does not recognize or otherwise distinguish an emphasis style value,
// then it must be interpreted as if a style of auto were specified; as such, an
// implementation that supports text emphasis marks must minimally support the auto value.
// If a vertical writing mode applies, then equivalent to filled sesame; otherwise, equivalent
// to filled circle.
@TextEmphasisSpan.Mark int mark = textEmphasis.mark;
if (textEmphasis.mark == TextEmphasisSpan.MARK_AUTO
|| textEmphasis.mark == TextEmphasisSpan.MARK_UNKNOWN) {
/**
* If an implementation does not recognize or otherwise distinguish an emphasis style value,
* then it must be interpreted as if a style of auto were specified; as such, an
* implementation that supports text emphasis marks must minimally support the auto value.
* If a vertical writing mode applies, then equivalent to filled sesame; otherwise, equivalent
* to filled circle.
* See https://www.w3.org/TR/ttml2/#style-value-emphasis-style
*/
@TextEmphasis.Mark int mark = textEmphasis.mark;
if (textEmphasis.mark == TextEmphasis.MARK_AUTO) {
mark = (verticalType == Cue.VERTICAL_TYPE_LR || verticalType == Cue.VERTICAL_TYPE_RL) ?
TextEmphasisSpan.MARK_FILLED_SESAME : TextEmphasisSpan.MARK_FILLED_CIRCLE;
}
@TextEmphasis.Position int position = textEmphasis.position;
if (textEmphasis.position == TextEmphasis.POSITION_OUTSIDE) {
/**
* Not supported in current implementation
* If an implementation does not recognize or otherwise distinguish an annotation position
* value, then it must be interpreted as if a position of before were specified; as such,
* an implementation that supports text annotation marks must minimally support the before
* value.
* See https://www.w3.org/TR/ttml2/#style-value-annotation-position
*/
position = TextAnnotation.POSITION_BEFORE;
}
SpanUtil.addOrReplaceSpan(
builder,
new TextEmphasisSpan(mark, textEmphasis.position),
new TextEmphasisSpan(mark, position),
start,
end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
......@@ -165,11 +181,11 @@ import java.util.Map;
}
// TODO: Get rubyPosition from `textNode` when TTML inheritance is implemented.
@RubySpan.Position
@TextAnnotation.Position
int rubyPosition =
containerNode.style != null
? containerNode.style.getRubyPosition()
: RubySpan.POSITION_UNKNOWN;
: TextAnnotation.POSITION_UNKNOWN;
builder.setSpan(
new RubySpan(rubyText, rubyPosition), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
......
......@@ -20,6 +20,7 @@ import android.text.Layout;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.text.span.RubySpan;
import com.google.android.exoplayer2.text.span.TextAnnotation;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
......@@ -83,7 +84,7 @@ import java.lang.annotation.RetentionPolicy;
private float fontSize;
@Nullable private String id;
@RubyType private int rubyType;
@RubySpan.Position private int rubyPosition;
@TextAnnotation.Position private int rubyPosition;
@Nullable private Layout.Alignment textAlign;
@OptionalBoolean private int textCombine;
......@@ -96,7 +97,7 @@ import java.lang.annotation.RetentionPolicy;
italic = UNSPECIFIED;
fontSizeUnit = UNSPECIFIED;
rubyType = UNSPECIFIED;
rubyPosition = RubySpan.POSITION_UNKNOWN;
rubyPosition = TextAnnotation.POSITION_UNKNOWN;
textCombine = UNSPECIFIED;
}
......@@ -227,7 +228,7 @@ import java.lang.annotation.RetentionPolicy;
if (underline == UNSPECIFIED) {
underline = ancestor.underline;
}
if (rubyPosition == RubySpan.POSITION_UNKNOWN) {
if (rubyPosition == TextAnnotation.POSITION_UNKNOWN) {
rubyPosition = ancestor.rubyPosition;
}
if (textAlign == null && ancestor.textAlign != null) {
......@@ -274,12 +275,12 @@ import java.lang.annotation.RetentionPolicy;
return rubyType;
}
public TtmlStyle setRubyPosition(@RubySpan.Position int position) {
public TtmlStyle setRubyPosition(@TextAnnotation.Position int position) {
this.rubyPosition = position;
return this;
}
@RubySpan.Position
@TextAnnotation.Position
public int getRubyPosition() {
return rubyPosition;
}
......
......@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.text.webvtt;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.text.span.RubySpan;
import com.google.android.exoplayer2.text.span.TextAnnotation;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ColorParser;
import com.google.android.exoplayer2.util.ParsableByteArray;
......@@ -195,9 +196,9 @@ import java.util.regex.Pattern;
style.setBackgroundColor(ColorParser.parseCssColor(value));
} else if (PROPERTY_RUBY_POSITION.equals(property)) {
if (VALUE_OVER.equals(value)) {
style.setRubyPosition(RubySpan.POSITION_OVER);
style.setRubyPosition(TextAnnotation.POSITION_BEFORE);
} else if (VALUE_UNDER.equals(value)) {
style.setRubyPosition(RubySpan.POSITION_UNDER);
style.setRubyPosition(TextAnnotation.POSITION_AFTER);
}
} else if (PROPERTY_TEXT_COMBINE_UPRIGHT.equals(property)) {
style.setCombineUpright(VALUE_ALL.equals(value) || value.startsWith(VALUE_DIGITS));
......
......@@ -21,6 +21,7 @@ import androidx.annotation.ColorInt;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.text.span.RubySpan;
import com.google.android.exoplayer2.text.span.TextAnnotation;
import com.google.android.exoplayer2.util.Util;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
......@@ -95,7 +96,7 @@ public final class WebvttCssStyle {
@OptionalBoolean private int italic;
@FontSizeUnit private int fontSizeUnit;
private float fontSize;
@RubySpan.Position private int rubyPosition;
@TextAnnotation.Position private int rubyPosition;
private boolean combineUpright;
public WebvttCssStyle() {
......@@ -111,7 +112,7 @@ public final class WebvttCssStyle {
bold = UNSPECIFIED;
italic = UNSPECIFIED;
fontSizeUnit = UNSPECIFIED;
rubyPosition = RubySpan.POSITION_UNKNOWN;
rubyPosition = TextAnnotation.POSITION_UNKNOWN;
combineUpright = false;
}
......@@ -272,12 +273,12 @@ public final class WebvttCssStyle {
return fontSize;
}
public WebvttCssStyle setRubyPosition(@RubySpan.Position int rubyPosition) {
public WebvttCssStyle setRubyPosition(@TextAnnotation.Position int rubyPosition) {
this.rubyPosition = rubyPosition;
return this;
}
@RubySpan.Position
@TextAnnotation.Position
public int getRubyPosition() {
return rubyPosition;
}
......
......@@ -39,6 +39,7 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan;
import com.google.android.exoplayer2.text.span.RubySpan;
import com.google.android.exoplayer2.text.span.TextAnnotation;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.ParsableByteArray;
......@@ -572,7 +573,7 @@ public final class WebvttCueParser {
StartTag startTag,
List<Element> nestedElements,
List<WebvttCssStyle> styles) {
@RubySpan.Position int rubyTagPosition = getRubyPosition(styles, cueId, startTag);
@TextAnnotation.Position int rubyTagPosition = getRubyPosition(styles, cueId, startTag);
List<Element> sortedNestedElements = new ArrayList<>(nestedElements.size());
sortedNestedElements.addAll(nestedElements);
Collections.sort(sortedNestedElements, Element.BY_START_POSITION_ASC);
......@@ -585,12 +586,12 @@ public final class WebvttCueParser {
Element rubyTextElement = sortedNestedElements.get(i);
// Use the <rt> element's ruby-position if set, otherwise the <ruby> element's and otherwise
// default to OVER.
@RubySpan.Position
@TextAnnotation.Position
int rubyPosition =
firstKnownRubyPosition(
getRubyPosition(styles, cueId, rubyTextElement.startTag),
rubyTagPosition,
RubySpan.POSITION_OVER);
TextAnnotation.POSITION_BEFORE);
// Move the rubyText from spannedText into the RubySpan.
int adjustedRubyTextStart = rubyTextElement.startTag.position - deletedCharCount;
int adjustedRubyTextEnd = rubyTextElement.endPosition - deletedCharCount;
......@@ -607,31 +608,31 @@ public final class WebvttCueParser {
}
}
@RubySpan.Position
@TextAnnotation.Position
private static int getRubyPosition(
List<WebvttCssStyle> styles, @Nullable String cueId, StartTag startTag) {
List<StyleMatch> styleMatches = getApplicableStyles(styles, cueId, startTag);
for (int i = 0; i < styleMatches.size(); i++) {
WebvttCssStyle style = styleMatches.get(i).style;
if (style.getRubyPosition() != RubySpan.POSITION_UNKNOWN) {
if (style.getRubyPosition() != TextAnnotation.POSITION_UNKNOWN) {
return style.getRubyPosition();
}
}
return RubySpan.POSITION_UNKNOWN;
return TextAnnotation.POSITION_UNKNOWN;
}
@RubySpan.Position
@TextAnnotation.Position
private static int firstKnownRubyPosition(
@RubySpan.Position int position1,
@RubySpan.Position int position2,
@RubySpan.Position int position3) {
if (position1 != RubySpan.POSITION_UNKNOWN) {
@TextAnnotation.Position int position1,
@TextAnnotation.Position int position2,
@TextAnnotation.Position int position3) {
if (position1 != TextAnnotation.POSITION_UNKNOWN) {
return position1;
}
if (position2 != RubySpan.POSITION_UNKNOWN) {
if (position2 != TextAnnotation.POSITION_UNKNOWN) {
return position2;
}
if (position3 != RubySpan.POSITION_UNKNOWN) {
if (position3 != TextAnnotation.POSITION_UNKNOWN) {
return position3;
}
throw new IllegalArgumentException();
......
......@@ -28,6 +28,7 @@ import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.Subtitle;
import com.google.android.exoplayer2.text.SubtitleDecoderException;
import com.google.android.exoplayer2.text.span.RubySpan;
import com.google.android.exoplayer2.text.span.TextAnnotation;
import com.google.android.exoplayer2.text.span.TextEmphasisSpan;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ColorParser;
......@@ -648,16 +649,16 @@ public final class TtmlDecoderTest {
assertThat(firstCue.toString()).isEqualTo("Cue with annotated text.");
assertThat(firstCue)
.hasRubySpanBetween("Cue with ".length(), "Cue with annotated".length())
.withTextAndPosition("1st rubies", RubySpan.POSITION_OVER);
.withTextAndPosition("1st rubies", TextAnnotation.POSITION_BEFORE);
assertThat(firstCue)
.hasRubySpanBetween("Cue with annotated ".length(), "Cue with annotated text".length())
.withTextAndPosition("2nd rubies", RubySpan.POSITION_UNKNOWN);
.withTextAndPosition("2nd rubies", TextAnnotation.POSITION_UNKNOWN);
Spanned secondCue = getOnlyCueTextAtTimeUs(subtitle, 20_000_000);
assertThat(secondCue.toString()).isEqualTo("Cue with annotated text.");
assertThat(secondCue)
.hasRubySpanBetween("Cue with ".length(), "Cue with annotated".length())
.withTextAndPosition("rubies", RubySpan.POSITION_UNKNOWN);
.withTextAndPosition("rubies", TextAnnotation.POSITION_UNKNOWN);
Spanned thirdCue = getOnlyCueTextAtTimeUs(subtitle, 30_000_000);
assertThat(thirdCue.toString()).isEqualTo("Cue with annotated text.");
......@@ -681,69 +682,68 @@ public final class TtmlDecoderTest {
TtmlSubtitle subtitle = getSubtitle(TEXT_EMPHASIS_FILE);
Spanned firstCue = getOnlyCueTextAtTimeUs(subtitle, 10_000_000);
assertThat(firstCue)
.hasNoTextEmphasisSpanBetween("None ".length(), "None おはよ".length());
assertThat(firstCue).hasNoSpans();
Spanned secondCue = getOnlyCueTextAtTimeUs(subtitle, 20_000_000);
assertThat(secondCue)
.hasTextEmphasisSpanBetween("Auto ".length(), "Auto ございます".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_CIRCLE,
TextEmphasisSpan.POSITION_UNKNOWN);
TextAnnotation.POSITION_BEFORE);
Spanned thirdCue = getOnlyCueTextAtTimeUs(subtitle, 30_000_000);
assertThat(thirdCue)
.hasTextEmphasisSpanBetween("Filled circle ".length(), "Filled circle こんばんは".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_CIRCLE,
TextEmphasisSpan.POSITION_UNKNOWN);
TextAnnotation.POSITION_BEFORE);
Spanned fourthCue = getOnlyCueTextAtTimeUs(subtitle, 40_000_000);
assertThat(fourthCue)
.hasTextEmphasisSpanBetween("Filled dot ".length(), "Filled dot ございます".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_DOT, TextEmphasisSpan.POSITION_UNKNOWN);
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_DOT, TextAnnotation.POSITION_BEFORE);
Spanned fifthCue = getOnlyCueTextAtTimeUs(subtitle, 50_000_000);
assertThat(fifthCue)
.hasTextEmphasisSpanBetween("Filled sesame ".length(), "Filled sesame おはよ".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_SESAME,
TextEmphasisSpan.POSITION_UNKNOWN);
TextAnnotation.POSITION_BEFORE);
Spanned sixthCue = getOnlyCueTextAtTimeUs(subtitle, 60_000_000);
assertThat(sixthCue)
.hasTextEmphasisSpanBetween("Open circle before ".length(),
"Open circle before ございます".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_OPEN_CIRCLE, TextEmphasisSpan.POSITION_BEFORE);
.withMarkAndPosition(TextEmphasisSpan.MARK_OPEN_CIRCLE, TextAnnotation.POSITION_BEFORE);
Spanned seventhCue = getOnlyCueTextAtTimeUs(subtitle, 70_000_000);
assertThat(seventhCue)
.hasTextEmphasisSpanBetween("Open dot after ".length(), "Open dot after おはよ".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_OPEN_DOT, TextEmphasisSpan.POSITION_AFTER);
.withMarkAndPosition(TextEmphasisSpan.MARK_OPEN_DOT, TextAnnotation.POSITION_AFTER);
Spanned eighthCue = getOnlyCueTextAtTimeUs(subtitle, 80_000_000);
assertThat(eighthCue)
.hasTextEmphasisSpanBetween("Open sesame outside ".length(),
"Open sesame outside ございます".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_OPEN_SESAME, TextEmphasisSpan.POSITION_OUTSIDE);
.withMarkAndPosition(TextEmphasisSpan.MARK_OPEN_SESAME, TextAnnotation.POSITION_BEFORE);
Spanned ninthCue = getOnlyCueTextAtTimeUs(subtitle, 90_000_000);
assertThat(ninthCue)
.hasTextEmphasisSpanBetween("Auto outside ".length(), "Auto outside おはよ".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_CIRCLE,
TextEmphasisSpan.POSITION_OUTSIDE);
TextAnnotation.POSITION_BEFORE);
Spanned tenthCue = getOnlyCueTextAtTimeUs(subtitle, 100_000_000);
assertThat(tenthCue)
.hasTextEmphasisSpanBetween("Circle before ".length(), "Circle before ございます".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_CIRCLE, TextEmphasisSpan.POSITION_BEFORE);
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_CIRCLE, TextAnnotation.POSITION_BEFORE);
Spanned eleventhCue = getOnlyCueTextAtTimeUs(subtitle, 110_000_000);
assertThat(eleventhCue)
.hasTextEmphasisSpanBetween("Sesame after ".length(), "Sesame after おはよ".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_SESAME, TextEmphasisSpan.POSITION_AFTER);
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_SESAME, TextAnnotation.POSITION_AFTER);
Spanned twelfthCue = getOnlyCueTextAtTimeUs(subtitle, 120_000_000);
assertThat(twelfthCue)
.hasTextEmphasisSpanBetween("Dot outside ".length(), "Dot outside ございます".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_DOT, TextEmphasisSpan.POSITION_OUTSIDE);
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_DOT, TextAnnotation.POSITION_BEFORE);
Spanned thirteenthCue = getOnlyCueTextAtTimeUs(subtitle, 130_000_000);
assertThat(thirteenthCue)
......@@ -754,25 +754,25 @@ public final class TtmlDecoderTest {
assertThat(fourteenthCue)
.hasTextEmphasisSpanBetween("Auto (TBLR) ".length(), "Auto (TBLR) ございます".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_SESAME,
TextEmphasisSpan.POSITION_UNKNOWN);
TextAnnotation.POSITION_BEFORE);
Spanned fifteenthCue = getOnlyCueTextAtTimeUs(subtitle, 150_000_000);
assertThat(fifteenthCue)
.hasTextEmphasisSpanBetween("Auto (TBRL) ".length(), "Auto (TBRL) おはよ".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_SESAME,
TextEmphasisSpan.POSITION_UNKNOWN);
TextAnnotation.POSITION_BEFORE);
Spanned sixteenthCue = getOnlyCueTextAtTimeUs(subtitle, 160_000_000);
assertThat(sixteenthCue)
.hasTextEmphasisSpanBetween("Auto (TB) ".length(), "Auto (TB) ございます".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_SESAME,
TextEmphasisSpan.POSITION_UNKNOWN);
TextAnnotation.POSITION_BEFORE);
Spanned seventeenthCue = getOnlyCueTextAtTimeUs(subtitle, 170_000_000);
assertThat(seventeenthCue)
.hasTextEmphasisSpanBetween("Auto (LR) ".length(), "Auto (LR) おはよ".length())
.withMarkAndPosition(TextEmphasisSpan.MARK_FILLED_CIRCLE,
TextEmphasisSpan.POSITION_UNKNOWN);
TextAnnotation.POSITION_BEFORE);
}
private static Spanned getOnlyCueTextAtTimeUs(Subtitle subtitle, long timeUs) {
......
......@@ -16,10 +16,9 @@
package com.google.android.exoplayer2.text.ttml;
import static android.graphics.Color.BLACK;
import static com.google.android.exoplayer2.text.span.TextAnnotation.POSITION_BEFORE;
import static com.google.android.exoplayer2.text.span.TextEmphasisSpan.MARK_FILLED_DOT;
import static com.google.android.exoplayer2.text.span.TextEmphasisSpan.MARK_OPEN_SESAME;
import static com.google.android.exoplayer2.text.span.TextEmphasisSpan.POSITION_AFTER;
import static com.google.android.exoplayer2.text.span.TextEmphasisSpan.POSITION_BEFORE;
import static com.google.android.exoplayer2.text.ttml.TtmlStyle.STYLE_BOLD;
import static com.google.android.exoplayer2.text.ttml.TtmlStyle.STYLE_BOLD_ITALIC;
import static com.google.android.exoplayer2.text.ttml.TtmlStyle.STYLE_ITALIC;
......@@ -32,7 +31,7 @@ import android.graphics.Color;
import android.text.Layout;
import androidx.annotation.ColorInt;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.text.span.RubySpan;
import com.google.android.exoplayer2.text.span.TextAnnotation;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -47,7 +46,7 @@ public final class TtmlStyleTest {
@TtmlStyle.FontSizeUnit private static final int FONT_SIZE_UNIT = TtmlStyle.FONT_SIZE_UNIT_EM;
@ColorInt private static final int BACKGROUND_COLOR = Color.BLACK;
private static final int RUBY_TYPE = TtmlStyle.RUBY_TYPE_TEXT;
private static final int RUBY_POSITION = RubySpan.POSITION_UNDER;
private static final int RUBY_POSITION = TextAnnotation.POSITION_AFTER;
private static final Layout.Alignment TEXT_ALIGN = Layout.Alignment.ALIGN_CENTER;
private static final boolean TEXT_COMBINE = true;
public static final String TEXT_EMPHASIS_STYLE="dot before";
......@@ -233,9 +232,9 @@ public final class TtmlStyleTest {
public void rubyPosition() {
TtmlStyle style = new TtmlStyle();
assertThat(style.getRubyPosition()).isEqualTo(RubySpan.POSITION_UNKNOWN);
style.setRubyPosition(RubySpan.POSITION_OVER);
assertThat(style.getRubyPosition()).isEqualTo(RubySpan.POSITION_OVER);
assertThat(style.getRubyPosition()).isEqualTo(TextAnnotation.POSITION_UNKNOWN);
style.setRubyPosition(POSITION_BEFORE);
assertThat(style.getRubyPosition()).isEqualTo(POSITION_BEFORE);
}
@Test
......@@ -264,6 +263,6 @@ public final class TtmlStyleTest {
assertThat(style.getTextEmphasis()).isNull();
style.setTextEmphasis(TextEmphasis.createTextEmphasis("open sesame after"));
assertThat(style.getTextEmphasis().mark).isEqualTo(MARK_OPEN_SESAME);
assertThat(style.getTextEmphasis().position).isEqualTo(POSITION_AFTER);
assertThat(style.getTextEmphasis().position).isEqualTo(TextAnnotation.POSITION_AFTER);
}
}
......@@ -27,6 +27,7 @@ import com.google.android.exoplayer2.testutil.TestUtil;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.SubtitleDecoderException;
import com.google.android.exoplayer2.text.span.RubySpan;
import com.google.android.exoplayer2.text.span.TextAnnotation;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ColorParser;
import com.google.common.collect.Iterables;
......@@ -349,7 +350,7 @@ public class WebvttDecoderTest {
assertThat(firstCue.text.toString()).isEqualTo("Some text with over-ruby.");
assertThat((Spanned) firstCue.text)
.hasRubySpanBetween("Some ".length(), "Some text with over-ruby".length())
.withTextAndPosition("over", RubySpan.POSITION_OVER);
.withTextAndPosition("over", TextAnnotation.POSITION_BEFORE);
// Check that `under` is read from CSS and unspecified defaults to `over`.
Cue secondCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(2)));
......@@ -357,25 +358,25 @@ public class WebvttDecoderTest {
.isEqualTo("Some text with under-ruby and over-ruby (default).");
assertThat((Spanned) secondCue.text)
.hasRubySpanBetween("Some ".length(), "Some text with under-ruby".length())
.withTextAndPosition("under", RubySpan.POSITION_UNDER);
.withTextAndPosition("under", TextAnnotation.POSITION_AFTER);
assertThat((Spanned) secondCue.text)
.hasRubySpanBetween(
"Some text with under-ruby and ".length(),
"Some text with under-ruby and over-ruby (default)".length())
.withTextAndPosition("over", RubySpan.POSITION_OVER);
.withTextAndPosition("over", TextAnnotation.POSITION_BEFORE);
// Check many <rt> tags with different positions nested in a single <ruby> span.
Cue thirdCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(4)));
assertThat(thirdCue.text.toString()).isEqualTo("base1base2base3.");
assertThat((Spanned) thirdCue.text)
.hasRubySpanBetween(/* start= */ 0, "base1".length())
.withTextAndPosition("over1", RubySpan.POSITION_OVER);
.withTextAndPosition("over1", TextAnnotation.POSITION_BEFORE);
assertThat((Spanned) thirdCue.text)
.hasRubySpanBetween("base1".length(), "base1base2".length())
.withTextAndPosition("under2", RubySpan.POSITION_UNDER);
.withTextAndPosition("under2", TextAnnotation.POSITION_AFTER);
assertThat((Spanned) thirdCue.text)
.hasRubySpanBetween("base1base2".length(), "base1base2base3".length())
.withTextAndPosition("under3", RubySpan.POSITION_UNDER);
.withTextAndPosition("under3", TextAnnotation.POSITION_AFTER);
// Check a <ruby> span with no <rt> tags.
Cue fourthCue = Iterables.getOnlyElement(subtitle.getCues(subtitle.getEventTime(6)));
......
......@@ -31,6 +31,7 @@ import android.util.SparseArray;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan;
import com.google.android.exoplayer2.text.span.RubySpan;
import com.google.android.exoplayer2.text.span.TextAnnotation;
import com.google.android.exoplayer2.text.span.TextEmphasisSpan;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
......@@ -187,11 +188,11 @@ import java.util.regex.Pattern;
} else if (span instanceof RubySpan) {
RubySpan rubySpan = (RubySpan) span;
switch (rubySpan.position) {
case RubySpan.POSITION_OVER:
case TextAnnotation.POSITION_BEFORE:
return "<ruby style='ruby-position:over;'>";
case RubySpan.POSITION_UNDER:
case TextAnnotation.POSITION_AFTER:
return "<ruby style='ruby-position:under;'>";
case RubySpan.POSITION_UNKNOWN:
case TextAnnotation.POSITION_UNKNOWN:
return "<ruby style='ruby-position:unset;'>";
default:
return null;
......@@ -256,23 +257,17 @@ import java.util.regex.Pattern;
return "open dot";
case TextEmphasisSpan.MARK_OPEN_SESAME:
return "open sesame";
case TextEmphasisSpan.MARK_AUTO: // TODO
// https://www.w3.org/TR/ttml2/#style-value-emphasis-style
// If a vertical writing mode applies, then equivalent to filled sesame; otherwise,
// equivalent to filled circle.
case TextEmphasisSpan.MARK_UNKNOWN:
default:
return "unset";
}
}
private static String getTextEmphasisPosition(@TextEmphasisSpan.Position int position){
private static String getTextEmphasisPosition(@TextAnnotation.Position int position){
switch (position) {
case TextEmphasisSpan.POSITION_AFTER:
case TextAnnotation.POSITION_AFTER:
return "under left";
case TextEmphasisSpan.POSITION_UNKNOWN:
case TextEmphasisSpan.POSITION_BEFORE:
case TextEmphasisSpan.POSITION_OUTSIDE: /* Not supported, fallback to "before" */
case TextAnnotation.POSITION_UNKNOWN:
case TextAnnotation.POSITION_BEFORE:
default:
// https://www.w3.org/TR/ttml2/#style-value-annotation-position
// If an implementation does not recognize or otherwise distinguish an annotation position
......
......@@ -34,6 +34,7 @@ import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan;
import com.google.android.exoplayer2.text.span.RubySpan;
import com.google.android.exoplayer2.text.span.TextAnnotation;
import com.google.android.exoplayer2.text.span.TextEmphasisSpan;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -251,12 +252,12 @@ public class SpannedToHtmlConverterTest {
SpannableString spanned =
new SpannableString("String with over-annotated and under-annotated section");
spanned.setSpan(
new RubySpan("ruby-text", RubySpan.POSITION_OVER),
new RubySpan("ruby-text", TextAnnotation.POSITION_BEFORE),
"String with ".length(),
"String with over-annotated".length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spanned.setSpan(
new RubySpan("non-àscìì-text", RubySpan.POSITION_UNDER),
new RubySpan("non-àscìì-text", TextAnnotation.POSITION_AFTER),
"String with over-annotated and ".length(),
"String with over-annotated and under-annotated".length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
......@@ -284,13 +285,13 @@ public class SpannedToHtmlConverterTest {
public void convert_supportsTextEmphasisSpan() {
SpannableString spanned = new SpannableString("Text emphasis おはよ ございます ");
spanned.setSpan(
new TextEmphasisSpan(TextEmphasisSpan.MARK_FILLED_CIRCLE, TextEmphasisSpan.POSITION_BEFORE),
new TextEmphasisSpan(TextEmphasisSpan.MARK_FILLED_CIRCLE, TextAnnotation.POSITION_BEFORE),
"Text emphasis ".length(),
"Text emphasis おはよ".length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spanned.setSpan(
new TextEmphasisSpan(TextEmphasisSpan.MARK_OPEN_SESAME, TextEmphasisSpan.POSITION_AFTER),
new TextEmphasisSpan(TextEmphasisSpan.MARK_OPEN_SESAME, TextAnnotation.POSITION_AFTER),
"Text emphasis おはよ ".length(),
"Text emphasis おはよ ございます ".length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
......
......@@ -3,10 +3,10 @@
xmlns:tts="http://www.w3.org/2006/10/ttaf1#style"
xmlns="http://www.w3.org/ns/ttml">
<head>
<region xml:id="region1" tts:extent="80.000% 80.000%" tts:origin="10.000% 10.000%" tts:writingMode="tbrl"/>
<region xml:id="region2" tts:extent="80.000% 80.000%" tts:origin="10.000% 10.000%" tts:writingMode="tblr"/>
<region xml:id="region3" tts:extent="80.000% 80.000%" tts:origin="10.000% 10.000%" tts:writingMode="tb"/>
<region xml:id="region4" tts:extent="80.000% 80.000%" tts:origin="10.000% 10.000%" tts:writingMode="lr"/>
<region xml:id="region_tbrl" tts:extent="80.000% 80.000%" tts:origin="10.000% 10.000%" tts:writingMode="tbrl"/>
<region xml:id="region_tblr" tts:extent="80.000% 80.000%" tts:origin="10.000% 10.000%" tts:writingMode="tblr"/>
<region xml:id="region_tb" tts:extent="80.000% 80.000%" tts:origin="10.000% 10.000%" tts:writingMode="tb"/>
<region xml:id="region_lr" tts:extent="80.000% 80.000%" tts:origin="10.000% 10.000%" tts:writingMode="lr"/>
</head>
<body>
<div>
......@@ -49,16 +49,16 @@
<p begin="130s" end="138s">No textEmphasis property <span>おはよ</span></p>
</div>
<div>
<p begin="140s" end="148s" region="region1">Auto (TBLR) <span tts:textEmphasis="auto">ございます</span></p>
<p begin="140s" end="148s" region="region_tbrl">Auto (TBLR) <span tts:textEmphasis="auto">ございます</span></p>
</div>
<div>
<p begin="150s" end="158s" region="region2">Auto (TBRL) <span tts:textEmphasis="auto">おはよ</span></p>
<p begin="150s" end="158s" region="region_tblr">Auto (TBRL) <span tts:textEmphasis="auto">おはよ</span></p>
</div>
<div>
<p begin="160s" end="168s" region="region3">Auto (TB) <span tts:textEmphasis="auto">ございます</span></p>
<p begin="160s" end="168s" region="region_tb">Auto (TB) <span tts:textEmphasis="auto">ございます</span></p>
</div>
<div>
<p begin="170s" end="178s" region="region4">Auto (LR) <span tts:textEmphasis="auto">おはよ</span></p>
<p begin="170s" end="178s" region="region_lr">Auto (LR) <span tts:textEmphasis="auto">おはよ</span></p>
</div>
</body>
......
......@@ -38,6 +38,7 @@ import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan;
import com.google.android.exoplayer2.text.span.RubySpan;
import com.google.android.exoplayer2.text.span.TextAnnotation;
import com.google.android.exoplayer2.text.span.TextEmphasisSpan;
import com.google.android.exoplayer2.util.Util;
import com.google.common.truth.Fact;
......@@ -1075,7 +1076,7 @@ public final class SpannedSubject extends Subject {
* @param position The expected position of the text.
* @return A {@link WithSpanFlags} object for optional additional assertions on the flags.
*/
AndSpanFlags withTextAndPosition(String text, @RubySpan.Position int position);
AndSpanFlags withTextAndPosition(String text, @TextAnnotation.Position int position);
}
private static final RubyText ALREADY_FAILED_WITH_TEXT =
......@@ -1099,7 +1100,7 @@ public final class SpannedSubject extends Subject {
}
@Override
public AndSpanFlags withTextAndPosition(String text, @RubySpan.Position int position) {
public AndSpanFlags withTextAndPosition(String text, @TextAnnotation.Position int position) {
List<Integer> matchingSpanFlags = new ArrayList<>();
List<TextAndPosition> spanTextsAndPositions = new ArrayList<>();
for (RubySpan span : actualSpans) {
......@@ -1116,7 +1117,7 @@ public final class SpannedSubject extends Subject {
private static final class TextAndPosition {
private final String text;
@RubySpan.Position private final int position;
@TextAnnotation.Position private final int position;
private TextAndPosition(String text, int position) {
this.text = text;
......@@ -1164,7 +1165,7 @@ public final class SpannedSubject extends Subject {
* @return A {@link WithSpanFlags} object for optional additional assertions on the flags.
*/
AndSpanFlags withMarkAndPosition(@TextEmphasisSpan.Mark int mark,
@TextEmphasisSpan.Position int position);
@TextAnnotation.Position int position);
}
private static final TextEmphasisDescription ALREADY_FAILED_WITH_MARK =
......@@ -1189,7 +1190,7 @@ public final class SpannedSubject extends Subject {
@Override
public AndSpanFlags withMarkAndPosition(@TextEmphasisSpan.Mark int mark,
@TextEmphasisSpan.Position int position) {
@TextAnnotation.Position int position) {
List<Integer> matchingSpanFlags = new ArrayList<>();
List<MarkAndPosition> textEmphasisMarksAndPositions = new ArrayList<>();
for (TextEmphasisSpan span : actualSpans) {
......@@ -1208,39 +1209,19 @@ public final class SpannedSubject extends Subject {
@TextEmphasisSpan.Mark
private final int mark;
@TextEmphasisSpan.Position
@TextAnnotation.Position
private final int position;
private MarkAndPosition(@TextEmphasisSpan.Mark int mark,
@TextEmphasisSpan.Position int position) {
@TextAnnotation.Position int position) {
this.mark = mark;
this.position = position;
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
TextEmphasisSubject.MarkAndPosition that = (TextEmphasisSubject.MarkAndPosition) o;
return (position == that.position) && (mark == that.mark);
}
@Override
public int hashCode() {
int result = 34613 * mark + position;
return result;
}
@Override
public String toString() {
return String.format("{mark=%s,position=%s}", mark, position);
}
}
}
}
......@@ -609,23 +609,23 @@ public class SpannedSubjectTest {
public void rubySpan_success() {
SpannableString spannable =
createSpannable(
new RubySpan("ruby text", RubySpan.POSITION_OVER), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
new RubySpan("ruby text", TextAnnotation.POSITION_BEFORE), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
assertThat(spannable)
.hasRubySpanBetween(SPAN_START, SPAN_END)
.withTextAndPosition("ruby text", RubySpan.POSITION_OVER)
.withTextAndPosition("ruby text", TextAnnotation.POSITION_BEFORE)
.andFlags(Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
@Test
public void rubySpan_wrongEndIndex() {
checkHasSpanFailsDueToIndexMismatch(
new RubySpan("ruby text", RubySpan.POSITION_OVER), SpannedSubject::hasRubySpanBetween);
new RubySpan("ruby text", TextAnnotation.POSITION_BEFORE), SpannedSubject::hasRubySpanBetween);
}
@Test
public void rubySpan_wrongText() {
SpannableString spannable = createSpannable(new RubySpan("ruby text", RubySpan.POSITION_OVER));
SpannableString spannable = createSpannable(new RubySpan("ruby text", TextAnnotation.POSITION_BEFORE));
AssertionError expected =
expectFailure(
......@@ -633,7 +633,7 @@ public class SpannedSubjectTest {
whenTesting
.that(spannable)
.hasRubySpanBetween(SPAN_START, SPAN_END)
.withTextAndPosition("incorrect text", RubySpan.POSITION_OVER));
.withTextAndPosition("incorrect text", TextAnnotation.POSITION_BEFORE));
assertThat(expected).factValue("value of").contains("rubyTextAndPosition");
assertThat(expected).factValue("expected").contains("text='incorrect text'");
......@@ -642,7 +642,7 @@ public class SpannedSubjectTest {
@Test
public void rubySpan_wrongPosition() {
SpannableString spannable = createSpannable(new RubySpan("ruby text", RubySpan.POSITION_OVER));
SpannableString spannable = createSpannable(new RubySpan("ruby text", TextAnnotation.POSITION_BEFORE));
AssertionError expected =
expectFailure(
......@@ -650,27 +650,27 @@ public class SpannedSubjectTest {
whenTesting
.that(spannable)
.hasRubySpanBetween(SPAN_START, SPAN_END)
.withTextAndPosition("ruby text", RubySpan.POSITION_UNDER));
.withTextAndPosition("ruby text", TextAnnotation.POSITION_AFTER));
assertThat(expected).factValue("value of").contains("rubyTextAndPosition");
assertThat(expected).factValue("expected").contains("position=" + RubySpan.POSITION_UNDER);
assertThat(expected).factValue("but was").contains("position=" + RubySpan.POSITION_OVER);
assertThat(expected).factValue("expected").contains("position=" + TextAnnotation.POSITION_AFTER);
assertThat(expected).factValue("but was").contains("position=" + TextAnnotation.POSITION_BEFORE);
}
@Test
public void rubySpan_wrongFlags() {
checkHasSpanFailsDueToFlagMismatch(
new RubySpan("ruby text", RubySpan.POSITION_OVER),
new RubySpan("ruby text", TextAnnotation.POSITION_BEFORE),
(subject, start, end) ->
subject
.hasRubySpanBetween(start, end)
.withTextAndPosition("ruby text", RubySpan.POSITION_OVER));
.withTextAndPosition("ruby text", TextAnnotation.POSITION_BEFORE));
}
@Test
public void noRubySpan_success() {
SpannableString spannable =
createSpannableWithUnrelatedSpanAnd(new RubySpan("ruby text", RubySpan.POSITION_OVER));
createSpannableWithUnrelatedSpanAnd(new RubySpan("ruby text", TextAnnotation.POSITION_BEFORE));
assertThat(spannable).hasNoRubySpanBetween(UNRELATED_SPAN_START, UNRELATED_SPAN_END);
}
......@@ -678,7 +678,7 @@ public class SpannedSubjectTest {
@Test
public void noRubySpan_failure() {
checkHasNoSpanFails(
new RubySpan("ruby text", RubySpan.POSITION_OVER), SpannedSubject::hasNoRubySpanBetween);
new RubySpan("ruby text", TextAnnotation.POSITION_BEFORE), SpannedSubject::hasNoRubySpanBetween);
}
@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