SvgRectRegion.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace WMFConverter.Svg
  7. {
  8. /// <summary>
  9. /// Scalable Vector Graphics - Represents SVG Rect Region object.
  10. /// </summary>
  11. public class SvgRectRegion : SvgRegion
  12. {
  13. #region Local Variables
  14. private int _left;
  15. private int _top;
  16. private int _right;
  17. private int _bottom;
  18. #endregion
  19. #region Properties
  20. /// <summary>
  21. /// Left value.
  22. /// </summary>
  23. public int Left
  24. {
  25. get
  26. {
  27. return _left;
  28. }
  29. }
  30. /// <summary>
  31. /// Top value.
  32. /// </summary>
  33. public int Top
  34. {
  35. get
  36. {
  37. return _top;
  38. }
  39. }
  40. /// <summary>
  41. /// Right value.
  42. /// </summary>
  43. public int Right
  44. {
  45. get
  46. {
  47. return _right;
  48. }
  49. }
  50. /// <summary>
  51. /// Bottom value.
  52. /// </summary>
  53. public int Bottom
  54. {
  55. get
  56. {
  57. return _bottom;
  58. }
  59. }
  60. #endregion
  61. #region Constructors
  62. /// <summary>
  63. /// Default constructor.
  64. /// </summary>
  65. /// <param name="gdi"></param>
  66. /// <param name="left"></param>
  67. /// <param name="top"></param>
  68. /// <param name="right"></param>
  69. /// <param name="bottom"></param>
  70. public SvgRectRegion(SvgGdi gdi, int left, int top, int right, int bottom)
  71. : base(gdi)
  72. {
  73. _left = left;
  74. _top = top;
  75. _right = right;
  76. _bottom = bottom;
  77. }
  78. #endregion
  79. #region Public Methods
  80. /// <summary>
  81. /// Create rect element.
  82. /// </summary>
  83. /// <returns></returns>
  84. public override System.Xml.XmlElement CreateElement()
  85. {
  86. System.Xml.XmlElement elem = GDI.Document.CreateElement("rect");
  87. elem.SetAttribute("x", "" + (int)GDI.DC.ToAbsoluteX(Left));
  88. elem.SetAttribute("y", "" + (int)GDI.DC.ToAbsoluteY(Top));
  89. elem.SetAttribute("width", "" + (int)GDI.DC.ToRelativeX(Right - Left));
  90. elem.SetAttribute("height", "" + (int)GDI.DC.ToRelativeY(Bottom - Top));
  91. return elem;
  92. }
  93. /// <summary>
  94. /// Serves as the default hash function.
  95. /// </summary>
  96. /// <returns></returns>
  97. public override int GetHashCode() {
  98. int prime = 31;
  99. int result = 1;
  100. result = prime * result + _bottom;
  101. result = prime * result + _left;
  102. result = prime * result + _right;
  103. result = prime * result + _top;
  104. return result;
  105. }
  106. /// <summary>
  107. /// Determines whether the specified object is equal to the current object.
  108. /// </summary>
  109. /// <param name="obj"></param>
  110. /// <returns></returns>
  111. public override bool Equals(Object obj)
  112. {
  113. if (this == obj)
  114. return true;
  115. if (obj == null)
  116. return false;
  117. if (typeof(SvgRectRegion) != obj.GetType())
  118. return false;
  119. SvgRectRegion other = (SvgRectRegion)obj;
  120. if (_bottom != other._bottom)
  121. return false;
  122. if (_left != other._left)
  123. return false;
  124. if (_right != other._right)
  125. return false;
  126. if (_top != other._top)
  127. return false;
  128. return true;
  129. }
  130. #endregion
  131. }
  132. }