Commit 6438e1cd by ibaker Committed by Oliver Woodman

Add support for tate-chu-yoko to SpannedToHtmlConverter

PiperOrigin-RevId: 304386857
parent fe013979
......@@ -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:
......
......@@ -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;
......@@ -50,6 +51,23 @@ public class SpannedToHtmlConverterTest {
}
@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 =
new SpannableString("String with bold, italic and bold-italic sections.");
......
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