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); 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); }
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 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); }
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); } }
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 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 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); }