public override void DrawBackground(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            this.editor = editor;
            int markerStart = base.Offset;
            int markerEnd   = base.EndOffset;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            double @from;
            double to;
            var    startXPos = metrics.TextRenderStartPosition;
            var    endXPos   = metrics.TextRenderEndPosition;
            var    y         = metrics.LineYRenderStartPosition;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int start = startOffset < markerStart ? markerStart : startOffset;
                int end   = endOffset < markerEnd ? endOffset : markerEnd;

                uint curIndex = 0, byteIndex = 0;
                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

                int x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
                x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
            }

            @from = Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from < to)
            {
                cr.SetSourceColor(background(editor).Color);
                cr.RoundedRectangle(@from + 2.5, y + 0.5, to - @from, editor.LineHeight - 1, 2);                  // 2.5 to make space for the column guideline

                if (background(editor).HasBorderColor)
                {
                    cr.FillPreserve();

                    cr.SetSourceColor(background(editor).BorderColor);
                    cr.Stroke();
                }
                else
                {
                    cr.Fill();
                }
            }
        }
        public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            if (OnlyShowLinkOnHover)
            {
                if (editor.TextViewMargin.MarginCursor != textLinkCursor)
                {
                    return;
                }
                if (editor.TextViewMargin.HoveredLine == null)
                {
                    return;
                }
                var hoverOffset = editor.LocationToOffset(editor.TextViewMargin.HoveredLocation);
                if (!Segment.Contains(hoverOffset))
                {
                    return;
                }
            }
            this.Color = editor.ColorStyle.LinkColor.Color;

            if (!OnlyShowLinkOnHover)
            {
                if (editor.TextViewMargin.MarginCursor == textLinkCursor && editor.TextViewMargin.HoveredLine != null)
                {
                    var hoverOffset = editor.LocationToOffset(editor.TextViewMargin.HoveredLocation);
                    if (Segment.Contains(hoverOffset))
                    {
                        this.Color = editor.ColorStyle.ActiveLinkColor.Color;
                    }
                }
            }

            base.Draw(editor, cr, metrics, startOffset, endOffset);
        }
Example #3
0
        public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            if (OnlyShowLinkOnHover)
            {
                if (editor.TextViewMargin.MarginCursor != textLinkCursor)
                {
                    return;
                }
                if (editor.TextViewMargin.HoveredLine == null)
                {
                    return;
                }
                var hoverOffset = editor.LocationToOffset(editor.TextViewMargin.HoveredLocation);
                if (!Segment.Contains(hoverOffset))
                {
                    return;
                }
            }

            this.Color = SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.Link);

            if (!OnlyShowLinkOnHover)
            {
                if (editor.TextViewMargin.MarginCursor == textLinkCursor && editor.TextViewMargin.HoveredLine != null)
                {
                    var hoverOffset = editor.LocationToOffset(editor.TextViewMargin.HoveredLocation);
                    // if (Segment.Contains (hoverOffset))
                    //	this.Color = editorEditorThemle.ActiveLinkColor.Color;
                }
            }

            base.Draw(editor, cr, metrics, startOffset, endOffset);
        }
        void DrawErrorMarkers(MonoTextEditor editor, Cairo.Context g, LineMetrics metrics, double y)
        {
            uint curIndex = 0, byteIndex = 0;

            var o = metrics.LineSegment.Offset;

            foreach (var task in errors.Select(t => t.Task))
            {
                var column = (uint)(Math.Min(Math.Max(0, task.Column - 1), metrics.Layout.LineChars.Length));
                var line   = editor.GetLine(task.Line);
                // skip possible white space locations
                while (column < line.Length && char.IsWhiteSpace(editor.GetCharAt(line.Offset + (int)column)))
                {
                    column++;
                }
                if (column >= line.Length)
                {
                    continue;
                }
                int index = (int)metrics.Layout.TranslateToUTF8Index(column, ref curIndex, ref byteIndex);
                var pos   = metrics.Layout.Layout.IndexToPos(index);
                var co    = o + task.Column - 1;
                g.SetSourceColor(GetMarkerColor(false, metrics.SelectionStart <= co && co < metrics.SelectionEnd));
                g.MoveTo(
                    metrics.TextRenderStartPosition + editor.TextViewMargin.TextStartPosition + pos.X / Pango.Scale.PangoScale,
                    y + editor.LineHeight - 3
                    );
                g.RelLineTo(3, 3);
                g.RelLineTo(-6, 0);
                g.ClosePath();

                g.Fill();
            }
        }
