Beispiel #1
0
        DoFormatLine2
            (TextSource textSource,
            int textStorePosition,
            double paragraphWidth,
            TextParagraphProperties paragraphProperties,
            DrawingContext myDc,
            Point linePosition, Func <InputTuple, ILineInfo2Base?, object?> delegate1, InputTuple t,
            Func <int, TextSpan, Rect, TextLine, ILineInfo2Base> createFunc, int lineNo, TextLineBreak?textLineBreak)
        {
            var textFormatter = Formatter.Value;

            var myTextLine = textFormatter !.FormatLine
                                 (textSource,
                                 textStorePosition,
                                 paragraphWidth + 10,
                                 paragraphProperties,
                                 textLineBreak);

            t.TextLine = myTextLine;

            DrawServiceClient c = new DrawServiceClient("xx");
            // myTextLine.Draw(myDc, linePosition, InvertAxes.None);
            DrawingVisual dv  = new DrawingVisual();
            var           dc1 = dv.RenderOpen();
            DrawingGroup  dd  = new DrawingGroup();
            var           dc2 = dd.Open();

            myTextLine.Draw(dc1, linePosition, InvertAxes.None);
            myTextLine.Draw(dc2, linePosition, InvertAxes.None);
            dc1.Close();
            dc2.Close();
            // c.SendDrawing(dd);
            myDc.DrawDrawing(dd);
            // Debug.WriteLine($"{Thread.CurrentThread.ManagedThreadId}: {linePosition}");
            var            length = myTextLine.Length;
            var            height = dd.Bounds.Height;// myTextLine.Height;
            var            arg3   = new Rect(new Point(myTextLine.Start, linePosition.Y), new Size(myTextLine.WidthIncludingTrailingWhitespace, myTextLine.Height));
            ILineInfo2Base li     = createFunc(lineNo, new TextSpan(textStorePosition, myTextLine.Length), arg3, myTextLine);

            delegate1.Invoke(t, li);
            var width = dd.Bounds.Width;//myTextLine.WidthIncludingTrailingWhitespace;

            return(height, length, width, li, myTextLine.GetTextLineBreak());
        }
Beispiel #2
0
        public static void FormatAndDrawLines(TextChange?change,
                                              int textStorePosition,
                                              ICustomTextSource source,
                                              double paragraphWidth0,
                                              Point linePosition,
                                              int lineNo,
                                              TextParagraphProperties genericTextParagraphProperties,
                                              DrawingContext myDc,
                                              Func <InputTuple, ILineInfo2Base?, object?> delegate1,
                                              ILineInfo2Base [] lineInfos,
                                              int liIndex,
                                              int batchLines,
                                              DrawingGroup myGroup0,
                                              object?batchArg, Func <DrawingContext?, DrawingGroup, ILineInfo2Base[], int, bool, object?, bool> batchAction, int?end)
        {
            TextLineBreak?prev = null;

            var myGroup        = myGroup0;
            var initialLineSet = true;

            while (textStorePosition < end.GetValueOrDefault(source.Length))
            {
                // Debug.WriteLine(Thread.CurrentThread.ManagedThreadId + ": "+ textStorePosition);
                var paragraphWidth = paragraphWidth0 - linePosition.X;
                if (paragraphWidth < 0)
                {
                    paragraphWidth = 0;
                }
                var textParagraphProperties = source.GetTextParagraphProperties(textStorePosition);

                var        pp  = textParagraphProperties ?? genericTextParagraphProperties;
                InputTuple in1 = new InputTuple(null, linePosition,
                                                source.AsTextSource(), textStorePosition, null,
                                                null, change, lineNo);
                var(height, length, _, li, prev1) = DoFormatLine2(source.AsTextSource(),
                                                                  textStorePosition, paragraphWidth, pp, myDc, linePosition, delegate1, in1, CreateLineInfo, lineNo, prev);
                prev = prev1;

                // var boundingRect = new Rect(linePosition.X, linePosition.Y, widthWithWs, height);

                lineInfos[liIndex++] = li;

                linePosition.Y += height;
                lineNo++;

                // Update the index position in the text store.
                textStorePosition += length;

                // if (lineNo % (lineCount / 10) == 0)
                // progress?.Report(new UpdateProgress(textStorePosition, lineNo, lineCount));

                if (lineNo <= 0 || lineNo % batchLines != 0)
                {
                    continue;
                }

                if (batchAction(myDc, myGroup, lineInfos, liIndex, initialLineSet, batchArg))
                {
                    myGroup = new DrawingGroup();
                    myDc    = myGroup.Open();
                }

                liIndex        = 0;
                initialLineSet = false;
            }

            if (lineNo % batchLines != 0)
            {
                batchAction(myDc, myGroup, lineInfos, liIndex, initialLineSet, batchArg);
            }
            // progress?.Report(new UpdateProgress(textStorePosition, lineNo, lineCount));
        }