Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: sky/sdk/lib/painting/text_style.dart

Issue 1174213005: Adds TextStyle decoration, decorationColor, decorationStyle (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Updated per review feedback Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/examples/widgets/styled_text.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
25 const bold = FontWeight.w700; 25 const bold = FontWeight.w700;
26 const extraBold = FontWeight.w800; 26 const extraBold = FontWeight.w800;
27 const black = FontWeight.w900; 27 const black = FontWeight.w900;
28 28
29 enum TextAlign { 29 enum TextAlign {
30 left, 30 left,
31 right, 31 right,
32 center 32 center
33 } 33 }
34 34
35 enum TextDecoration {
36 none,
37 underline,
38 overline,
39 lineThrough
40 }
41
42 const underline = const <TextDecoration> [TextDecoration.underline];
43 const overline = const <TextDecoration> [TextDecoration.overline];
44 const lineThrough = const <TextDecoration> [TextDecoration.lineThrough];
45
46 enum TextDecorationStyle {
47 solid,
48 double,
49 dotted,
50 dashed,
51 wavy
52 }
53
35 class TextStyle { 54 class TextStyle {
36 const TextStyle({ 55 const TextStyle({
37 this.color, 56 this.color,
38 this.fontFamily, 57 this.fontFamily,
39 this.fontSize, 58 this.fontSize,
40 this.fontWeight, 59 this.fontWeight,
41 this.textAlign 60 this.textAlign,
61 List<TextDecoration> this.decoration,
62 this.decorationColor,
63 this.decorationStyle
42 }); 64 });
43 65
44 final Color color; 66 final Color color;
45 final String fontFamily; 67 final String fontFamily;
46 final double fontSize; // in pixels 68 final double fontSize; // in pixels
47 final FontWeight fontWeight; 69 final FontWeight fontWeight;
48 final TextAlign textAlign; 70 final TextAlign textAlign;
71 final List<TextDecoration> decoration;
72 final Color decorationColor;
73 final TextDecorationStyle decorationStyle;
74
75 String _decorationToString() {
76 assert(decoration != null);
77 const toCSS = const {
78 TextDecoration.none: 'none',
79 TextDecoration.underline: 'underline',
80 TextDecoration.overline: 'overline',
81 TextDecoration.lineThrough: 'lineThrough'
82 };
83 return decoration.map((d) => toCSS[d]).join(' ');
84 }
49 85
50 TextStyle copyWith({ 86 TextStyle copyWith({
51 Color color, 87 Color color,
52 double fontSize, 88 double fontSize,
53 FontWeight fontWeight, 89 FontWeight fontWeight,
54 TextAlign textAlign 90 TextAlign textAlign,
91 TextDecoration decoration,
92 Color decorationColor,
93 TextDecorationStyle decorationStyle
55 }) { 94 }) {
56 return new TextStyle( 95 return new TextStyle(
57 color: color != null ? color : this.color, 96 color: color != null ? color : this.color,
58 fontFamily: fontFamily != null ? fontFamily : this.fontFamily, 97 fontFamily: fontFamily != null ? fontFamily : this.fontFamily,
59 fontSize: fontSize != null ? fontSize : this.fontSize, 98 fontSize: fontSize != null ? fontSize : this.fontSize,
60 fontWeight: fontWeight != null ? fontWeight : this.fontWeight, 99 fontWeight: fontWeight != null ? fontWeight : this.fontWeight,
61 textAlign: textAlign != null ? textAlign : this.textAlign 100 textAlign: textAlign != null ? textAlign : this.textAlign,
101 decoration: decoration != null ? decoration : this.decoration,
102 decorationColor: decorationColor != null ? decorationColor : this.decorati onColor,
103 decorationStyle: decorationStyle != null ? decorationStyle : this.decorati onStyle
62 ); 104 );
63 } 105 }
64 106
65 bool operator ==(other) { 107 bool operator ==(other) {
66 return other is TextStyle && 108 return other is TextStyle &&
67 color == other.color && 109 color == other.color &&
68 fontFamily == other.fontFamily && 110 fontFamily == other.fontFamily &&
69 fontSize == other.fontSize && 111 fontSize == other.fontSize &&
70 fontWeight == other.fontWeight && 112 fontWeight == other.fontWeight &&
71 textAlign == other.textAlign; 113 textAlign == other.textAlign &&
114 decoration == other.decoration &&
115 decorationColor == other.decorationColor &&
116 decorationStyle == other.decorationStyle;
72 } 117 }
73 118
74 int get hashCode { 119 int get hashCode {
75 // Use Quiver: https://github.com/domokit/mojo/issues/236 120 // Use Quiver: https://github.com/domokit/mojo/issues/236
76 int value = 373; 121 int value = 373;
77 value = 37 * value + color.hashCode; 122 value = 37 * value + color.hashCode;
78 value = 37 * value + fontFamily.hashCode; 123 value = 37 * value + fontFamily.hashCode;
79 value = 37 * value + fontSize.hashCode; 124 value = 37 * value + fontSize.hashCode;
80 value = 37 * value + fontWeight.hashCode; 125 value = 37 * value + fontWeight.hashCode;
81 value = 37 * value + textAlign.hashCode; 126 value = 37 * value + textAlign.hashCode;
127 value = 37 * value + decoration.hashCode;
128 value = 37 * value + decorationColor.hashCode;
129 value = 37 * value + decorationStyle.hashCode;
82 return value; 130 return value;
83 } 131 }
84 132
85 void applyToCSSStyle(CSSStyleDeclaration cssStyle) { 133 void applyToCSSStyle(CSSStyleDeclaration cssStyle) {
86 if (color != null) { 134 if (color != null) {
87 cssStyle['color'] = 'rgba(${color.red}, ${color.green}, ${color.blue}, ${c olor.alpha / 255.0})'; 135 cssStyle['color'] = 'rgba(${color.red}, ${color.green}, ${color.blue}, ${c olor.alpha / 255.0})';
88 } 136 }
89 // TODO(hansmuller): escape the fontFamily string. 137 // TODO(hansmuller): escape the fontFamily string.
90 if (fontFamily != null) { 138 if (fontFamily != null) {
91 cssStyle['font-family'] = fontFamily; 139 cssStyle['font-family'] = fontFamily;
(...skipping 14 matching lines...) Expand all
106 FontWeight.w900: '900' 154 FontWeight.w900: '900'
107 }[fontWeight]; 155 }[fontWeight];
108 } 156 }
109 if (textAlign != null) { 157 if (textAlign != null) {
110 cssStyle['text-align'] = const { 158 cssStyle['text-align'] = const {
111 TextAlign.left: 'left', 159 TextAlign.left: 'left',
112 TextAlign.right: 'right', 160 TextAlign.right: 'right',
113 TextAlign.center: 'center', 161 TextAlign.center: 'center',
114 }[textAlign]; 162 }[textAlign];
115 } 163 }
164 if (decoration != null) {
165 cssStyle['text-decoration'] = _decorationToString();
166 }
167 // TODO(hansmuller): add support for decoration color and style.
116 } 168 }
117 169
118 String toString([String prefix = '']) { 170 String toString([String prefix = '']) {
119 List<String> result = []; 171 List<String> result = [];
120 if (color != null) 172 if (color != null)
121 result.add('${prefix}color: $color'); 173 result.add('${prefix}color: $color');
122 // TODO(hansmuller): escape the fontFamily string. 174 // TODO(hansmuller): escape the fontFamily string.
123 if (fontFamily != null) 175 if (fontFamily != null)
124 result.add('${prefix}fontFamily: "${fontFamily}"'); 176 result.add('${prefix}fontFamily: "${fontFamily}"');
125 if (fontSize != null) 177 if (fontSize != null)
126 result.add('${prefix}fontSize: $fontSize'); 178 result.add('${prefix}fontSize: $fontSize');
127 if (fontWeight != null) 179 if (fontWeight != null)
128 result.add('${prefix}fontWeight: $fontWeight'); 180 result.add('${prefix}fontWeight: $fontWeight');
129 if (textAlign != null) 181 if (textAlign != null)
130 result.add('${prefix}textAlign: $textAlign'); 182 result.add('${prefix}textAlign: $textAlign');
183 if (decoration != null)
184 result.add('${prefix}decoration: ${_decorationToString()}');
185 if (decorationColor != null)
186 result.add('${prefix}decorationColor: $decorationColor');
187 if (decorationStyle != null)
188 result.add('${prefix}decorationStyle: $decorationStyle');
131 if (result.isEmpty) 189 if (result.isEmpty)
132 return '${prefix}<no style specified>'; 190 return '${prefix}<no style specified>';
133 return result.join('\n'); 191 return result.join('\n');
134 } 192 }
135 } 193 }
OLDNEW
« no previous file with comments | « sky/examples/widgets/styled_text.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698