| Index: sky/sdk/lib/painting/text_style.dart
|
| diff --git a/sky/sdk/lib/painting/text_style.dart b/sky/sdk/lib/painting/text_style.dart
|
| index c9fda03bff783713d042ac24ff597c6b81a094e7..19d3c547e0447c9560d92de91ce36220cb91490f 100644
|
| --- a/sky/sdk/lib/painting/text_style.dart
|
| +++ b/sky/sdk/lib/painting/text_style.dart
|
| @@ -39,9 +39,9 @@ enum TextDecoration {
|
| lineThrough
|
| }
|
|
|
| -const underline = const <TextDecoration> [TextDecoration.underline];
|
| -const overline = const <TextDecoration> [TextDecoration.overline];
|
| -const lineThrough = const <TextDecoration> [TextDecoration.lineThrough];
|
| +const underline = const <TextDecoration>[TextDecoration.underline];
|
| +const overline = const <TextDecoration>[TextDecoration.overline];
|
| +const lineThrough = const <TextDecoration>[TextDecoration.lineThrough];
|
|
|
| enum TextDecorationStyle {
|
| solid,
|
| @@ -58,7 +58,7 @@ class TextStyle {
|
| this.fontSize,
|
| this.fontWeight,
|
| this.textAlign,
|
| - List<TextDecoration> this.decoration,
|
| + this.decoration,
|
| this.decorationColor,
|
| this.decorationStyle
|
| });
|
| @@ -68,21 +68,10 @@ class TextStyle {
|
| final double fontSize; // in pixels
|
| final FontWeight fontWeight;
|
| final TextAlign textAlign;
|
| - final List<TextDecoration> decoration;
|
| + final List<TextDecoration> decoration; // TODO(ianh): Switch this to a Set<> once Dart supports constant Sets
|
| final Color decorationColor;
|
| final TextDecorationStyle decorationStyle;
|
|
|
| - String _decorationToString() {
|
| - assert(decoration != null);
|
| - const toCSS = const {
|
| - TextDecoration.none: 'none',
|
| - TextDecoration.underline: 'underline',
|
| - TextDecoration.overline: 'overline',
|
| - TextDecoration.lineThrough: 'lineThrough'
|
| - };
|
| - return decoration.map((d) => toCSS[d]).join(' ');
|
| - }
|
| -
|
| TextStyle copyWith({
|
| Color color,
|
| double fontSize,
|
| @@ -104,41 +93,44 @@ class TextStyle {
|
| );
|
| }
|
|
|
| - bool operator ==(other) {
|
| - if (identical(this, other))
|
| - return true;
|
| - return other is TextStyle &&
|
| - color == other.color &&
|
| - fontFamily == other.fontFamily &&
|
| - fontSize == other.fontSize &&
|
| - fontWeight == other.fontWeight &&
|
| - textAlign == other.textAlign &&
|
| - decoration == other.decoration &&
|
| - decorationColor == other.decorationColor &&
|
| - decorationStyle == other.decorationStyle;
|
| + static String _colorToCSSString(Color color) {
|
| + return 'rgba(${color.red}, ${color.green}, ${color.blue}, ${color.alpha / 255.0})';
|
| }
|
|
|
| - int get hashCode {
|
| - // Use Quiver: https://github.com/domokit/mojo/issues/236
|
| - int value = 373;
|
| - value = 37 * value + color.hashCode;
|
| - value = 37 * value + fontFamily.hashCode;
|
| - value = 37 * value + fontSize.hashCode;
|
| - value = 37 * value + fontWeight.hashCode;
|
| - value = 37 * value + textAlign.hashCode;
|
| - value = 37 * value + decoration.hashCode;
|
| - value = 37 * value + decorationColor.hashCode;
|
| - value = 37 * value + decorationStyle.hashCode;
|
| - return value;
|
| + static String _fontFamilyToCSSString(String fontFamily) {
|
| + // TODO(hansmuller): escape the fontFamily string.
|
| + return fontFamily;
|
| + }
|
| +
|
| + static String _decorationToCSSString(List<TextDecoration> decoration) {
|
| + assert(decoration != null);
|
| + const toCSS = const <TextDecoration, String>{
|
| + TextDecoration.none: 'none',
|
| + TextDecoration.underline: 'underline',
|
| + TextDecoration.overline: 'overline',
|
| + TextDecoration.lineThrough: 'lineThrough'
|
| + };
|
| + return decoration.map((d) => toCSS[d]).join(' ');
|
| + }
|
| +
|
| + static String _decorationStyleToCSSString(TextDecorationStyle decorationStyle) {
|
| + assert(decorationStyle != null);
|
| + const toCSS = const <TextDecorationStyle, String>{
|
| + TextDecorationStyle.solid: 'solid',
|
| + TextDecorationStyle.double: 'double',
|
| + TextDecorationStyle.dotted: 'dotted',
|
| + TextDecorationStyle.dashed: 'dashed',
|
| + TextDecorationStyle.wavy: 'wavy'
|
| + };
|
| + return toCSS[decorationStyle];
|
| }
|
|
|
| void applyToCSSStyle(CSSStyleDeclaration cssStyle) {
|
| if (color != null) {
|
| - cssStyle['color'] = 'rgba(${color.red}, ${color.green}, ${color.blue}, ${color.alpha / 255.0})';
|
| + cssStyle['color'] = _colorToCSSString(color);
|
| }
|
| - // TODO(hansmuller): escape the fontFamily string.
|
| if (fontFamily != null) {
|
| - cssStyle['font-family'] = fontFamily;
|
| + cssStyle['font-family'] = _fontFamilyToCSSString(fontFamily);
|
| }
|
| if (fontSize != null) {
|
| cssStyle['font-size'] = "${fontSize}px";
|
| @@ -164,9 +156,40 @@ class TextStyle {
|
| }[textAlign];
|
| }
|
| if (decoration != null) {
|
| - cssStyle['text-decoration'] = _decorationToString();
|
| + cssStyle['text-decoration'] = _decorationToCSSString(decoration);
|
| + if (decorationColor != null)
|
| + cssStyle['text-decoration-color'] = _colorToCSSString(decorationColor);
|
| + if (decorationStyle != null)
|
| + cssStyle['text-decoration-style'] = _decorationStyleToCSSString(decorationStyle);
|
| }
|
| - // TODO(hansmuller): add support for decoration color and style.
|
| + }
|
| +
|
| + bool operator ==(other) {
|
| + if (identical(this, other))
|
| + return true;
|
| + return other is TextStyle &&
|
| + color == other.color &&
|
| + fontFamily == other.fontFamily &&
|
| + fontSize == other.fontSize &&
|
| + fontWeight == other.fontWeight &&
|
| + textAlign == other.textAlign &&
|
| + decoration == other.decoration &&
|
| + decorationColor == other.decorationColor &&
|
| + decorationStyle == other.decorationStyle;
|
| + }
|
| +
|
| + int get hashCode {
|
| + // Use Quiver: https://github.com/domokit/mojo/issues/236
|
| + int value = 373;
|
| + value = 37 * value + color.hashCode;
|
| + value = 37 * value + fontFamily.hashCode;
|
| + value = 37 * value + fontSize.hashCode;
|
| + value = 37 * value + fontWeight.hashCode;
|
| + value = 37 * value + textAlign.hashCode;
|
| + value = 37 * value + decoration.hashCode;
|
| + value = 37 * value + decorationColor.hashCode;
|
| + value = 37 * value + decorationStyle.hashCode;
|
| + return value;
|
| }
|
|
|
| String toString([String prefix = '']) {
|
| @@ -183,7 +206,7 @@ class TextStyle {
|
| if (textAlign != null)
|
| result.add('${prefix}textAlign: $textAlign');
|
| if (decoration != null)
|
| - result.add('${prefix}decoration: ${_decorationToString()}');
|
| + result.add('${prefix}decoration: $decoration');
|
| if (decorationColor != null)
|
| result.add('${prefix}decorationColor: $decorationColor');
|
| if (decorationStyle != null)
|
|
|