Пример #1
0
 public void SetTextColor(MyTextLayout layout, int start, int length, Color4?color)
 {
     if (color == null)
     {
         return;
     }
     layout.SetDrawingEffect(this._factory.GetSolidColorBrush((Color4)color), new DW.TextRange(start, length));
 }
Пример #2
0
        public ITextLayout CreateLaytout(string str, SyntaxInfo[] syntaxCollection, IEnumerable <Marker> MarkerRanges, IEnumerable <Selection> SelectRanges, double WrapWidth)
        {
            float dpix, dpiy;

            this.GetDpi(out dpix, out dpiy);

            double layoutWidth = this.TextArea.Width;

            if (WrapWidth != LineToIndexTable.NONE_BREAK_LINE)
            {
                this.format.WordWrapping = DW.WordWrapping.Wrap;
                layoutWidth = WrapWidth;
            }
            else
            {
                this.format.WordWrapping = DW.WordWrapping.NoWrap;
            }

            bool         hasNewLine = str.Length > 0 && str[str.Length - 1] == Document.NewLine;
            MyTextLayout newLayout  = this._factory.GetTextLayout(
                str,
                this.format,
                layoutWidth,
                this.TextArea.Height,
                dpiy,
                hasNewLine && this.ShowLineBreak);

            newLayout.SetLineSpacing(this.emSize.Height);
            newLayout.SetLineBreakBrush(this._factory.GetSolidColorBrush(this.ControlChar));
            if (syntaxCollection != null)
            {
                foreach (SyntaxInfo s in syntaxCollection)
                {
                    D2D.SolidColorBrush brush = this._factory.GetSolidColorBrush(this.Foreground);
                    switch (s.type)
                    {
                    case TokenType.Comment:
                        brush = this._factory.GetSolidColorBrush(this.Comment);
                        break;

                    case TokenType.Keyword1:
                        brush = this._factory.GetSolidColorBrush(this.Keyword1);
                        break;

                    case TokenType.Keyword2:
                        brush = this._factory.GetSolidColorBrush(this.Keyword2);
                        break;

                    case TokenType.Literal:
                        brush = this._factory.GetSolidColorBrush(this.Literal);
                        break;
                    }
                    newLayout.SetDrawingEffect(brush, new DW.TextRange(s.index, s.length));
                }
            }

            if (syntaxCollection != null)
            {
                foreach (SyntaxInfo s in syntaxCollection)
                {
                    D2D.SolidColorBrush brush = null;
                    switch (s.type)
                    {
                    case TokenType.Comment:
                        brush = this._factory.GetSolidColorBrush(this.Comment);
                        break;

                    case TokenType.Keyword1:
                        brush = this._factory.GetSolidColorBrush(this.Keyword1);
                        break;

                    case TokenType.Keyword2:
                        brush = this._factory.GetSolidColorBrush(this.Keyword2);
                        break;

                    case TokenType.Literal:
                        brush = this._factory.GetSolidColorBrush(this.Literal);
                        break;
                    }
                    newLayout.SetDrawingEffect(brush, new DW.TextRange(s.index, s.length));
                }
            }

            if (MarkerRanges != null)
            {
                newLayout.Markers = MarkerRanges.ToArray();
                foreach (Marker sel in newLayout.Markers)
                {
                    if (sel.length == 0 || sel.start == -1)
                    {
                        continue;
                    }
                    if (sel.hilight == HilightType.Url)
                    {
                        newLayout.SetDrawingEffect(this._factory.GetSolidColorBrush(this.Url), new DW.TextRange(sel.start, sel.length));
                    }
                }
            }

            if (SelectRanges != null)
            {
                newLayout.Selects = SelectRanges.ToArray();
                if (this.HilightForeground.Alpha > 0.0)
                {
                    foreach (Selection sel in SelectRanges)
                    {
                        if (sel.length == 0 || sel.start == -1)
                        {
                            continue;
                        }

                        newLayout.SetDrawingEffect(this._factory.GetSolidColorBrush(this.HilightForeground), new DW.TextRange(sel.start, sel.length));
                    }
                }
            }

            this.format.WordWrapping = DW.WordWrapping.NoWrap;

            return(newLayout);
        }