Exemplo n.º 1
0
        /// <summary>
        /// Paints the background of the box
        /// </summary>
        /// <param name="g"></param>
        /// <param name="rectangle"> </param>
        /// <param name="b"> </param>
        /// <param name="isLast">is the </param>
        private void PaintBackground(Graphics g, RectangleF rectangle, bool isLast)
        {
            //HACK: Background rectangles are being deactivated when justifying text.
            if (ContainingBlock.TextAlign != CssConstants.Justify && rectangle.Width > 0 && rectangle.Height > 0)
            {
                Brush         brush   = null;
                bool          dispose = false;
                SmoothingMode smooth  = g.SmoothingMode;

                if (BackgroundGradient != CssConstants.None)
                {
                    brush   = new LinearGradientBrush(rectangle, ActualBackgroundColor, ActualBackgroundGradient, ActualBackgroundGradientAngle);
                    dispose = true;
                }
                else if (ActualBackgroundColor != System.Drawing.Color.Empty && ActualBackgroundColor != System.Drawing.Color.Transparent)
                {
                    brush = CssUtils.GetSolidBrush(ActualBackgroundColor);
                }

                if (brush != null)
                {
                    // atodo: handle it correctly (tables background)
//                    if (isLast)
//                        rectangle.Width -= ActualWordSpacing + CssUtils.GetWordEndWhitespace(ActualFont);

                    GraphicsPath roundrect = null;
                    if (IsRounded)
                    {
                        roundrect = CssDrawingUtils.GetRoundRect(rectangle, ActualCornerNW, ActualCornerNE, ActualCornerSE, ActualCornerSW);
                    }

                    if (HtmlContainer != null && !HtmlContainer.AvoidGeometryAntialias && IsRounded)
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                    }

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

                    g.SmoothingMode = smooth;

                    if (roundrect != null)
                    {
                        roundrect.Dispose();
                    }
                    if (dispose)
                    {
                        brush.Dispose();
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Paints the border of the box
        /// </summary>
        /// <param name="g"></param>
        /// <param name="rectangle"> </param>
        /// <param name="isFirst"> </param>
        /// <param name="isLast"> </param>
        private void PaintBorder(Graphics g, RectangleF rectangle, bool isFirst, bool isLast)
        {
            if (rectangle.Width > 0 && rectangle.Height > 0)
            {
                SmoothingMode smooth = g.SmoothingMode;

                if (HtmlContainer != null && !HtmlContainer.AvoidGeometryAntialias && IsRounded)
                {
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                }

                //Top border
                if (!(string.IsNullOrEmpty(BorderTopStyle) || BorderTopStyle == CssConstants.None))
                {
                    var b = CssUtils.GetSolidBrush(BorderTopStyle == CssConstants.Inset ? CssDrawingUtils.Darken(ActualBorderTopColor) : ActualBorderTopColor);
                    g.FillPath(b, CssDrawingUtils.GetBorderPath(CssDrawingUtils.Border.Top, this, rectangle, isFirst, isLast));
                }


                if (isLast)
                {
                    //Right Border
                    if (!(string.IsNullOrEmpty(BorderRightStyle) || BorderRightStyle == CssConstants.None))
                    {
                        var b = CssUtils.GetSolidBrush(BorderRightStyle == CssConstants.Outset ? CssDrawingUtils.Darken(ActualBorderRightColor) : ActualBorderRightColor);
                        g.FillPath(b, CssDrawingUtils.GetBorderPath(CssDrawingUtils.Border.Right, this, rectangle, isFirst, true));
                    }
                }

                //Bottom border
                if (!(string.IsNullOrEmpty(BorderBottomStyle) || BorderBottomStyle == CssConstants.None))
                {
                    var b = CssUtils.GetSolidBrush(BorderBottomStyle == CssConstants.Outset ? CssDrawingUtils.Darken(ActualBorderBottomColor) : ActualBorderBottomColor);
                    g.FillPath(b, CssDrawingUtils.GetBorderPath(CssDrawingUtils.Border.Bottom, this, rectangle, isFirst, isLast));
                }

                if (isFirst)
                {
                    //Left Border
                    if (!(string.IsNullOrEmpty(BorderLeftStyle) || BorderLeftStyle == CssConstants.None))
                    {
                        var b = CssUtils.GetSolidBrush(BorderLeftStyle == CssConstants.Inset ? CssDrawingUtils.Darken(ActualBorderLeftColor) : ActualBorderLeftColor);
                        g.FillPath(b, CssDrawingUtils.GetBorderPath(CssDrawingUtils.Border.Left, this, rectangle, true, isLast));
                    }
                }

                g.SmoothingMode = smooth;
            }
        }