/////
        float MeasurePrintingHeight(Graphics g, LineSegment line, float maxWidth)
        {
            float         xPos          = 0;
            float         yPos          = 0;
            float         fontHeight    = _editor.Font.GetHeight(g);
            FontContainer fontContainer = _editor.TextEditorProperties.FontContainer;

            foreach (TextWord word in line.Words)
            {
                switch (word.Type)
                {
                case TextWordType.Space:
                case TextWordType.Tab:
                    //TODO2 this blows up throw new NotImplementedException();
                    break;

                case TextWordType.Word:
                    SizeF drawingSize = g.MeasureString(word.Word, word.GetFont(fontContainer), new SizeF(maxWidth, fontHeight * 100), _printingStringFormat);
                    Advance(ref xPos, ref yPos, maxWidth, drawingSize.Width, _ySpace);
                    break;
                }
            }

            return(yPos + fontHeight);
        }
示例#2
0
 void CheckFontChange(object sender, PropertyChangedEventArgs e)
 {
     if (e.Key == "DefaultFont")
     {
         fontContainer.DefaultFont = FontContainer.ParseFont(e.NewValue.ToString());
     }
 }
        static SharpDevelopTextEditorProperties()
        {
            Properties properties2 = ((Properties)PropertyService.Get("ICSharpCode.TextEditor.Document.Document.DefaultDocumentAggregatorProperties", new Properties()));

            fontContainer = new FontContainer(FontContainer.ParseFont(properties2.Get("DefaultFont", ResourceService.DefaultMonospacedFont.ToString())));
            properties2.PropertyChanged += new PropertyChangedEventHandler(CheckFontChange);
        }
示例#4
0
        // retrieve font set and populate font directory.
        private async void PopulateFonts()
        {
            var fontPacks = await FontContainer.List();

            foreach (var fontPack in fontPacks)
            {
                var thisFontPack = Path.Combine(CurrentOptions.FontPath, fontPack);
                if (await FontContainer.GetIfNewer(fontPack, thisFontPack))
                {
                    using (var zip = ZipFile.OpenRead(thisFontPack))
                    {
                        foreach (var entry in zip.Entries)
                        {
                            if (entry.Length != 0)
                            {
                                var fontFile = Path.Combine(CurrentOptions.FontPath, entry.FullName);
                                if (NeedToExtract(fontFile, entry.Length))
                                {
                                    entry.ExtractToFile(fontFile, true);
                                }
                            }
                            else
                            {
                                var dir = Path.Combine(CurrentOptions.FontPath, entry.FullName);
                                Directory.CreateDirectory(dir);
                            }
                        }
                    }
                }
            }
        }
        void DrawLine(Graphics g, LineSegment line, float yPos, RectangleF margin)
        {
            float xPos       = 0;
            float fontHeight = Font.GetHeight(g);

            _currentTabIndent = 0;

            FontContainer fontContainer = TextEditorProperties.FontContainer;

            foreach (TextWord word in line.Words)
            {
                switch (word.Type)
                {
                case TextWordType.Space:
                    Advance(ref xPos, ref yPos, margin.Width, _primaryTextArea.TextArea.TextView.SpaceWidth, fontHeight);
                    break;

                case TextWordType.Tab:
                    Advance(ref xPos, ref yPos, margin.Width, TabIndent * _primaryTextArea.TextArea.TextView.ColumnWidth, fontHeight);
                    break;

                case TextWordType.Word:
                    g.DrawString(word.Word, word.GetFont(fontContainer), BrushRegistry.GetBrush(word.Color), xPos + margin.X, yPos);
                    SizeF drawingSize = g.MeasureString(word.Word, word.GetFont(fontContainer), new SizeF(margin.Width, fontHeight * 100), _printingStringFormat);
                    Advance(ref xPos, ref yPos, margin.Width, drawingSize.Width, fontHeight);
                    break;
                }
            }
        }
        // btw. I hate source code duplication ... but this time I don't care !!!!
        float MeasurePrintingHeight(Graphics g, LineSegment line, float maxWidth)
        {
            float xPos       = 0;
            float yPos       = 0;
            float fontHeight = Font.GetHeight(g);

            _currentTabIndent = 0;
            FontContainer fontContainer = TextEditorProperties.FontContainer;

            foreach (TextWord word in line.Words)
            {
                switch (word.Type)
                {
                case TextWordType.Space:
                    Advance(ref xPos, ref yPos, maxWidth, _primaryTextArea.TextArea.TextView.SpaceWidth, fontHeight);
                    break;

                case TextWordType.Tab:
                    Advance(ref xPos, ref yPos, maxWidth, TabIndent * _primaryTextArea.TextArea.TextView.ColumnWidth, fontHeight);
                    break;

                case TextWordType.Word:
                    SizeF drawingSize = g.MeasureString(word.Word, word.GetFont(fontContainer), new SizeF(maxWidth, fontHeight * 100), _printingStringFormat);
                    Advance(ref xPos, ref yPos, maxWidth, drawingSize.Width, fontHeight);
                    break;
                }
            }
            return(yPos + fontHeight);
        }
