protected override void Encode(string barcodeValue) { LoadSymbologyPattern(); // Add check digit to barcode value. if (_useCheckDigit) { int checkDigit = LinearHelpers.GetUpcCheckDigit(barcodeValue); barcodeValue += checkDigit; EncodedValue = barcodeValue; } EncodedValue = barcodeValue; ZplEncode = EncodedValue; for (int encodePosition = 0; encodePosition <= barcodeValue.Length - 1; encodePosition += 2) { // Check if first or last character in barcode and insert start/stop symbol if (encodePosition == 0) { LinearEncoding.Add("*", 1, _patternDictionary["START"]); } string digitPair = barcodeValue.Substring(encodePosition, 2); LinearEncoding.Add(digitPair, 0, _patternDictionary[digitPair]); if (encodePosition == barcodeValue.Length - 2) { LinearEncoding.Add("*", 1, _patternDictionary["STOP"]); } } SetMinXDimension(); SetMinBarcodeHeight(); }
/// <summary> /// Returns a string compatible with the given Code39 symbology. /// </summary> /// <param name="text">Text to convert from.</param> /// <param name="symbology">Code39 symbology to be used.</param> /// <returns>Code39 supported string.</returns> public string Parse(string text, Symbology symbology) { switch (symbology) { case Symbology.Code39Full: return(LinearHelpers.GetOnlyAscii(text)); case Symbology.Code39FullC: return(LinearHelpers.GetOnlyAscii(text)); default: return(GetOnlyCode39(text)); } }
protected override void Encode(string barcodeValue) { ZplEncode = ""; LoadSymbologyPattern(); LoadGroupPattern(); int startPoint; int midPoint; int endPoint; string group; int encodeOffset; int checkDigit = LinearHelpers.GetUpcCheckDigit(barcodeValue); switch (Symbology) { case Symbology.Ean13: startPoint = 1; midPoint = 7; endPoint = 12; // Set the group pattern to use, based on the first digit of the barcode. group = _groupDictionary[barcodeValue[0]]; // Set human readable prefix to the first digit of the barcode value. LinearEncoding.HumanReadablePrefix = barcodeValue.Substring(0, 1); LinearEncoding.HumanReadableSuffix = ">"; encodeOffset = 1; break; case Symbology.UpcA: startPoint = 0; midPoint = 6; endPoint = 11; // Set UPC-A group pattern group = _groupDictionary[48]; // Set human readable prefix to the first digit of the barcode value. LinearEncoding.HumanReadablePrefix = barcodeValue.Substring(0, 1); // Set human readable suffix to the check digit value of the barcode. LinearEncoding.HumanReadableSuffix = checkDigit.ToString(); encodeOffset = 0; break; case Symbology.Ean8: startPoint = 0; midPoint = 4; endPoint = 7; // Set EAN-8 group pattern group = _groupDictionary[8]; LinearEncoding.HumanReadablePrefix = "<"; LinearEncoding.HumanReadableSuffix = ">"; encodeOffset = 0; break; default: startPoint = 1; midPoint = 7; endPoint = 12; // Set the group pattern to use, based on the first digit of the barcode. group = _groupDictionary[barcodeValue[0]]; // Set human readable prefix to the first digit of the barcode value. LinearEncoding.HumanReadablePrefix = barcodeValue.Substring(0, 1); LinearEncoding.HumanReadableSuffix = ">"; encodeOffset = 1; break; } for (int encodePosition = startPoint; encodePosition <= endPoint - 1; encodePosition++) { // Check if first digit in barcode and insert start symbol. if (encodePosition == startPoint) { LinearEncoding.Add("*", 1, _patternDictionary["START"]); } // Check if mid point and insert separator. if (encodePosition == midPoint) { LinearEncoding.Add("*", 1, _patternDictionary["MID"]); } int characterType = LinearHelpers.GetCharacterType(Symbology, encodePosition, barcodeValue.Length); string digitEncode = barcodeValue.Substring(encodePosition, 1) + group.Substring(encodePosition - encodeOffset, 1); LinearEncoding.Add(digitEncode.Substring(0, 1), characterType, _patternDictionary[digitEncode]); ZplEncode += barcodeValue.Substring(encodePosition, 1); // Add check digit and stop symbol if last encoding character. if (encodePosition == endPoint - 1) { characterType = LinearHelpers.GetCharacterType(Symbology, encodePosition + 1, barcodeValue.Length); string checkDigitCode = checkDigit + group.Substring(encodePosition - encodeOffset, 1); LinearEncoding.Add(checkDigitCode.Substring(0, 1), characterType, _patternDictionary[checkDigitCode]); EncodedValue = barcodeValue + checkDigit; LinearEncoding.Add("*", 1, _patternDictionary["STOP"]); } } SetMinXDimension(); SetMinBarcodeHeight(); }