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.
This commit is contained in:
aptly-io 2015-12-12 21:09:43 +01:00
parent 38148b303f
commit d753378b2f

View file

@ -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<String, TtmlStyle> 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,