Fix a bug with TTML font styling that displays empty lines.

If the caption line has no text (empty line or only line break), we should not
display its background.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=196823319
This commit is contained in:
hoangtc 2018-05-16 07:09:55 -07:00 committed by Andrew Lewis
parent 972304f16b
commit 24b16f3419
2 changed files with 18 additions and 5 deletions

View File

@ -20,8 +20,11 @@
* Fix playback of livestreams with EXT-X-PROGRAM-DATE-TIME tags * Fix playback of livestreams with EXT-X-PROGRAM-DATE-TIME tags
([#4239](https://github.com/google/ExoPlayer/issues/4239)). ([#4239](https://github.com/google/ExoPlayer/issues/4239)).
* Caption: * Caption:
* Fix a TTML styling issue when there are multiple regions displayed at the * TTML:
same time that can make text size of each region much smaller than defined. * Fix a styling issue when there are multiple regions displayed at the same
time that can make text size of each region much smaller than defined.
* Fix an issue when the caption line has no text (empty line or only line
break), and the line's background is still displayed.
### 2.8.0 ### ### 2.8.0 ###

View File

@ -372,14 +372,24 @@ import com.google.android.exoplayer2.util.Util;
float previousBottom = layout.getLineTop(0); float previousBottom = layout.getLineTop(0);
int lineCount = layout.getLineCount(); int lineCount = layout.getLineCount();
for (int i = 0; i < lineCount; i++) { for (int i = 0; i < lineCount; i++) {
lineBounds.left = layout.getLineLeft(i) - textPaddingX; float lineTextBoundLeft = layout.getLineLeft(i);
lineBounds.right = layout.getLineRight(i) + textPaddingX; float lineTextBoundRight = layout.getLineRight(i);
lineBounds.left = lineTextBoundLeft - textPaddingX;
lineBounds.right = lineTextBoundRight + textPaddingX;
lineBounds.top = previousBottom; lineBounds.top = previousBottom;
lineBounds.bottom = layout.getLineBottom(i); lineBounds.bottom = layout.getLineBottom(i);
previousBottom = lineBounds.bottom; previousBottom = lineBounds.bottom;
float lineTextWidth = lineTextBoundRight - lineTextBoundLeft;
if (lineTextWidth > 0) {
// Do not draw a line's background color if it has no text.
// For some reason, calculating the width manually is more reliable than
// layout.getLineWidth().
// Sometimes, lineTextBoundRight == lineTextBoundLeft, and layout.getLineWidth() still
// returns non-zero value.
canvas.drawRoundRect(lineBounds, cornerRadius, cornerRadius, paint); canvas.drawRoundRect(lineBounds, cornerRadius, cornerRadius, paint);
} }
} }
}
if (edgeType == CaptionStyleCompat.EDGE_TYPE_OUTLINE) { if (edgeType == CaptionStyleCompat.EDGE_TYPE_OUTLINE) {
textPaint.setStrokeJoin(Join.ROUND); textPaint.setStrokeJoin(Join.ROUND);