Esempio n. 1
0
        /// <summary>
        /// The first part of the split version of Display decorations.
        /// </summary>
        /// <param name="visiblePair">The pair representing the first character of the Visible text with respect to the whole text</param>
        /// <param name="decorations">The List of Decorations</param>
        /// <returns></returns>
        private Dictionary <EDecorationType, Dictionary <Decoration, List <Geometry> > > GeneratePreparedDecorations(Pair visiblePair, List <Decoration> decorations)
        {
            Dictionary <EDecorationType, Dictionary <Decoration, List <Geometry> > > preparedDecorations = new Dictionary <EDecorationType, Dictionary <Decoration, List <Geometry> > >();
            Dictionary <Decoration, List <Geometry> > hilightgeometryDictionary = PrepareGeometries(visiblePair, formattedText, decorations, EDecorationType.Hilight, HilightGeometryMaker);

            preparedDecorations.Add(EDecorationType.Hilight, hilightgeometryDictionary);
            Dictionary <Decoration, List <Geometry> > strikethroughGeometryDictionary = PrepareGeometries(visiblePair, formattedText, decorations, EDecorationType.Strikethrough, StrikethroughGeometryMaker);

            preparedDecorations.Add(EDecorationType.Strikethrough, strikethroughGeometryDictionary);
            Dictionary <Decoration, List <Geometry> > underlineGeometryDictionary = PrepareGeometries(visiblePair, formattedText, decorations, EDecorationType.Underline, UnderlineGeometryMaker);

            preparedDecorations.Add(EDecorationType.Underline, underlineGeometryDictionary);
            return(preparedDecorations);
        }
Esempio n. 2
0
 /// <summary>
 /// 实现了Hilight类型的文本装饰
 /// </summary>
 /// <param name="text">待装饰的文本</param>
 /// <param name="p">待装饰的区域</param>
 /// <returns></returns>
 private Geometry HilightGeometryMaker(FormattedText text, Pair p)
 {
     return(text.BuildHighlightGeometry(new Point(0, 0), p.Start, p.Length));
 }
Esempio n. 3
0
        /// <summary>
        /// 主要渲染逻辑
        /// </summary>
        /// <param name="drawingContext"></param>
        protected void OnRenderRuntime(DrawingContext drawingContext)
        {
            drawingContext.PushClip(new RectangleGeometry(new Rect(0, 0, this.ActualWidth, this.ActualHeight)));             // 限定绘制区域
            drawingContext.DrawRectangle(CodeBoxBackground, null, new Rect(0, 0, this.ActualWidth, this.ActualHeight));      // 绘制背景

            // 绘制光标所在行的背景
            Rect caretLineRect = GetRectFromCharacterIndex(this.CaretIndex);

            caretLineRect.X     = LineNumberMarginWidth;
            caretLineRect.Width = this.ActualWidth;
            if (this.SelectionLength == 0)
            {
                drawingContext.DrawRectangle(null, new Pen(CaretLineForeground, 2), caretLineRect);
            }


            int firstLine = GetFirstVisibleLineIndex();
            int firstChar;

            if (firstLine == 0)
            {
                firstChar = 0;
            }
            else
            {
                try
                {
                    firstChar = GetCharacterIndexFromLineIndex(firstLine);
                }
                catch
                {
                    firstChar = 0;
                }
            }
            Point renderPoint = GetRenderPoint(firstChar);

            // 绘制行号
            if (ShowLineNumbers && this.LineNumberMarginWidth > 0)
            {
                if (this.GetLastVisibleLineIndex() != -1)
                {
                    FormattedText lineNumbers = GenerateLineNumbers();
                    if (lineNumbers.Width + 6 > LineNumberMarginWidth)
                    {
                        LineNumberMarginWidth = lineNumbers.Width + 6;
                    }
                    drawingContext.DrawText(lineNumbers, new Point(3, renderPoint.Y));
                    renderinfo.LineNumbers = lineNumbers;
                }
                else
                {
                    drawingContext.DrawText(renderinfo.LineNumbers, new Point(3, renderPoint.Y));
                }
            }

            // if (this.Text == "") return;

            string visibleText = VisibleText;

            if (visibleText == null)
            {
                return;
            }

            formattedText = new FormattedText(
                visibleText,
                CultureInfo.GetCultureInfo("en-us"),
                FlowDirection.LeftToRight,
                new Typeface(this.FontFamily.Source),
                this.FontSize,
                BaseForeground);
            formattedText.Trimming = TextTrimming.None;

            ApplyTextWrapping(formattedText);

            Pair visiblePair = new Pair(firstChar, visibleText.Length);

            //Generates the prepared decorations for the BaseDecorations
            Dictionary <EDecorationType, Dictionary <Decoration, List <Geometry> > > basePreparedDecorations
                = GeneratePreparedDecorations(visiblePair, DecorationScheme.BaseDecorations);

            //Displays the prepared decorations for the BaseDecorations
            DisplayPreparedDecorations(drawingContext, basePreparedDecorations, renderPoint);

            //Generates the prepared decorations for the Decorations
            Dictionary <EDecorationType, Dictionary <Decoration, List <Geometry> > > preparedDecorations
                = GeneratePreparedDecorations(visiblePair, mDecorations);

            //Displays the prepared decorations for the Decorations
            DisplayPreparedDecorations(drawingContext, preparedDecorations, renderPoint);

            // 文本着色
            ColorText(firstChar, DecorationScheme.BaseDecorations);
            ColorText(firstChar, mDecorations);
            drawingContext.DrawText(formattedText, renderPoint);

            // 缓存渲染信息
            renderinfo.BoxText                 = formattedText;
            renderinfo.CaretLineRect           = caretLineRect;
            renderinfo.BasePreparedDecorations = basePreparedDecorations;
            renderinfo.PreparedDecorations     = preparedDecorations;
        }