mirror of
https://github.com/androidx/media.git
synced 2025-05-11 01:31:40 +08:00
Add support for tate-chu-yoko to SpannedToHtmlConverter
PiperOrigin-RevId: 304386857
This commit is contained in:
parent
fe013979c2
commit
6438e1cdbc
@ -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;
|
||||
@ -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 =
|
||||
|
Loading…
x
Reference in New Issue
Block a user