mirror of
https://github.com/samsonjs/media.git
synced 2026-04-02 10:45:51 +00:00
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:
parent
38148b303f
commit
d753378b2f
1 changed files with 3 additions and 13 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue