Commit d753378b by aptly-io

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.
parent 38148b30
...@@ -35,16 +35,6 @@ import java.util.Map; ...@@ -35,16 +35,6 @@ import java.util.Map;
*/ */
/* package */ final class TtmlRenderUtil { /* 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, public static TtmlStyle resolveStyle(TtmlStyle style, String[] styleIds,
Map<String, TtmlStyle> globalStyles) { Map<String, TtmlStyle> globalStyles) {
if (style == null && styleIds == null) { if (style == null && styleIds == null) {
...@@ -78,14 +68,14 @@ import java.util.Map; ...@@ -78,14 +68,14 @@ import java.util.Map;
int start, int end, TtmlStyle style) { int start, int end, TtmlStyle style) {
if (style.getStyle() != TtmlStyle.UNSPECIFIED) { 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); Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} }
if (style.isLinethrough()) { 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()) { 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()) { if (style.hasColorSpecified()) {
builder.setSpan(new ForegroundColorSpan(style.getColor()), start, end, builder.setSpan(new ForegroundColorSpan(style.getColor()), start, end,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment