Search in sources :

Example 1 with TextEmphasisSpan

use of com.google.android.exoplayer2.text.span.TextEmphasisSpan in project ExoPlayer by google.

the class SpannedToHtmlConverterTest method convert_supportsTextEmphasisSpan.

@Test
public void convert_supportsTextEmphasisSpan() {
    SpannableString spanned = new SpannableString("Text emphasis おはよ ございます");
    spanned.setSpan(new TextEmphasisSpan(TextEmphasisSpan.MARK_SHAPE_CIRCLE, TextEmphasisSpan.MARK_FILL_FILLED, TextAnnotation.POSITION_BEFORE), "Text emphasis ".length(), "Text emphasis おはよ".length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spanned.setSpan(new TextEmphasisSpan(TextEmphasisSpan.MARK_SHAPE_SESAME, TextEmphasisSpan.MARK_FILL_OPEN, TextAnnotation.POSITION_AFTER), "Text emphasis おはよ ".length(), "Text emphasis おはよ ございます".length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    SpannedToHtmlConverter.HtmlAndCss htmlAndCss = SpannedToHtmlConverter.convert(spanned, displayDensity);
    assertThat(htmlAndCss.cssRuleSets).isEmpty();
    assertThat(htmlAndCss.html).isEqualTo("Text emphasis <span style='" + "-webkit-text-emphasis-style:filled circle;text-emphasis-style:filled circle;" + "-webkit-text-emphasis-position:over right;text-emphasis-position:over right;" + "display:inline-block;'>&#12362;&#12399;&#12424;</span> <span style='" + "-webkit-text-emphasis-style:open sesame;text-emphasis-style:open sesame;" + "-webkit-text-emphasis-position:under left;text-emphasis-position:under left;" + "display:inline-block;'>&#12372;&#12374;&#12356;&#12414;&#12377;</span>");
}
Also used : SpannableString(android.text.SpannableString) TextEmphasisSpan(com.google.android.exoplayer2.text.span.TextEmphasisSpan) Test(org.junit.Test)

Example 2 with TextEmphasisSpan

use of com.google.android.exoplayer2.text.span.TextEmphasisSpan in project ExoPlayer by google.

the class SubtitleViewUtilsTest method buildCue.

private static Cue buildCue() {
    SpannableString spanned = new SpannableString("TextEmphasis おはよ Ruby ございます 123 Underline RelativeSize AbsoluteSize");
    spanned.setSpan(new TextEmphasisSpan(TextEmphasisSpan.MARK_SHAPE_CIRCLE, TextEmphasisSpan.MARK_FILL_FILLED, TextAnnotation.POSITION_BEFORE), "Text emphasis ".length(), "Text emphasis おはよ".length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spanned.setSpan(new RubySpan("おはよ", TextAnnotation.POSITION_BEFORE), "TextEmphasis おはよ Ruby ".length(), "TextEmphasis おはよ Ruby ございます".length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spanned.setSpan(new HorizontalTextInVerticalContextSpan(), "TextEmphasis おはよ Ruby ございます ".length(), "TextEmphasis おはよ Ruby ございます 123".length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spanned.setSpan(new UnderlineSpan(), "TextEmphasis おはよ Ruby ございます 123 ".length(), "TextEmphasis おはよ Ruby ございます 123 Underline".length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spanned.setSpan(new RelativeSizeSpan(1f), "TextEmphasis おはよ Ruby ございます 123 Underline ".length(), "TextEmphasis おはよ Ruby ございます 123 Underline RelativeSize".length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spanned.setSpan(new AbsoluteSizeSpan(10), "TextEmphasis おはよ Ruby ございます 123 Underline RelativeSize ".length(), "TextEmphasis おはよ Ruby ございます 123 Underline RelativeSize AbsoluteSize".length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return new Cue.Builder().setText(spanned).setTextAlignment(Layout.Alignment.ALIGN_CENTER).setMultiRowAlignment(Layout.Alignment.ALIGN_NORMAL).setLine(5, Cue.LINE_TYPE_NUMBER).setLineAnchor(Cue.ANCHOR_TYPE_END).setPosition(0.4f).setPositionAnchor(Cue.ANCHOR_TYPE_MIDDLE).setTextSize(0.2f, Cue.TEXT_SIZE_TYPE_FRACTIONAL).setSize(0.8f).setWindowColor(Color.CYAN).setVerticalType(Cue.VERTICAL_TYPE_RL).setShearDegrees(-15f).build();
}
Also used : SpannableString(android.text.SpannableString) RubySpan(com.google.android.exoplayer2.text.span.RubySpan) Cue(com.google.android.exoplayer2.text.Cue) HorizontalTextInVerticalContextSpan(com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan) TextEmphasisSpan(com.google.android.exoplayer2.text.span.TextEmphasisSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) UnderlineSpan(android.text.style.UnderlineSpan) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan)

Example 3 with TextEmphasisSpan

use of com.google.android.exoplayer2.text.span.TextEmphasisSpan in project ExoPlayer by google.

the class SubtitleViewUtilsTest method testRemoveEmbeddedFontSizes.

@Test
public void testRemoveEmbeddedFontSizes() {
    Cue.Builder cueBuilder = CUE.buildUpon();
    SubtitleViewUtils.removeEmbeddedFontSizes(cueBuilder);
    Cue strippedCue = cueBuilder.build();
    Spanned originalText = (Spanned) CUE.text;
    Spanned strippedText = (Spanned) strippedCue.text;
    // Assert all non text-size properties and spans are kept
    assertThat(strippedCue.textAlignment).isEqualTo(CUE.textAlignment);
    assertThat(strippedCue.multiRowAlignment).isEqualTo(CUE.multiRowAlignment);
    assertThat(strippedCue.line).isEqualTo(CUE.line);
    assertThat(strippedCue.lineType).isEqualTo(CUE.lineType);
    assertThat(strippedCue.position).isEqualTo(CUE.position);
    assertThat(strippedCue.positionAnchor).isEqualTo(CUE.positionAnchor);
    assertThat(strippedCue.size).isEqualTo(CUE.size);
    assertThat(strippedCue.windowColor).isEqualTo(CUE.windowColor);
    assertThat(strippedCue.windowColorSet).isEqualTo(CUE.windowColorSet);
    assertThat(strippedCue.verticalType).isEqualTo(CUE.verticalType);
    assertThat(strippedCue.shearDegrees).isEqualTo(CUE.shearDegrees);
    TextEmphasisSpan expectedTextEmphasisSpan = originalText.getSpans(0, originalText.length(), TextEmphasisSpan.class)[0];
    assertThat(strippedText).hasTextEmphasisSpanBetween(originalText.getSpanStart(expectedTextEmphasisSpan), originalText.getSpanEnd(expectedTextEmphasisSpan));
    RubySpan expectedRubySpan = originalText.getSpans(0, originalText.length(), RubySpan.class)[0];
    assertThat(strippedText).hasRubySpanBetween(originalText.getSpanStart(expectedRubySpan), originalText.getSpanEnd(expectedRubySpan));
    HorizontalTextInVerticalContextSpan expectedHorizontalTextInVerticalContextSpan = originalText.getSpans(0, originalText.length(), HorizontalTextInVerticalContextSpan.class)[0];
    assertThat(strippedText).hasHorizontalTextInVerticalContextSpanBetween(originalText.getSpanStart(expectedHorizontalTextInVerticalContextSpan), originalText.getSpanEnd(expectedHorizontalTextInVerticalContextSpan));
    UnderlineSpan expectedUnderlineSpan = originalText.getSpans(0, originalText.length(), UnderlineSpan.class)[0];
    assertThat(strippedText).hasUnderlineSpanBetween(originalText.getSpanStart(expectedUnderlineSpan), originalText.getSpanEnd(expectedUnderlineSpan));
    // Assert the text-size properties and spans are removed
    assertThat(strippedCue.textSize).isEqualTo(Cue.DIMEN_UNSET);
    assertThat(strippedCue.textSizeType).isEqualTo(Cue.TYPE_UNSET);
    assertThat(strippedText).hasNoRelativeSizeSpanBetween(0, strippedText.length());
    assertThat(strippedText).hasNoAbsoluteSizeSpanBetween(0, strippedText.length());
}
Also used : RubySpan(com.google.android.exoplayer2.text.span.RubySpan) Cue(com.google.android.exoplayer2.text.Cue) HorizontalTextInVerticalContextSpan(com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan) TextEmphasisSpan(com.google.android.exoplayer2.text.span.TextEmphasisSpan) Spanned(android.text.Spanned) UnderlineSpan(android.text.style.UnderlineSpan) Test(org.junit.Test)

Example 4 with TextEmphasisSpan

use of com.google.android.exoplayer2.text.span.TextEmphasisSpan in project ExoPlayer by google.

the class SpannedSubjectTest method textEmphasis_wrongMarkShape.

@Test
public void textEmphasis_wrongMarkShape() {
    SpannableString spannable = createSpannable(new TextEmphasisSpan(TextEmphasisSpan.MARK_SHAPE_CIRCLE, TextEmphasisSpan.MARK_FILL_FILLED, TextAnnotation.POSITION_AFTER));
    AssertionError expected = expectFailure(whenTesting -> whenTesting.that(spannable).hasTextEmphasisSpanBetween(SPAN_START, SPAN_END).withMarkAndPosition(TextEmphasisSpan.MARK_SHAPE_SESAME, TextEmphasisSpan.MARK_FILL_FILLED, TextAnnotation.POSITION_AFTER));
    assertThat(expected).factValue("value of").contains("textEmphasisMarkAndPosition");
    assertThat(expected).factValue("expected").contains(Util.formatInvariant("{markShape=%d,markFill=%d,position=%d}", TextEmphasisSpan.MARK_SHAPE_SESAME, TextEmphasisSpan.MARK_FILL_FILLED, TextAnnotation.POSITION_AFTER));
    assertThat(expected).factValue("but was").contains(Util.formatInvariant("{markShape=%d,markFill=%d,position=%d}", TextEmphasisSpan.MARK_SHAPE_CIRCLE, TextEmphasisSpan.MARK_FILL_FILLED, TextAnnotation.POSITION_AFTER));
}
Also used : SpannableString(android.text.SpannableString) TextEmphasisSpan(com.google.android.exoplayer2.text.span.TextEmphasisSpan) Test(org.junit.Test)

Example 5 with TextEmphasisSpan

use of com.google.android.exoplayer2.text.span.TextEmphasisSpan in project ExoPlayer by google.

the class SpannedSubjectTest method textEmphasis_wrongPosition.

@Test
public void textEmphasis_wrongPosition() {
    SpannableString spannable = createSpannable(new TextEmphasisSpan(TextEmphasisSpan.MARK_SHAPE_CIRCLE, TextEmphasisSpan.MARK_FILL_FILLED, TextAnnotation.POSITION_BEFORE));
    AssertionError expected = expectFailure(whenTesting -> whenTesting.that(spannable).hasTextEmphasisSpanBetween(SPAN_START, SPAN_END).withMarkAndPosition(TextEmphasisSpan.MARK_SHAPE_CIRCLE, TextEmphasisSpan.MARK_FILL_FILLED, TextAnnotation.POSITION_AFTER));
    assertThat(expected).factValue("value of").contains("textEmphasisMarkAndPosition");
    assertThat(expected).factValue("expected").contains(Util.formatInvariant("{markShape=%d,markFill=%d,position=%d}", TextEmphasisSpan.MARK_SHAPE_CIRCLE, TextEmphasisSpan.MARK_FILL_FILLED, TextAnnotation.POSITION_AFTER));
    assertThat(expected).factValue("but was").contains(Util.formatInvariant("{markShape=%d,markFill=%d,position=%d}", TextEmphasisSpan.MARK_SHAPE_CIRCLE, TextEmphasisSpan.MARK_FILL_FILLED, TextAnnotation.POSITION_BEFORE));
}
Also used : SpannableString(android.text.SpannableString) TextEmphasisSpan(com.google.android.exoplayer2.text.span.TextEmphasisSpan) Test(org.junit.Test)

Aggregations

TextEmphasisSpan (com.google.android.exoplayer2.text.span.TextEmphasisSpan)11 Test (org.junit.Test)8 SpannableString (android.text.SpannableString)7 HorizontalTextInVerticalContextSpan (com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan)5 RubySpan (com.google.android.exoplayer2.text.span.RubySpan)5 UnderlineSpan (android.text.style.UnderlineSpan)4 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)3 RelativeSizeSpan (android.text.style.RelativeSizeSpan)3 Cue (com.google.android.exoplayer2.text.Cue)3 Spanned (android.text.Spanned)2 BackgroundColorSpan (android.text.style.BackgroundColorSpan)2 ForegroundColorSpan (android.text.style.ForegroundColorSpan)2 StrikethroughSpan (android.text.style.StrikethroughSpan)2 StyleSpan (android.text.style.StyleSpan)2 TypefaceSpan (android.text.style.TypefaceSpan)2 Nullable (androidx.annotation.Nullable)2