protected override void Draw(IBarCodeBuilder builder, string data) { ValidateCharacters(data); // store the current data string oldData = data; // translate the extended characters data = Code39Translator.TranslateExtended(data); data = AppendChecksum(data); BitArray encoded = Encoder.Encode(data); BitArray guard = Encoder.Encode("*"); float totalWidth = SymbolWidth * data.Length + GuardWidth + OffsetWidth * 2 + QuietZone * 2 + CalculateExtraWidth(guard, guard, encoded); // set the canvas size builder.Prepare(totalWidth, TotalHeight); // draw the background builder.DrawRectangle(BackColor, 0, 0, totalWidth, TotalHeight); // draw the barcode float x = 0, y = 0; float textX = x + totalWidth / 2; x += OffsetWidth + QuietZone; y += OffsetHeight + ExtraTopHeight; x = DrawSymbol(builder, x, y, BarHeight, guard); x = DrawSymbol(builder, x, y, BarHeight, encoded); x = DrawSymbol(builder, x, y, BarHeight, guard); DrawText(builder, true, new float[] { textX }, y - TextHeight, new string[] { oldData }); }
public string Calculate(string data) { int sum = 0; foreach (char c in data) { sum += Code39Translator.CheckValue(c); } return((sum % 43).ToString()); }