Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e6e1e2c1
authored
Sep 10, 2015
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Tweaking TTML parsing logic.
parent
04342f2b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
1 deletions
library/src/androidTest/assets/ttml/namespace_confusion.xml
library/src/androidTest/assets/ttml/namespace_not_declared.xml
library/src/androidTest/java/com/google/android/exoplayer/text/ttml/TtmlParserTest.java
library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlParser.java
library/src/androidTest/assets/ttml/namespace_confusion.xml
0 → 100644
View file @
e6e1e2c1
<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>
library/src/androidTest/assets/ttml/namespace_not_declared.xml
0 → 100644
View file @
e6e1e2c1
<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>
library/src/androidTest/java/com/google/android/exoplayer/text/ttml/TtmlParserTest.java
View file @
e6e1e2c1
...
@@ -45,6 +45,10 @@ public final class TtmlParserTest extends InstrumentationTestCase {
...
@@ -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 {
...
@@ -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
++)
{
...
...
library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlParser.java
View file @
e6e1e2c1
...
@@ -194,7 +194,6 @@ public final class TtmlParser implements SubtitleParser {
...
@@ -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
()))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment