Search in sources :

Example 6 with HorizontalTextInVerticalContextSpan

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

the class SpannedSubjectTest method noHorizontalTextInVerticalContextSpan_success.

@Test
public void noHorizontalTextInVerticalContextSpan_success() {
    SpannableString spannable = createSpannableWithUnrelatedSpanAnd(new HorizontalTextInVerticalContextSpan());
    assertThat(spannable).hasNoHorizontalTextInVerticalContextSpanBetween(UNRELATED_SPAN_START, UNRELATED_SPAN_END);
}
Also used : SpannableString(android.text.SpannableString) HorizontalTextInVerticalContextSpan(com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan) Test(org.junit.Test)

Example 7 with HorizontalTextInVerticalContextSpan

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

the class SubtitleViewUtilsTest method testRemoveAllEmbeddedStyling.

@Test
public void testRemoveAllEmbeddedStyling() {
    Cue.Builder cueBuilder = CUE.buildUpon();
    SubtitleViewUtils.removeAllEmbeddedStyling(cueBuilder);
    Cue strippedCue = cueBuilder.build();
    Spanned originalText = (Spanned) CUE.text;
    Spanned strippedText = (Spanned) strippedCue.text;
    // Assert all non styling 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.textSize).isEqualTo(Cue.DIMEN_UNSET);
    assertThat(strippedCue.textSizeType).isEqualTo(Cue.TYPE_UNSET);
    assertThat(strippedCue.size).isEqualTo(CUE.size);
    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));
    // Assert all styling properties and spans are removed
    assertThat(strippedCue.windowColorSet).isFalse();
    assertThat(strippedText).hasNoUnderlineSpanBetween(0, strippedText.length());
    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) Test(org.junit.Test)

Example 8 with HorizontalTextInVerticalContextSpan

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

the class SpannedToHtmlConverter method getOpeningTag.

@Nullable
private static String getOpeningTag(Object span, float displayDensity) {
    if (span instanceof StrikethroughSpan) {
        return "<span style='text-decoration:line-through;'>";
    } else if (span instanceof ForegroundColorSpan) {
        ForegroundColorSpan colorSpan = (ForegroundColorSpan) span;
        return Util.formatInvariant("<span style='color:%s;'>", HtmlUtils.toCssRgba(colorSpan.getForegroundColor()));
    } else if (span instanceof BackgroundColorSpan) {
        BackgroundColorSpan colorSpan = (BackgroundColorSpan) span;
        return Util.formatInvariant("<span class='bg_%s'>", colorSpan.getBackgroundColor());
    } else if (span instanceof HorizontalTextInVerticalContextSpan) {
        return "<span style='text-combine-upright:all;'>";
    } else if (span instanceof AbsoluteSizeSpan) {
        AbsoluteSizeSpan absoluteSizeSpan = (AbsoluteSizeSpan) span;
        float sizeCssPx = absoluteSizeSpan.getDip() ? absoluteSizeSpan.getSize() : absoluteSizeSpan.getSize() / displayDensity;
        return Util.formatInvariant("<span style='font-size:%.2fpx;'>", sizeCssPx);
    } else if (span instanceof RelativeSizeSpan) {
        return Util.formatInvariant("<span style='font-size:%.2f%%;'>", ((RelativeSizeSpan) span).getSizeChange() * 100);
    } else if (span instanceof TypefaceSpan) {
        @Nullable String fontFamily = ((TypefaceSpan) span).getFamily();
        return fontFamily != null ? Util.formatInvariant("<span style='font-family:\"%s\";'>", fontFamily) : null;
    } else if (span instanceof StyleSpan) {
        switch(((StyleSpan) span).getStyle()) {
            case Typeface.BOLD:
                return "<b>";
            case Typeface.ITALIC:
                return "<i>";
            case Typeface.BOLD_ITALIC:
                return "<b><i>";
            default:
                return null;
        }
    } else if (span instanceof RubySpan) {
        RubySpan rubySpan = (RubySpan) span;
        switch(rubySpan.position) {
            case TextAnnotation.POSITION_BEFORE:
                return "<ruby style='ruby-position:over;'>";
            case TextAnnotation.POSITION_AFTER:
                return "<ruby style='ruby-position:under;'>";
            case TextAnnotation.POSITION_UNKNOWN:
                return "<ruby style='ruby-position:unset;'>";
            default:
                return null;
        }
    } else if (span instanceof UnderlineSpan) {
        return "<u>";
    } else if (span instanceof TextEmphasisSpan) {
        TextEmphasisSpan textEmphasisSpan = (TextEmphasisSpan) span;
        String style = getTextEmphasisStyle(textEmphasisSpan.markShape, textEmphasisSpan.markFill);
        String position = getTextEmphasisPosition(textEmphasisSpan.position);
        return Util.formatInvariant("<span style='-webkit-text-emphasis-style:%1$s;text-emphasis-style:%1$s;" + "-webkit-text-emphasis-position:%2$s;text-emphasis-position:%2$s;" + "display:inline-block;'>", style, position);
    } else {
        return null;
    }
}
Also used : RubySpan(com.google.android.exoplayer2.text.span.RubySpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TextEmphasisSpan(com.google.android.exoplayer2.text.span.TextEmphasisSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) UnderlineSpan(android.text.style.UnderlineSpan) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) HorizontalTextInVerticalContextSpan(com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan) StyleSpan(android.text.style.StyleSpan) BackgroundColorSpan(android.text.style.BackgroundColorSpan) Nullable(androidx.annotation.Nullable) StrikethroughSpan(android.text.style.StrikethroughSpan) TypefaceSpan(android.text.style.TypefaceSpan) Nullable(androidx.annotation.Nullable)

Aggregations

HorizontalTextInVerticalContextSpan (com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan)8 RubySpan (com.google.android.exoplayer2.text.span.RubySpan)5 TextEmphasisSpan (com.google.android.exoplayer2.text.span.TextEmphasisSpan)5 Test (org.junit.Test)5 SpannableString (android.text.SpannableString)4 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