public void DrawString(string str, double x, double y, StringAlignment align, Size layoutRect, StringColorType colorType = StringColorType.Forground) { TextAlignment TextAlign = TextAlignment.Left; switch (align) { case StringAlignment.Left: TextAlign = TextAlignment.Left; break; case StringAlignment.Center: TextAlign = TextAlignment.Center; break; case StringAlignment.Right: TextAlign = TextAlignment.Right; break; } TextLayout layout = new TextLayout(str, this.FontFamily, this.FontSize, this.Brushes[this.ForegroundColor], layoutRect.Width, TextAlign); layout.FlowDirection = this.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight; layout.Draw(this.Context, x, y); layout.Dispose(); }
public ITextLayout CreateLaytout(string str, SyntaxInfo[] syntaxCollection, IEnumerable <Marker> MarkerRanges, IEnumerable <Selection> SelectRanges, double wrapwidth) { TextLayout layout; if (wrapwidth == LineToIndexTable.NONE_BREAK_LINE) { layout = new TextLayout(str, this.FontFamily, this.FontSize, Brushes[this.Foreground], this.TextArea.Width); layout.TextWarpping = TextWrapping.NoWrap; } else { layout = new TextLayout(str, this.FontFamily, this.FontSize, Brushes[this.Foreground], wrapwidth); layout.TextWarpping = TextWrapping.Wrap; } layout.FlowDirection = this.RightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight; if (syntaxCollection != null) { foreach (SyntaxInfo s in syntaxCollection) { Brush brush = this.Brushes[this.Foreground]; switch (s.type) { case TokenType.Comment: brush = this.Brushes[this.Comment]; break; case TokenType.Keyword1: brush = this.Brushes[this.Keyword1]; break; case TokenType.Keyword2: brush = this.Brushes[this.Keyword2]; break; case TokenType.Literal: brush = this.Brushes[this.Literal]; break; } TextEffect effect = new TextEffect(null, brush, null, s.index, s.length); effect.Freeze(); layout.SetTextEffect(effect); } } if (MarkerRanges != null) { foreach (Marker m in MarkerRanges) { if (m.start == -1 || m.length == 0) { continue; } Brush brush; if (m.hilight == HilightType.Url) { brush = this.Brushes[this.Url]; TextEffect effect = new TextEffect(null, brush, null, m.start, m.length); effect.Freeze(); layout.SetTextEffect(effect); } else { System.Windows.Media.Color color = new System.Windows.Media.Color(); color.A = m.color.A; color.R = m.color.R; color.G = m.color.G; color.B = m.color.B; brush = this.Brushes[color]; } Pen pen = this.Pens.Get(brush, m.hilight); TextDecorationCollection collection = new TextDecorationCollection(); TextDecoration decoration = new TextDecoration(); decoration.Pen = pen; decoration.Location = TextDecorationLocation.Underline; decoration.Freeze(); collection.Add(decoration); if (m.hilight == HilightType.Squiggle) { layout.SetSquilleLine(m.start, m.length, collection); } else { layout.SetTextDecoration(m.start, m.length, collection); } } } return(layout); }