Commit 27576cfc by Denise LaFayette

Fix bug where rubyPosition in text node is not applied

Also fix bug where rubyPosition in ruby container style is not applied
parent 227f9a3b
...@@ -178,12 +178,21 @@ import java.util.Map; ...@@ -178,12 +178,21 @@ import java.util.Map;
break; break;
} }
// TODO: Get rubyPosition from `textNode` when TTML inheritance is implemented. @Nullable TtmlStyle textStyle = resolveStyle(textNode.style, textNode.getStyleIds(),
globalStyles);
// Use position from ruby text node if defined
@TextAnnotation.Position @TextAnnotation.Position
int rubyPosition = int rubyPosition =
containerNode.style != null textStyle != null ? textStyle.getRubyPosition() : TextAnnotation.POSITION_UNKNOWN;
? containerNode.style.getRubyPosition()
: TextAnnotation.POSITION_UNKNOWN; if (rubyPosition == TextAnnotation.POSITION_UNKNOWN) {
// If ruby position is not defined, use position info from container node
@Nullable TtmlStyle containerStyle = resolveStyle(containerNode.style,
containerNode.getStyleIds(), globalStyles);
rubyPosition = containerStyle != null ? containerStyle.getRubyPosition() : rubyPosition;
}
builder.setSpan( builder.setSpan(
new RubySpan(rubyText, rubyPosition), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); new RubySpan(rubyText, rubyPosition), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
break; break;
......
...@@ -37,7 +37,9 @@ import java.util.Map; ...@@ -37,7 +37,9 @@ import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** Unit test for {@link TtmlDecoder}. */ /**
* Unit test for {@link TtmlDecoder}.
*/
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class TtmlDecoderTest { public final class TtmlDecoderTest {
...@@ -114,10 +116,8 @@ public final class TtmlDecoderTest { ...@@ -114,10 +116,8 @@ public final class TtmlDecoderTest {
* </code>. * </code>.
* *
* @throws IOException thrown if reading subtitle file fails. * @throws IOException thrown if reading subtitle file fails.
* @see <a * @see <a href="https://github.com/android/platform_frameworks_base/blob/jb-mr2-release/graphics/java/android/graphics/Color.java#L414">
* href="https://github.com/android/platform_frameworks_base/blob/jb-mr2-release/graphics/java/android/graphics/Color.java#L414"> * JellyBean Color</a> <a href="https://github.com/android/platform_frameworks_base/blob/kitkat-mr2.2-release/graphics/java/android/graphics/Color.java#L414">
* JellyBean Color</a> <a
* href="https://github.com/android/platform_frameworks_base/blob/kitkat-mr2.2-release/graphics/java/android/graphics/Color.java#L414">
* Kitkat Color</a> * Kitkat Color</a>
*/ */
@Test @Test
...@@ -710,6 +710,18 @@ public final class TtmlDecoderTest { ...@@ -710,6 +710,18 @@ public final class TtmlDecoderTest {
Spanned sixthCue = getOnlyCueTextAtTimeUs(subtitle, 60_000_000); Spanned sixthCue = getOnlyCueTextAtTimeUs(subtitle, 60_000_000);
assertThat(sixthCue.toString()).isEqualTo("Cue with annotated text."); assertThat(sixthCue.toString()).isEqualTo("Cue with annotated text.");
assertThat(sixthCue).hasNoRubySpanBetween(0, sixthCue.length()); assertThat(sixthCue).hasNoRubySpanBetween(0, sixthCue.length());
Spanned seventhCue = getOnlyCueTextAtTimeUs(subtitle, 70_000_000);
assertThat(seventhCue.toString()).isEqualTo("Cue with annotated text.");
assertThat(seventhCue)
.hasRubySpanBetween("Cue with ".length(), "Cue with annotated".length())
.withTextAndPosition("rubies", TextAnnotation.POSITION_BEFORE);
Spanned eighthCue = getOnlyCueTextAtTimeUs(subtitle, 80_000_000);
assertThat(eighthCue.toString()).isEqualTo("Cue with annotated text.");
assertThat(eighthCue)
.hasRubySpanBetween("Cue with ".length(), "Cue with annotated".length())
.withTextAndPosition("rubies", TextAnnotation.POSITION_AFTER);
} }
@Test @Test
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
<style id="cont" tts:ruby="container" /> <style id="cont" tts:ruby="container" />
<style id="base" tts:ruby="base" /> <style id="base" tts:ruby="base" />
<style id="text" tts:ruby="text" /> <style id="text" tts:ruby="text" />
<style id="contpos" tts:ruby="container" tts:rubyPosition="before" />
<style id="textpos" tts:ruby="text" tts:rubyPosition="after" />
</styling> </styling>
</head> </head>
<body> <body>
...@@ -76,5 +78,27 @@ ...@@ -76,5 +78,27 @@
text. text.
</p> </p>
</div> </div>
<div>
<!-- ruby info in style block and ruby position in contpos -->
<p begin="70s" end="78s">
Cue with
<span style="contpos">
<span style="base">annotated</span>
<span style="text">rubies</span>
text.
</span>
</p>
</div>
<div>
<!-- ruby info and position in style block for base and text -->
<p begin="80s" end="88s">
Cue with
<span style="contpos">
<span style="base">annotated</span>
<span style="textpos">rubies</span>
text.
</span>
</p>
</div>
</body> </body>
</tt> </tt>
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