/// <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);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pixelsPerDip"></param>
        /// <param name="fontRendering"></param>
        /// <param name="genericTextRunProperties"></param>
        /// <param name="debugFn"></param>
        public CustomTextSource4(double pixelsPerDip, FontRendering fontRendering,
                                 GenericTextRunProperties genericTextRunProperties, RoslynCodeBase.DebugDelegate debugFn)
        {
            CurrentRendering = fontRendering;
            PixelsPerDip     = pixelsPerDip;

            BaseProps = genericTextRunProperties;
            _debugFn  = debugFn;
        }
 public GenericTextParagraphPropertiesImpl(FontRendering newRendering, double pixelsPerDip,
                                           List <TextTabProperties> tabs) : base(newRendering, pixelsPerDip)
 {
     if (tabs != null)
     {
         foreach (var textTabPropertiese in tabs)
         {
             _tabs.Add(textTabPropertiese);
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="newRender"></param>
 /// <param name="pixelsPerDip"></param>
 /// <param name="foregroundBrush"></param>
 /// <param name="hintingSize"></param>
 /// <param name="pDebugFn"></param>
 public GenericTextRunProperties(FontRendering newRender,
                                 double pixelsPerDip, Brush foregroundBrush = null, FontStyle?style = null)
 {
     _typeface          = newRender.Typeface;
     _emSize            = newRender.FontSize;
     _emHintingSize     = newRender.FontSize;
     _textDecorations   = newRender.TextDecorations;
     _foregroundBrush   = foregroundBrush ?? Brushes.Black;
     _backgroundBrush   = null;
     _baselineAlignment = BaselineAlignment.Baseline;
     _culture           = CultureInfo.CurrentUICulture;
     PixelsPerDip       = pixelsPerDip;
 }
        private static CustomTextSource4 CreateCustomTextSource4(
            TextSourceInitializationParameters p)
        {
            var customTextSource4 =
                CommonText.CreateAndInitTextSource(p.PixelsPerDip, p.Tf,
                                                   p.Tree, p.Node0,
                                                   p.Compilation, p.EmSize0, p.DebugFn);

            customTextSource4.CurrentRendering = FontRendering.CreateInstance(p.EmSize0,
                                                                              TextAlignment.Left,
                                                                              new TextDecorationCollection(), Brushes.Black, p.Tf);

            return(customTextSource4);
        }
Esempio n. 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="newRender"></param>
 /// <exception cref="ArgumentNullException"></exception>
 public GenericTextRunProperties([NotNull] FontRendering newRender)
 {
     if (newRender == null)
     {
         throw new ArgumentNullException(nameof(newRender));
     }
     _typeface          = newRender.Typeface;
     _emSize            = newRender.FontSize;
     _emHintingSize     = newRender.FontSize;
     _textDecorations   = newRender.TextDecorations;
     _foregroundBrush   = newRender.TextColor;
     _backgroundBrush   = null;
     _baselineAlignment = BaselineAlignment.Baseline;
     _culture           = CultureInfo.CurrentUICulture;
 }
 public GenericTextParagraphProperties(FontRendering newRendering, double pixelsPerDip)
 {
     _flowDirection            = FlowDirection.LeftToRight;
     _textAlignment            = newRendering.TextAlignment;
     _firstLineInParagraph     = false;
     _alwaysCollapsible        = false;
     _defaultTextRunProperties = new GenericTextRunProperties(
         newRendering.Typeface, pixelsPerDip, newRendering.FontSize, newRendering.FontSize,
         newRendering.TextDecorations, newRendering.TextColor, null,
         BaselineAlignment.Baseline, CultureInfo.CurrentUICulture);
     _textWrap        = TextWrapping.Wrap;
     _lineHeight      = 0;
     _indent          = 0;
     _paragraphIndent = 0;
 }
        public static unsafe CustomTextSource4 InnerUpdateAsync(MainUpdateParameters mainUpdateParameters,
                                                                Func <CustomTextSource4> makeSource)
        {
            LinkedListNode <CharInfo> charInfoNode = null;
            const int batchLines = 100;
            var       lineInfos0 = new LineInfo2[batchLines];
            var       lineInfos1 = new LineInfo2[batchLines];
            var       lineInfos  = lineInfos0;
            int       @switch    = 0;

            mainUpdateParameters.DebugFn?.Invoke($"{nameof(InnerUpdateAsync)}", 5);
            var tf = CreateTypeface(new FontFamily(mainUpdateParameters.FaceName), FontStyles.Normal,

                                    FontStretches.Normal,
                                    mainUpdateParameters.FontWeight);

            var currentRendering = FontRendering.CreateInstance(mainUpdateParameters.FontSize,
                                                                TextAlignment.Left,
                                                                null,
                                                                Brushes.Black,
                                                                tf);

            var customTextSource4 = makeSource();

            var myGroup = new DrawingGroup();
            var myDc    = myGroup.Open();

            var genericTextParagraphProperties =
                new GenericTextParagraphProperties(currentRendering, mainUpdateParameters.PixelsPerDip);
            var runsInfos         = new List <TextRunInfo>();
            var allCharInfos      = new LinkedList <CharInfo>();
            var textStorePosition = mainUpdateParameters.TextStorePosition;
            var lineNo            = mainUpdateParameters.LineNo;
            // var tasks = new List<Task>();
            var linePosition = mainUpdateParameters.LinePosition;
            var liIndex      = 0;

            while (textStorePosition < customTextSource4.Length)
            {
                var runCount = customTextSource4.Runs.Count;
#if DEBUGTEXTSOURCE
                Debug.WriteLine("Runcount = " + runCount);
#endif
                var numPages  = 0;
                var pageBegin = new Point(0, 0);
                var pageEnd   = new Point(0, 0);
                if (mainUpdateParameters.Paginate)
                {
                    // ReSharper disable once PossibleInvalidOperationException
                    pageEnd.Offset(mainUpdateParameters.PageSize.Value.Width,
                                   mainUpdateParameters.PageSize.Value.Height);
                }

                LineInfo2 lineInfo;
                var       linePositionX = mainUpdateParameters.ParagraphWidth - linePosition.X;
                if (linePositionX < 0)
                {
                    linePositionX = 0;
                }
                using (var myTextLine = mainUpdateParameters.TextFormatter.FormatLine(customTextSource4,
                                                                                      textStorePosition, linePositionX,
                                                                                      genericTextParagraphProperties,
                                                                                      null))
                {
                    var nRuns = customTextSource4.Runs.Count - runCount;
                    if (nRuns < 0)
                    {
                        throw new InvalidOperationException("NRuns is negative" + nRuns);
                    }
#if DEBUGTEXTSOURCE
                    Debug.WriteLine("num runs for line is " + nRuns);
#endif

                    var curCharInfoNode = charInfoNode;
                    HandleLine(allCharInfos, linePosition, myTextLine, customTextSource4, runCount,
                               nRuns, lineNo, textStorePosition, runsInfos, curCharInfoNode, out charInfoNode,
                               mainUpdateParameters.DebugFn);
                    myTextLine.Draw(myDc, linePosition, InvertAxes.None);

                    lineInfos[liIndex++] = new LineInfo2(lineNo, curCharInfoNode != null? curCharInfoNode.Next : allCharInfos.First, textStorePosition, linePosition, myTextLine.Height,
                                                         myTextLine.Length);
                    linePosition.Y += myTextLine.Height;
                    lineNo++;

                    // Update the index position in the text store.
                    textStorePosition += myTextLine.Length;
                    if (mainUpdateParameters.Paginate && linePosition.Y >= pageEnd.Y)
                    {
                        Debug.WriteLine($"numPages: {numPages}");
                        numPages++;
                    }
                }

#if GROUPEDDG
                if (lineNo > 0 && lineNo % batchLines == 0)
                {
                    myDc.Close();
                    myGroup.Freeze();
                    var curUi = new UpdateInfo()
                    {
                        DrawingGroup = myGroup, CharInfos = allCharInfos.ToList <CharInfo>()
                    };
                    await mainUpdateParameters.ChannelWriter.WriteAsync(curUi);

                    // tasks.Add(writeAsync.AsTask());
                    myGroup = new DrawingGroup();
                    myDc    = myGroup.Open();
                }
#else
                if (lineNo <= 0 || lineNo % batchLines != 0)
                {
                    continue;
                }
                myDc.Close();
                myGroup.Freeze();
                var curUi = new UpdateInfo(
                    myGroup,
                    liIndex,
                    lineInfos
                    );
                liIndex = 0;
                if (@switch == 0)
                {
                    lineInfos = lineInfos1;
                    @switch   = 1;
                }
                else
                {
                    lineInfos = lineInfos0;
                    @switch   = 0;
                }
                mainUpdateParameters.ChannelWriter.WriteAsync(curUi);
                myGroup = new DrawingGroup();
                myDc    = myGroup.Open();
#endif
            }

            customTextSource4.RunInfos = runsInfos;
#if GROUPEDDG
            if (lineNo % 100 != 0)
            {
                myDc.Close();
                myGroup.Freeze();
                var curUi = new UpdateInfo()
                {
                    DrawingGroup = myGroup, CharInfos = Enumerable.ToList <CharInfo>(allCharInfos), FinalBlock = true
                };
                await mainUpdateParameters.ChannelWriter.WriteAsync(curUi);

                // tasks.Add(writeAsync.AsTask());
            }
            else
            {
                myDc.Close();
            }
#else
            if (lineNo % batchLines == 0)
            {
                return(customTextSource4);
            }
            {
                myDc.Close();
                myGroup.Freeze();
                var curUi = new UpdateInfo(
                    myGroup,
                    liIndex,
                    lineInfos
                    );
                mainUpdateParameters.ChannelWriter.WriteAsync(curUi);
            }
#endif
            // await Task.WhenAll(tasks);

            return(customTextSource4);
        }