ShapeStyle.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System.ComponentModel;
  2. using System.Drawing;
  3. using System.Drawing.Design;
  4. using System.Drawing.Drawing2D;
  5. using FastReport.Utils;
  6. namespace FastReport.Map
  7. {
  8. /// <summary>
  9. /// Represents the style of a shape.
  10. /// </summary>
  11. [TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
  12. public class ShapeStyle
  13. {
  14. #region Fields
  15. private Color borderColor;
  16. private DashStyle borderStyle;
  17. private float borderWidth;
  18. private Color fillColor;
  19. private Font font;
  20. private Color textColor;
  21. private float pointSize;
  22. #endregion // Fields
  23. #region Properties
  24. /// <summary>
  25. /// Gets or sets the border color.
  26. /// </summary>
  27. [Editor("FastReport.TypeEditors.ColorEditor, FastReport", typeof(UITypeEditor))]
  28. public Color BorderColor
  29. {
  30. get { return borderColor; }
  31. set { borderColor = value; }
  32. }
  33. /// <summary>
  34. /// Gets or sets the border style.
  35. /// </summary>
  36. [DefaultValue(DashStyle.Solid)]
  37. public DashStyle BorderStyle
  38. {
  39. get { return borderStyle; }
  40. set { borderStyle = value; }
  41. }
  42. /// <summary>
  43. /// Gets or sets the border width.
  44. /// </summary>
  45. [DefaultValue(1f)]
  46. public float BorderWidth
  47. {
  48. get { return borderWidth; }
  49. set { borderWidth = value; }
  50. }
  51. /// <summary>
  52. /// Gets or sets the fill color.
  53. /// </summary>
  54. [Editor("FastReport.TypeEditors.ColorEditor, FastReport", typeof(UITypeEditor))]
  55. public Color FillColor
  56. {
  57. get { return fillColor; }
  58. set { fillColor = value; }
  59. }
  60. /// <summary>
  61. /// Gets or sets the font.
  62. /// </summary>
  63. public Font Font
  64. {
  65. get { return font; }
  66. set { font = value; }
  67. }
  68. /// <summary>
  69. /// Gets or sets the text color.
  70. /// </summary>
  71. [Editor("FastReport.TypeEditors.ColorEditor, FastReport", typeof(UITypeEditor))]
  72. public Color TextColor
  73. {
  74. get { return textColor; }
  75. set { textColor = value; }
  76. }
  77. /// <summary>
  78. /// Gets or sets the point size, in pixels.
  79. /// </summary>
  80. [DefaultValue(10f)]
  81. public float PointSize
  82. {
  83. get { return pointSize; }
  84. set { pointSize = value; }
  85. }
  86. #endregion // Properties
  87. #region Public Methods
  88. /// <summary>
  89. /// Copies contents from another similar object.
  90. /// </summary>
  91. /// <param name="src">The object to copy the contents from.</param>
  92. public void Assign(ShapeStyle src)
  93. {
  94. BorderColor = src.BorderColor;
  95. BorderStyle = src.BorderStyle;
  96. BorderWidth = src.BorderWidth;
  97. FillColor = src.FillColor;
  98. Font = src.Font;
  99. TextColor = src.TextColor;
  100. PointSize = src.PointSize;
  101. }
  102. internal void Serialize(FRWriter writer, string prefix, ShapeStyle c)
  103. {
  104. if (BorderColor != c.BorderColor)
  105. writer.WriteValue(prefix + ".BorderColor", BorderColor);
  106. if (BorderStyle != c.BorderStyle)
  107. writer.WriteValue(prefix + ".BorderStyle", BorderStyle);
  108. if (BorderWidth != c.BorderWidth)
  109. writer.WriteFloat(prefix + ".BorderWidth", BorderWidth);
  110. if (FillColor != c.FillColor)
  111. writer.WriteValue(prefix + ".FillColor", FillColor);
  112. if ((writer.SerializeTo!= SerializeTo.Preview || !Font.Equals(c.Font)) && writer.ItemName != "inherited")
  113. writer.WriteValue(prefix + ".Font", Font);
  114. if (TextColor != c.TextColor)
  115. writer.WriteValue(prefix + ".TextColor", TextColor);
  116. if (PointSize != c.PointSize)
  117. writer.WriteFloat(prefix + ".PointSize", PointSize);
  118. }
  119. #endregion // Public Methods
  120. /// <summary>
  121. /// Initializes a new instance of the <see cref="ShapeStyle"/> class.
  122. /// </summary>
  123. public ShapeStyle()
  124. {
  125. BorderColor = Color.DarkGray;
  126. BorderStyle = DashStyle.Solid;
  127. BorderWidth = 1;
  128. FillColor = Color.White;
  129. Font = DrawUtils.DefaultFont;
  130. TextColor = Color.Black;
  131. PointSize = 10;
  132. }
  133. }
  134. }