From d753378b2f5111bd715968530f2cf552015e2351 Mon Sep 17 00:00:00 2001 From: aptly-io Date: Sat, 12 Dec 2015 21:09:43 +0100 Subject: [PATCH] Allow multiple identical but intermittent spans Multiple identical TTML fontStyles or fontWeights or textDecorations on the content for a specific moment were rendered as if there's only one decoration (span). That's because SpannableStringBuilder.setSpan(span, start, end, flag) found an earlier set span (the static allocated span's reference is the same each time) and only refreshed this first span's start and end values instead of adding a new span at its (new) different range. This patch removes the static data members; this makes the newly allocated span objects distinguishable. A correct implementation is favoured over worries about memory consumption. --- .../exoplayer/text/ttml/TtmlRenderUtil.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlRenderUtil.java b/library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlRenderUtil.java index 63b6cc8886..a2bff2ec1d 100644 --- a/library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlRenderUtil.java +++ b/library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlRenderUtil.java @@ -35,16 +35,6 @@ import java.util.Map; */ /* package */ final class TtmlRenderUtil { - /* spans which are always the same can be reused to avoid object creation */ - private static final StrikethroughSpan STRIKETHROUGH_SPAN = new StrikethroughSpan(); - private static final UnderlineSpan UNDERLINE_SPAN = new UnderlineSpan(); - private static final StyleSpan[] STYLE_SPANS = new StyleSpan[] { - new StyleSpan(TtmlStyle.STYLE_NORMAL), - new StyleSpan(TtmlStyle.STYLE_BOLD), - new StyleSpan(TtmlStyle.STYLE_ITALIC), - new StyleSpan(TtmlStyle.STYLE_BOLD_ITALIC), - }; - public static TtmlStyle resolveStyle(TtmlStyle style, String[] styleIds, Map globalStyles) { if (style == null && styleIds == null) { @@ -78,14 +68,14 @@ import java.util.Map; int start, int end, TtmlStyle style) { if (style.getStyle() != TtmlStyle.UNSPECIFIED) { - builder.setSpan(STYLE_SPANS[style.getStyle()], start, end, + builder.setSpan(new StyleSpan(style.getStyle()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } if (style.isLinethrough()) { - builder.setSpan(STRIKETHROUGH_SPAN, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + builder.setSpan(new StrikethroughSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } if (style.isUnderline()) { - builder.setSpan(UNDERLINE_SPAN, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + builder.setSpan(new UnderlineSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } if (style.hasColorSpecified()) { builder.setSpan(new ForegroundColorSpan(style.getColor()), start, end,