StyleBase.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using FastReport.Utils;
  2. using System.Drawing;
  3. namespace FastReport
  4. {
  5. /// <summary>
  6. /// Represents the base class for the report style or the highlight condition.
  7. /// </summary>
  8. public partial class StyleBase : IFRSerializable
  9. {
  10. #region Private Fields
  11. private bool applyBorder;
  12. private bool applyFill;
  13. private bool applyFont;
  14. private bool applyTextFill;
  15. private Border border;
  16. private FillBase fill;
  17. private Font font;
  18. private FillBase textFill;
  19. #endregion Private Fields
  20. #region Public Properties
  21. /// <summary>
  22. /// Gets or sets a value determines that the border must be applied.
  23. /// </summary>
  24. public bool ApplyBorder
  25. {
  26. get { return applyBorder; }
  27. set { applyBorder = value; }
  28. }
  29. /// <summary>
  30. /// Gets or sets a value determines that the fill must be applied.
  31. /// </summary>
  32. public bool ApplyFill
  33. {
  34. get { return applyFill; }
  35. set { applyFill = value; }
  36. }
  37. /// <summary>
  38. /// Gets or sets a value determines that the font must be applied.
  39. /// </summary>
  40. public bool ApplyFont
  41. {
  42. get { return applyFont; }
  43. set { applyFont = value; }
  44. }
  45. /// <summary>
  46. /// Gets or sets a value determines that the text fill must be applied.
  47. /// </summary>
  48. public bool ApplyTextFill
  49. {
  50. get { return applyTextFill; }
  51. set { applyTextFill = value; }
  52. }
  53. /// <summary>
  54. /// Gets or sets a border.
  55. /// </summary>
  56. public Border Border
  57. {
  58. get { return border; }
  59. set { border = value; }
  60. }
  61. /// <summary>
  62. /// Gets or sets a fill.
  63. /// </summary>
  64. public FillBase Fill
  65. {
  66. get { return fill; }
  67. set { fill = value; }
  68. }
  69. /// <summary>
  70. /// Gets or sets a font.
  71. /// </summary>
  72. public Font Font
  73. {
  74. get { return font; }
  75. set { font = value; }
  76. }
  77. /// <summary>
  78. /// Gets or sets a text fill.
  79. /// </summary>
  80. public FillBase TextFill
  81. {
  82. get { return textFill; }
  83. set { textFill = value; }
  84. }
  85. #endregion Public Properties
  86. #region Public Constructors
  87. /// <summary>
  88. /// Initializes a new instance of the <see cref="StyleBase"/> class with default settings.
  89. /// </summary>
  90. public StyleBase()
  91. {
  92. Border = new Border();
  93. Fill = new SolidFill();
  94. TextFill = new SolidFill(Color.Black);
  95. Font = GetDefaultFontInternal();
  96. }
  97. #endregion Public Constructors
  98. #region Public Methods
  99. /// <summary>
  100. /// Assigns values from another source.
  101. /// </summary>
  102. /// <param name="source">Source to assign from.</param>
  103. public virtual void Assign(StyleBase source)
  104. {
  105. Border = source.Border.Clone();
  106. Fill = source.Fill.Clone();
  107. TextFill = source.TextFill.Clone();
  108. Font = source.Font;
  109. ApplyBorder = source.ApplyBorder;
  110. ApplyFill = source.ApplyFill;
  111. ApplyTextFill = source.ApplyTextFill;
  112. ApplyFont = source.ApplyFont;
  113. }
  114. /// <summary>
  115. /// Deserializes the style.
  116. /// </summary>
  117. /// <param name="reader">Reader object.</param>
  118. /// <remarks>
  119. /// This method is for internal use only.
  120. /// </remarks>
  121. public void Deserialize(FRReader reader)
  122. {
  123. reader.ReadProperties(this);
  124. Fill.Deserialize(reader, "Fill");
  125. TextFill.Deserialize(reader, "TextFill");
  126. }
  127. /// <summary>
  128. /// Serializes the style.
  129. /// </summary>
  130. /// <param name="writer">Writer object.</param>
  131. /// <remarks>
  132. /// This method is for internal use only.
  133. /// </remarks>
  134. public virtual void Serialize(FRWriter writer)
  135. {
  136. StyleBase c = writer.DiffObject as StyleBase;
  137. Border.Serialize(writer, "Border", c.Border);
  138. Fill.Serialize(writer, "Fill", c.Fill);
  139. TextFill.Serialize(writer, "TextFill", c.TextFill);
  140. if ((writer.SerializeTo != SerializeTo.Preview || !Font.Equals(c.Font)) && writer.ItemName != "inherited")
  141. writer.WriteValue("Font", Font);
  142. if (ApplyBorder != c.ApplyBorder)
  143. writer.WriteBool("ApplyBorder", ApplyBorder);
  144. if (ApplyFill != c.ApplyFill)
  145. writer.WriteBool("ApplyFill", ApplyFill);
  146. if (ApplyTextFill != c.ApplyTextFill)
  147. writer.WriteBool("ApplyTextFill", ApplyTextFill);
  148. if (ApplyFont != c.ApplyFont)
  149. writer.WriteBool("ApplyFont", ApplyFont);
  150. }
  151. #endregion Public Methods
  152. }
  153. }