Index: sky/sdk/lib/framework/rendering/paragraph.dart |
diff --git a/sky/sdk/lib/framework/rendering/paragraph.dart b/sky/sdk/lib/framework/rendering/paragraph.dart |
index c0823a7b591e1456d9e54bf315baaaf46c38a6ed..7494b2c6c2b988e6013d1a08c57f182ffed9475e 100644 |
--- a/sky/sdk/lib/framework/rendering/paragraph.dart |
+++ b/sky/sdk/lib/framework/rendering/paragraph.dart |
@@ -11,6 +11,40 @@ class RenderInline extends RenderObject { |
String data; |
} |
+enum FontWeight { |
+ light, // 300 |
+ regular, // 400 |
+ medium, // 500 |
+} |
+ |
+int trueTypeWeightNumber(FontWeight weight) { |
jackson
2015/06/12 01:32:50
This global function might make sense as a getter
|
+ switch(weight) { |
+ case FontWeight.light: |
+ return 300; |
+ case FontWeight.regular: |
+ return 400; |
+ case FontWeight.medium: |
+ return 500; |
+ } |
+} |
+ |
+class TextStyle { |
+ final Color color; |
+ final String fontSize; |
+ final FontWeight fontWeight; |
+ |
+ const TextStyle({ |
+ this.color, |
+ this.fontSize, |
+ this.fontWeight |
+ }); |
+ |
+ bool operator ==(other) => other is TextStyle && |
+ color == other.color && |
+ fontSize == other.fontSize && |
+ fontWeight == other.fontWeight; |
+} |
+ |
// Unfortunately, using full precision floating point here causes bad layouts |
// because floating point math isn't associative. If we add and subtract |
// padding, for example, we'll get different values when we estimate sizes and |
@@ -26,8 +60,9 @@ class RenderParagraph extends RenderBox { |
RenderParagraph({ |
String text, |
- Color color |
- }) : _color = color { |
+ Color color, |
+ TextStyle style |
+ }) : _style = style { |
_layoutRoot.rootElement = _document.createElement('p'); |
this.text = text; |
} |
@@ -41,12 +76,13 @@ class RenderParagraph extends RenderBox { |
markNeedsLayout(); |
} |
- Color _color = const Color(0xFF000000); |
- Color get color => _color; |
- void set color (Color value) { |
- if (_color != value) { |
- _color = value; |
- markNeedsPaint(); |
+ TextStyle _style; |
+ TextStyle get style => _style; |
+ void set style (TextStyle value) { |
+ if (_style != value) { |
+ // TODO(hansmuller): decide if a new layout or paint is needed |
+ markNeedsLayout(); |
+ _style = value; |
} |
} |
@@ -106,9 +142,19 @@ class RenderParagraph extends RenderBox { |
if (_constraintsForCurrentLayout != constraints && constraints != null) |
_layout(constraints); |
- if (_color != null) { |
- _layoutRoot.rootElement.style['color'] = |
- 'rgba(${_color.red}, ${_color.green}, ${_color.blue}, ${_color.alpha / 255.0 })'; |
+ if (style != null) { |
+ var cssStyle = _layoutRoot.rootElement.style; |
+ if (style.color != null) { |
+ Color c = style.color; |
+ cssStyle['color'] = |
+ 'rgba(${c.red}, ${c.green}, ${c.blue}, ${c.alpha / 255.0 })'; |
jackson
2015/06/12 01:32:50
you've got an extra space here
|
+ } |
+ if (style.fontSize != null) { |
+ cssStyle['font-size'] = style.fontSize; |
+ } |
+ if (style.fontWeight != null) { |
+ cssStyle['font-weight'] = trueTypeWeightNumber(style.fontWeight).toString(); |
+ } |
} |
_layoutRoot.paint(canvas); |
} |