Skip to content

Commit

Permalink
google#1583 - Modify in event time generation of TtmlNode
Browse files Browse the repository at this point in the history
Look for "div" tags when generating the set of times.
  • Loading branch information
szaboa committed Nov 8, 2018
1 parent eafca54 commit c7f763a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ private TtmlNode parseNode(XmlPullParser parser, TtmlNode parent,
long startTime = C.TIME_UNSET;
long endTime = C.TIME_UNSET;
String regionId = TtmlNode.ANONYMOUS_REGION_ID;
String imageId = "";
String imageId = null;
String[] styleIds = null;
int attributeCount = parser.getAttributeCount();
TtmlStyle style = parseStyleAttributes(parser, null);
Expand Down Expand Up @@ -511,7 +511,11 @@ private TtmlNode parseNode(XmlPullParser parser, TtmlNode parent,
}
break;
case ATTR_IMAGE:
imageId = value.substring(1);
// Parse URI reference only if refers to an element in the same document (it must start with '#')
// Resolving URIs from external sources is not supported
if (value.startsWith("#")) {
imageId = value.substring(1);
}
break;
default:
// Do nothing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ public long[] getEventTimesUs() {

private void getEventTimes(TreeSet<Long> out, boolean descendsPNode) {
boolean isPNode = TAG_P.equals(tag);
if (descendsPNode || isPNode) {
boolean isDivNode = TAG_DIV.equals(tag);
if (descendsPNode || isPNode || (isDivNode && imageId != null)) {
if (startTimeUs != C.TIME_UNSET) {
out.add(startTimeUs);
}
Expand All @@ -180,7 +181,7 @@ public String[] getStyleIds() {
}

public List<Cue> getCues(long timeUs, Map<String, TtmlStyle> globalStyles,
Map<String, TtmlRegion> regionMap, Map<String, String> imageMap) {
Map<String, TtmlRegion> regionMap, Map<String, String> imageMap) {

TreeMap<String, SpannableStringBuilder> regionOutputs = new TreeMap<>();
List<Pair<String, String>> regionImageList = new ArrayList<>();
Expand All @@ -204,7 +205,7 @@ public List<Cue> getCues(long timeUs, Map<String, TtmlStyle> globalStyles,
Cue.TYPE_UNSET,
region.line,
region.lineAnchor,
region.width,
region.width == Cue.DIMEN_UNSET ? 0.5f : region.width,
Cue.DIMEN_UNSET
)
);
Expand All @@ -229,12 +230,17 @@ public List<Cue> getCues(long timeUs, Map<String, TtmlStyle> globalStyles,
return cues;
}

private void traverseForImage(long timeUs, String inheritedRegion, List<Pair<String, String>> regionImageList) {
// TODO isActive needed?
private void traverseForImage(
long timeUs,
String inheritedRegion,
List<Pair<String, String>> regionImageList) {

String resolvedRegionId = ANONYMOUS_REGION_ID.equals(regionId) ? inheritedRegion : regionId;
if (TAG_DIV.equals(tag) && imageId != null) {
regionImageList.add(new Pair<>(resolvedRegionId, imageId));

if (isActive(timeUs)) {
if (TAG_DIV.equals(tag) && imageId != null) {
regionImageList.add(new Pair<>(resolvedRegionId, imageId));
}
}

for (int i = 0; i < getChildCount(); ++i) {
Expand Down

0 comments on commit c7f763a

Please sign in to comment.