protected override void Draw(IBarCodeBuilder builder, string data) { ValidateCharacters(data); string coded = new Code128Coder().Code(data); coded = AppendChecksum(coded); BitArray encoded = Encoder.Encode(coded); float totalWidth = ModuleWidth * encoded.Count + GuardWidth + OffsetWidth * 2 + QuietZone * 2; // 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, encoded); x = DrawSymbol(builder, x, y, BarHeight, StopGuard); x = DrawSymbol(builder, x, y, BarHeight, EndGuard); DrawText(builder, true, new float[] { textX }, y - TextHeight, data); }
protected override void Draw(IBarCodeBuilder builder, string data) { ValidateCharacters(data); data = AppendChecksum(data); BitArray encoded = Encoder.Encode(data); float totalWidth = FixedWidth + SymbolWidth * data.Length; // 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 = ModuleBarCode.DrawSymbol(builder, x, y, NarrowWidth, BarHeight, Start, BarColor); x = DrawSymbol(builder, x, y, BarHeight, encoded); x = ModuleBarCode.DrawSymbol(builder, x, y, NarrowWidth, BarHeight, End, BarColor); // draw the text strings DrawText(builder, true, new float[] { textX }, y - TextHeight, new string[] { data }); }
protected override void Draw(IBarCodeBuilder builder, string data) { Validate(data); // append the checksum - note: the checksum won't appear in the text string string dataWithCheck = data + Checksum.Calculate(data); // encode the data BitArray encoded = Encoder.Encode(dataWithCheck); // calculate total width float totalWidth = WideWidth * (encoded.Length + 2 /*frames*/) + NarrowWidth * (encoded.Length + 1 /*frames*/) + OffsetWidth * 2 + QuietZone * 2; // 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, Frame); x = DrawSymbol(builder, x, y, BarHeight, encoded); x = DrawSymbol(builder, x, y, BarHeight, Frame); // draw the text strings DrawText(builder, true, new float[] { textX }, y - TextHeight, data); }
protected override float DrawSymbol(IBarCodeBuilder builder, float x, float y, float height, BitArray symbol) { // the symbol for Wide is encoded as 1 and // the symbol for Narrow is encoded as 0 // the symbols encode bars and spaces, starting with a bar bool drawBar = true; // start drawing a bar foreach (bool bit in symbol) { float width = bit ? WideWidth : NarrowWidth; if (drawBar) { builder.DrawRectangle(BarColor, x, y, width, height); } else { // spaces must be wider width += NarrowWidth; } x += width; // skip element (bar or space) drawBar = !drawBar; // draw the other element next time } return(x); }
internal static float DrawSymbol(IBarCodeBuilder builder, float x, float y, float moduleWidth, float height, BitArray symbol, Color barColor) { float start = x; bool wasSpace = true; foreach (bool bit in symbol) { if (bit) { if (wasSpace) { start = x; wasSpace = false; } } else { if (!wasSpace) { builder.DrawRectangle(barColor, start, y, x - start, height); wasSpace = true; } } x += moduleWidth; } if (!wasSpace) { builder.DrawRectangle(barColor, start, y, x - start, height); } return(x); }
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 }); }
protected float DrawSymbols(IBarCodeBuilder builder, float x, float y, float height, BitArray[] symbols) // base class?? { foreach (BitArray arr in symbols) { x = DrawSymbol(builder, x, y, height, arr); } return(x); }
public override void Draw(IBarCodeBuilder builder, string data, float x, float y) { // validate the supplement data Validate(data, 2); // calculate the parity string parity = (int.Parse(data) % 4).ToString(); Draw(builder, data, parity, x, y); }
public override void Draw(IBarCodeBuilder builder, string data, float x, float y) { // validate the supplement data Validate(data, 5); // calculate checksum to use in parity string parity = Checksum.Calculate(data); Draw(builder, data, parity, x, y); }
protected override void Draw(IBarCodeBuilder builder, string data) { int count = data.Length + (UseChecksum ? 1 : 0); if (count % 2 != 0) { throw new BarCodeFormatException("Interleaved 2 of 5 must encode an even number of elements."); } base.Draw(builder, data); }
public override void Draw(IBarCodeBuilder builder, string data, string supplement) { // resolve the supplement barcode EanUpcSupplement supp = ResolveSupplement(supplement); // the data is Upca data data = Validate(data, 12); if (data[0] != '0' && data[0] != '1') { throw new BarCodeFormatException("Can't encode Upce for Upca Number System."); } // Upce data to be encoded string upce = FromUpca(data); // encode the Upce symbol using the number system and check digit of the Upca data BitArray[] encoded = EncodeLeft(upce, ParityEncoder.Encode(data[0].ToString() + data[11])); // calculate total width float totalWidth = TotalWidth + (supp == null ? 0 : SupplementOffset + supp.TotalWidth); // 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 = new float[3]; x += OffsetWidth + QuietZone; y += OffsetHeight; textX[0] = x; x += TextWidth; x = DrawSymbol(builder, x, y, BarHeight + GuardExtraHeight, LeftGuard); textX[1] = x; x = DrawSymbols(builder, x, y, BarHeight, encoded); x = DrawSymbol(builder, x, y, BarHeight + GuardExtraHeight, RightGuard); textX[2] = x; // draw the text strings DrawText(builder, textX, y - TextHeight, new string[] { data[0].ToString(), upce, data[11].ToString() }); // draw the supplement barcode, if one is present if (supp != null) { supp.Draw(builder, supplement, x + TextWidth + SupplementOffset, y - OffsetHeight); } }
protected void Draw(IBarCodeBuilder builder, string data, int length) { // TODO: BUG: account for digit! can have 6 different sizes: // (2 supplements + 1 non-supp) * 2 modes (with or without digit) if (data.Length > length) { Draw(builder, data.Substring(0, length), data.Substring(length)); } else { Draw(builder, data, null); } }
public override void Draw(IBarCodeBuilder builder, string data, string supplement) { // resolve the supplement barcode EanUpcSupplement supp = ResolveSupplement(supplement); // validate Ean13 data data = Validate(data, 13); // split the data in its sub components string[] text = new string[] { data.Substring(0, 1), data.Substring(1, 6), data.Substring(7, 6) }; // encode the data BitArray[] left = EncodeLeft(text[1], ParityEncoder.Encode(text[0])); BitArray[] right = EncodeRight(text[2]); // calculate total width float totalWidth = TotalWidth + (supp == null ? 0 : SupplementOffset + supp.TotalWidth); // 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 = new float[3]; x += OffsetWidth + QuietZone; y += OffsetHeight; textX[0] = x; x += TextWidth; x = DrawSymbol(builder, x, y, BarHeight + GuardExtraHeight, LeftGuard); textX[1] = x; x = DrawSymbols(builder, x, y, BarHeight, left); x = DrawSymbol(builder, x, y, BarHeight + GuardExtraHeight, CenterGuard); textX[2] = x; x = DrawSymbols(builder, x, y, BarHeight, right); x = DrawSymbol(builder, x, y, BarHeight + GuardExtraHeight, RightGuard); // draw the text strings DrawText(builder, textX, y - TextHeight, text); // draw the supplement barcode, if one is present if (supp != null) { supp.Draw(builder, supplement, x + SupplementOffset, y - OffsetHeight); } }
protected void DrawText(IBarCodeBuilder builder, bool centered, float[] x, float y, params string[] data) { if ((TextPosition & TextPosition.Top) != 0) { for (int i = 0; i < x.Length; ++i) { builder.DrawString(Font, FontColor, centered, data[i], x[i], y); } } if ((TextPosition & TextPosition.Bottom) != 0) { for (int i = 0; i < x.Length; ++i) { builder.DrawString(Font, FontColor, centered, data[i], x[i], y + TextHeight + BarHeight); } } }
protected override float DrawSymbol(IBarCodeBuilder builder, float x, float y, float height, BitArray symbol) { // the symbol for Wide is encoded as 1 and // the symbol for Narrow is encoded as 0 // a space lies between every symbol and // has the width of the Narrow bar // only bars are encoded in the symbols foreach (bool bit in symbol) { // draw bar float width = bit ? WideWidth : NarrowWidth; builder.DrawRectangle(BarColor, x, y, width, height); x += width + NarrowWidth; // skip bar and white space } return(x); }
protected void Draw(IBarCodeBuilder builder, string data, string parity, float x, float y) { // encode the symbol BitArray[] encoded = EanUpc.EncodeLeft(data, ParityEncoder.Encode(parity)); // draw the bars; size and background have already been set by the base barcode float textX = x + TotalWidth / 2; y += OffsetHeight + TextHeight; x = DrawSymbol(builder, x, y, BarHeight, LeftGuard); x = DrawSymbol(builder, x, y, BarHeight, encoded[0]); for (int i = 1; i < encoded.Length; ++i) { x = DrawSymbol(builder, x, y, BarHeight, SeparatorBar); x = DrawSymbol(builder, x, y, BarHeight, encoded[i]); } // draw the text string DrawText(builder, true, new float[] { textX }, y - TextHeight, new string[] { data }); }
protected override float DrawSymbol(IBarCodeBuilder builder, float x, float y, float fullHeight, BitArray symbol) { float shortHeight = fullHeight / 2f; foreach (bool bit in symbol) { if (bit) { // tall bar builder.DrawRectangle(BarColor, x, y, WideWidth, fullHeight); } else { // short bar builder.DrawRectangle(BarColor, x, y + shortHeight, WideWidth, shortHeight); } // skip bar and space x += WideWidth + NarrowWidth; } return(x); }
protected override float DrawSymbol(IBarCodeBuilder builder, float x, float y, float height, BitArray symbol) { // the symbol for Wide is encoded as 1 and // the symbol for Narrow is encoded as 0 // five elements denote a symbol // symbols are interleaved with the next symbol // so one symbol represents the bars and the next, the spaces for (int i = 0; i < symbol.Count; i += 10) { for (int j = 0; j < 5; ++j) { // draw a bar float width = symbol[i + j] ? WideWidth : NarrowWidth; builder.DrawRectangle(BarColor, x, y, width, height); x += width; // skip a space x += symbol[i + j + 5] ? WideWidth : NarrowWidth; } } return(x); }
protected override void Draw(IBarCodeBuilder builder, string data) { Draw(builder, data, 8); }
protected float DrawSymbol(IBarCodeBuilder builder, float x, float y, float height, BitArray symbol) { return(DrawSymbol(builder, x, y, ModuleWidth, height, symbol, BarColor)); }
public abstract void Draw(IBarCodeBuilder builder, string data, string supplement);
protected override void Draw(IBarCodeBuilder builder, string data) // never used { Draw(builder, data, 0, 0); }
protected void DrawText(IBarCodeBuilder builder, float[] x, float y, params string[] data) { DrawText(builder, false, x, y, data); }
protected abstract void Draw(IBarCodeBuilder builder, string data);
public virtual void Build(IBarCodeBuilder builder, string data) { builder.Dpi = Dpi; builder.Unit = Unit; Draw(builder, data); }
public abstract void Draw(IBarCodeBuilder builder, string data, float x, float y);