SvgSwitch.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System.Drawing;
  2. using System.Drawing.Drawing2D;
  3. #pragma warning disable
  4. namespace Svg
  5. {
  6. /// <summary>
  7. /// The �switch� element evaluates the �requiredFeatures�, �requiredExtensions� and �systemLanguage� attributes on its direct child elements in order, and then processes and renders the first child for which these attributes evaluate to true
  8. /// </summary>
  9. [SvgElement("switch")]
  10. public class SvgSwitch : SvgVisualElement
  11. {
  12. public SvgSwitch()
  13. {
  14. }
  15. /// <summary>
  16. /// Gets the <see cref="GraphicsPath"/> for this element.
  17. /// </summary>
  18. /// <value></value>
  19. public override System.Drawing.Drawing2D.GraphicsPath Path(ISvgRenderer renderer)
  20. {
  21. return GetPaths(this, renderer);
  22. }
  23. /// <summary>
  24. /// Gets the bounds of the element.
  25. /// </summary>
  26. /// <value>The bounds.</value>
  27. public override System.Drawing.RectangleF Bounds
  28. {
  29. get
  30. {
  31. var r = new RectangleF();
  32. foreach (var c in this.Children)
  33. {
  34. if (c is SvgVisualElement)
  35. {
  36. // First it should check if rectangle is empty or it will return the wrong Bounds.
  37. // This is because when the Rectangle is Empty, the Union method adds as if the first values where X=0, Y=0
  38. if (r.IsEmpty)
  39. {
  40. r = ((SvgVisualElement)c).Bounds;
  41. }
  42. else
  43. {
  44. var childBounds = ((SvgVisualElement)c).Bounds;
  45. if (!childBounds.IsEmpty)
  46. {
  47. r = RectangleF.Union(r, childBounds);
  48. }
  49. }
  50. }
  51. }
  52. return r;
  53. }
  54. }
  55. /// <summary>
  56. /// Renders the <see cref="SvgElement"/> and contents to the specified <see cref="Graphics"/> object.
  57. /// </summary>
  58. /// <param name="renderer">The <see cref="Graphics"/> object to render to.</param>
  59. protected override void Render(ISvgRenderer renderer)
  60. {
  61. if (!Visible || !Displayable)
  62. return;
  63. this.PushTransforms(renderer);
  64. this.SetClip(renderer);
  65. base.RenderChildren(renderer);
  66. this.ResetClip(renderer);
  67. this.PopTransforms(renderer);
  68. }
  69. public override SvgElement DeepCopy()
  70. {
  71. return DeepCopy<SvgSwitch>();
  72. }
  73. public override SvgElement DeepCopy<T>()
  74. {
  75. var newObj = base.DeepCopy<T>() as SvgSwitch;
  76. if (this.Fill != null)
  77. newObj.Fill = this.Fill.DeepCopy() as SvgPaintServer;
  78. return newObj;
  79. }
  80. }
  81. }
  82. #pragma warning restore