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; internal bool showMarker; private Color color; private Font font; private static readonly Font DefaultFont = new Font("Arial", 8); #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; } } /// /// Gets or sets the font of barcode. /// public Font Font { get { return font; } set { font = 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; Font = source.Font; } 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); if (diff.Font != Font) writer.WriteValue(prefix + "Font", Font); } 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 void Initialize(string text, bool showText, int angle, float zoom, bool showMarker) { this.text = text; this.showText = showText; this.angle = (angle / 90 * 90) % 360; this.zoom = zoom; this.showMarker = showMarker; } internal virtual SizeF CalcBounds() { return SizeF.Empty; } internal virtual string StripControlCodes(string data) { return data; } /// /// Draws a barcode. /// /// The graphic surface. /// Display rectangle. 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; Font = DefaultFont; } /// /// Get default value of this barcode /// /// public virtual string GetDefaultValue() { return "12345678"; } } }