Example #5
0
        /// <summary>
        /// Building main entry point.
        /// </summary>
        /// <param name="abstractOpen"></param>
        /// <param name="output"></param>
        /// <param name="fxCopPath">FxCopCmd.exe path</param>
        /// <param name="fXCopOut">FxCop result directory</param>
        /// <param name="row">CSV file second row</param>
        public static void Start(AbstractOpen abstractOpen, string output, string fxCopPath, string fXCopOut, string outListFilePath)
        {
            WriteMsg.WriteLine("Starting analysis...");
            MainDeclaration.Instance.CSSIExtension = (abstractOpen is FileOpen) ? Constants.CSSIEXTENSION : Constants.LCSSIEXTENSION;
            MainDeclaration.Instance.Solution      = abstractOpen.Solution;

            foreach (Project project in abstractOpen.TopologicallySortedProjectDependencies)
            {
                if (Commons.Common.CheckOuterFilters(project.FilePath))
                {
                    continue;
                }

                WriteMsg.WriteWithBreak("Analyzing {0}...", WriteMsg.MsgLevel.Normal, 4, project.AssemblyName);
                Analyse(project, output, fxCopPath, fXCopOut);
            }

            MainDeclaration.Instance.Statistics[0].CSharpASGBuildingTime = MainDeclaration.Instance.CSSIWatch.ElapsedSeconds;
            MainDeclaration.Instance.Statistics[0].LIMASGBildingTime     = MainDeclaration.Instance.LIMWatch.ElapsedSeconds;

            LineMetrics.Calculate();

            WriteMsg.WriteLine("Analysis finished");
            if (!string.IsNullOrEmpty(outListFilePath))
            {
                File.WriteAllText(outListFilePath, string.Join(Environment.NewLine, outfiles));
            }
            MainDeclaration.Instance.FxCopTasks.WaitAll();
        }
Example #6
0
 public override void DrawBackground(MonoTextEditor editor, Context cr, LineMetrics metrics, int startOffset, int endOffset)
 {
     int x1 = editor.LocationToPoint(editor.OffsetToLocation(this.Offset), false).X;
     int x2 = editor.LocationToPoint(editor.OffsetToLocation(this.Offset + this.Length), false).X;
     cr.Rectangle(x1, metrics.LineYRenderStartPosition + 0.5, x2 - x1, metrics.LineHeight - 1);
     cr.SetSourceRGB(1.0, 1.0, 0.0);
     cr.Fill();
 }
        public LineMetrics[] GetLineMetrics()
        {
            GetLineMetrics(null, 0, out var actualLineCount);
            var lineMetrics = new LineMetrics[actualLineCount];

            if (actualLineCount > 0)
            {
                GetLineMetrics(lineMetrics, lineMetrics.Length, out _).CheckError();
            }

            return(lineMetrics);
        }
Example #8
0
        public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics)
        {
            var color = SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.FoldLine);

            cr.SetSourceColor(color);

            cr.LineWidth = 1 * editor.Options.Zoom;
            var y = metrics.LineYRenderStartPosition;

            cr.MoveTo(metrics.TextRenderStartPosition, y + metrics.LineHeight - 1.5);
            cr.LineTo(editor.Allocation.Width, y + metrics.LineHeight - 1.5);
            cr.Stroke();
        }
Example #9
0
        public override void DrawBackground(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            int markerStart = Offset;
            int markerEnd   = EndOffset;

            double @from;
            double to;
            var    startXPos = metrics.TextRenderStartPosition;
            var    endXPos   = metrics.TextRenderEndPosition;
            var    y         = metrics.LineYRenderStartPosition;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int start = startOffset < markerStart ? markerStart : startOffset;
                int end   = endOffset < markerEnd ? endOffset : markerEnd;

                uint curIndex = 0, byteIndex = 0;
                TextViewMargin.TranslateToUTF8Index(metrics.Layout.Text, (uint)(start - startOffset), ref curIndex, ref byteIndex);

                int x_pos = metrics.Layout.IndexToPos((int)byteIndex).X;

                @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                TextViewMargin.TranslateToUTF8Index(metrics.Layout.Text, (uint)(end - startOffset), ref curIndex, ref byteIndex);
                x_pos = metrics.Layout.IndexToPos((int)byteIndex).X;

                to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
            }

            @from = Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from <= to)
            {
                if (metrics.TextEndOffset < markerEnd)
                {
                    to = metrics.WholeLineWidth + metrics.TextRenderStartPosition;
                }

                var c1 = (Cairo.Color)SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.Background);
                var c2 = (Cairo.Color)SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.Selection);
                cr.SetSourceRGB((c1.R + c2.R) / 2, (c1.G + c2.G) / 2, (c1.B + c2.B) / 2);
                cr.Rectangle(@from, y, to - @from, metrics.LineHeight);
                cr.Fill();
            }
        }
