using System; using System.Drawing; using System.ComponentModel; using FastReport.Utils; namespace FastReport.Barcode { /// /// The base class for all barcodes. /// [TypeConverter(typeof(FastReport.TypeConverters.BarcodeConverter))] public abstract class BarcodeBase { #region Fields internal string text; internal int angle; internal bool showText; internal float zoom; private Color color; #endregion #region Properties /// /// Gets the name of barcode. /// [Browsable(false)] public string Name { get { return Barcodes.GetName(GetType()); } } /// /// Gets or sets the color of barcode. /// public Color Color { get { return color; } set { color = value; } } #endregion #region Public Methods /// /// Creates the exact copy of this barcode. /// /// The copy of this barcode. public BarcodeBase Clone() { BarcodeBase result = Activator.CreateInstance(GetType()) as BarcodeBase; result.Assign(this); return result; } /// /// Assigns properties from other, similar barcode. /// /// Barcode object to assign properties from. public virtual void Assign(BarcodeBase source) { Color = source.Color; } internal virtual void Serialize(FRWriter writer, string prefix, BarcodeBase diff) { if (diff.GetType() != GetType()) writer.WriteStr("Barcode", Name); if (diff.Color != Color) writer.WriteValue(prefix + "Color", Color); } internal virtual void Initialize(string text, bool showText, int angle, float zoom) { this.text = text; this.showText = showText; this.angle = (angle / 90 * 90) % 360; this.zoom = zoom; } internal virtual SizeF CalcBounds() { return SizeF.Empty; } internal virtual string StripControlCodes(string data) { return data; } public virtual void DrawBarcode(IGraphics g, RectangleF displayRect) { } #endregion /// /// Initializes a new instance of the class with default settings. /// public BarcodeBase() { text = ""; color = Color.Black; } /// /// Get default value of this barcode /// /// public virtual string GetDefaultValue() { return "12345678"; } } }