Discard subtitles with invalid positions

textWidth can be negative if textLeft extends parentRight (i.e.
the subtitle is positioned entirely off the screen to the RHS).
We should just discard and log a warning in this case.

Issue: #2497

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148481310
This commit is contained in:
olly 2017-02-24 11:19:42 -08:00 committed by Oliver Woodman
parent 129334d2a0
commit ad857852e5

View file

@ -266,6 +266,12 @@ import com.google.android.exoplayer2.util.Util;
textRight = textLeft + textWidth;
}
textWidth = textRight - textLeft;
if (textWidth <= 0) {
Log.w(TAG, "Skipped drawing subtitle cue (invalid horizontal positioning)");
return;
}
int textTop;
if (cueLine != Cue.DIMEN_UNSET) {
int anchorPosition;
@ -292,8 +298,6 @@ import com.google.android.exoplayer2.util.Util;
textTop = parentBottom - textHeight - (int) (parentHeight * bottomPaddingFraction);
}
textWidth = textRight - textLeft;
// Update the derived drawing variables.
this.textLayout = new StaticLayout(cueText, textPaint, textWidth, textAlignment, spacingMult,
spacingAdd, true);