Example #10
0
        private void DetermineScaledDims(TextMeshProUGUI dummyPage, LineMetrics line)
        {
            float widthProportion  = bookMetrics.LineWidthProportion(line);
            float heightProportion = bookMetrics.LineHeightProportion(line);

            dummyPage.text     = line.ToString();
            dummyPage.fontSize = line.ChunkMetrices[0].GetFontSize();
            Vector2 vec = dummyPage.GetPreferredValues(line.ToString());

            float tmpWidthProportion  = vec.x / bookMetrics.PageMaxWidth;
            float tmpHeightProportion = vec.y / bookMetrics.PageMaxHeight;

            scaleFactorW = widthProportion / tmpWidthProportion;
            scaleFactorH = heightProportion / tmpHeightProportion;
        }
Example #11
0
        /// <summary>
        /// Retrieves the information about each individual text line of the  text string.
        /// </summary>
        /// <remarks>
        /// If maxLineCount is not large enough E_NOT_SUFFICIENT_BUFFER, which is equivalent to HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), is returned and *actualLineCount is set to the number of lines needed.
        /// </remarks>
        /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. </returns>
        /// <unmanaged>HRESULT IDWriteTextLayout::GetLineMetrics([Out, Buffer, Optional] DWRITE_LINE_METRICS* lineMetrics,[None] int maxLineCount,[Out] int* actualLineCount)</unmanaged>
        public LineMetrics[] GetLineMetrics()
        {
            var lineMetrics  = new LineMetrics[0];
            int lineCount    = 0;
            int maxLineCount = 0;

            GetLineMetrics(lineMetrics, lineCount, out maxLineCount);
            if (maxLineCount > 0)
            {
                lineMetrics = new LineMetrics[maxLineCount];
                GetLineMetrics(lineMetrics, maxLineCount, out maxLineCount);
            }

            return(lineMetrics);
        }
        public void Evaluate(int SpreadMax)
        {
            if (this.FInText.IsConnected == false)
            {
                this.metricsCount.SliceCount             = 0;
                this.length.SliceCount                   = 0;
                this.trailingWhitespaceLength.SliceCount = 0;
                this.newlineLength.SliceCount            = 0;
                this.height.SliceCount                   = 0;
                this.baseline.SliceCount                 = 0;
                this.isTrimmed.SliceCount                = 0;
                return;
            }

            if (this.FInText.IsChanged)
            {
                this.metricsCount.SliceCount = SpreadMax;

                cm.Clear();
                for (int i = 0; i < SpreadMax; i++)
                {
                    TextLayout    tl  = this.FInText[i];
                    LineMetrics[] cms = tl.GetLineMetrics();
                    this.metricsCount[i] = cms.Length;
                    cm.AddRange(cms);
                }

                this.length.SliceCount = cm.Count;
                this.trailingWhitespaceLength.SliceCount = cm.Count;
                this.newlineLength.SliceCount            = cm.Count;
                this.height.SliceCount    = cm.Count;
                this.baseline.SliceCount  = cm.Count;
                this.isTrimmed.SliceCount = cm.Count;

                for (int i = 0; i < cm.Count; i++)
                {
                    LineMetrics c = cm[i];
                    this.length[i] = c.Length;
                    this.trailingWhitespaceLength[i] = c.TrailingWhitespaceLength;
                    this.newlineLength[i]            = c.NewlineLength;
                    this.height[i]    = c.Height;
                    this.baseline[i]  = c.Baseline;
                    this.isTrimmed[i] = c.IsTrimmed;
                }
            }
        }
