diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-07-31 12:29:20 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-07-31 12:29:20 +0200 |
| commit | 9a8f162ca773a0a4b8748e631d53935dfd9831dc (patch) | |
| tree | 70d93447dbfaaf7b04474ddb7542a34bf4faed10 /src/GraphicObjects/TextRun.cs | |
| parent | 5236bd6b11d26f08ed49462252bb815314e9e7dc (diff) | |
| parent | 58ca25a123f4cf8ac959d9ad372494b0c40a41bb (diff) | |
Merge branch 'StylingImprovments'
Diffstat (limited to 'src/GraphicObjects/TextRun.cs')
| -rw-r--r-- | src/GraphicObjects/TextRun.cs | 136 |
1 files changed, 67 insertions, 69 deletions
diff --git a/src/GraphicObjects/TextRun.cs b/src/GraphicObjects/TextRun.cs index 6af22025..35b46f18 100644 --- a/src/GraphicObjects/TextRun.cs +++ b/src/GraphicObjects/TextRun.cs @@ -10,32 +10,30 @@ using System.ComponentModel; namespace Crow { - [Serializable] - [DefaultStyle("#Crow.Styles.TextRun.style")] - public class TextRun : GraphicObject - { + public class TextRun : GraphicObject + { #region CTOR - public TextRun() - { + public TextRun () + { } - public TextRun(string _text) - : base() + public TextRun (string _text) + : base () { Text = _text; } #endregion - //TODO:change protected to private - + //TODO:change protected to private + #region private and protected fields protected string _text = "label"; - Alignment _textAlignment = Alignment.Left; + Alignment _textAlignment = Alignment.Left; bool horizontalStretch = false; bool verticalStretch = false; bool _multiline; bool wordWrap; - protected Rectangle rText; + protected Rectangle rText; protected float widthRatio = 1f; protected float heightRatio = 1f; protected FontExtents fe; @@ -43,69 +41,70 @@ namespace Crow #endregion - [XmlAttributeAttribute()][DefaultValue(Alignment.Left)] - public Alignment TextAlignment - { - get { return _textAlignment; } - set { _textAlignment = value; } - } - [XmlAttributeAttribute()][DefaultValue(false)] + [XmlAttributeAttribute ()] + [DefaultValue (Alignment.Left)] + public Alignment TextAlignment { + get { return _textAlignment; } + set { _textAlignment = value; } + } + [XmlAttributeAttribute ()] + [DefaultValue (false)] public virtual bool HorizontalStretch { get { return horizontalStretch; } set { if (horizontalStretch == value) return; - horizontalStretch = value; + horizontalStretch = value; RegisterForGraphicUpdate (); NotifyValueChanged ("HorizontalStretch", horizontalStretch); } } - [XmlAttributeAttribute()][DefaultValue(false)] + [XmlAttributeAttribute ()] + [DefaultValue (false)] public virtual bool VerticalStretch { get { return verticalStretch; } set { if (verticalStretch == value) return; - verticalStretch = value; + verticalStretch = value; NotifyValueChanged ("VerticalStretch", verticalStretch); } - } - [XmlAttributeAttribute()][DefaultValue("label")] - public string Text - { - get { - return lines == null ? - _text : lines.Aggregate((i, j) => i + Interface.LineBreak + j); + } + [XmlAttributeAttribute ()] + [DefaultValue ("label")] + public string Text { + get { + return lines == null ? + _text : lines.Aggregate ((i, j) => i + Interface.LineBreak + j); } - set - { - if (_text == value) - return; - - RegisterForGraphicUpdate(); + set { + if (_text == value) + return; + + RegisterForGraphicUpdate (); this.RegisterForLayouting (LayoutingType.Sizing); - _text = value; + _text = value; - if (string.IsNullOrEmpty(_text)) + if (string.IsNullOrEmpty (_text)) _text = ""; lines = getLines; - } - } - [XmlAttributeAttribute()][DefaultValue(false)] - public bool Multiline - { + } + } + [XmlAttributeAttribute ()] + [DefaultValue (false)] + public bool Multiline { get { return _multiline; } - set - { + set { _multiline = value; - RegisterForGraphicUpdate(); + RegisterForGraphicUpdate (); } } - [XmlAttributeAttribute()][DefaultValue(false)] + [XmlAttributeAttribute ()] + [DefaultValue (false)] public bool WordWrap { get { return wordWrap; @@ -114,22 +113,22 @@ namespace Crow if (wordWrap == value) return; wordWrap = value; - RegisterForGraphicUpdate(); + RegisterForGraphicUpdate (); } } List<string> lines; List<string> getLines { - get { + get { return _multiline ? - Regex.Split (_text, "\r\n|\r|\n").ToList() : - new List<string>(new string[] { _text }); + Regex.Split (_text, "\r\n|\r|\n").ToList () : + new List<string> (new string [] { _text }); } } #region GraphicObject overrides - protected override int measureRawSize(LayoutingType lt) - { + protected override int measureRawSize (LayoutingType lt) + { if (lines == null) lines = getLines; @@ -142,13 +141,13 @@ namespace Crow fe = gr.FontExtents; - te = new TextExtents(); + te = new TextExtents (); - if (lt == LayoutingType.Height){ + if (lt == LayoutingType.Height) { int lc = lines.Count; //ensure minimal height = text line height if (lc == 0) - lc = 1; + lc = 1; return (int)(fe.Height * lc) + Margin * 2; } @@ -173,8 +172,8 @@ namespace Crow gr.Antialias = Antialias.Subpixel; - rText = new Rectangle(new Size( - measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height))); + rText = new Rectangle (new Size ( + measureRawSize (LayoutingType.Width), measureRawSize (LayoutingType.Height))); rText.Width -= 2 * Margin; rText.Height -= 2 * Margin; @@ -185,16 +184,16 @@ namespace Crow //ignore text alignment if size to content = true //or if text size is larger than client bounds - if (Width < 0 || Height < 0 || rText.Width > cb.Width) - { + if (Width < 0 || Height < 0 || rText.Width > cb.Width) { rText.X = cb.X; rText.Y = cb.Y; - }else { + } else { if (horizontalStretch) { widthRatio = (float)cb.Width / rText.Width; if (!verticalStretch) heightRatio = widthRatio; - }if (verticalStretch) { + } + if (verticalStretch) { heightRatio = (float)cb.Height / rText.Height; if (!horizontalStretch) widthRatio = heightRatio; @@ -203,8 +202,7 @@ namespace Crow rText.Width = (int)(widthRatio * cb.Width); rText.Height = (int)(heightRatio * cb.Height); - switch (TextAlignment) - { + switch (TextAlignment) { case Alignment.TopLeft: //ok rText.X = cb.X; rText.Y = cb.Y; @@ -244,11 +242,11 @@ namespace Crow } } - gr.FontMatrix = new Matrix(widthRatio * Font.Size, 0, 0, heightRatio * Font.Size, 0, 0); + gr.FontMatrix = new Matrix (widthRatio * Font.Size, 0, 0, heightRatio * Font.Size, 0, 0); int curLineCount = 0; - for (int i = 0;i < lines.Count;i++) { + for (int i = 0; i < lines.Count; i++) { string l = lines [i].Replace ("\t", new String (' ', Interface.TabSize)); List<string> wl = new List<string> (); int lineLength = (int)gr.TextExtents (l).XAdvance; @@ -272,14 +270,14 @@ namespace Crow foreach (string ll in wl) { lineLength = (int)gr.TextExtents (ll).XAdvance; - + if (string.IsNullOrWhiteSpace (ll)) { curLineCount++; continue; } - Foreground.SetAsSource (gr); + Foreground.SetAsSource (gr); gr.MoveTo (rText.X, rText.Y + fe.Ascent + fe.Height * curLineCount); gr.ShowText (ll); @@ -287,8 +285,8 @@ namespace Crow curLineCount++; } - } + } } #endregion - } + } } |