/// <summary> /// Draw video image over the iframe if found. /// </summary> private void DrawImage(RGraphics g, RPoint offset, RRect rect) { if (_imageWord.Image != null) { if (rect.Width > 0 && rect.Height > 0) { if (_imageWord.ImageRectangle == RRect.Empty) { g.DrawImage(_imageWord.Image, rect); } else { g.DrawImage(_imageWord.Image, rect, _imageWord.ImageRectangle); } if (_imageWord.Selected) { g.DrawRectangle(GetSelectionBackBrush(g, true), _imageWord.Left + offset.X, _imageWord.Top + offset.Y, _imageWord.Width + 2, DomUtils.GetCssLineBoxByWord(_imageWord).LineHeight); } } } else if (_isVideo && !_imageLoadingComplete) { RenderUtils.DrawImageLoadingIcon(g, HtmlContainer, rect); if (rect.Width > 19 && rect.Height > 19) { g.DrawRectangle(g.GetPen(RColor.LightGray), rect.X, rect.Y, rect.Width, rect.Height); } } }
/// <summary> /// Paints the fragment /// </summary> /// <param name="g">the device to draw to</param> protected override void PaintImp(RGraphics g) { var offset = (this.HtmlContainer != null && !this.IsFixed) ? this.HtmlContainer.ScrollOffset : RPoint.Empty; var rect = new RRect(this.Bounds.X + offset.X, this.Bounds.Y + offset.Y, this.Bounds.Width, this.Bounds.Height); if (rect.Height > 2 && RenderUtils.IsColorVisible(this.ActualBackgroundColor)) { g.DrawRectangle(g.GetSolidBrush(this.ActualBackgroundColor), rect.X, rect.Y, rect.Width, rect.Height); } var b1 = g.GetSolidBrush(this.ActualBorderTopColor); BordersDrawHandler.DrawBorder(Border.Top, g, this, b1, rect); if (rect.Height > 1) { var b2 = g.GetSolidBrush(this.ActualBorderLeftColor); BordersDrawHandler.DrawBorder(Border.Left, g, this, b2, rect); var b3 = g.GetSolidBrush(this.ActualBorderRightColor); BordersDrawHandler.DrawBorder(Border.Right, g, this, b3, rect); var b4 = g.GetSolidBrush(this.ActualBorderBottomColor); BordersDrawHandler.DrawBorder(Border.Bottom, g, this, b4, rect); } }
/// <summary> /// Draw image failed to load icon. /// </summary> /// <param name="g">the device to draw into</param> /// <param name="htmlContainer"></param> /// <param name="r">the rectangle to draw icon in</param> public static void DrawImageErrorIcon(RGraphics g, HtmlContainerInt htmlContainer, RRect r) { g.DrawRectangle(g.GetPen(RColor.LightGray), r.Left + 2, r.Top + 2, 15, 15); var image = htmlContainer.Adapter.GetLoadingFailedImage(); g.DrawImage(image, new RRect(r.Left + 3, r.Top + 3, image.Width, image.Height)); }
/// <summary> /// Draw image loading icon. /// </summary> /// <param name="g">the device to draw into</param> /// <param name="htmlContainer"></param> /// <param name="r">the rectangle to draw icon in</param> public static void DrawImageLoadingIcon(RGraphics g, HtmlContainerInt htmlContainer, RRect r) { g.DrawRectangle(g.GetPen(RColor.LightGray), r.Left + 3, r.Top + 3, 13, 14); var image = htmlContainer.Adapter.GetLoadingImage(); if (image != null) { g.DrawImage(image, new RRect(r.Left + 4, r.Top + 4, image.Width, image.Height)); } }
/// <summary> /// Draw video title on top of the iframe if found. /// </summary> private void DrawTitle(RGraphics g, RRect rect) { if (_videoTitle != null && _imageWord.Width > 40 && _imageWord.Height > 40) { var font = HtmlContainer.Adapter.GetFont("Arial", 9f, RFontStyle.Regular); g.DrawRectangle(g.GetSolidBrush(RColor.FromArgb(160, 0, 0, 0)), rect.Left, rect.Top, rect.Width, ActualFont.Height + 7); var titleRect = new RRect(rect.Left + 3, rect.Top + 3, rect.Width - 6, rect.Height - 6); g.DrawString(_videoTitle, font, RColor.WhiteSmoke, titleRect.Location, RSize.Empty, false); } }
/// <summary> /// Draw the background image at the required location repeating it over the Y axis.<br/> /// Adjust location to top if starting location doesn't include all the range (adjusted to center or bottom). /// </summary> private static void DrawRepeatY(RGraphics g, ImageLoadHandler imageLoadHandler, RRect rectangle, RRect srcRect, RRect destRect, RSize imgSize) { while (destRect.Y > rectangle.Y) { destRect.Y -= imgSize.Height; } using (var brush = g.GetTextureBrush(imageLoadHandler.Image, srcRect, destRect.Location)) { g.DrawRectangle(brush, destRect.X, rectangle.Y, srcRect.Width, rectangle.Height); } }
/// <summary> /// Draw the background image at the required location repeating it over the X axis.<br/> /// Adjust location to left if starting location doesn't include all the range (adjusted to center or right). /// </summary> private static void DrawRepeatX(RGraphics g, RImage image, RRect rectangle, RRect srcRect, RRect destRect, RSize imgSize) { while (destRect.X > rectangle.X) { destRect.X -= imgSize.Width; } using (var brush = g.GetTextureBrush(image, srcRect, destRect.Location)) { g.DrawRectangle(brush, rectangle.X, destRect.Y, rectangle.Width, srcRect.Height); } }
/// <summary> /// Draw play over the iframe if we found link url. /// </summary> private void DrawPlay(RGraphics g, RRect rect) { if (_isVideo && _imageWord.Width > 70 && _imageWord.Height > 50) { var prevMode = g.SetAntiAliasSmoothingMode(); var size = new RSize(60, 40); var left = rect.Left + (rect.Width - size.Width) / 2; var top = rect.Top + (rect.Height - size.Height) / 2; g.DrawRectangle(g.GetSolidBrush(RColor.FromArgb(160, 0, 0, 0)), left, top, size.Width, size.Height); RPoint[] points = { new RPoint(left + size.Width / 3f + 1, top + 3 * size.Height / 4f), new RPoint(left + size.Width / 3f + 1, top + size.Height / 4f), new RPoint(left + 2 * size.Width / 3f + 1, top + size.Height / 2f) }; g.DrawPolygon(g.GetSolidBrush(RColor.White), points); g.ReturnPreviousSmoothingMode(prevMode); } }
/// <summary> /// Paints the fragment /// </summary> /// <param name="g">the device to draw to</param> protected override void PaintImp(RGraphics g) { // load image if it is in visible rectangle if (_imageLoadHandler == null) { _imageLoadHandler = new ImageLoadHandler(HtmlContainer, OnLoadImageComplete); _imageLoadHandler.LoadImage(GetAttribute("src"), HtmlTag != null ? HtmlTag.Attributes : null); } var rect = CommonUtils.GetFirstValueOrDefault(Rectangles); RPoint offset = RPoint.Empty; if (!IsFixed) { offset = HtmlContainer.ScrollOffset; } rect.Offset(offset); var clipped = RenderUtils.ClipGraphicsByOverflow(g, this); PaintBackground(g, rect, true, true); BordersDrawHandler.DrawBoxBorders(g, this, rect, true, true); RRect r = _imageWord.Rectangle; r.Offset(offset); r.Height -= ActualBorderTopWidth + ActualBorderBottomWidth + ActualPaddingTop + ActualPaddingBottom; r.Y += ActualBorderTopWidth + ActualPaddingTop; r.X = Math.Floor(r.X); r.Y = Math.Floor(r.Y); if (_imageWord.Image != null) { if (r.Width > 0 && r.Height > 0) { if (_imageWord.ImageRectangle == RRect.Empty) { g.DrawImage(_imageWord.Image, r); } else { g.DrawImage(_imageWord.Image, r, _imageWord.ImageRectangle); } if (_imageWord.Selected) { g.DrawRectangle(GetSelectionBackBrush(g, true), _imageWord.Left + offset.X, _imageWord.Top + offset.Y, _imageWord.Width + 2, DomUtils.GetCssLineBoxByWord(_imageWord).LineHeight); } } } else if (_imageLoadingComplete) { if (_imageLoadingComplete && r.Width > 19 && r.Height > 19) { RenderUtils.DrawImageErrorIcon(g, HtmlContainer, r); } } else { RenderUtils.DrawImageLoadingIcon(g, HtmlContainer, r); if (r.Width > 19 && r.Height > 19) { g.DrawRectangle(g.GetPen(RColor.LightGray), r.X, r.Y, r.Width, r.Height); } } if (clipped) { g.PopClip(); } }
/// <summary> /// Draw the background image of the given box in the given rectangle.<br/> /// Handle background-repeat and background-position values. /// </summary> /// <param name="g">the device to draw into</param> /// <param name="box">the box to draw its background image</param> /// <param name="imageLoadHandler">the handler that loads image to draw</param> /// <param name="rectangle">the rectangle to draw image in</param> public static void DrawBackgroundImage(RGraphics g, CssBox box, ImageLoadHandler imageLoadHandler, RRect rectangle, RGraphicsPath roundrect = null) { // image size depends if specific rectangle given in image loader var imgSize = new RSize(imageLoadHandler.Rectangle == RRect.Empty ? imageLoadHandler.Image.Width : imageLoadHandler.Rectangle.Width, imageLoadHandler.Rectangle == RRect.Empty ? imageLoadHandler.Image.Height : imageLoadHandler.Rectangle.Height); // get the location by BackgroundPosition value var location = GetLocation(box.BackgroundPosition, rectangle, imgSize, box); var srcRect = imageLoadHandler.Rectangle == RRect.Empty ? new RRect(0, 0, imgSize.Width, imgSize.Height) : new RRect(imageLoadHandler.Rectangle.Left, imageLoadHandler.Rectangle.Top, imgSize.Width, imgSize.Height); // initial image destination rectangle var destRect = new RRect(location, imgSize); // need to clip so repeated image will be cut on rectangle var lRectangle = rectangle; lRectangle.Intersect(g.GetClip()); g.PushClip(lRectangle); //rectangle - box to draw in //imgSize - image size //localion - inital location of image wo repeat //destRect - RRect(location, imgSize) //srcRect (0,0,imgSize) //brushRect - This is rectangle which needs to be filled with Image from brushRect.Location with brushRect.Size multiple to Image size. RRect brushRect = new RRect(location, imgSize); switch (box.BackgroundRepeat) { case "no-repeat": //brushRect = destRect; break; case "repeat-x": if (brushRect.X > rectangle.X) { brushRect.X -= imgSize.Width * ((int)((brushRect.X - rectangle.X) / imgSize.Width) + 1); } if (brushRect.X + brushRect.Width < rectangle.X + rectangle.Width) { brushRect.Width = imgSize.Width * ((int)((rectangle.X + rectangle.Width - brushRect.X) / imgSize.Width) + 1); } break; case "repeat-y": if (brushRect.Y > rectangle.Y) { brushRect.Y -= imgSize.Height * ((int)((brushRect.Y - rectangle.Y) / imgSize.Height) + 1); } if (brushRect.Y + brushRect.Height < rectangle.Y + rectangle.Height) { brushRect.Height = imgSize.Height * ((int)((rectangle.Y + rectangle.Height - brushRect.Y) / imgSize.Height) + 1); } break; default: if (brushRect.X > rectangle.X) { brushRect.X -= imgSize.Width * ((int)((brushRect.X - rectangle.X) / imgSize.Width) + 1); } if (brushRect.X + brushRect.Width < rectangle.X + rectangle.Width) { brushRect.Width = imgSize.Width * ((int)((rectangle.X + rectangle.Width - brushRect.X) / imgSize.Width) + 1); } if (brushRect.Y > rectangle.Y) { brushRect.Y -= imgSize.Height * ((int)((brushRect.Y - rectangle.Y) / imgSize.Height) + 1); } if (brushRect.Y + brushRect.Height < rectangle.Y + rectangle.Height) { brushRect.Height = imgSize.Height * ((int)((rectangle.Y + rectangle.Height - brushRect.Y) / imgSize.Height) + 1); } break; } using (var brush = g.GetTextureBrush(imageLoadHandler.Image, brushRect, brushRect.Location)) { if (roundrect == null) { g.DrawRectangle(brush, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); } else { g.DrawPath(brush, roundrect); } } g.PopClip(); }