Add support for tate-chu-yoko to SpannedToHtmlConverter

PiperOrigin-RevId: 304386857
This commit is contained in:
ibaker 2020-04-02 14:23:51 +01:00 committed by Oliver Woodman
parent fe013979c2
commit 6438e1cdbc
2 changed files with 23 additions and 0 deletions

View File

@ -26,6 +26,7 @@ import android.text.style.UnderlineSpan;
import android.util.SparseArray;
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.util.Assertions;
import com.google.android.exoplayer2.util.Util;
@ -124,6 +125,8 @@ import java.util.regex.Pattern;
ForegroundColorSpan colorSpan = (ForegroundColorSpan) span;
return Util.formatInvariant(
"<span style='color:%s;'>", toCssColor(colorSpan.getForegroundColor()));
} else if (span instanceof HorizontalTextInVerticalContextSpan) {
return "<span style='text-combine-upright:all;'>";
} else if (span instanceof StyleSpan) {
switch (((StyleSpan) span).getStyle()) {
case Typeface.BOLD:
@ -158,6 +161,8 @@ import java.util.regex.Pattern;
private static String getClosingTag(Object span) {
if (span instanceof ForegroundColorSpan) {
return "</span>";
} else if (span instanceof HorizontalTextInVerticalContextSpan) {
return "</span>";
} else if (span instanceof StyleSpan) {
switch (((StyleSpan) span).getStyle()) {
case Typeface.BOLD:

View File

@ -26,6 +26,7 @@ import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan;
import com.google.android.exoplayer2.text.span.RubySpan;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -49,6 +50,23 @@ public class SpannedToHtmlConverterTest {
.isEqualTo("String with <span style='color:rgba(64,32,16,0.502);'>colored</span> section");
}
@Test
public void convert_supportsHorizontalTextInVerticalContextSpan() {
SpannableString spanned = new SpannableString("Vertical text with 123 horizontal numbers");
spanned.setSpan(
new HorizontalTextInVerticalContextSpan(),
"Vertical text with ".length(),
"Vertical text with 123".length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
String html = SpannedToHtmlConverter.convert(spanned);
assertThat(html)
.isEqualTo(
"Vertical text with <span style='text-combine-upright:all;'>123</span> "
+ "horizontal numbers");
}
@Test
public void convert_supportsStyleSpan() {
SpannableString spanned =