Contains all the paint code to paint different background images.
Exemplo n.º 1
0
        /// <summary>
        /// Paints the background of the box
        /// </summary>
        /// <param name="g">the device to draw into</param>
        /// <param name="rect">the bounding rectangle to draw in</param>
        /// <param name="isFirst">is it the first rectangle of the element</param>
        /// <param name="isLast">is it the last rectangle of the element</param>
        internal void PaintBackground(PaintVisitor p, RectangleF rect, bool isFirst, bool isLast)
        {
            //return;
            //if (this.dbugMark1 > 0)
            //{
            //    Console.WriteLine(this.dbugMark1);
            //    if ((this.dbugMark1 % 2) == 0)
            //    {
            //    }
            //    else
            //    {
            //    }
            //}
            if (!this.HasVisibleBgColor)
            {
                return;
            }

            if (rect.Width > 0 && rect.Height > 0)
            {
                Brush brush   = null;
                bool  dispose = false;
                if (BackgroundGradient != Color.Transparent)
                {
                    //use bg gradient

                    brush = LinearGradientBrush.CreateLinearGradientBrush(rect,
                                                                          ActualBackgroundColor,
                                                                          ActualBackgroundGradient,
                                                                          ActualBackgroundGradientAngle);
                    dispose = true;
                }
                else if (RenderUtils.IsColorVisible(ActualBackgroundColor))
                {
                    brush   = new SolidBrush(this.ActualBackgroundColor);
                    dispose = true;
                }


                DrawBoard     g      = p.InnerCanvas;
                SmoothingMode smooth = g.SmoothingMode;
                if (brush != null)
                {
                    // atodo: handle it correctly (tables background)
                    // if (isLast)
                    //  rectangle.Width -= ActualWordSpacing + CssUtils.GetWordEndWhitespace(ActualFont);
                    GraphicsPath roundrect          = null;
                    bool         hasSomeRoundCorner = this.HasSomeRoundCorner;
                    if (hasSomeRoundCorner)
                    {
                        roundrect = RenderUtils.GetRoundRect(rect, ActualCornerNW, ActualCornerNE, ActualCornerSE, ActualCornerSW);
                    }

                    if (!p.AvoidGeometryAntialias && hasSomeRoundCorner)
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                    }

                    if (roundrect != null)
                    {
                        g.FillPath(brush, roundrect);
                    }
                    else
                    {
                        g.FillRectangle(brush, (float)Math.Ceiling(rect.X), (float)Math.Ceiling(rect.Y), rect.Width, rect.Height);
                    }

                    g.SmoothingMode = smooth;
                    if (roundrect != null)
                    {
                        roundrect.Dispose();
                    }
                    if (dispose)
                    {
                        brush.Dispose();
                    }
                }

                if (isFirst)
                {
                    var bgImageBinder = this.BackgroundImageBinder;
                    if (bgImageBinder != null && bgImageBinder.Image != null)
                    {
                        BackgroundImagePaintHelper.DrawBackgroundImage(g, this, bgImageBinder, rect);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Paints the background of the box
        /// </summary>
        /// <param name="g">the device to draw into</param>
        /// <param name="rect">the bounding rectangle to draw in</param>
        /// <param name="isFirst">is it the first rectangle of the element</param>
        /// <param name="isLast">is it the last rectangle of the element</param>
        internal void PaintBackground(PaintVisitor p, RectangleF rect, bool isFirst, bool isLast)
        {
            if (!this.HasVisibleBgColor)
            {
                return;
            }

            if (rect.Width == 0 || rect.Height == 0)
            {
                return;
            }

            Brush brush   = null;
            bool  dispose = false;

            if (BackgroundGradient != Color.Transparent)
            {
                //use bg gradient

                p.CurrentSolidBackgroundColorHint = Color.Transparent;

                //linear brush
                brush = CreateLinearGradientBrush(rect,
                                                  ActualBackgroundColor,
                                                  ActualBackgroundGradient,
                                                  ActualBackgroundGradientAngle);

                dispose = true; //dispose***
            }
            else if (RenderUtils.IsColorVisible(ActualBackgroundColor))
            {
                //TODO: review here,
                //
                //solid brush hint for text
                p.CurrentSolidBackgroundColorHint = (ActualBackgroundColor.A == 255) ? ActualBackgroundColor : Color.Transparent;

                brush   = new SolidBrush(this.ActualBackgroundColor);
                dispose = true;
            }


            DrawBoard     g      = p.InnerDrawBoard;
            SmoothingMode smooth = g.SmoothingMode;

            if (brush != null)
            {
                // atodo: handle it correctly (tables background)
                // if (isLast)
                //  rectangle.Width -= ActualWordSpacing + CssUtils.GetWordEndWhitespace(ActualFont);
                //GraphicsPath roundrect = null;
                bool hasSomeRoundCorner = this.HasSomeRoundCorner;
                if (hasSomeRoundCorner)
                {
                    //roundrect = RenderUtils.GetRoundRect(rect, ActualCornerNW, ActualCornerNE, ActualCornerSE, ActualCornerSW);
                }

                if (!p.AvoidGeometryAntialias && hasSomeRoundCorner)
                {
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                }

                //if (roundrect != null)
                //{
                //    g.FillPath(brush, roundrect);
                //}
                //else
                //{

                g.FillRectangle(brush, (float)Math.Ceiling(rect.Left), (float)Math.Ceiling(rect.Top), rect.Width, rect.Height);

                //}

                g.SmoothingMode = smooth;
                //if (roundrect != null) roundrect.Dispose();
                if (dispose)
                {
                    brush.Dispose();
                }
            }

            if (isFirst)
            {
                ImageBinder bgImageBinder = this.BackgroundImageBinder;
                if (bgImageBinder != null && bgImageBinder.LocalImage != null)
                {
                    BackgroundImagePaintHelper.DrawBackgroundImage(g, this, bgImageBinder, rect);
                }
            }
        }