private void CheckValues() { if (Values == null) { throw new InvalidOperationException("Text or Values must be set"); } if (Values.Length == 0) { throw new InvalidOperationException("Text or Values must have content"); } for (int x = 0; x < Values.Length; x++) { if (Values[x] > 102) { throw new ArgumentOutOfRangeException(BcgSR.InvalidCode128(x)); } } }
private void CheckValues() { if (BarCode == null) { throw new InvalidOperationException("Text or Values must be set"); } if (BarCode.Length == 0) { throw new InvalidOperationException("Text or Values must have content"); } for (int x = 0; x < BarCode.Length; x++) { var charNumber = BarCode[x]; if (charNumber > 127 && charNumber != FNC1) { throw new ArgumentOutOfRangeException(BcgSR.InvalidCode128(x)); } } }
/// <summary> /// Renders the content found in Text /// </summary> /// <param name="gfx"> /// XGraphics - Instance of the drawing surface /// </param> /// <param name="brush"> /// XBrush - Line and Color to draw the bar code /// </param> /// <param name="font"> /// XFont - Font to use to draw the text string /// </param> /// <param name="position"> /// XPoint - Location to render the bar code /// </param> protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position) { // Create the array to hold the values to be rendered this.Values = this.Code128Code == Code128Type.C ? new byte[this.text.Length / 2] : new byte[this.text.Length]; String buffer = String.Empty; for (Int32 index = 0; index < text.Length; index++) { switch (this.Code128Code) { case Code128Type.A: if (text[index] < 32) { this.Values[index] = (byte)(text[index] + 64); } else if ((text[index] >= 32) && (text[index] < 64)) { this.Values[index] = (byte)(text[index] - 32); } else { this.Values[index] = (byte)text[index]; } break; case Code128Type.B: this.Values[index] = (byte)(text[index] - 32); break; case Code128Type.C: if ((text[index] >= '0') && (text[index] <= '9')) { buffer += text[index]; if (buffer.Length == 2) { this.Values[index / 2] = byte.Parse(buffer); buffer = String.Empty; } } else { throw new ArgumentOutOfRangeException("Parameter text (string) can only contain numeric characters for Code 128 - Code C"); } break; } } if (this.Values == null) { throw new InvalidOperationException("Text or Values must be set"); } if (this.Values.Length == 0) { throw new InvalidOperationException("Text or Values must have content"); } for (int x = 0; x < this.Values.Length; x++) { if (this.Values[x] > 102) { throw new ArgumentOutOfRangeException(BcgSR.InvalidCode128(x)); } } XGraphicsState state = gfx.Save(); BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position); this.InitRendering(info); info.CurrPosInString = 0; info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size); this.RenderStart(info); foreach (byte c in this.Values) { this.RenderValue(info, c); } this.RenderStop(info); if (this.TextLocation != TextLocation.None) { this.RenderText(info); } gfx.Restore(state); }