Fix positioning issues with ttml regions.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=126790829
This commit is contained in:
olly 2016-07-07 03:49:58 -07:00 committed by Oliver Woodman
parent d3cd0c2ee4
commit 2426907f34
4 changed files with 10 additions and 5 deletions

View file

@ -216,6 +216,9 @@ import android.util.Log;
for (int i = 0; i < lineCount; i++) {
textWidth = Math.max((int) Math.ceil(textLayout.getLineWidth(i)), textWidth);
}
if (cueSize != Cue.DIMEN_UNSET && textWidth < availableWidth) {
textWidth = availableWidth;
}
textWidth += textPaddingX * 2;
int textLeft;

View file

@ -180,7 +180,7 @@ import java.util.TreeSet;
List<Cue> cues = new ArrayList<>();
for (Entry<String, SpannableStringBuilder> entry : regionOutputs.entrySet()) {
TtmlRegion region = regionMap.get(entry.getKey());
cues.add(new Cue(cleanUpText(entry.getValue()), null, region.line, Cue.TYPE_UNSET,
cues.add(new Cue(cleanUpText(entry.getValue()), null, region.line, region.lineType,
Cue.TYPE_UNSET, region.position, Cue.TYPE_UNSET, region.width));
}
return cues;

View file

@ -218,8 +218,8 @@ public final class TtmlParser extends SimpleSubtitleParser {
}
}
}
return position != Cue.DIMEN_UNSET ? new Pair<>(regionId, new TtmlRegion(position, line, width))
: null;
return position != Cue.DIMEN_UNSET ? new Pair<>(regionId, new TtmlRegion(position, line,
Cue.LINE_TYPE_FRACTION, width)) : null;
}
private String[] parseStyleIds(String parentStyleIds) {

View file

@ -24,15 +24,17 @@ import com.google.android.exoplayer.text.Cue;
public final float position;
public final float line;
public final int lineType;
public final float width;
public TtmlRegion() {
this(Cue.DIMEN_UNSET, Cue.DIMEN_UNSET, Cue.DIMEN_UNSET);
this(Cue.DIMEN_UNSET, Cue.DIMEN_UNSET, Cue.TYPE_UNSET, Cue.DIMEN_UNSET);
}
public TtmlRegion(float position, float line, float width) {
public TtmlRegion(float position, float line, int lineType, float width) {
this.position = position;
this.line = line;
this.lineType = lineType;
this.width = width;
}