/// <summary>
        ///
        /// </summary>
        /// <param name="pixelsPerDip"></param>
        /// <param name="tf"></param>
        /// <param name="st"></param>
        /// <param name="node"></param>
        /// <param name="compilation"></param>
        /// <param name="fontSize"></param>
        /// <param name="pDebugFn"></param>
        /// <returns></returns>
        public static CustomTextSource4 CreateAndInitTextSource(double pixelsPerDip,
                                                                Typeface tf, SyntaxTree st, SyntaxNode node, Compilation compilation, double fontSize,
                                                                RoslynCodeBase.DebugDelegate pDebugFn)

        {
            if (st == null)
            {
                st          = SyntaxFactory.ParseSyntaxTree("");
                node        = st.GetRoot();
                compilation = null;
            }

            var textDecorationCollection = new TextDecorationCollection();
            var typeface      = tf;
            var fontRendering = FontRendering.CreateInstance(fontSize,
                                                             TextAlignment.Left, textDecorationCollection,
                                                             Brushes.Black, typeface);
            var genericTextRunProperties = new GenericTextRunProperties(
                fontRendering,
                pixelsPerDip);
            var source = new CustomTextSource4(pixelsPerDip, fontRendering, genericTextRunProperties, pDebugFn)
            {
                EmSize      = fontSize,
                Compilation = compilation,
                Tree        = st,
                Node        = node
            };

            //source.PropertyChanged += x;
            source.Init();
            return(source);
        }
 public RenderRequestInput(RoslynCodeControl roslynCodeControl, int lineNo, int offset, double y, double x, TextFormatter textFormatter, double paragraphWidth,
                           double pixelsPerDip, CustomTextSource4 customTextSource4, double maxY, double maxX, double fontSize,
                           string fontFamilyName, FontWeight fontWeight)
 {
     // Timestamp = DateTime.Now;
     RoslynCodeControl = roslynCodeControl;
     LineNo            = lineNo;
     Offset            = offset;
     Y                 = y;
     X                 = x;
     TextFormatter     = textFormatter;
     ParagraphWidth    = paragraphWidth;
     PixelsPerDip      = pixelsPerDip;
     CustomTextSource4 = customTextSource4;
     MaxY              = maxY;
     MaxX              = maxX;
     FontSize          = fontSize;
     FontFamilyName    = fontFamilyName;
     FontWeight        = fontWeight;
 }
        public static DispatcherOperation MainUpdateContinuation(ICodeView iface1, CustomTextSource4 source)
        {
            return(iface1.Dispatcher.InvokeAsync(() =>
            {
                iface1.CustomTextSource = source;
                Debug.WriteLine("Return from await inner update");

                // ;(int.TryParse("Setting reactangle width to " +new NTComputer ({ff, line) || Device<int>()))};

                iface1.PerformingUpdate = false;
                iface1.InitialUpdate = false;
                iface1.RaiseEvent(new RoutedEventArgs(RoslynCodeBase.RenderCompleteEvent, iface1));
                iface1.Status = CodeControlStatus.Rendered;
                var insertionPoint = iface1.InsertionPoint;
                if (insertionPoint == 0)
                {
                    iface1.InsertionCharInfo = iface1.CharInfos.FirstOrDefault();
                }
            }, DispatcherPriority.Send));
        }
 public void Deconstruct(out RoslynCodeControl roslynCodeControl, out int lineNo, out int offset, out double y, out double x, out TextFormatter textFormatter, out double paragraphWidth, out double pixelsPerDip, out CustomTextSource4 customTextSource4, out double maxY, out double maxX, out string fontFamilyName, out double fontSize, out FontWeight fontWeight)
 {
     roslynCodeControl = RoslynCodeControl;
     lineNo            = LineNo;
     offset            = Offset;
     y                 = Y;
     x                 = X;
     textFormatter     = TextFormatter;
     paragraphWidth    = ParagraphWidth;
     pixelsPerDip      = PixelsPerDip;
     customTextSource4 = CustomTextSource4;
     maxY              = MaxY;
     maxX              = MaxX;
     fontFamilyName    = FontFamilyName;
     fontSize          = FontSize;
     fontWeight        = FontWeight;
 }
        public static void HandleLine(LinkedList <CharInfo> allCharInfos, Point linePosition, TextLine myTextLine,
                                      CustomTextSource4 customTextSource4, int runCount, int nRuns, int lineNo, int textStorePosition,
                                      List <TextRunInfo> runsInfos,
                                      LinkedListNode <CharInfo> curCharInfoNode,
                                      out LinkedListNode <CharInfo> lastCharInfoNode,
                                      RoslynCodeBase.DebugDelegate?debugFn = null, TextChange?change = null,
                                      LineInfo2?curLineInfo = null)
        {
            lastCharInfoNode = null;
            var curPos = linePosition;
            // var positions = new List<Rect>();
            var indexedGlyphRuns = myTextLine.GetIndexedGlyphRuns();

            var runs = customTextSource4.Runs;

            debugFn?.Invoke($"Runs is count is {runs.Count}", 1);
            var textRuns = runs.Skip(runCount).Take(nRuns).ToList();

            debugFn?.Invoke($"{runCount} {nRuns} TextRuns enumerator count is {textRuns.Count}", 1);
            var curCi = curCharInfoNode;

            using (var enum1 = textRuns.GetEnumerator())
            {
                var moveNext      = enum1.MoveNext();
                var lineCharIndex = 0;
                var xOrigin       = linePosition.X;
                if (indexedGlyphRuns == null)
                {
                    return;
                }
                foreach (var glyphRunC in indexedGlyphRuns)
                {
                    var gl         = glyphRunC.GlyphRun;
                    var advanceSum = gl.AdvanceWidths.Sum();
                    var startCi    = curCi;
                    for (var i = 0; i < gl.Characters.Count; i++)
                    {
                        var i0             = gl.ClusterMap?[i] ?? i;
                        var glAdvanceWidth = gl.AdvanceWidths[i0];
                        var glCharacter    = gl.Characters[i];
                        var glCaretStop    = gl.CaretStops?[i0];
                        if (curCi != null && curLineInfo != null)
                        {
                            // ReSharper disable once PossibleInvalidOperationException
#pragma warning disable 8629
                            if (lineCharIndex + curLineInfo.Offset >= change.Value.Span.Start)
#pragma warning restore 8629
                            {
                                curCi.Value.Index        = textStorePosition + lineCharIndex;
                                curCi.Value.RunIndex     = i;
                                curCi.Value.Character    = glCharacter;
                                curCi.Value.AdvanceWidth = glAdvanceWidth;
                                curCi.Value.XOrigin      = xOrigin;
                                if (Math.Abs(curCi.Value.YOrigin - linePosition.Y) > 0.5)
                                {
                                    curCi.Value.YOrigin = linePosition.Y;
                                }
                            }
                            if (curCi.Value.RunIndex != i)
                            {
                                curCi.Value.RunIndex = i;
                            }
                            curCi = curCi.Next;
                        }
                        else
                        {
                            var ci = new CharInfo(lineNo, textStorePosition + lineCharIndex, lineCharIndex, i,
                                                  glCharacter, glAdvanceWidth,
                                                  glCaretStop, xOrigin, linePosition.Y);
                            allCharInfos.AddLast(ci);
                        }

                        lineCharIndex++;
                        xOrigin += glAdvanceWidth;
                    }

                    var item = new Rect(curPos, new Size(advanceSum, myTextLine.Height));
                    if (!moveNext)
                    {
                        StringBuilder sb = new StringBuilder();
                        for (var c = curCharInfoNode; c != null; c = c.Next)
                        {
                            sb.Append(c.Value.Character);
                        }

                        throw new CodeControlException("enumerator empty " + sb);
                    }

                    var enum1Current = enum1.Current;
                    var textRunInfo  = new TextRunInfo(enum1Current, item, startCi);
                    debugFn?.Invoke(textRunInfo.ToString(), 2);
                    runsInfos?.Add(textRunInfo);

                    curPos.X += advanceSum;
                }
            }

#pragma warning disable 8601
            lastCharInfoNode = allCharInfos.Last;
#pragma warning restore 8601
        }