Example #13
0
        private LineMetrics[] formatText(Face face, string text, bool wrapText)
        {
            List <LineMetrics> lineMetrics = new List <LineMetrics>();

            //Remove all \r characters, since we use \n to seperate lines
            text = text.Replace("\r", string.Empty);

            //Split the current text by newlines which act as paragraphs
            string[] lines = text.Split('\n');
            for (int lineIndex = 0; lineIndex < lines.Length; lineIndex++)
            {
                string[] words = lines[lineIndex].Split(' ');
                if (words.Length == 0)
                {
                    continue;
                }

                //Go through each individual word and measure the new line (currentText + newWord) to see if it is less than the buffer width
                StringBuilder lineText    = (words.Length > 1) ? new StringBuilder(words[0] + " ") : new StringBuilder(words[0]);
                LineMetrics   currentLine = measureText(face, lineText.ToString());
                for (int wordIndex = 1; wordIndex < words.Length; wordIndex++)
                {
                    string newText = words[wordIndex];
                    if (wordIndex < words.Length - 1)
                    {
                        newText += " ";
                    }

                    LineMetrics testLine = measureText(face, lineText + newText);
                    if (testLine.Width <= BufferWidth || !wrapText)
                    {
                        currentLine = testLine;
                        lineText.Append(newText);
                    }
                    else
                    {
                        lineMetrics.Add(currentLine);
                        lineText = new StringBuilder(newText);
                    }
                }
                lineMetrics.Add(currentLine);
            }

            return(lineMetrics.ToArray());
        }
        Tuple <int, int> GetErrorCountBounds(LineMetrics metrics)
        {
            EnsureLayoutCreated(editor);
            var lineTextPx = editor.TextViewMargin.XOffset + metrics.TextRenderEndPosition;

            if (errors.Count > 1 && errorCountLayout != null || editor.Allocation.Width < lineTextPx + layouts [0].Width)
            {
                int ew = 0, eh = 0;
                if (errorCountLayout != null)
                {
                    errorCountLayout.GetPixelSize(out ew, out eh);
                }
                else
                {
                    ew = 10;
                }
                return(Tuple.Create(ew + 10, eh));
            }
            return(Tuple.Create(0, 0));
        }
Example #15
0
        void AlignLineChunks(LineMetrics currentLineMetric, float availableWidth)
        {
            var   extraSpace = availableWidth - currentLineMetric.MinWidth;
            float extraX;

            switch (GetAlignment())
            {
            case Alignment.Fill:
            case Alignment.Start:
            {
                extraX = 0;
                break;
            }

            case Alignment.End:
            {
                extraX = extraSpace;
                break;
            }

            case Alignment.Center:
                extraX = extraSpace / 2f;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            for (var idx = currentLineMetric.StartIndex; idx < currentLineMetric.EndIndex; idx += 1)
            {
                var chunk = lineBreakContent[idx];
                chunk.X              += (int)extraX;
                chunk.BaseLine        = currentLineMetric.BaseLine;
                lineBreakContent[idx] = chunk;
            }
        }
        void DrawErrorMarkers(TextEditor editor, Cairo.Context g, LineMetrics metrics, double y)
        {
            uint curIndex = 0, byteIndex = 0;

            var o = metrics.LineSegment.Offset;

            foreach (var task in errors.Select(t => t.Task))
            {
                var column = (uint)(Math.Min(Math.Max(0, task.Column - 1), metrics.Layout.LineChars.Length));
                int index  = (int)metrics.Layout.TranslateToUTF8Index(column, ref curIndex, ref byteIndex);
                var pos    = metrics.Layout.Layout.IndexToPos(index);
                var co     = o + task.Column - 1;
                g.SetSourceColor(GetMarkerColor(false, metrics.SelectionStart <= co && co < metrics.SelectionEnd));
                g.MoveTo(
                    metrics.TextRenderStartPosition + editor.TextViewMargin.TextStartPosition + pos.X / Pango.Scale.PangoScale,
                    y + editor.LineHeight - 3
                    );
                g.RelLineTo(3, 3);
                g.RelLineTo(-6, 0);
                g.ClosePath();

                g.Fill();
            }
        }
 public override void Draw(Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
 {
     Color = info.ErrorType == ErrorType.Warning ? editor.ColorStyle.UnderlineWarning.Color : editor.ColorStyle.UnderlineError.Color;
     base.Draw(editor, cr, metrics, startOffset, endOffset);
 }
Example #18
0
        public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics layout, int startOffset, int endOffset)
        {
            if (DebuggingService.IsDebugging)
            {
                return;
            }
            int markerStart = Segment.Offset;
            int markerEnd   = Segment.EndOffset;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            double drawFrom;
            double drawTo;
            double y         = layout.LineYRenderStartPosition;
            double startXPos = layout.TextRenderStartPosition;
            double endXPos   = layout.TextRenderEndPosition;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                drawTo = endXPos;
                var line   = editor.GetLineByOffset(startOffset);
                int offset = line.GetIndentation(editor.Document).Length;
                drawFrom = startXPos + (layout.Layout.IndexToPos(offset).X / Pango.Scale.PangoScale);
            }
            else
            {
                int start;
                if (startOffset < markerStart)
                {
                    start = markerStart;
                }
                else
                {
                    var line   = editor.GetLineByOffset(startOffset);
                    int offset = line.GetIndentation(editor.Document).Length;
                    start = startOffset + offset;
                }
                int end = endOffset < markerEnd ? endOffset : markerEnd;
                int x_pos;

                x_pos    = layout.Layout.IndexToPos(start - startOffset).X;
                drawFrom = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
                x_pos    = layout.Layout.IndexToPos(end - startOffset).X;

                drawTo = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
            }

            drawFrom = Math.Max(drawFrom, editor.TextViewMargin.XOffset);
            drawTo   = Math.Max(drawTo, editor.TextViewMargin.XOffset);
            if (drawFrom >= drawTo)
            {
                return;
            }

            double height = editor.LineHeight / 5;

            cr.SetSourceColor(Color);
            if (effect == MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.WavedLine)
            {
                Pango.CairoHelper.ShowErrorUnderline(cr, drawFrom, y + editor.LineHeight - height, drawTo - drawFrom, height);
            }
            else if (effect == MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.DottedLine)
            {
                cr.Save();
                cr.LineWidth = 1;
                cr.MoveTo(drawFrom + 1, y + editor.LineHeight - 1 + 0.5);
                cr.RelLineTo(Math.Min(drawTo - drawFrom, 4 * 3), 0);
                cr.SetDash(new double[] { 2, 2 }, 0);
                cr.Stroke();
                cr.Restore();
            }
            else
            {
                cr.MoveTo(drawFrom, y + editor.LineHeight - 1);
                cr.LineTo(drawTo, y + editor.LineHeight - 1);
                cr.Stroke();
            }
        }
