Exemple #1
0
        /// <summary>
        /// 实现了Strikethrough类型的文本装饰.
        /// </summary>
        /// <param name="text">待装饰的文本</param>
        /// <param name="p">待装饰的区域</param>
        /// <returns></returns>
        private Geometry StrikethroughGeometryMaker(FormattedText text, Pair p)
        {
            Geometry geom = text.BuildHighlightGeometry(new Point(0, 0), p.Start, p.Length);

            if (geom != null)
            {
                StackedRectangleGeometryHelper srgh = new StackedRectangleGeometryHelper(geom);
                return(srgh.CenterLineRectangleGeometry());
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// 实现了Underline类型的文本装饰
        /// </summary>
        /// <param name="text">待装饰的文本</param>
        /// <param name="p">待装饰的区域</param>
        /// <returns></returns>
        private Geometry UnderlineGeometryMaker(FormattedText text, Pair p)
        {
            Geometry geom = text.BuildHighlightGeometry(new Point(0, 0), p.Start, p.Length);

            if (geom != null)
            {
                StackedRectangleGeometryHelper srgh = new StackedRectangleGeometryHelper(geom);
                return(srgh.BottomEdgeRectangleGeometry());
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            //base.OnRender(drawingContext);
            if (this.Text != "")
            {
                FormattedText formattedText = null;
                double        leftMargin    = 4.0 + this.BorderThickness.Left;
                double        topMargin     = 2 + this.BorderThickness.Top;

                if (IsAllowFormatSqlContent)
                {
                    #region MyRendering
                    EnsureScrolling();
                    formattedText = new FormattedText(
                        this.Text,
                        CultureInfo.GetCultureInfo("en-us"),
                        FlowDirection.LeftToRight,
                        new Typeface(this.FontFamily.Source),
                        this.FontSize,
                        BaseForeground);                                                                                 //Text that matches the textbox's

                    formattedText.MaxTextWidth  = this.ViewportWidth;                                                    // space for scrollbar
                    formattedText.MaxTextHeight = Math.Max(this.ActualHeight + this.VerticalOffset, 0);                  //Adjust for scrolling
                    drawingContext.PushClip(new RectangleGeometry(new Rect(0, 0, this.ActualWidth, this.ActualHeight))); //restrict text to textbox

                    //Background hilight
                    foreach (Decoration dec in mDecorations)
                    {
                        if (dec.DecorationType == EDecorationType.Hilight)
                        {
                            List <Pair> ranges = dec.Ranges(this.Text);
                            foreach (Pair p in ranges)
                            {
                                Geometry geom = formattedText.BuildHighlightGeometry(new Point(leftMargin, topMargin - this.VerticalOffset), p.Start, p.Length);
                                if (geom != null)
                                {
#if DEBUG
                                    Debug.WriteLine("Draw geometry");
#endif
                                    drawingContext.DrawGeometry(dec.Brush, null, geom);
                                }
                            }
                        }
                    }

                    //Underline
                    foreach (Decoration dec in mDecorations)
                    {
                        if (dec.DecorationType == EDecorationType.Underline)
                        {
                            List <Pair> ranges = dec.Ranges(this.Text);
                            foreach (Pair p in ranges)
                            {
                                Geometry geom = formattedText.BuildHighlightGeometry(new Point(leftMargin, topMargin - this.VerticalOffset), p.Start, p.Length);
                                if (geom != null)
                                {
                                    StackedRectangleGeometryHelper srgh = new StackedRectangleGeometryHelper(geom);

                                    foreach (Geometry g in srgh.BottomEdgeRectangleGeometries())
                                    {
#if DEBUG
                                        Debug.WriteLine("Draw geometry2");
#endif
                                        drawingContext.DrawGeometry(dec.Brush, null, g);
                                    }
                                }
                            }
                        }
                    }


                    //Strikethrough
                    foreach (Decoration dec in mDecorations)
                    {
                        if (dec.DecorationType == EDecorationType.Strikethrough)
                        {
                            List <Pair> ranges = dec.Ranges(this.Text);
                            foreach (Pair p in ranges)
                            {
                                Geometry geom = formattedText.BuildHighlightGeometry(new Point(leftMargin, topMargin - this.VerticalOffset), p.Start, p.Length);
                                if (geom != null)
                                {
                                    StackedRectangleGeometryHelper srgh = new StackedRectangleGeometryHelper(geom);

                                    foreach (Geometry g in srgh.CenterLineRectangleGeometries())
                                    {
#if DEBUG
                                        Debug.WriteLine("Draw geometry3");
#endif
                                        drawingContext.DrawGeometry(dec.Brush, null, g);
                                    }
                                }
                            }
                        }
                    }


                    #region TextColor
                    foreach (Decoration dec in mDecorations)
                    {
                        if (dec.DecorationType == EDecorationType.TextColor)
                        {
                            List <Pair> ranges = dec.Ranges(this.Text);
                            foreach (Pair p in ranges)
                            {
#if DEBUG
                                Debug.WriteLine("Set background brush" + p.Start.ToString());
#endif
                                //this method will paint the text ,it will cost many ,many times,
                                //if the sql script large enough (more than 100k)
                                //So I'd rather use simplest textbox with no formatted sql text replace this control.
                                formattedText.SetForegroundBrush(dec.Brush, p.Start, p.Length);
                            }
                        }
                    }
                    #endregion

#if DEBUG
                    Debug.WriteLine("End drawing");
#endif

                    #endregion
                }

                if (formattedText == null)
                {
                    this.Foreground = new SolidColorBrush(Colors.Black);
                }
                drawingContext.DrawText(formattedText, new Point(leftMargin, topMargin - this.VerticalOffset));
            }
        }