BarcodeBase.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.Drawing;
  3. using System.ComponentModel;
  4. using FastReport.Utils;
  5. namespace FastReport.Barcode
  6. {
  7. /// <summary>
  8. /// The base class for all barcodes.
  9. /// </summary>
  10. [TypeConverter(typeof(FastReport.TypeConverters.BarcodeConverter))]
  11. public abstract class BarcodeBase
  12. {
  13. #region Fields
  14. internal string text;
  15. internal int angle;
  16. internal bool showText;
  17. internal float zoom;
  18. private Color color;
  19. #endregion
  20. #region Properties
  21. /// <summary>
  22. /// Gets the name of barcode.
  23. /// </summary>
  24. [Browsable(false)]
  25. public string Name
  26. {
  27. get { return Barcodes.GetName(GetType()); }
  28. }
  29. /// <summary>
  30. /// Gets or sets the color of barcode.
  31. /// </summary>
  32. public Color Color
  33. {
  34. get { return color; }
  35. set { color = value; }
  36. }
  37. #endregion
  38. #region Public Methods
  39. /// <summary>
  40. /// Creates the exact copy of this barcode.
  41. /// </summary>
  42. /// <returns>The copy of this barcode.</returns>
  43. public BarcodeBase Clone()
  44. {
  45. BarcodeBase result = Activator.CreateInstance(GetType()) as BarcodeBase;
  46. result.Assign(this);
  47. return result;
  48. }
  49. /// <summary>
  50. /// Assigns properties from other, similar barcode.
  51. /// </summary>
  52. /// <param name="source">Barcode object to assign properties from.</param>
  53. public virtual void Assign(BarcodeBase source)
  54. {
  55. Color = source.Color;
  56. }
  57. internal virtual void Serialize(FRWriter writer, string prefix, BarcodeBase diff)
  58. {
  59. if (diff.GetType() != GetType())
  60. writer.WriteStr("Barcode", Name);
  61. if (diff.Color != Color)
  62. writer.WriteValue(prefix + "Color", Color);
  63. }
  64. internal virtual void Initialize(string text, bool showText, int angle, float zoom)
  65. {
  66. this.text = text;
  67. this.showText = showText;
  68. this.angle = (angle / 90 * 90) % 360;
  69. this.zoom = zoom;
  70. }
  71. internal virtual SizeF CalcBounds()
  72. {
  73. return SizeF.Empty;
  74. }
  75. internal virtual string StripControlCodes(string data)
  76. {
  77. return data;
  78. }
  79. public virtual void DrawBarcode(IGraphics g, RectangleF displayRect)
  80. {
  81. }
  82. #endregion
  83. /// <summary>
  84. /// Initializes a new instance of the <see cref="BarcodeBase"/> class with default settings.
  85. /// </summary>
  86. public BarcodeBase()
  87. {
  88. text = "";
  89. color = Color.Black;
  90. }
  91. /// <summary>
  92. /// Get default value of this barcode
  93. /// </summary>
  94. /// <returns></returns>
  95. public virtual string GetDefaultValue()
  96. {
  97. return "12345678";
  98. }
  99. }
  100. }