Пример #1
0
        /// <summary>
        /// Paints the fragment
        /// </summary>
        /// <param name="g">the device to draw to</param>
        protected override void PaintImp(Graphics g)
        {
            var offset = HtmlContainer != null ? HtmlContainer.ScrollOffset : PointF.Empty;
            var rect   = new RectangleF(Bounds.X + offset.X, Bounds.Y + offset.Y, Bounds.Width, Bounds.Height);

            if (rect.Height > 2 && CssUtils.IsColorVisible(ActualBackgroundColor))
            {
                g.FillRectangle(CssUtils.GetSolidBrush(ActualBackgroundColor), rect);
            }

            var b1 = CssUtils.GetSolidBrush(ActualBorderTopColor);

            DrawingUtils.DrawBorder(Border.Top, g, this, b1, rect, true, true);

            if (rect.Height > 1)
            {
                var b2 = CssUtils.GetSolidBrush(ActualBorderLeftColor);
                DrawingUtils.DrawBorder(Border.Left, g, this, b2, rect, true, true);

                var b3 = CssUtils.GetSolidBrush(ActualBorderRightColor);
                DrawingUtils.DrawBorder(Border.Right, g, this, b3, rect, true, true);

                var b4 = CssUtils.GetSolidBrush(ActualBorderBottomColor);
                DrawingUtils.DrawBorder(Border.Bottom, g, this, b4, rect, true, true);
            }
        }
Пример #2
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();
                    }
                }
            }
        }
Пример #3
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;
            }
        }
Пример #4
0
        /// <summary>
        /// Draw video title on top of the iframe if found.
        /// </summary>
        private void DrawTitle(Graphics g, Rectangle rect)
        {
            if (_videoTitle != null && _imageWord.Width > 40 && _imageWord.Height > 40)
            {
                var font = CssUtils.GetCachedFont("Arial", 9f, System.Drawing.FontStyle.Regular);
                g.FillRectangle(CssUtils.GetSolidBrush(System.Drawing.Color.FromArgb(160, 0, 0, 0)), rect.Left, rect.Top, rect.Width, CssUtils.GetFontHeight(font) + 7);

                using (var sf = new StringFormat(StringFormat.GenericTypographic))
                {
                    sf.FormatFlags = StringFormatFlags.NoWrap;
                    sf.Trimming    = StringTrimming.EllipsisCharacter;
                    var titleRect = new RectangleF(rect.Left + 3, rect.Top + 3, rect.Width - 6, rect.Height - 6);
                    g.DrawString(_videoTitle, font, Brushes.WhiteSmoke, titleRect, sf);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Draw play over the iframe if we found link url.
        /// </summary>
        private void DrawPlay(Graphics g, Rectangle rect)
        {
            if (_isVideo && _imageWord.Width > 70 && _imageWord.Height > 50)
            {
                var smooth = g.SmoothingMode;
                g.SmoothingMode = SmoothingMode.AntiAlias;

                var size = new Size(60, 40);
                var left = rect.Left + (rect.Width - size.Width) / 2;
                var top  = rect.Top + (rect.Height - size.Height) / 2;
                g.FillRectangle(CssUtils.GetSolidBrush(System.Drawing.Color.FromArgb(160, 0, 0, 0)), left, top, size.Width, size.Height);

                using (var path = new GraphicsPath())
                {
                    path.AddLine(left + size.Width / 3f + 1, top + 3 * size.Height / 4f, left + size.Width / 3f + 1, top + size.Height / 4f);
                    path.AddLine(left + size.Width / 3f + 1, top + size.Height / 4f, left + 2 * size.Width / 3f + 1, top + size.Height / 2f);
                    path.CloseFigure();
                    g.FillPath(Brushes.White, path);
                }

                g.SmoothingMode = smooth;
            }
        }
Пример #6
0
        /// <summary>
        /// Paints the fragment
        /// </summary>
        /// <param name="g"></param>
        private void PaintImp(Graphics g)
        {
            if (Display != CssConstants.None && (Display != CssConstants.TableCell || EmptyCells != CssConstants.Hide || !IsSpaceOrEmpty))
            {
                var areas = Rectangles.Count == 0 ? new List <RectangleF>(new[] { Bounds }) : new List <RectangleF>(Rectangles.Values);

                RectangleF[] rects  = areas.ToArray();
                PointF       offset = HtmlContainer != null ? HtmlContainer.ScrollOffset : PointF.Empty;

                for (int i = 0; i < rects.Length; i++)
                {
                    var actualRect = rects[i];
                    actualRect.Offset(offset);

                    PaintBackground(g, actualRect, i == rects.Length - 1);
                    PaintBorder(g, actualRect, i == 0, i == rects.Length - 1);
                }

                if (IsImage)
                {
                    var        word = Words[0];
                    RectangleF r    = word.Bounds;
                    r.Offset(offset);
                    r.Height -= ActualBorderTopWidth + ActualBorderBottomWidth + ActualPaddingTop + ActualPaddingBottom;
                    r.Y      += ActualBorderTopWidth + ActualPaddingTop;

                    //HACK: round rectangle only when necessary
                    g.DrawImage(word.Image, Rectangle.Round(r));

                    if (word.Selected)
                    {
                        g.FillRectangle(CssUtils.SelectionBackcolor, word.Left - word.LastMeasureOffset.X + offset.X, word.Top + offset.Y, word.Width, DomUtils.GetCssLineBoxByWord(word).LineHeight);
                    }
                }
                else if (Words.Count > 0)
                {
                    Font font  = ActualFont;
                    var  brush = CssUtils.GetSolidBrush(CssValueParser.GetActualColor(Color));
                    foreach (var word in Words)
                    {
                        if (word.Selected)
                        {
                            // handle paint selected word background and with partial word selection
                            var left  = word.SelectedStartOffset > -1 ? word.SelectedStartOffset : 0;
                            var width = word.SelectedEndOffset > -1 ? word.SelectedEndOffset + word.LastMeasureOffset.X : word.Width;


                            //REFACTOR THIS STUFF
                            Brush      b   = CssUtils.SelectionBackcolor;
                            CssLineBox box = DomUtils.GetCssLineBoxByWord(word);
                            float      h   = box != null ? box.LineHeight : 0;
                            float      w   = width - left;
                            float      x   = word.Left - word.LastMeasureOffset.X + offset.X + left;
                            float      y   = word.Top + offset.Y;


                            g.FillRectangle(b, x, y, w, h);
                        }

                        g.DrawString(word.Text, font, brush, word.Left - word.LastMeasureOffset.X + offset.X, word.Top + offset.Y);
                    }
                }

                for (int i = 0; i < rects.Length; i++)
                {
                    var actualRect = rects[i];
                    actualRect.Offset(offset);
                    PaintDecoration(g, actualRect, i == 0, i == rects.Length - 1);
                }

                foreach (CssBox b in Boxes)
                {
                    b.Paint(g);
                }

                CreateListItemBox(g);

                if (ListItemBox != null)
                {
                    ListItemBox.Paint(g);
                }
            }
        }