示例#7
0
        /// <summary>
        /// 添加
        /// </summary>
        private void InitAdd()
        {
            int    top         = this.PParser.GetSelectPartPoint[0].Y;
            string spaceString = " ".PadLeft(this.PParser.PLanguageMode.TabSpaceCount);
            int    width       = FontContainer.GetSpaceWidth(this.PParser.PIEdit.GetGraphics);

            while (top <= this.PParser.GetSelectPartPoint[1].Y)
            {
                var ls = this.PParser.PLineString[top / FontContainer.FontHeight];
                ls.SetText(ls.Text.Insert(0, spaceString));
                ls.Width += width * this.PParser.PLanguageMode.TabSpaceCount;
                for (var i = 0; i < this.PParser.PLanguageMode.TabSpaceCount; i++)
                {
                    ls.PWord.Insert(0, new Word()
                    {
                        Text       = " ",
                        PEWordType = EWordType.Space,
                        Width      = width,
                    });
                }
                top += FontContainer.FontHeight;
            }

            width = width * this.PParser.PLanguageMode.TabSpaceCount;
            this.PParser.GetSelectPartPoint[0].LineStringIndex += this.PParser.PLanguageMode.TabSpaceCount;
            this.PParser.GetSelectPartPoint[0].LineWidth       += width;
            this.PParser.GetSelectPartPoint[1].LineStringIndex += this.PParser.PLanguageMode.TabSpaceCount;
            this.PParser.GetSelectPartPoint[1].LineWidth       += width;
            this.PParser.GetSelectPartPoint[1].X += width;
        }
 public DefaultTextEditorProperties()
 {
     if (DefaultFont == null)
     {
         DefaultFont = new Font("Consolas", 9.75F);
     }
     FontContainer = new FontContainer(DefaultFont);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultTextEditorProperties"/> class.
        /// </summary>
        public DefaultTextEditorProperties()
        {
            if (DefaultFont == null)
            {
                DefaultFont = new Font("Courier New", 10);
            }

            this.fontContainer = new FontContainer(DefaultFont);
        }
示例#10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultTextEditorProperties"/> class.
        /// </summary>
        public DefaultTextEditorProperties()
        {
            if (_defaultFont == null)
            {
                _defaultFont = new Font("Courier New", 10);
            }

            _fontContainer = new FontContainer(_defaultFont);
        }
示例#11
0
 // Start is called before the first frame update
 void OnEnable()
 {
     if (fC == null)
     {
         fC = this;
     }
     else
     {
         Destroy(this);
     }
 }
示例#12
0
        /// <summary>
        /// 获取文本的宽度
        /// </summary>
        /// <param name="w"></param>
        /// <param name="g"></param>
        /// <param name="f"></param>
        /// <param name="tagSpaceCount"></param>
        /// <returns></returns>
        public static int GetWrodWidth(Word w, Graphics g, Font f, int tabSpaceCount)
        {
            switch (w.PEWordType)
            {
            case EWordType.Tab:
                return(FontContainer.GetSpaceWidth(g) * tabSpaceCount);

            case EWordType.Space:
                return(FontContainer.GetSpaceWidth(g));

            default:
                return(CharCommand.GetCharWidth(g, w.Text, f ?? FontContainer.DefaultFont));
            }
        }
示例#13
0
        private unsafe void SetFonts()
        {
            var folder = "fonts";
            var files  = Directory.GetFiles(folder);

            if (!(Directory.Exists(folder) && files.Length > 0))
            {
                return;
            }

            var fontsForLoad = new List <(string, int)>();

            if (files.Contains($"{folder}\\config.ini"))
            {
                var lines = File.ReadAllLines($"{folder}\\config.ini");

                foreach (var line in lines)
                {
                    var split = line.Split(':');
                    fontsForLoad.Add(($"{folder}\\{split[0]}.ttf", int.Parse(split[1])));
                }
            }

            var          sm   = new ImFontAtlas();
            ImFontAtlas *some = &sm;

            var imFontAtlasGetGlyphRangesCyrillic = ImGuiNative.ImFontAtlas_GetGlyphRangesCyrillic(some);

            fonts["Default:13"] = new FontContainer(ImGuiNative.ImFontAtlas_AddFontDefault(some, null),
                                                    "Default", 13);

            foreach (var tuple in fontsForLoad)
            {
                var bytes = Encoding.UTF8.GetBytes(tuple.Item1);

                fixed(byte *f = &bytes[0])
                {
                    fonts[$"{tuple.Item1.Replace(".ttf", "").Replace("fonts\\", "")}:{tuple.Item2}"] =
                        new FontContainer(
                            ImGuiNative.ImFontAtlas_AddFontFromFileTTF(some, f, tuple.Item2, null,
                                                                       imFontAtlasGetGlyphRangesCyrillic), tuple.Item1, tuple.Item2);
                }
            }

            Settings.Font.Values = new List <string>(fonts.Keys);
        }
示例#14
0
        public AutoComplete(Panel panel, bool colored)
        {
            this.panel   = panel;
            this.colored = colored;

            FontFamily family = Settings.Fonts.Families.FirstOrDefault(f => f.Name == "InputMono");

            this.font = new FontContainer(new Font((family ?? FontFamily.GenericMonospace), 10, FontStyle.Regular, GraphicsUnit.Point));

            AutoComleteList                = new CompleteListBox();
            AutoComleteList.Cursor         = Cursors.Help;
            AutoComleteList.ItemHeight     = height;
            AutoComleteList.MaximumSize    = new Size(350, (countItems * height) + 4);
            AutoComleteList.MinimumSize    = new Size(120, height + 3);
            AutoComleteList.Font           = colored ? font.BoldFont : font.RegularFont;
            AutoComleteList.Visible        = false;
            AutoComleteList.DrawMode       = DrawMode.OwnerDrawFixed;
            AutoComleteList.IntegralHeight = false;

            AutoComleteList.DrawItem             += ACL_Draw;
            AutoComleteList.VisibleChanged       += ACL_VisibleChanged;
            AutoComleteList.SelectedIndexChanged += ACL_SelectedIndexChanged;
            AutoComleteList.MouseMove            += ACL_MouseMove;
            AutoComleteList.MouseEnter           += ACL_MouseEnter;
            AutoComleteList.PreviewKeyDown       += ACL_PreviewKeyDown;
            AutoComleteList.MouseClick           += ACL_MouseClick;
            AutoComleteList.KeyDown += ACL_KeyDown;

            tipAC           = new ToolTip();
            tipAC.OwnerDraw = true;
            tipAC.Draw     += tipDraw;

            imageList = new ImageList();
            imageList.TransparentColor = Color.FromArgb(255, 0, 255);
            imageList.Images.Add(NameType.Macro.ToString(), Properties.Resources.macros);
            imageList.Images.Add(NameType.Proc.ToString(), Properties.Resources.procedure);
            imageList.Images.Add(NameType.GVar.ToString(), Properties.Resources.variable);
            imageList.Images.Add(NameType.None.ToString(), Properties.Resources.opcode);

            panel.Controls.Add(AutoComleteList);
            AutoComleteList.BringToFront();

            UpdateColor();
            Program.SetDoubleBuffered(AutoComleteList);
        }
        /////
        void DrawLine(Graphics g, LineSegment line, float yPos, RectangleF margin)
        {
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

            float xPos = 0.0f;

            FontContainer fontContainer = _editor.TextEditorProperties.FontContainer;

            foreach (TextWord word in line.Words)
            {
                switch (word.Type)
                {
                case TextWordType.Space:
                case TextWordType.Tab:
                //TODO2 this blows up throw new NotImplementedException();

                case TextWordType.Word:
                    Font f = word.GetFont(fontContainer);

                    // Check for run off side of page.
                    // Note that MeasureString does not count the same way as DrawString but should be close enough.
                    float reqWidth = _xSpace * word.Word.Length;
                    if (xPos + reqWidth > margin.Width)
                    {
                        Advance(ref xPos, ref yPos, margin.Width, reqWidth, _ySpace);
                    }

                    // Print word one letter at a time to control spacing.
                    for (int i = 0; i < word.Word.Length; i++)
                    {
                        // If bg is not "white" draw a colored rectangle first.
                        if (word.SyntaxColor.BackgroundColor != _hcDef.BackgroundColor)
                        {
                            g.FillRectangle(BrushRegistry.GetBrush(word.SyntaxColor.BackgroundColor),
                                            xPos + margin.X + 2.0f, yPos, _xSpace, f.Height); // have to add 2.0 to start to make bg work?!?
                        }

                        g.DrawString(new string(word.Word[i], 1), f, BrushRegistry.GetBrush(word.SyntaxColor.Color), xPos + margin.X, yPos);

                        xPos += _xSpace;
                    }
                    break;
                }
            }
        }
示例#16
0
        void DrawLine(Graphics g, LineSegment line, float yPos, RectangleF margin)
        {
            float xPos             = 0;
            float fontHeight       = Font.GetHeight(g);
            bool  gotNonWhitespace = false;

            curTabIndent = 0;

            FontContainer fontContainer = TextEditorProperties.FontContainer;

            foreach (TextWord word in line.Words)
            {
                switch (word.Type)
                {
                case TextWordType.Space:
                    Advance(ref xPos, ref yPos, margin.Width, primaryTextArea.TextArea.TextView.SpaceWidth, fontHeight);
                    if (!gotNonWhitespace)
                    {
                        curTabIndent = xPos;
                    }
                    break;

                case TextWordType.Tab:
                    Advance(ref xPos, ref yPos, margin.Width, TabIndent * primaryTextArea.TextArea.TextView.WideSpaceWidth, fontHeight);
                    if (!gotNonWhitespace)
                    {
                        curTabIndent = xPos;
                    }
                    break;

                case TextWordType.Word:
                    if (!gotNonWhitespace)
                    {
                        gotNonWhitespace = true;
//							curTabIndent    += TabIndent * primaryTextArea.TextArea.TextView.GetWidth(' ');
                    }
                    g.DrawString(word.Word, word.GetFont(fontContainer), BrushRegistry.GetBrush(word.Color), xPos + margin.X, yPos);
                    SizeF drawingSize = g.MeasureString(word.Word, word.GetFont(fontContainer), new SizeF(margin.Width, fontHeight * 100), printingStringFormat);
                    Advance(ref xPos, ref yPos, margin.Width, drawingSize.Width, fontHeight);
                    break;
                }
            }
        }
示例#17
0
        // btw. I hate source code duplication ... but this time I don't care !!!!
        float MeasurePrintingHeight(Graphics g, LineSegment line, float maxWidth)
        {
            float xPos       = 0;
            float yPos       = 0;
            float fontHeight = Font.GetHeight(g);

//			bool  gotNonWhitespace = false;
            curTabIndent = 0;
            FontContainer fontContainer = TextEditorProperties.FontContainer;

            foreach (TextWord word in line.Words)
            {
                switch (word.Type)
                {
                case TextWordType.Space:
                    Advance(ref xPos, ref yPos, maxWidth, primaryTextArea.TextArea.TextView.SpaceWidth, fontHeight);
//						if (!gotNonWhitespace) {
//							curTabIndent = xPos;
//						}
                    break;

                case TextWordType.Tab:
                    Advance(ref xPos, ref yPos, maxWidth, TabIndent * primaryTextArea.TextArea.TextView.WideSpaceWidth, fontHeight);
//						if (!gotNonWhitespace) {
//							curTabIndent = xPos;
//						}
                    break;

                case TextWordType.Word:
//						if (!gotNonWhitespace) {
//							gotNonWhitespace = true;
//							curTabIndent    += TabIndent * primaryTextArea.TextArea.TextView.GetWidth(' ');
//						}
                    SizeF drawingSize = g.MeasureString(word.Word, word.GetFont(fontContainer), new SizeF(maxWidth, fontHeight * 100), printingStringFormat);
                    Advance(ref xPos, ref yPos, maxWidth, drawingSize.Width, fontHeight);
                    break;
                }
            }
            return(yPos + fontHeight);
        }
示例#18
0
        private float MeasurePrintingHeight(Graphics g, LineSegment line, float maxWidth)
        {
            float single  = 0f;
            float single1 = 0f;
            float height  = this.Font.GetHeight(g);

            this.curTabIndent = 0f;
            FontContainer fontContainer = base.TextEditorProperties.FontContainer;

            foreach (TextWord word in line.Words)
            {
                switch (word.Type)
                {
                case TextWordType.Word:
                {
                    SizeF sizeF = g.MeasureString(word.Word, word.GetFont(fontContainer), new SizeF(maxWidth, height * 100f), this.printingStringFormat);
                    this.Advance(ref single, ref single1, maxWidth, sizeF.Width, height);
                    continue;
                }

                case TextWordType.Space:
                {
                    this.Advance(ref single, ref single1, maxWidth, (float)this.primaryTextArea.TextArea.TextView.SpaceWidth, height);
                    continue;
                }

                case TextWordType.Tab:
                {
                    this.Advance(ref single, ref single1, maxWidth, (float)(base.TabIndent * this.primaryTextArea.TextArea.TextView.WideSpaceWidth), height);
                    continue;
                }

                default:
                {
                    continue;
                }
                }
            }
            return(single1 + height);
        }
示例#19
0
        private void DrawLine(Graphics g, LineSegment line, float yPos, RectangleF margin)
        {
            float single = 0f;
            float height = this.Font.GetHeight(g);

            this.curTabIndent = 0f;
            FontContainer fontContainer = base.TextEditorProperties.FontContainer;

            foreach (TextWord word in line.Words)
            {
                switch (word.Type)
                {
                case TextWordType.Word:
                {
                    g.DrawString(word.Word, word.GetFont(fontContainer), BrushRegistry.GetBrush(word.Color), single + margin.X, yPos);
                    SizeF sizeF = g.MeasureString(word.Word, word.GetFont(fontContainer), new SizeF(margin.Width, height * 100f), this.printingStringFormat);
                    this.Advance(ref single, ref yPos, margin.Width, sizeF.Width, height);
                    continue;
                }

                case TextWordType.Space:
                {
                    this.Advance(ref single, ref yPos, margin.Width, (float)this.primaryTextArea.TextArea.TextView.SpaceWidth, height);
                    continue;
                }

                case TextWordType.Tab:
                {
                    this.Advance(ref single, ref yPos, margin.Width, (float)(base.TabIndent * this.primaryTextArea.TextArea.TextView.WideSpaceWidth), height);
                    continue;
                }

                default:
                {
                    continue;
                }
                }
            }
        }
 public DefaultTextEditorProperties()
 {
     properties = ((IProperties)propertyService.GetProperty("NetFocus.DataStructure.TextEditor.Document.DefaultDocumentProperties", new DefaultProperties()));
     FontContainer.DefaultFont   = FontContainer.ParseFont(properties.GetProperty("DefaultFont", new Font("Courier New", 10).ToString()));
     properties.PropertyChanged += new PropertyEventHandler(CheckFontChange);
 }
示例#21
0
        private float CountColumns(ref int column, int start, int end, int logicalLine, Graphics g)
        {
            if (start > end)
            {
                throw new ArgumentException("start > end");
            }
            if (start == end)
            {
                return(0f);
            }
            float           spaceWidth     = (float)this.SpaceWidth;
            float           wideSpaceWidth = 0f;
            int             tabIndent      = base.Document.TextEditorProperties.TabIndent;
            LineSegment     lineSegment    = base.Document.GetLineSegment(logicalLine);
            List <TextWord> words          = lineSegment.Words;

            if (words == null)
            {
                return(0f);
            }
            int           count         = words.Count;
            int           length        = 0;
            FontContainer fontContainer = base.TextEditorProperties.FontContainer;

            for (int i = 0; i < count; i++)
            {
                TextWord item = words[i];
                if (length >= end)
                {
                    break;
                }
                if (length + item.Length >= start)
                {
                    switch (item.Type)
                    {
                    case TextWordType.Word:
                    {
                        int    num  = Math.Max(length, start);
                        int    num1 = Math.Min(length + item.Length, end) - num;
                        string text = base.Document.GetText(lineSegment.Offset + num, num1);
                        wideSpaceWidth = wideSpaceWidth + (float)this.MeasureStringWidth(g, text, item.GetFont(fontContainer) ?? fontContainer.RegularFont);
                        break;
                    }

                    case TextWordType.Space:
                    {
                        wideSpaceWidth += spaceWidth;
                        break;
                    }

                    case TextWordType.Tab:
                    {
                        wideSpaceWidth  = (float)((int)((wideSpaceWidth + 4f) / (float)tabIndent / (float)this.WideSpaceWidth) * tabIndent * this.WideSpaceWidth);
                        wideSpaceWidth += (float)(tabIndent * this.WideSpaceWidth);
                        break;
                    }
                    }
                }
                length += item.Length;
            }
            for (int j = lineSegment.Length; j < end; j++)
            {
                wideSpaceWidth += (float)this.WideSpaceWidth;
            }
            column += (int)((wideSpaceWidth + 1f) / (float)this.WideSpaceWidth);
            return(wideSpaceWidth);
        }
示例#22
0
        private int GetLogicalColumnInternal(Graphics g, LineSegment line, int start, int end, ref int drawingPos, int targetVisualPosX)
        {
            int num;

            if (start == end)
            {
                return(end);
            }
            int             tabIndent     = base.Document.TextEditorProperties.TabIndent;
            FontContainer   fontContainer = base.TextEditorProperties.FontContainer;
            List <TextWord> words         = line.Words;

            if (words == null)
            {
                return(0);
            }
            int length = 0;

            for (int i = 0; i < words.Count; i++)
            {
                TextWord item = words[i];
                if (length >= end)
                {
                    return(length);
                }
                if (length + item.Length >= start)
                {
                    switch (item.Type)
                    {
                    case TextWordType.Word:
                    {
                        int    num1 = Math.Max(length, start);
                        int    num2 = Math.Min(length + item.Length, end) - num1;
                        string text = base.Document.GetText(line.Offset + num1, num2);
                        Font   font = item.GetFont(fontContainer) ?? fontContainer.RegularFont;
                        num = drawingPos + this.MeasureStringWidth(g, text, font);
                        if (num < targetVisualPosX)
                        {
                            break;
                        }
                        for (int j = 0; j < text.Length; j++)
                        {
                            char chr = text[j];
                            num = drawingPos + this.MeasureStringWidth(g, chr.ToString(), font);
                            if (num >= targetVisualPosX)
                            {
                                if (TextView.IsNearerToAThanB(targetVisualPosX, drawingPos, num))
                                {
                                    return(num1 + j);
                                }
                                return(num1 + j + 1);
                            }
                            drawingPos = num;
                        }
                        return(num1 + text.Length);
                    }

                    case TextWordType.Space:
                    {
                        num = drawingPos + this.spaceWidth;
                        if (num < targetVisualPosX)
                        {
                            break;
                        }
                        if (TextView.IsNearerToAThanB(targetVisualPosX, drawingPos, num))
                        {
                            return(length);
                        }
                        return(length + 1);
                    }

                    case TextWordType.Tab:
                    {
                        drawingPos = (drawingPos + 4) / tabIndent / this.WideSpaceWidth * tabIndent * this.WideSpaceWidth;
                        num        = drawingPos + tabIndent * this.WideSpaceWidth;
                        if (num < targetVisualPosX)
                        {
                            break;
                        }
                        if (TextView.IsNearerToAThanB(targetVisualPosX, drawingPos, num))
                        {
                            return(length);
                        }
                        return(length + 1);
                    }

                    default:
                    {
                        throw new NotSupportedException();
                    }
                    }
                    drawingPos = num;
                }
                length += item.Length;
            }
            return(length);
        }
示例#23
0
        private int PaintLinePart(Graphics g, int lineNumber, int startColumn, int endColumn, Rectangle lineRectangle, int physicalXPos)
        {
            IList <TextMarker> textMarkers;
            Color              color;
            RectangleF         rectangleF;
            IList <TextMarker> markers;
            bool           flag            = this.DrawLineMarkerAtLine(lineNumber);
            Brush          brush           = (this.textArea.Enabled ? this.GetBgColorBrush(lineNumber) : SystemBrushes.InactiveBorder);
            HighlightColor colorFor        = this.textArea.Document.HighlightingStrategy.GetColorFor("Selection");
            ColumnRange    selectionAtLine = this.textArea.SelectionManager.GetSelectionAtLine(lineNumber);
            HighlightColor highlightColor  = this.textArea.Document.HighlightingStrategy.GetColorFor("TabMarkers");
            HighlightColor colorFor1       = this.textArea.Document.HighlightingStrategy.GetColorFor("SpaceMarkers");
            LineSegment    lineSegment     = this.textArea.Document.GetLineSegment(lineNumber);
            Brush          brush1          = BrushRegistry.GetBrush(colorFor.BackgroundColor);

            if (lineSegment.Words == null)
            {
                return(physicalXPos);
            }
            int           length        = 0;
            TextWord      textWord      = null;
            FontContainer fontContainer = base.TextEditorProperties.FontContainer;

            for (int i = 0; i < lineSegment.Words.Count; i++)
            {
                TextWord item = lineSegment.Words[i];
                if (length >= startColumn)
                {
                    while (length < endColumn && physicalXPos < lineRectangle.Right)
                    {
                        int          num  = length + item.Length - 1;
                        TextWordType type = item.Type;
                        if (type != TextWordType.Space)
                        {
                            color = (type != TextWordType.Tab ? item.Color : highlightColor.Color);
                        }
                        else
                        {
                            color = colorFor1.Color;
                        }
                        Brush markerBrushAt = this.GetMarkerBrushAt(lineSegment.Offset + length, item.Length, ref color, out textMarkers);
                        if (item.Length > 1)
                        {
                            int num1 = 2147483647;
                            if (this.highlight != null)
                            {
                                if (this.highlight.OpenBrace.Y == lineNumber && this.highlight.OpenBrace.X >= length && this.highlight.OpenBrace.X <= num)
                                {
                                    TextLocation openBrace = this.highlight.OpenBrace;
                                    num1 = Math.Min(num1, openBrace.X - length);
                                }
                                if (this.highlight.CloseBrace.Y == lineNumber && this.highlight.CloseBrace.X >= length && this.highlight.CloseBrace.X <= num)
                                {
                                    TextLocation closeBrace = this.highlight.CloseBrace;
                                    num1 = Math.Min(num1, closeBrace.X - length);
                                }
                                if (num1 == 0)
                                {
                                    num1 = 1;
                                }
                            }
                            if (endColumn < num)
                            {
                                num1 = Math.Min(num1, endColumn - length);
                            }
                            if (selectionAtLine.StartColumn > length && selectionAtLine.StartColumn <= num)
                            {
                                num1 = Math.Min(num1, selectionAtLine.StartColumn - length);
                            }
                            else if (selectionAtLine.EndColumn > length && selectionAtLine.EndColumn <= num)
                            {
                                num1 = Math.Min(num1, selectionAtLine.EndColumn - length);
                            }
                            foreach (TextMarker textMarker in textMarkers)
                            {
                                int offset    = textMarker.Offset - lineSegment.Offset;
                                int endOffset = textMarker.EndOffset - lineSegment.Offset + 1;
                                if (offset <= length || offset > num)
                                {
                                    if (endOffset <= length || endOffset > num)
                                    {
                                        continue;
                                    }
                                    num1 = Math.Min(num1, endOffset - length);
                                }
                                else
                                {
                                    num1 = Math.Min(num1, offset - length);
                                }
                            }
                            if (num1 != 2147483647)
                            {
                                if (textWord != null)
                                {
                                    throw new ApplicationException("split part invalid: first part cannot be splitted further");
                                }
                                textWord = TextWord.Split(ref item, num1);
                                continue;
                            }
                        }
                        if (ColumnRange.WholeColumn.Equals(selectionAtLine) || selectionAtLine.StartColumn <= length && selectionAtLine.EndColumn > num)
                        {
                            markerBrushAt = brush1;
                            if (colorFor.HasForeground)
                            {
                                color = colorFor.Color;
                            }
                        }
                        else if (flag)
                        {
                            markerBrushAt = brush;
                        }
                        if (markerBrushAt == null)
                        {
                            markerBrushAt = (item.SyntaxColor == null || !item.SyntaxColor.HasBackground ? brush : BrushRegistry.GetBrush(item.SyntaxColor.BackgroundColor));
                        }
                        if (item.Type == TextWordType.Space)
                        {
                            this.physicalColumn++;
                            rectangleF = new RectangleF((float)physicalXPos, (float)lineRectangle.Y, (float)this.SpaceWidth, (float)lineRectangle.Height);
                            g.FillRectangle(markerBrushAt, rectangleF);
                            if (base.TextEditorProperties.ShowSpaces)
                            {
                                this.DrawSpaceMarker(g, color, physicalXPos, lineRectangle.Y);
                            }
                            physicalXPos += this.SpaceWidth;
                        }
                        else if (item.Type != TextWordType.Tab)
                        {
                            int num2 = this.DrawDocumentWord(g, item.Word, new Point(physicalXPos, lineRectangle.Y), item.GetFont(fontContainer), color, markerBrushAt);
                            rectangleF    = new RectangleF((float)physicalXPos, (float)lineRectangle.Y, (float)num2, (float)lineRectangle.Height);
                            physicalXPos += num2;
                        }
                        else
                        {
                            this.physicalColumn += base.TextEditorProperties.TabIndent;
                            this.physicalColumn  = this.physicalColumn / base.TextEditorProperties.TabIndent * base.TextEditorProperties.TabIndent;
                            int wideSpaceWidth = (physicalXPos + 4 - lineRectangle.X) / this.WideSpaceWidth / base.TextEditorProperties.TabIndent * this.WideSpaceWidth * base.TextEditorProperties.TabIndent + lineRectangle.X;
                            wideSpaceWidth = wideSpaceWidth + this.WideSpaceWidth * base.TextEditorProperties.TabIndent;
                            rectangleF     = new RectangleF((float)physicalXPos, (float)lineRectangle.Y, (float)(wideSpaceWidth - physicalXPos), (float)lineRectangle.Height);
                            g.FillRectangle(markerBrushAt, rectangleF);
                            if (base.TextEditorProperties.ShowTabs)
                            {
                                this.DrawTabMarker(g, color, physicalXPos, lineRectangle.Y);
                            }
                            physicalXPos = wideSpaceWidth;
                        }
                        foreach (TextMarker textMarker1 in textMarkers)
                        {
                            if (textMarker1.TextMarkerType == TextMarkerType.SolidBlock)
                            {
                                continue;
                            }
                            this.DrawMarker(g, textMarker1, rectangleF);
                        }
                        if (this.highlight != null && (this.highlight.OpenBrace.Y == lineNumber && this.highlight.OpenBrace.X == length || this.highlight.CloseBrace.Y == lineNumber && this.highlight.CloseBrace.X == length))
                        {
                            this.DrawBracketHighlight(g, new Rectangle((int)rectangleF.X, lineRectangle.Y, (int)rectangleF.Width - 1, lineRectangle.Height - 1));
                        }
                        length += item.Length;
                        if (textWord == null)
                        {
                            goto label0;
                        }
                        item     = textWord;
                        textWord = null;
                    }
                    if (physicalXPos < lineRectangle.Right && endColumn >= lineSegment.Length)
                    {
                        markers = base.Document.MarkerStrategy.GetMarkers(lineSegment.Offset + lineSegment.Length);
                        foreach (TextMarker marker in markers)
                        {
                            if (marker.TextMarkerType == TextMarkerType.SolidBlock)
                            {
                                continue;
                            }
                            this.DrawMarker(g, marker, new RectangleF((float)physicalXPos, (float)lineRectangle.Y, (float)this.WideSpaceWidth, (float)lineRectangle.Height));
                        }
                    }
                    return(physicalXPos);
                }
                else
                {
                    length += item.Length;
                }
                label0 :;
            }
            if (physicalXPos < lineRectangle.Right && endColumn >= lineSegment.Length)
            {
                markers = base.Document.MarkerStrategy.GetMarkers(lineSegment.Offset + lineSegment.Length);
                foreach (TextMarker marker1 in markers)
                {
                    if (marker1.TextMarkerType == TextMarkerType.SolidBlock)
                    {
                        continue;
                    }
                    this.DrawMarker(g, marker1, new RectangleF((float)physicalXPos, (float)lineRectangle.Y, (float)this.WideSpaceWidth, (float)lineRectangle.Height));
                }
            }
            return(physicalXPos);
        }
示例#24
0
 internal SpriteFont GetFont()
 {
     return(FontContainer.Resolve(this.FontFamily));
 }
示例#25
0
 public MockTextEditorProperties()
 {
     FontContainer = new FontContainer(SystemFonts.MenuFont);
 }
示例#26
0
        internal GraphicsContext(FlaiGame game)
        {
            Ensure.NotNull(game);

            _game = game;
            _fontContainer = new FontContainer(_game.Services);
            _game.Services.Add(this); // GraphicsContext, not IGraphicsContext
            _primitiveRenderer = new PrimitiveRenderer(this);
        }