コード例 #1
0
        public void DrawString(string str, double x, double y, StringAlignment align, Size layoutRect, StringColorType colorType = StringColorType.Forground)
        {
            if (this.render == null || this.render.IsDisposed)
            {
                return;
            }
            float dpix, dpiy;

            D2D.SolidColorBrush brush;
            switch (colorType)
            {
            case StringColorType.Forground:
                brush = this._factory.GetSolidColorBrush(this.Foreground);
                break;

            case StringColorType.LineNumber:
                brush = this._factory.GetSolidColorBrush(this.LineNumber);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            this.GetDpi(out dpix, out dpiy);
            MyTextLayout layout = this._factory.GetTextLayout(str, this.format, (float)layoutRect.Width, (float)layoutRect.Height, dpix, false);

            layout.StringAlignment = align;
            layout.Draw(this.render, (float)x, (float)y, brush);
            layout.Dispose();
        }
コード例 #2
0
        public void DrawOneLine(Document doc, LineToIndexTable lti, int row, double x, double y, PreDrawOneLineHandler PreDrawOneLine)
        {
            int lineLength = lti.GetLengthFromLineNumber(row);

            if (lineLength == 0 || this.render == null || this.render.IsDisposed)
            {
                return;
            }

            MyTextLayout layout = (MyTextLayout)lti.GetLayout(row);

            if (PreDrawOneLine != null)
            {
                PreDrawOneLine(layout, lti, row, x, y);
            }

            if (layout.Markers != null)
            {
                foreach (Marker sel in layout.Markers)
                {
                    if (sel.length == 0 || sel.start == -1)
                    {
                        continue;
                    }
                    Color4 color = new Color4()
                    {
                        Alpha = sel.color.A, Red = sel.color.R, Blue = sel.color.B, Green = sel.color.G
                    };
                    if (sel.hilight == HilightType.Url)
                    {
                        color = this.Url;
                    }
                    this.DrawMarkerEffect(layout, sel.hilight, sel.start, sel.length, x, y, sel.isBoldLine, color);
                }
            }
            if (layout.Selects != null)
            {
                foreach (Selection sel in layout.Selects)
                {
                    if (sel.length == 0 || sel.start == -1)
                    {
                        continue;
                    }

                    this.DrawMarkerEffect(layout, HilightType.Select, sel.start, sel.length, x, y, false);
                }
            }

            if (this.ShowFullSpace || this.ShowHalfSpace || this.ShowTab)
            {
                string str = lti[row];
                D2D.GeometryRealization geo = null;
                for (int i = 0; i < lineLength; i++)
                {
                    Point pos = new Point(0, 0);
                    if (this.ShowTab && str[i] == '\t')
                    {
                        pos = layout.GetPostionFromIndex(i);
                        geo = this._factory.CreateSymbol(ShowSymbol.Tab, this.format);
                    }
                    else if (this.ShowFullSpace && str[i] == ' ')
                    {
                        pos = layout.GetPostionFromIndex(i);
                        geo = this._factory.CreateSymbol(ShowSymbol.FullSpace, this.format);
                    }
                    else if (this.ShowHalfSpace && str[i] == ' ')
                    {
                        pos = layout.GetPostionFromIndex(i);
                        geo = this._factory.CreateSymbol(ShowSymbol.HalfSpace, this.format);
                    }
                    if (geo != null)
                    {
                        var old_trans = this.render.Transform;
                        this.render.Transform = SharpDX.Matrix3x2.Translation(new Vector2((float)(pos.X + x), (float)(pos.Y + y)));
                        this.render.DrawGeometryRealization(geo, this._factory.GetSolidColorBrush(this.ControlChar));
                        this.render.Transform = old_trans;
                        geo = null;
                    }
                }
            }

            layout.Draw(this.render, (float)x, (float)y, this._factory.GetSolidColorBrush(this.Foreground));
        }