| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:sky'; | 5 import 'dart:sky'; |
| 6 | 6 |
| 7 enum FontWeight { | 7 enum FontWeight { |
| 8 w100, | 8 w100, |
| 9 w200, | 9 w200, |
| 10 w300, | 10 w300, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 final String fontFamily; | 67 final String fontFamily; |
| 68 final double fontSize; // in pixels | 68 final double fontSize; // in pixels |
| 69 final FontWeight fontWeight; | 69 final FontWeight fontWeight; |
| 70 final TextAlign textAlign; | 70 final TextAlign textAlign; |
| 71 final List<TextDecoration> decoration; // TODO(ianh): Switch this to a Set<> o
nce Dart supports constant Sets | 71 final List<TextDecoration> decoration; // TODO(ianh): Switch this to a Set<> o
nce Dart supports constant Sets |
| 72 final Color decorationColor; | 72 final Color decorationColor; |
| 73 final TextDecorationStyle decorationStyle; | 73 final TextDecorationStyle decorationStyle; |
| 74 | 74 |
| 75 TextStyle copyWith({ | 75 TextStyle copyWith({ |
| 76 Color color, | 76 Color color, |
| 77 String fontFamily, |
| 77 double fontSize, | 78 double fontSize, |
| 78 FontWeight fontWeight, | 79 FontWeight fontWeight, |
| 79 TextAlign textAlign, | 80 TextAlign textAlign, |
| 80 TextDecoration decoration, | 81 List<TextDecoration> decoration, |
| 81 Color decorationColor, | 82 Color decorationColor, |
| 82 TextDecorationStyle decorationStyle | 83 TextDecorationStyle decorationStyle |
| 83 }) { | 84 }) { |
| 84 return new TextStyle( | 85 return new TextStyle( |
| 85 color: color != null ? color : this.color, | 86 color: color != null ? color : this.color, |
| 86 fontFamily: fontFamily != null ? fontFamily : this.fontFamily, | 87 fontFamily: fontFamily != null ? fontFamily : this.fontFamily, |
| 87 fontSize: fontSize != null ? fontSize : this.fontSize, | 88 fontSize: fontSize != null ? fontSize : this.fontSize, |
| 88 fontWeight: fontWeight != null ? fontWeight : this.fontWeight, | 89 fontWeight: fontWeight != null ? fontWeight : this.fontWeight, |
| 89 textAlign: textAlign != null ? textAlign : this.textAlign, | 90 textAlign: textAlign != null ? textAlign : this.textAlign, |
| 90 decoration: decoration != null ? decoration : this.decoration, | 91 decoration: decoration != null ? decoration : this.decoration, |
| 91 decorationColor: decorationColor != null ? decorationColor : this.decorati
onColor, | 92 decorationColor: decorationColor != null ? decorationColor : this.decorati
onColor, |
| 92 decorationStyle: decorationStyle != null ? decorationStyle : this.decorati
onStyle | 93 decorationStyle: decorationStyle != null ? decorationStyle : this.decorati
onStyle |
| 93 ); | 94 ); |
| 94 } | 95 } |
| 95 | 96 |
| 96 static String _colorToCSSString(Color color) { | 97 static String _colorToCSSString(Color color) { |
| 97 return 'rgba(${color.red}, ${color.green}, ${color.blue}, ${color.alpha / 25
5.0})'; | 98 return 'rgba(${color.red}, ${color.green}, ${color.blue}, ${color.alpha / 25
5.0})'; |
| 98 } | 99 } |
| 99 | 100 |
| 101 TextStyle merge(TextStyle other) { |
| 102 return copyWith( |
| 103 color: other.color, |
| 104 fontFamily: other.fontFamily, |
| 105 fontSize: other.fontSize, |
| 106 fontWeight: other.fontWeight, |
| 107 textAlign: other.textAlign, |
| 108 decoration: other.decoration, |
| 109 decorationColor: other.decorationColor, |
| 110 decorationStyle: other.decorationStyle |
| 111 ); |
| 112 } |
| 113 |
| 100 static String _fontFamilyToCSSString(String fontFamily) { | 114 static String _fontFamilyToCSSString(String fontFamily) { |
| 101 // TODO(hansmuller): escape the fontFamily string. | 115 // TODO(hansmuller): escape the fontFamily string. |
| 102 return fontFamily; | 116 return fontFamily; |
| 103 } | 117 } |
| 104 | 118 |
| 105 static String _decorationToCSSString(List<TextDecoration> decoration) { | 119 static String _decorationToCSSString(List<TextDecoration> decoration) { |
| 106 assert(decoration != null); | 120 assert(decoration != null); |
| 107 const toCSS = const <TextDecoration, String>{ | 121 const toCSS = const <TextDecoration, String>{ |
| 108 TextDecoration.none: 'none', | 122 TextDecoration.none: 'none', |
| 109 TextDecoration.underline: 'underline', | 123 TextDecoration.underline: 'underline', |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 result.add('${prefix}decoration: $decoration'); | 223 result.add('${prefix}decoration: $decoration'); |
| 210 if (decorationColor != null) | 224 if (decorationColor != null) |
| 211 result.add('${prefix}decorationColor: $decorationColor'); | 225 result.add('${prefix}decorationColor: $decorationColor'); |
| 212 if (decorationStyle != null) | 226 if (decorationStyle != null) |
| 213 result.add('${prefix}decorationStyle: $decorationStyle'); | 227 result.add('${prefix}decorationStyle: $decorationStyle'); |
| 214 if (result.isEmpty) | 228 if (result.isEmpty) |
| 215 return '${prefix}<no style specified>'; | 229 return '${prefix}<no style specified>'; |
| 216 return result.join('\n'); | 230 return result.join('\n'); |
| 217 } | 231 } |
| 218 } | 232 } |
| OLD | NEW |