mirror of
https://github.com/androidx/media.git
synced 2025-05-14 11:09:53 +08:00
Fix bug in TTML inherited text alignment
Fix bug where child does not correctly inherit ancestor's text alignment setting. Make it so that alignment is only applied on a P node. https://www.w3.org/TR/2018/REC-ttml2-20181108/#style-attribute-textAlign
This commit is contained in:
parent
1d96d6b6b0
commit
5ef0ba4171
@ -409,7 +409,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
if (resolvedStyle != null) {
|
if (resolvedStyle != null) {
|
||||||
TtmlRenderUtil.applyStylesToSpan(
|
TtmlRenderUtil.applyStylesToSpan(
|
||||||
text, start, end, resolvedStyle, parent, globalStyles, verticalType);
|
text, start, end, resolvedStyle, parent, globalStyles, verticalType);
|
||||||
if (resolvedStyle.getShearPercentage() != TtmlStyle.UNSPECIFIED_SHEAR && TAG_P.equals(tag)) {
|
if (TAG_P.equals(tag)) {
|
||||||
|
if (resolvedStyle.getShearPercentage() != TtmlStyle.UNSPECIFIED_SHEAR) {
|
||||||
// Shear style should only be applied to P nodes
|
// Shear style should only be applied to P nodes
|
||||||
// https://www.w3.org/TR/2018/REC-ttml2-20181108/#style-attribute-shear
|
// https://www.w3.org/TR/2018/REC-ttml2-20181108/#style-attribute-shear
|
||||||
// The spec doesn't specify the coordinate system to use for block shear
|
// The spec doesn't specify the coordinate system to use for block shear
|
||||||
@ -419,9 +420,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
// This maps the shear percentage to shear angle in graphics coordinates
|
// This maps the shear percentage to shear angle in graphics coordinates
|
||||||
regionOutput.setShearDegrees((resolvedStyle.getShearPercentage() * -90) / 100);
|
regionOutput.setShearDegrees((resolvedStyle.getShearPercentage() * -90) / 100);
|
||||||
}
|
}
|
||||||
|
if (resolvedStyle.getTextAlign() != null) {
|
||||||
regionOutput.setTextAlignment(resolvedStyle.getTextAlign());
|
regionOutput.setTextAlignment(resolvedStyle.getTextAlign());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void cleanUpText(SpannableStringBuilder builder) {
|
private static void cleanUpText(SpannableStringBuilder builder) {
|
||||||
// Having joined the text elements, we need to do some final cleanup on the result.
|
// Having joined the text elements, we need to do some final cleanup on the result.
|
||||||
|
@ -607,6 +607,14 @@ public final class TtmlDecoderTest {
|
|||||||
Cue seventhCue = getOnlyCueAtTimeUs(subtitle, 70_000_000);
|
Cue seventhCue = getOnlyCueAtTimeUs(subtitle, 70_000_000);
|
||||||
assertThat(seventhCue.text.toString()).isEqualTo("No textAlign property");
|
assertThat(seventhCue.text.toString()).isEqualTo("No textAlign property");
|
||||||
assertThat(seventhCue.textAlignment).isNull();
|
assertThat(seventhCue.textAlignment).isNull();
|
||||||
|
|
||||||
|
Cue eighthCue = getOnlyCueAtTimeUs(subtitle, 80_000_000);
|
||||||
|
assertThat(eighthCue.text.toString()).isEqualTo("Ancestor start alignment");
|
||||||
|
assertThat(eighthCue.textAlignment).isEqualTo(Layout.Alignment.ALIGN_NORMAL);
|
||||||
|
|
||||||
|
Cue ninthCue = getOnlyCueAtTimeUs(subtitle, 90_000_000);
|
||||||
|
assertThat(ninthCue.text.toString()).isEqualTo("Not a P node");
|
||||||
|
assertThat(ninthCue.textAlignment).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -24,5 +24,11 @@
|
|||||||
<div>
|
<div>
|
||||||
<p begin="70s" end="78s">No textAlign property</p>
|
<p begin="70s" end="78s">No textAlign property</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<p begin="80s" end="88s" tts:textAlign="start"><span tts:fontSize="50%">Ancestor start</span> alignment</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p begin="90s" end="98s"><span tts:textAlign="start">Not a P node</span></p>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</tt>
|
</tt>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user