spanStyle static method
Implementation
static TextStyle spanStyle(SpannedTag tag, [TextStyle? style]) {
style ??= TextStyle();
TextDecoration td(TextDecoration decoration) {
if (style?.decoration == null) return decoration;
return TextDecoration.combine([style!.decoration!, decoration]);
}
switch (tag.tag) {
case 'b':
case 'bold':
return style.copyWith(fontWeight: FontWeight.bold);
case 'i':
case 'italic':
return style.copyWith(fontStyle: FontStyle.italic);
case 'l':
case 'lt':
case 'line_through':
case 'line-through':
return style.copyWith(decoration: td(TextDecoration.lineThrough));
case 'o':
case 'overline':
return style.copyWith(decoration: td(TextDecoration.overline));
case 'u':
case 'underline':
return style.copyWith(decoration: td(TextDecoration.underline));
case 'c':
case 'color':
if (tag.attr == null) return style;
return style.copyWith(color: _color(tag.attr!));
case 'bg':
case 'background':
case 'background_color':
case 'background-color':
if (tag.attr == null) return style;
return style.copyWith(backgroundColor: _color(tag.attr!));
case 'dc':
case 'decoration_color':
case 'decoration-color':
if (tag.attr == null) return style;
return style.copyWith(decorationColor: _color(tag.attr!));
case 'ds':
case 'decoration_style':
case 'decoration-style':
if (tag.attr == null) return style;
return style.copyWith(decorationStyle: _decorationStyle(tag.attr!));
case 'dt':
case 'decoration_thickness':
case 'decoration-thickness':
if (tag.attr == null) return style;
return style.copyWith(decorationThickness: _double(tag.attr!));
case 'f':
case 'ff':
case 'family':
case 'font_family':
case 'font-family':
if (tag.attr == null) return style;
return style.copyWith(fontFamily: _string(tag.attr!));
case 's':
case 'fs':
case 'font_size':
case 'font-size':
if (tag.attr == null) return style;
return style.copyWith(fontSize: _double(tag.attr!));
case 'w':
case 'fw':
case 'weight':
case 'font_weight':
case 'font-weight':
if (tag.attr == null) return style;
return style.copyWith(fontWeight: _fontWeight(tag.attr!));
case 'h':
case 'height':
if (tag.attr == null) return style;
return style.copyWith(height: _double(tag.attr!));
case 'lo':
case 'locale':
if (tag.attr == null) return style;
return style.copyWith(locale: _locale(tag.attr!));
case 'ls':
case 'letter_spacing':
case 'letter-spacing':
if (tag.attr == null) return style;
return style.copyWith(letterSpacing: _double(tag.attr!));
case 'ws':
case 'word_spacing':
case 'word-spacing':
if (tag.attr == null) return style;
return style.copyWith(wordSpacing: _double(tag.attr!));
default:
return style;
}
}