Tweaking TTML parsing logic.
This commit is contained in:
parent
04342f2b76
commit
e6e1e2c1d1
17
library/src/androidTest/assets/ttml/namespace_confusion.xml
Normal file
17
library/src/androidTest/assets/ttml/namespace_confusion.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<tt xmlns:ttm="http://www.w3.org/2006/10/ttaf1#metadata"
|
||||||
|
xmlns:ttp="http://www.w3.org/2006/10/ttaf1#parameter"
|
||||||
|
xmlns:tts="http://www.w3.org/2006/10/ttaf1#style"
|
||||||
|
xmlns="http://www.w3.org/ns/ttml"
|
||||||
|
xmlns="http://www.w3.org/2006/10/ttaf1">
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<p begin="10s" end="18s"
|
||||||
|
tts:backgroundColor="black"
|
||||||
|
abc:fontFamily="sansSerif"
|
||||||
|
def:fontStyle="italic"
|
||||||
|
ghi:textDecoration="lineThrough"
|
||||||
|
jkl:color="yellow">text 1</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</tt>
|
||||||
|
|
@ -0,0 +1,13 @@
|
|||||||
|
<tt>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<p begin="10s" end="18s"
|
||||||
|
tts:backgroundColor="black"
|
||||||
|
abc:fontFamily="sansSerif"
|
||||||
|
def:fontStyle="italic"
|
||||||
|
ghi:textDecoration="lineThrough"
|
||||||
|
jkl:color="yellow">text 1</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</tt>
|
||||||
|
|
@ -45,6 +45,10 @@ public final class TtmlParserTest extends InstrumentationTestCase {
|
|||||||
"ttml/no_underline_linethrough.xml";
|
"ttml/no_underline_linethrough.xml";
|
||||||
private static final String INSTANCE_CREATION_TTML_FILE =
|
private static final String INSTANCE_CREATION_TTML_FILE =
|
||||||
"ttml/instance_creation.xml";
|
"ttml/instance_creation.xml";
|
||||||
|
private static final String NAMESPACE_CONFUSION_TTML_FILE =
|
||||||
|
"ttml/namespace_confusion.xml";
|
||||||
|
private static final String NAMESPACE_NOT_DECLARED_TTML_FILE =
|
||||||
|
"ttml/namespace_not_declared.xml";
|
||||||
|
|
||||||
public void testInlineAttributes() throws IOException {
|
public void testInlineAttributes() throws IOException {
|
||||||
TtmlSubtitle subtitle = getSubtitle(INLINE_ATTRIBUTES_TTML_FILE);
|
TtmlSubtitle subtitle = getSubtitle(INLINE_ATTRIBUTES_TTML_FILE);
|
||||||
@ -331,6 +335,44 @@ public final class TtmlParserTest extends InstrumentationTestCase {
|
|||||||
assertNotSame(thirdP.style.getInheritableStyle(), thirdSpan.style);
|
assertNotSame(thirdP.style.getInheritableStyle(), thirdSpan.style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNamspaceConfusionDoesNotHurt() throws IOException {
|
||||||
|
TtmlSubtitle subtitle = getSubtitle(NAMESPACE_CONFUSION_TTML_FILE);
|
||||||
|
assertEquals(2, subtitle.getEventTimeCount());
|
||||||
|
|
||||||
|
TtmlNode root = subtitle.getRoot();
|
||||||
|
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||||
|
TtmlNode div = queryChildrenForTag(body, TtmlNode.TAG_DIV, 0);
|
||||||
|
TtmlStyle style = queryChildrenForTag(div, TtmlNode.TAG_P, 0).style;
|
||||||
|
|
||||||
|
assertNotNull(style);
|
||||||
|
assertEquals(Color.BLACK, style.getBackgroundColor());
|
||||||
|
assertEquals(Color.YELLOW, style.getColor());
|
||||||
|
assertEquals(TtmlStyle.STYLE_ITALIC, style.getStyle());
|
||||||
|
assertEquals("sansSerif", style.getFontFamily());
|
||||||
|
assertFalse(style.isUnderline());
|
||||||
|
assertTrue(style.isLinethrough());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testNamespaceNotDeclared() throws IOException {
|
||||||
|
TtmlSubtitle subtitle = getSubtitle(NAMESPACE_NOT_DECLARED_TTML_FILE);
|
||||||
|
assertEquals(2, subtitle.getEventTimeCount());
|
||||||
|
|
||||||
|
TtmlNode root = subtitle.getRoot();
|
||||||
|
TtmlNode body = queryChildrenForTag(root, TtmlNode.TAG_BODY, 0);
|
||||||
|
TtmlNode div = queryChildrenForTag(body, TtmlNode.TAG_DIV, 0);
|
||||||
|
TtmlStyle style = queryChildrenForTag(div, TtmlNode.TAG_P, 0).style;
|
||||||
|
|
||||||
|
assertNotNull(style);
|
||||||
|
assertEquals(Color.BLACK, style.getBackgroundColor());
|
||||||
|
assertEquals(Color.YELLOW, style.getColor());
|
||||||
|
assertEquals(TtmlStyle.STYLE_ITALIC, style.getStyle());
|
||||||
|
assertEquals("sansSerif", style.getFontFamily());
|
||||||
|
assertFalse(style.isUnderline());
|
||||||
|
assertTrue(style.isLinethrough());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private TtmlNode queryChildrenForTag(TtmlNode node, String tag, int pos) {
|
private TtmlNode queryChildrenForTag(TtmlNode node, String tag, int pos) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = 0; i < node.getChildCount(); i++) {
|
for (int i = 0; i < node.getChildCount(); i++) {
|
||||||
|
@ -194,7 +194,6 @@ public final class TtmlParser implements SubtitleParser {
|
|||||||
for (int i = 0; i < attributeCount; i++) {
|
for (int i = 0; i < attributeCount; i++) {
|
||||||
String attributeName = parser.getAttributeName(i);
|
String attributeName = parser.getAttributeName(i);
|
||||||
String attributeValue = parser.getAttributeValue(i);
|
String attributeValue = parser.getAttributeValue(i);
|
||||||
// TODO: check if it is safe to remove the namespace prefix
|
|
||||||
switch (ParserUtil.removeNamespacePrefix(attributeName)) {
|
switch (ParserUtil.removeNamespacePrefix(attributeName)) {
|
||||||
case TtmlNode.ATTR_ID:
|
case TtmlNode.ATTR_ID:
|
||||||
if (TtmlNode.TAG_STYLE.equals(parser.getName())) {
|
if (TtmlNode.TAG_STYLE.equals(parser.getName())) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user