Example #19
0
        /// <summary>	
        /// Retrieves the information about each individual text line of the  text string. 	
        /// </summary>	
        /// <remarks>	
        /// If maxLineCount is not large enough E_NOT_SUFFICIENT_BUFFER, which is equivalent to HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), is returned and *actualLineCount is set to the number of lines needed.  	
        /// </remarks>	
        /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. </returns>
        /// <unmanaged>HRESULT IDWriteTextLayout::GetLineMetrics([Out, Buffer, Optional] DWRITE_LINE_METRICS* lineMetrics,[None] int maxLineCount,[Out] int* actualLineCount)</unmanaged>
        public LineMetrics[] GetLineMetrics()
        {
            var lineMetrics = new LineMetrics[0];
            int lineCount = 0;
            int maxLineCount = 0;
            GetLineMetrics(lineMetrics, lineCount, out maxLineCount);
            if (maxLineCount > 0)
            {
                lineMetrics = new LineMetrics[maxLineCount];
                GetLineMetrics(lineMetrics, maxLineCount, out maxLineCount);
            }

            return lineMetrics;            
        }
Example #20
0
        public override void Draw(Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            this.editor = editor;
            var line = editor.GetLine(loc.Line);

            if (line == null)
            {
                return;
            }
            var x = editor.ColumnToX(line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition;

            cr.Rectangle(Math.Floor(x) + 0.5, Math.Floor(metrics.LineYRenderStartPosition) + 0.5 + (line == editor.GetLineByOffset(startOffset) ? editor.LineHeight - tagMarkerHeight - 1 : 0), tagMarkerWidth * cr.LineWidth, tagMarkerHeight * cr.LineWidth);

            if (HslColor.Brightness(editor.ColorStyle.PlainText.Background) < 0.5)
            {
                cr.SetSourceRGBA(0.8, 0.8, 1, 0.9);
            }
            else
            {
                cr.SetSourceRGBA(0.2, 0.2, 1, 0.9);
            }
            cr.Stroke();
        }
Example #21
0
        public Texture2D RenderString(Face font, string text, Color4 foreColor, Color4 backColor, bool wrapText)
        {
            LineMetrics[] metrics = formatText(font, text, wrapText);

            float maxWidth = 0f, maxHeight = 0f, totalHeight = 0f;

            for (int lineIndex = 0; lineIndex < metrics.Length; lineIndex++)
            {
                LineMetrics lineMetric = metrics[lineIndex];
                maxWidth  = (lineMetric.Width > maxWidth) ? lineMetric.Width : maxWidth;
                maxHeight = (lineMetric.Height > maxHeight) ? lineMetric.Height : maxHeight;

                //Check is to ensure we don't have additional extra space accumulating beneath the texture for large Heights (commas being an example)
                totalHeight += (lineIndex < metrics.Length - 1) ? lineMetric.BaseHeight + LineSpacing : lineMetric.Height;

                metrics[lineIndex] = lineMetric;
            }

            //If any dimension is 0, we can't create a bitmap
            if (maxWidth <= 0 || totalHeight <= 0)
            {
                return(null);
            }

            //Create a new bitmap that fits the string.
            Bitmap bmp = new Bitmap((int)Math.Ceiling(maxWidth), (int)Math.Ceiling(totalHeight));

            using (var g = Graphics.FromImage(bmp))
            {
                #region Rendering Code
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.SmoothingMode      = SmoothingMode.HighQuality;
                g.CompositingMode    = CompositingMode.SourceOver;

                g.Clear((Color)backColor);

                //Draw the string into the bitmap.
                float lineOffset = 0f;
                for (int lineIndex = 0; lineIndex < metrics.Length; lineIndex++)
                {
                    LineMetrics lineMetrics = metrics[lineIndex];

                    //float xOffset = (maxWidth - lineMetrics.Width) / 2f; //Centered
                    float xOffset = 0f;
                    //float xOffset = maxWidth - lineMetrics.Width - 20f;

                    float penX = 0f, penY = 0f;
                    for (int i = 0; i < lineMetrics.Characters.Count; i++)
                    {
                        var  cm = lineMetrics.Characters[i];
                        char c  = cm.Character;

                        uint glyphIndex = font.GetCharIndex(c);
                        font.LoadGlyph(glyphIndex, LoadFlags.Default, LoadTarget.Normal);
                        font.Glyph.RenderGlyph(RenderMode.Normal);
                        FTBitmap ftbmp = font.Glyph.Bitmap;

                        //Underrun
                        if (penX == 0) //First character
                        {
                            penX += -(cm.BearingX);
                        }

                        //We can't draw a 0-size bitmap, but the pen position will still get advanced.
                        if (ftbmp.Width > 0 && ftbmp.Rows > 0)
                        {
                            using (Bitmap cBmp = ftbmp.ToGdipBitmap((Color)foreColor))
                            {
                                int x = (int)Math.Round(penX + cm.BearingX + xOffset);
                                int y = (int)Math.Round(penY + lineMetrics.Top - cm.BearingY + lineOffset);

                                g.DrawImageUnscaled(cBmp, x, y);
                            }
                        }

                        //Advance pen position for the next character
                        penX += cm.AdvanceX + cm.Kern;
                    }

                    lineOffset += lineMetrics.BaseHeight + LineSpacing;
                }
                #endregion
            }

            Texture2D texture = Texture2D.CreateFromBitmap(bmp);
            bmp.Dispose();

            return(texture);
        }
Example #22
0
 public override void Draw(MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
 {
     // nothing (is drawn using chunk marker)
 }
        public override bool DrawBackground(TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
        {
            // check, if a message bubble is active in that line.
            if (LineSegment != null && LineSegment.Markers.Any(m => m != this && (m is IExtendingTextLineMarker)))
            {
                return(false);
            }

            var sidePadding = 4;
            var rounding    = editor.LineHeight / 2 - 1;

            var d = metrics.TextRenderEndPosition - metrics.TextRenderStartPosition;

            if (d > 0)
            {
                cr.LineWidth = 1;
                cr.RoundedRectangle(metrics.TextRenderStartPosition, Math.Floor(y) + 0.5, d + sidePadding, metrics.LineHeight - 1, rounding);
                cr.SetSourceColor(BackgroundColor);
                cr.FillPreserve();
                cr.SetSourceColor(BorderColor);
                cr.Stroke();
            }

            return(base.DrawBackground(editor, cr, y, metrics));
        }
        public override bool DrawBackground(MonoTextEditor editor, Cairo.Context g, LineMetrics metrics)
        {
            if (!IsVisible)
            {
                return(false);
            }
            bool markerShouldDrawnAsHidden = cache.CurrentSelectedTextMarker != null && cache.CurrentSelectedTextMarker != this;

            if (editor.Document.GetTextSegmentMarkersAt(metrics.LineSegment).Any(m => m is DebugTextMarker))
            {
                return(false);
            }

            EnsureLayoutCreated(editor);
            double x                 = editor.TextViewMargin.XOffset;
            int    right             = editor.Allocation.Width;
            bool   isCaretInLine     = metrics.TextStartOffset <= editor.Caret.Offset && editor.Caret.Offset <= metrics.TextEndOffset;
            int    errorCounterWidth = GetErrorCountBounds(metrics).Item1;

            var    min = right - LayoutWidth - border - (ShowIconsInBubble ? cache.errorPixbuf.Width : 0) - errorCounterWidth;
            var    max = Math.Round(editor.TextViewMargin.XOffset + editor.LineHeight / 2);
            double x2  = Math.Max(min, max);

            bool isEolSelected = editor.IsSomethingSelected && editor.SelectionMode != Mono.TextEditor.SelectionMode.Block ? editor.SelectionRange.Contains(LineSegment.Offset + LineSegment.Length) : false;

            int  active      = 0;
            bool highlighted = active == 0 && isCaretInLine;
            var  y           = metrics.LineYRenderStartPosition;

            // draw background
            if (!markerShouldDrawnAsHidden)
            {
                DrawRectangle(g, x, y, right, editor.LineHeight);
                g.SetSourceColor(LineColor.Color);
                g.Fill();

                if (metrics.Layout.StartSet || metrics.SelectionStart == metrics.TextEndOffset)
                {
                    double startX;
                    double endX;

                    if (metrics.SelectionStart != metrics.TextEndOffset)
                    {
                        var start = metrics.Layout.Layout.IndexToPos((int)metrics.Layout.SelectionStartIndex);
                        startX = (int)(start.X / Pango.Scale.PangoScale);
                        var end = metrics.Layout.Layout.IndexToPos((int)metrics.Layout.SelectionEndIndex);
                        endX = (int)(end.X / Pango.Scale.PangoScale);
                    }
                    else
                    {
                        startX = x2;
                        endX   = startX;
                    }

                    if (editor.MainSelection.SelectionMode == Mono.TextEditor.SelectionMode.Block && startX == endX)
                    {
                        endX = startX + 2;
                    }
                    startX += metrics.TextRenderStartPosition;
                    endX   += metrics.TextRenderStartPosition;
                    startX  = Math.Max(editor.TextViewMargin.XOffset, startX);
                    // clip region to textviewmargin start
                    if (isEolSelected)
                    {
                        endX = editor.Allocation.Width + (int)editor.HAdjustment.Value;
                    }
                    if (startX < endX)
                    {
                        DrawRectangle(g, startX, y, endX - startX, editor.LineHeight);
                        g.SetSourceColor(GetLineColor(highlighted, true));
                        g.Fill();
                    }
                }
                DrawErrorMarkers(editor, g, metrics, y);
            }

            double y2         = y + 0.5;
            double y2Bottom   = y2 + editor.LineHeight - 1;
            var    selected   = isEolSelected;
            var    lineTextPx = editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition + metrics.Layout.Width;

            if (x2 < lineTextPx)
            {
                x2 = lineTextPx;
            }

            if (editor.Options.ShowRuler)
            {
                double divider = Math.Max(editor.TextViewMargin.XOffset, x + editor.TextViewMargin.RulerX);
                if (divider >= x2)
                {
                    g.MoveTo(new Cairo.PointD(divider + 0.5, y2));
                    g.LineTo(new Cairo.PointD(divider + 0.5, y2Bottom));
                    g.SetSourceColor(GetLineColorBorder(highlighted, selected));
                    g.Stroke();
                }
            }

            return(true);
        }
 public override void Draw(MonoTextEditor editor, Cairo.Context g, LineMetrics metrics)
 {
 }
        public override void DrawBackground(Mono.TextEditor.MonoTextEditor editor, Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            int markerStart = usage.Offset;
            int markerEnd   = usage.EndOffset;

            if (markerEnd < startOffset || markerStart > endOffset)
            {
                return;
            }

            double @from;
            double to;
            var    startXPos = metrics.TextRenderStartPosition;
            var    endXPos   = metrics.TextRenderEndPosition;
            var    y         = metrics.LineYRenderStartPosition;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int start = startOffset < markerStart ? markerStart : startOffset;
                int end   = endOffset < markerEnd ? endOffset : markerEnd;

                uint curIndex = 0, byteIndex = 0;
                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(start - startOffset), ref curIndex, ref byteIndex);

                int x_pos = metrics.Layout.IndexToPos((int)byteIndex).X;

                @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(end - startOffset), ref curIndex, ref byteIndex);
                x_pos = metrics.Layout.IndexToPos((int)byteIndex).X;

                to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
            }

            @from = Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = Math.Max(to, editor.TextViewMargin.XOffset);
            if (@from < to)
            {
                HslColor colorStyle;
                if ((usage.UsageType & ReferenceUsageType.Write) == ReferenceUsageType.Write ||
                    (usage.UsageType & ReferenceUsageType.Declariton) == ReferenceUsageType.Declariton)
                {
                    colorStyle = SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.ChangingUsagesRectangle);
                    if (colorStyle.Alpha == 0.0)
                    {
                        colorStyle = SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.UsagesRectangle);
                    }
                }
                else
                {
                    colorStyle = SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.UsagesRectangle);
                }

                using (var lg = new LinearGradient(@from + 1, y + 1.5, to, y + editor.LineHeight - 1)) {
                    lg.AddColorStop(0, colorStyle);
                    lg.AddColorStop(1, colorStyle);
                    cr.SetSource(lg);
                    cr.RoundedRectangle(@from - 0.5, y + 0.5, to - @from + 1, editor.LineHeight - 1, 2);
                    cr.FillPreserve();
                }
                // TODO: EditorTheme : do we need the border ?!
                cr.SetSourceColor(colorStyle);
                cr.Stroke();
            }
        }
