SvgGroup.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Drawing;
  2. using System.Drawing.Drawing2D;
  3. #pragma warning disable
  4. namespace Svg
  5. {
  6. /// <summary>
  7. /// An element used to group SVG shapes.
  8. /// </summary>
  9. [SvgElement("g")]
  10. public class SvgGroup : SvgVisualElement
  11. {
  12. /// <summary>
  13. /// Gets the <see cref="GraphicsPath"/> for this element.
  14. /// </summary>
  15. /// <value></value>
  16. public override System.Drawing.Drawing2D.GraphicsPath Path(ISvgRenderer renderer)
  17. {
  18. return GetPaths(this, renderer);
  19. }
  20. /// <summary>
  21. /// Gets the bounds of the element.
  22. /// </summary>
  23. /// <value>The bounds.</value>
  24. public override System.Drawing.RectangleF Bounds
  25. {
  26. get
  27. {
  28. var r = new RectangleF();
  29. foreach (var c in this.Children)
  30. {
  31. if (c is SvgVisualElement)
  32. {
  33. // First it should check if rectangle is empty or it will return the wrong Bounds.
  34. // This is because when the Rectangle is Empty, the Union method adds as if the first values where X=0, Y=0
  35. if (r.IsEmpty)
  36. {
  37. r = ((SvgVisualElement)c).Bounds;
  38. }
  39. else
  40. {
  41. var childBounds = ((SvgVisualElement)c).Bounds;
  42. if (!childBounds.IsEmpty)
  43. {
  44. r = RectangleF.Union(r, childBounds);
  45. }
  46. }
  47. }
  48. }
  49. return r;
  50. }
  51. }
  52. protected override bool Renderable { get { return false; } }
  53. public override SvgElement DeepCopy()
  54. {
  55. return DeepCopy<SvgGroup>();
  56. }
  57. public override SvgElement DeepCopy<T>()
  58. {
  59. var newObj = base.DeepCopy<T>() as SvgGroup;
  60. if (this.Fill != null)
  61. newObj.Fill = this.Fill.DeepCopy() as SvgPaintServer;
  62. return newObj;
  63. }
  64. }
  65. }
  66. #pragma warning restore