Search in sources :

Example 11 with RubySpan

use of com.google.android.exoplayer2.text.span.RubySpan 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

RubySpan (com.google.android.exoplayer2.text.span.RubySpan)11 Test (org.junit.Test)7 SpannableString (android.text.SpannableString)6 HorizontalTextInVerticalContextSpan (com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan)5 TextEmphasisSpan (com.google.android.exoplayer2.text.span.TextEmphasisSpan)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 ArrayList (java.util.ArrayList)1