Example #27
0
        public override bool DrawBackground(TextEditor editor, Cairo.Context cr, double y, LineMetrics metrics)
        {
            // check, if a message bubble is active in that line.
            if (LineSegment != null && LineSegment.Markers.Any(m => m != this && (m is IExtendingTextLineMarker)))
            {
                return(false);
            }

            return(base.DrawBackground(editor, cr, y, metrics));
        }
 public override void Draw(TextEditor editor, Cairo.Context g, double y, LineMetrics metrics)
 {
 }
Example #29
0
            public override bool DrawBackground(TextEditor editor, Context cr, double y, LineMetrics metrics)
            {
                if (metrics.SelectionStart >= 0 || editor.CurrentMode is TextLinkEditMode || editor.TextViewMargin.SearchResultMatchCount > 0)
                {
                    return(false);
                }
                foreach (var usage in Usages)
                {
                    int markerStart = usage.TextSegment.Offset;
                    int markerEnd   = usage.TextSegment.EndOffset;

                    if (markerEnd < metrics.TextStartOffset || markerStart > metrics.TextEndOffset)
                    {
                        return(false);
                    }

                    double @from;
                    double to;

                    if (markerStart < metrics.TextStartOffset && metrics.TextEndOffset < markerEnd)
                    {
                        @from = metrics.TextRenderStartPosition;
                        to    = metrics.TextRenderEndPosition;
                    }
                    else
                    {
                        int start = metrics.TextStartOffset < markerStart ? markerStart : metrics.TextStartOffset;
                        int end   = metrics.TextEndOffset < markerEnd ? metrics.TextEndOffset : markerEnd;

                        uint curIndex = 0, byteIndex = 0;
                        TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(start - metrics.TextStartOffset), ref curIndex, ref byteIndex);

                        int x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                        @from = metrics.TextRenderStartPosition + (int)(x_pos / Pango.Scale.PangoScale);

                        TextViewMargin.TranslateToUTF8Index(metrics.Layout.LineChars, (uint)(end - metrics.TextStartOffset), ref curIndex, ref byteIndex);
                        x_pos = metrics.Layout.Layout.IndexToPos((int)byteIndex).X;

                        to = metrics.TextRenderStartPosition + (int)(x_pos / Pango.Scale.PangoScale);
                    }

                    @from = Math.Max(@from, editor.TextViewMargin.XOffset);
                    to    = Math.Max(to, editor.TextViewMargin.XOffset);
                    if (@from < to)
                    {
                        Mono.TextEditor.Highlighting.AmbientColor colorStyle;
                        if ((usage.UsageType & ReferenceUsageType.Write) == ReferenceUsageType.Write)
                        {
                            colorStyle = editor.ColorStyle.ChangingUsagesRectangle;
                        }
                        else
                        {
                            colorStyle = editor.ColorStyle.UsagesRectangle;
                        }

                        using (var lg = new LinearGradient(@from + 1, y + 1, to, y + editor.LineHeight)) {
                            lg.AddColorStop(0, colorStyle.Color);
                            lg.AddColorStop(1, colorStyle.SecondColor);
                            cr.SetSource(lg);
                            cr.RoundedRectangle(@from - 0.5, y + 0.5, to - @from + 1, editor.LineHeight - 1, 2);
                            cr.FillPreserve();
                        }

                        cr.SetSourceColor(colorStyle.BorderColor);
                        cr.Stroke();
                    }
                }
                return(true);
            }
Example #30
0
 public override void Draw(Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
 {
     Color = SyntaxHighlightingService.GetColor(editor.EditorTheme, info.ErrorType == ErrorType.Warning ? EditorThemeColors.UnderlineWarning : EditorThemeColors.UnderlineError);
     base.Draw(editor, cr, metrics, startOffset, endOffset);
 }
Example #31
0
        public override void Draw(Mono.TextEditor.MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, int startOffset, int endOffset)
        {
            this.editor = editor;
            var line = editor.GetLine(loc.Line);

            if (line == null)
            {
                return;
            }
            var x = editor.ColumnToX(line, loc.Column) - editor.HAdjustment.Value + editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition;

            cr.Rectangle(Math.Floor(x), Math.Floor(metrics.LineYRenderStartPosition) + editor.LineHeight - tagMarkerHeight, tagMarkerWidth, tagMarkerHeight);
            cr.SetSourceColor((HslColor.Brightness(SyntaxHighlightingService.GetColor(editor.EditorTheme, EditorThemeColors.Background)) < 0.5 ? Ide.Gui.Styles.Editor.SmartTagMarkerColorDark : Ide.Gui.Styles.Editor.SmartTagMarkerColorLight).ToCairoColor());
            cr.Fill();
        }