private void PharmaOne() { ulong tester; List <char> intermediate = new List <char>(); /* 131070 -> 17 bits */ StringBuilder rowPattern = new StringBuilder(); /* 17 * 2 + 1 */ int inputLength = barcodeData.Length; if (inputLength > 6) { throw new InvalidDataLengthException("Pharmacode: Input data too long."); } tester = ulong.Parse(barcodeMessage, CultureInfo.CurrentCulture); if ((tester < 3) || (tester > 131070)) { throw new InvalidDataException("Pharmacode: Input data out of range."); } do { if ((tester & 1) == 0) { intermediate.Add('W'); tester = (tester - 2) / 2; } else { intermediate.Add('N'); tester = (tester - 1) / 2; } } while (tester != 0); int iLength = intermediate.Count; for (int c = iLength - 1; c >= 0; c--) { if (intermediate[c] == 'W') { rowPattern.Append("32"); } else { rowPattern.Append("12"); } } // Expand row into the symbol data. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f); }
private void Code39() { int index; char checkDigit; int inputLength = barcodeData.Length; StringBuilder rowPattern = new StringBuilder(); if (inputLength > 74) { throw new InvalidDataLengthException("Code 39: Input data too long."); } for (int i = 0; i < inputLength; i++) { if (CharacterSets.Code39Set.IndexOf(barcodeData[i]) == -1) { throw new InvalidDataException("Code 39: Invalid characters in input data."); } } rowPattern.Append(Code39Table[43]); for (int i = 0; i < inputLength; i++) { index = CharacterSets.Code39Set.IndexOf(barcodeData[i]); rowPattern.Append(Code39Table[index]); } if (optionalCheckDigit) { checkDigit = CheckSum.Mod43CheckDigit(barcodeData); index = CharacterSets.Code39Set.IndexOf(checkDigit); rowPattern.Append(Code39Table[index]); checkDigitText = checkDigit.ToString(); } rowPattern.Append(Code39Table[43]); if (symbolId == Symbology.LOGMARS || encodingMode == EncodingMode.HIBC) { rowPattern.Replace('2', '3'); } barcodeText = barcodeMessage; // Expand the row pattern into the symbol data. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f); }
private void Flattermarken() { StringBuilder rowPattern = new StringBuilder(); int inputLength = barcodeData.Length; if (inputLength > 90) { throw new InvalidDataLengthException("Flattermarken: Input data too long."); } for (int l = 0; l < inputLength; l++) { int value = barcodeData[l] - '0'; rowPattern.Append(FlatTable[value]); } // Expand the row pattern into the symbol data. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f); }
private void KoreaPost() { int sum = 0; int checkValue; int value; int inputLength = barcodeData.Length; StringBuilder rowPattern = new StringBuilder(); if (inputLength > 6) { throw new InvalidDataLengthException("Korean Post: Input data too long."); } if (inputLength < 6) { string zeros = new String('0', 6 - inputLength); barcodeData = ArrayExtensions.Insert(barcodeData, 0, zeros); inputLength = barcodeData.Length; } sum = 0; for (int l = 0; l < 6; l++) { sum += barcodeData[l] - '0'; } checkValue = (10 - (sum % 10)) % 10; barcodeData = ArrayExtensions.Insert(barcodeData, barcodeData.Length, checkValue.ToString(CultureInfo.CurrentCulture)); for (int l = 5; l >= 0; l--) { value = barcodeData[l] - '0'; rowPattern.Append(KoreanTable[value]); } value = barcodeData[6] - '0'; rowPattern.Append(KoreanTable[value]); barcodeText = new string(barcodeData); // Expand the row pattern into the symbol data. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f); }
private void FIM() { StringBuilder rowPattern = new StringBuilder(); int inputLength = barcodeData.Length; if (inputLength > 1) { throw new InvalidDataLengthException("FIM Code: Input data too long."); } switch ((char)barcodeData[0]) { case 'a': case 'A': rowPattern.Append("111515111"); break; case 'b': case 'B': rowPattern.Append("13111311131"); break; case 'c': case 'C': rowPattern.Append("11131313111"); break; case 'd': case 'D': rowPattern.Append("1111131311111"); break; default: throw new InvalidDataException("FIM Code: Invalid characters in input data."); } // Expand the row pattern into the symbol data. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f); }
private void Telepen() { int check_digit; int count = 0; StringBuilder rowPattern = new StringBuilder(); int inputLength = barcodeData.Length; if (inputLength > 30) { throw new InvalidDataLengthException("Telepen: Input data too long."); } // Start character. rowPattern.Append(TeleTable['_']); for (int i = 0; i < inputLength; i++) { if (barcodeData[i] > 126) { throw new InvalidDataException("Telpen: Invalid characters in input data."); // Cannot encode extended ASCII. } rowPattern.Append(TeleTable[barcodeData[i]]); count += barcodeData[i]; } check_digit = 127 - (count % 127); if (check_digit == 127) { check_digit = 0; } rowPattern.Append(TeleTable[check_digit]); // Stop character. rowPattern.Append(TeleTable['z']); // Expand row into the symbol data. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f); }
private void Codabar() { StringBuilder rowPattern = new StringBuilder(); int inputLength = barcodeData.Length; for (int i = 0; i < inputLength; i++) { if (CharacterSets.CodaBarSet.IndexOf(barcodeData[i]) == -1) { throw new InvalidDataException("Codabar: Invalid characters in input data."); } } // Codabar must begin and end with the characters A, B, C or D if ((barcodeData[0] != 'A') && (barcodeData[0] != 'B') && (barcodeData[0] != 'C') && (barcodeData[0] != 'D')) { throw new InvalidDataException("Codabar: Invalid start character in input data."); } if ((barcodeData[inputLength - 1] != 'A') && (barcodeData[inputLength - 1] != 'B') && (barcodeData[inputLength - 1] != 'C') && (barcodeData[inputLength - 1] != 'D')) { throw new InvalidDataException("Codabar: Invalid stop character in input data."); } for (int i = 0; i < inputLength; i++) { int iValue = CharacterSets.CodaBarSet.IndexOf(barcodeData[i]); rowPattern.Append(CodabarTable[iValue]); } barcodeText = new String(barcodeData); // Expand row into the symbol data. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f); }
private void Code93() { int cWeight = 0; int kWeight = 0; int cCount = 1; int kCount = 2; int checkDigitC = 0; int checkDigitK = 0; StringBuilder inputBuffer = new StringBuilder(); StringBuilder rowPattern = new StringBuilder(); int inputLength = barcodeData.Length; // Check for valid characters and expand the input data. for (int i = 0; i < inputLength; i++) { if (barcodeData[i] > 127) { throw new InvalidDataException("Code 93: Invalid characters in input data."); } inputBuffer.Append(C93Expanded[barcodeData[i]]); } inputLength = inputBuffer.Length; if (inputLength > 107) { throw new InvalidDataLengthException("Code 93: Input data too long."); } int[] values = new int[inputLength]; for (int i = 0; i < inputLength; i++) { values[i] = CharacterSets.Code93Set.IndexOf(inputBuffer[i]); } // Calculate the check characters starting from the right most position. for (int i = values.Length - 1; i >= 0; i--) { cWeight += (values[i] * cCount); cCount++; if (cCount == 21) { cCount = 1; } kWeight += (values[i] * kCount); kCount++; if (kCount == 16) { kCount = 1; } } checkDigitC = (cWeight % 47); kWeight += checkDigitC; checkDigitK = (kWeight % 47); rowPattern.Append(Code93Table[47]); // Add the start character. for (int i = 0; i < inputLength; i++) { rowPattern.Append(Code93Table[values[i]]); } // Add the "C" and "K" check digits, stop character and termination bar rowPattern.Append(Code93Table[checkDigitC]); rowPattern.Append(Code93Table[checkDigitK]); rowPattern.Append(Code93Table[47] + "1"); barcodeText = new string(barcodeData); checkDigitText += CharacterSets.Code93Set[checkDigitC]; checkDigitText += CharacterSets.Code93Set[checkDigitK]; // Expand the row pattern into the symbol data. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f); }
private void Code16K() { int rowsRequired; int padding; bool fState; int mode, lastSet, currentSet; char[] set = new char[160]; char[] fset = new char[160]; int m, position; int[] values = new int[160]; int barCharacters; float glyphCount; int glyphs; int checkValue1, checkValue2; int checkSum1, checkSum2; int inputLength; int j = 0; StringBuilder rowPattern; inputLength = barcodeData.Length; if (inputLength > 157) { throw new InvalidDataLengthException("Code 16K: Input data too long."); } // Initialise set and fset to spaces. for (int i = 0; i < set.Length; i++) { set[i] = ' '; fset[i] = ' '; } barCharacters = 0; // Detect extended ASCII characters. for (int i = 0; i < inputLength; i++) { if (barcodeData[i] >= 128) { fset[i] = 'f'; } } // Decide when to latch to extended mode - Annex E note 3. for (int i = 0; i < inputLength; i++) { if (fset[i] == 'f') { j++; } else { j = 0; } if (j >= 5) { for (int k = i; k > (i - 5); k--) { fset[k] = 'F'; } } if ((j >= 3) && (i == (inputLength - 1))) { for (int k = i; k > (i - 3); k--) { fset[k] = 'F'; } } } // Decide if it is worth reverting to 646 encodation for a few characters as described in 4.3.4.2 (d). for (int i = 1; i < inputLength; i++) { if ((fset[i - 1] == 'F') && (fset[i] == ' ')) { // Detected a change from 8859-1 to 646 - count how long for. for (j = 0; (fset[i + j] == ' ') && ((i + j) < inputLength); j++) { ; } if ((j < 5) || ((j < 3) && ((i + j) == (inputLength - 1)))) { // Uses the same figures recommended by Annex E note 3. // Change to shifting back rather than latching back. for (int k = 0; k < j; k++) { fset[i + k] = 'n'; } } } } // Decide on mode using of ISO 15417 Annex E int listIndex = 0; int sourceIndex = 0; mode = GetMode(barcodeData[sourceIndex]); if (barcodeData[sourceIndex] == '[') { mode = ABORC; } for (int i = 0; i < 170; i++) { encodingList[0, i] = 0; } do { encodingList[1, listIndex] = mode; while ((encodingList[1, listIndex] == mode) && (sourceIndex < inputLength)) { encodingList[0, listIndex]++; sourceIndex++; if (sourceIndex >= inputLength) { break; } mode = GetMode(barcodeData[sourceIndex]); if (isGS1 && barcodeData[sourceIndex] == '[') { mode = ABORC; } } listIndex++; } while (sourceIndex < inputLength); DxSmooth(ref listIndex); // Put set data into set[]. position = 0; for (int i = 0; i < listIndex; i++) { for (j = 0; j < encodingList[0, i]; j++) { switch (encodingList[1, i]) { case SHIFTA: set[position] = 'a'; break; case LATCHA: set[position] = 'A'; break; case SHIFTB: set[position] = 'b'; break; case LATCHB: set[position] = 'B'; break; case LATCHC: set[position] = 'C'; break; } position++; } } // Adjust for strings which start with shift characters - make them latch instead. if (set[0] == 'a') { int idx = 0; do { set[idx] = 'A'; idx++; } while (set[idx] == 'a'); } if (set[0] == 'b') { int idx = 0; do { set[idx] = 'B'; idx++; } while (set[idx] == 'b'); } // Watch out for odd-length Mode C blocks. int count = 0; int x; for (x = 0; x < position; x++) { if (set[x] == 'C') { if (barcodeData[x] == '[') { if ((count & 1) > 0) { if ((x - count) != 0) { set[x - count] = 'B'; } else { set[x - 1] = 'B'; } } count = 0; } else { count++; } } else { if ((count & 1) > 0) { if ((x - count) != 0) { set[x - count] = 'B'; } else { set[x - 1] = 'B'; } } count = 0; } } if ((count & 1) > 0) { if ((x - count) != 0) { set[x - count] = 'B'; } else { set[x - 1] = 'B'; } } for (x = 1; x < position - 1; x++) { if ((set[x] == 'C') && ((set[x - 1] == 'B') && (set[x + 1] == 'B'))) { set[x] = 'B'; } } // Now we can calculate how long the barcode is going to be - and stop it from being too long. lastSet = ' '; glyphCount = 0.0f; for (int i = 0; i < inputLength; i++) { if ((set[i] == 'a') || (set[i] == 'b')) { glyphCount = glyphCount + 1.0f; } if ((fset[i] == 'f') || (fset[i] == 'n')) { glyphCount = glyphCount + 1.0f; } if (((set[i] == 'A') || (set[i] == 'B')) || (set[i] == 'C')) { if (set[i] != lastSet) { lastSet = set[i]; glyphCount = glyphCount + 1.0f; } } if ((set[i] == 'C') && (barcodeData[i] != '[')) { glyphCount = glyphCount + 0.5f; } else { glyphCount = glyphCount + 1.0f; } } if (isGS1 && (set[0] != 'A')) // FNC1 can be integrated with mode character. { glyphCount--; } if (glyphCount > 77.0) { throw new InvalidDataLengthException("Code 16K: Input data too long."); } // Calculate how tall the symbol will be. glyphCount = glyphCount + 2.0f; glyphs = (int)glyphCount; rowsRequired = (glyphs / 5); if (glyphs % 5 > 0) { rowsRequired++; } if (rowsRequired == 1) { rowsRequired = 2; } // Start with the mode character - Table 2. m = 0; switch (set[0]) { case 'A': m = 0; break; case 'B': m = 1; break; case 'C': m = 2; break; } /*if (symbol->output_options & READER_INIT) * { * if (m == 2) * m = 5; * * if (isGS1) * { * strcpy(symbol->errtxt, "Cannot use both GS1 mode and Reader Initialisation (D22)"); * return ZINT_ERROR_INVALID_OPTION; * } * * else * { * if ((set[0] == 'B') && (set[1] == 'C')) * m = 6; * } * * values[bar_characters] = (7 * (rowsRequired - 2)) + m; // See 4.3.4.2 * values[bar_characters + 1] = 96; // FNC3. * bar_characters += 2; * } * * else * {*/ if (isGS1) { // Integrate FNC1. switch (set[0]) { case 'B': m = 3; break; case 'C': m = 4; break; } } else { if ((set[0] == 'B') && (set[1] == 'C')) { m = 5; } if (((set[0] == 'B') && (set[1] == 'B')) && (set[2] == 'C')) { m = 6; } } values[barCharacters] = (7 * (rowsRequired - 2)) + m; // See 4.3.4.2 barCharacters++; currentSet = set[0]; fState = false; // fState remembers if we are in Extended ASCII mode (value true) or in ISO/IEC 646 mode (value false) if (fset[0] == 'F') { switch (currentSet) { case 'A': values[barCharacters] = 101; values[barCharacters + 1] = 101; break; case 'B': values[barCharacters] = 100; values[barCharacters + 1] = 100; break; } barCharacters += 2; fState = true; } position = 0; // Encode the data. do { if ((position != 0) && (set[position] != set[position - 1])) { /* Latch different code set */ switch (set[position]) { case 'A': values[barCharacters] = 101; barCharacters++; currentSet = 'A'; break; case 'B': values[barCharacters] = 100; barCharacters++; currentSet = 'B'; break; case 'C': if (!((position == 1) && (set[0] == 'B'))) { // Not Mode C, Shift B. if (!((position == 2) && ((set[0] == 'B') && (set[1] == 'B')))) { // Not Mode C, Double Shift B. values[barCharacters] = 99; barCharacters++; } } currentSet = 'C'; break; } } if (position != 0) { if ((fset[position] == 'F') && (fState == false)) { // Latch beginning of extended mode. switch (currentSet) { case 'A': values[barCharacters] = 101; values[barCharacters + 1] = 101; break; case 'B': values[barCharacters] = 100; values[barCharacters + 1] = 100; break; } barCharacters += 2; fState = true; } if ((fset[position] == ' ') && (fState == true)) { // Latch end of extended mode. switch (currentSet) { case 'A': values[barCharacters] = 101; values[barCharacters + 1] = 101; break; case 'B': values[barCharacters] = 100; values[barCharacters + 1] = 100; break; } barCharacters += 2; fState = false; } } if ((fset[glyphs] == 'f') || (fset[glyphs] == 'n')) { // Shift extended mode. switch (currentSet) { case 'A': values[barCharacters] = 101; /* FNC 4 */ break; case 'B': values[barCharacters] = 100; /* FNC 4 */ break; } barCharacters++; } if ((set[glyphs] == 'a') || (set[glyphs] == 'b')) { // Insert shift character. values[barCharacters] = 98; barCharacters++; } if (!((isGS1) && (barcodeData[position] == '['))) { switch (set[position]) { /* Encode data characters */ case 'A': case 'a': Code16KSetA(barcodeData[position], values, ref barCharacters); position++; break; case 'B': case 'b': Code16KSetB(barcodeData[position], values, ref barCharacters); position++; break; case 'C': Code16KSetC(barcodeData[position], barcodeData[position + 1], values, ref barCharacters); position += 2; break; } } else { values[barCharacters] = 102; barCharacters++; position++; } } while (position < inputLength); padding = 5 - ((barCharacters + 2) % 5); if (padding == 5) { padding = 0; } if ((barCharacters + padding) < 8) { padding += 8 - (barCharacters + padding); } for (int i = 0; i < padding; i++) { values[barCharacters] = 106; barCharacters++; } // Calculate check digits. checkSum1 = 0; checkSum2 = 0; for (int i = 0; i < barCharacters; i++) { checkSum1 += (i + 2) * values[i]; checkSum2 += (i + 1) * values[i]; } checkValue1 = checkSum1 % 107; checkSum2 += checkValue1 * (barCharacters + 1); checkValue2 = checkSum2 % 107; values[barCharacters] = checkValue1; values[barCharacters + 1] = checkValue2; barCharacters += 2; for (int row = 0; row < rowsRequired; row++) { rowPattern = new StringBuilder(); rowPattern.Append(C16KStartStop[C16KStartValues[row]]); rowPattern.Append("1"); for (int i = 0; i < 5; i++) { rowPattern.Append(Code16KTable[values[(row * 5) + i]]); } rowPattern.Append(C16KStartStop[C16KStopValues[row]]); // Expand row into the symbol data. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 10.0f); } }
private void Code11() { int index; StringBuilder rowPattern = new StringBuilder(); int inputLength = barcodeData.Length; if (inputLength > 121) { throw new InvalidDataLengthException("Code 11: Input data too long."); } // Catch any invalid characters. for (int i = 0; i < inputLength; i++) { if (CharacterSets.Code11Set.IndexOf(barcodeData[i]) == -1) { throw new InvalidDataException("Code 11: Invalid data in input."); } } if (optionalCheckDigit) { // Calculate the "C" & "K" checksums. int cCount = 1; int kCount = 2; int cWeight = 0; int kWeight = 0; int checkDigitC = 0; int checkDigitK = 0; for (int i = inputLength - 1; i >= 0; i--) { index = CharacterSets.Code11Set.IndexOf(barcodeData[i]); cWeight += (index * cCount); cCount++; if (cCount == 11) { cCount = 1; } kWeight += (index * kCount); kCount++; if (kCount == 10) { kCount = 1; } } checkDigitC = (cWeight % 11); kWeight += checkDigitC; checkDigitK = (kWeight % 11); checkDigitText = checkDigitText += CharacterSets.Code11Set[checkDigitC]; // Using 2 check digits. if (numberOfCheckDigits == 2) { checkDigitText += CharacterSets.Code11Set[checkDigitK]; } } // Add the start character. rowPattern.Append(Code11Table[11]); for (int i = 0; i < inputLength; i++) { index = CharacterSets.Code11Set.IndexOf(barcodeData[i]); rowPattern.Append(Code11Table[index]); } for (int i = 0; i < checkDigitText.Length; i++) { index = CharacterSets.Code11Set.IndexOf(checkDigitText[i]); rowPattern.Append(Code11Table[index]); } // Add stop character. rowPattern.Append(Code11Table[11]); barcodeText = barcodeMessage; // Expand row into the symbol data. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f); }
private void CodaBlockF() { bool error; int usableColumns; int checksum1, checkSum2; int currentRows; int currentCharacter; int currentCharacterSet; int emptyColumns; byte[] data; int[] characterSet; byte[] symbolGrid; int gridPosition; int rows = codaBlockRows; int columns = codaBlockColumns; int fillings = 0; int dataLength = 0; StringBuilder rowPattern; int inputLength = barcodeData.Length; List <byte> dataList = new List <byte>(); for (int i = 0; i < inputLength; i++) { if (barcodeData[i] > 127) { dataList.Add(aFNC4); dataList.Add((byte)(barcodeData[i] & 127)); } else { dataList.Add((byte)barcodeData[i]); } } dataLength = dataList.Count; data = dataList.ToArray(); characterSet = new int[dataLength]; Collection <CharacterSetTable> characterSetTables = new Collection <CharacterSetTable>(); for (int i = 0; i < dataLength; i++) { characterSetTables.Add(new CharacterSetTable()); } CreateCharacterSetTable(characterSetTables, data, dataLength); // Find final row and column count. // Nor row nor column count given. if (rows <= 0 && columns <= 5) { // Use Code128 until reasonable size. if (dataLength < 9) { rows = 1; } else { // Use 1/1 aspect/ratio Codablock. columns = ((int)Math.Floor(Math.Sqrt(1.0 * dataLength)) + 5); if (columns > 64) { columns = 64; } } } // There are 5 Codewords for Organisation Start(2), row(1), CheckSum & Stop. usableColumns = columns - 5; if (rows > 0) // Row count given. { error = RowsToColumns(characterSetTables, dataLength, ref rows, ref usableColumns, characterSet, ref fillings); } else // Column count given. { error = ColumnsToRows(characterSetTables, dataLength, ref rows, ref usableColumns, characterSet, ref fillings); } if (error == true) { throw new InvalidDataLengthException("Codablock-F: Input data too long."); } // Checksum. checksum1 = checkSum2 = 0; if (rows > 1) { for (int p = 0; p < dataLength; p++) { checksum1 = (checksum1 + (p % 86 + 1) * data[p]) % 86; checkSum2 = (checkSum2 + (p % 86) * data[p]) % 86; } } columns = usableColumns + 5; symbolGrid = new byte[columns * rows]; gridPosition = 0; currentCharacter = 0; // Loop over rows. for (currentRows = 0; currentRows < rows; currentRows++) { if (currentCharacter >= dataLength) { // Empty line with StartCCodeBCodeC. currentCharacterSet = CodeC; symbolGrid[gridPosition] = 0x67; gridPosition++; symbolGrid[gridPosition] = 0x63; gridPosition++; SumASCII(symbolGrid, ref gridPosition, currentRows + 42, CodeC); emptyColumns = usableColumns - 2; while (emptyColumns > 0) { if (currentCharacterSet == CodeC) { A2C128_C(symbolGrid, ref gridPosition, aCodeB, 0); currentCharacterSet = CodeB; } else { A2C128_B(symbolGrid, ref gridPosition, aCodeC); currentCharacterSet = CodeC; } emptyColumns--; } } else { // Normal Line. // Startcode. switch (characterSet[currentCharacter] & (CodeA + CodeB + CodeC)) { case CodeA: symbolGrid[gridPosition] = 0x67; gridPosition++; if (rows > 1) { symbolGrid[gridPosition] = 0x62; gridPosition++; } currentCharacterSet = CodeA; break; case CodeB: if (rows == 1) { symbolGrid[gridPosition] = 0x68; gridPosition++; } else { symbolGrid[gridPosition] = 0x67; gridPosition++; symbolGrid[gridPosition] = 0x64; gridPosition++; } currentCharacterSet = CodeB; break; case CodeC: default: if (rows == 1) { symbolGrid[gridPosition] = 0x69; gridPosition++; } else { symbolGrid[gridPosition] = 0x67; gridPosition++; symbolGrid[gridPosition] = 0x63; gridPosition++; } currentCharacterSet = CodeC; break; } if (rows > 1) { // Set F1 // In first line : # of rows // In Case of CodeA we shifted to CodeB SumASCII(symbolGrid, ref gridPosition, (currentRows == 0) ? rows - 2 : currentRows + 42, (currentCharacterSet == CodeA) ? CodeB : currentCharacterSet); } // Data emptyColumns = usableColumns; // One liners don't have start/stop code. if (rows == 1) { emptyColumns += 2; } while (emptyColumns > 0) { // Change character set // not at first possition (It was then the start set) // special case for one-liner if (emptyColumns < usableColumns || (rows == 1 && currentCharacter != 0)) { if ((characterSet[currentCharacter] & CodeA) != 0) { // Change to A. ASCIIZ128(symbolGrid, ref gridPosition, currentCharacterSet, aCodeA, 0); emptyColumns--; currentCharacterSet = CodeA; } else if ((characterSet[currentCharacter] & CodeB) != 0) { // Change to B. ASCIIZ128(symbolGrid, ref gridPosition, currentCharacterSet, aCodeB, 0); emptyColumns--; currentCharacterSet = CodeB; } else if ((characterSet[currentCharacter] & CodeC) != 0) { // Change to C. ASCIIZ128(symbolGrid, ref gridPosition, currentCharacterSet, aCodeC, 0); emptyColumns--; currentCharacterSet = CodeC; } } if ((characterSet[currentCharacter] & CShift) != 0) { // Shift it and put out the shifted character. ASCIIZ128(symbolGrid, ref gridPosition, currentCharacterSet, aShift, 0); emptyColumns -= 2; currentCharacterSet = (currentCharacterSet == CodeB) ? CodeA : CodeB; ASCIIZ128(symbolGrid, ref gridPosition, currentCharacterSet, data[currentCharacter], 0); currentCharacterSet = (currentCharacterSet == CodeB) ? CodeA : CodeB; } else { // Normal character. if (currentCharacterSet == CodeC) { if (data[currentCharacter] == aFNC1) { A2C128_C(symbolGrid, ref gridPosition, aFNC1, 0); } else { A2C128_C(symbolGrid, ref gridPosition, data[currentCharacter], data[currentCharacter + 1]); currentCharacter++; } } else { ASCIIZ128(symbolGrid, ref gridPosition, currentCharacterSet, data[currentCharacter], 0); } emptyColumns--; } // End Criteria. if ((characterSet[currentCharacter] & CFill) != 0) { // Fill Line but leave space for checks in last line. if (currentRows == rows - 1 && emptyColumns >= 2) { emptyColumns -= 2; } while (emptyColumns > 0) { switch (currentCharacterSet) { case CodeC: A2C128_C(symbolGrid, ref gridPosition, aCodeB, 0); currentCharacterSet = CodeB; break; case CodeB: A2C128_B(symbolGrid, ref gridPosition, aCodeC); currentCharacterSet = CodeC; break; case CodeA: A2C128_A(symbolGrid, ref gridPosition, aCodeC); currentCharacterSet = CodeC; break; } emptyColumns--; } } if ((characterSet[currentCharacter] & CEnd) != 0) { emptyColumns = 0; } currentCharacter++; } } // Add checksum in last line. if (rows > 1 && currentRows == rows - 1) { SumASCII(symbolGrid, ref gridPosition, checksum1, currentCharacterSet); SumASCII(symbolGrid, ref gridPosition, checkSum2, currentCharacterSet); } // Add Code 128 checksum. { int code128Checksum = 0; int position = 0; for (; position < usableColumns + 3; position++) { code128Checksum = (code128Checksum + ((position == 0 ? 1 : position) * symbolGrid[columns * currentRows + position]) % 103) % 103; } symbolGrid[gridPosition] = (byte)code128Checksum; gridPosition++; } // Add terminaton character. symbolGrid[gridPosition] = 106; gridPosition++; } Debug.WriteLine("\nCode 128 Code Numbers:"); { int DPos, DPos2; for (DPos = 0; DPos < rows; DPos++) { for (DPos2 = 0; DPos2 < columns; DPos2++) { Debug.Write(String.Format("{0,4}", symbolGrid[DPos * columns + DPos2])); } Debug.Write("\n"); } } Debug.WriteLine(String.Format("rows={0} columns={1} fillings={2}", rows, columns, fillings)); // Build the symbol. for (int r = 0; r < rows; r++) { rowPattern = new StringBuilder(); for (int c = 0; c < columns; c++) { rowPattern.Append(Code128Table[symbolGrid[r * columns + c]]); } // Expand row into the symbol data.. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 10.0f); } }
public override Collection <SymbolData> EncodeData() { Symbol = new Collection <SymbolData>(); switch (symbolId) { case Symbology.Code128: switch (encodingMode) { case EncodingMode.Standard: barcodeData = MessagePreProcessor.TildeParser(barcodeMessage); Code128(); barcodeText = new String(barcodeData); break; case EncodingMode.GS1: isGS1 = true; barcodeData = MessagePreProcessor.AIParser(barcodeMessage); EAN128(); barcodeText = barcodeMessage; barcodeText = barcodeText.Replace('[', '('); barcodeText = barcodeText.Replace(']', ')'); break; case EncodingMode.HIBC: barcodeData = MessagePreProcessor.HIBCParser(barcodeMessage); Code128(); barcodeText = new String(barcodeData); break; } break; case Symbology.EAN14: isCompositeSymbol = false; barcodeData = MessagePreProcessor.MessageParser(barcodeMessage); EAN14(); barcodeText = new string(barcodeData); break; case Symbology.SSCC18: isCompositeSymbol = false; barcodeData = MessagePreProcessor.MessageParser(barcodeMessage); SSC18(); barcodeText = new string(barcodeData); break; } // Expand the row pattern into the symbol data. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f); // Build the symbol separator and add the 2D component (GS1-128) if (isGS1 && isCompositeSymbol) { byte[] rowData = new byte[Symbol[0].GetRowData().Length]; for (int i = 0; i < rowData.Length; i++) { if (Symbol[0].GetRowData()[i] == 0) { rowData[i] = 1; } } // Insert the separator to the symbol (top down ). SymbolData symbolData = new SymbolData(rowData, 1.0f); Symbol.Insert(0, symbolData); CompositeEncoder.AddComposite(symbolId, compositeMessage, Symbol, compositeMode, rowData.Length); } return(Symbol); }
private void ChannelCode() { bool outOfRange = false; targetValue = 0; rowPattern = new StringBuilder(); S = new int[11]; B = new int[11]; int inputLength = barcodeData.Length; if (inputLength > 7) { throw new InvalidDataLengthException("Channel Code: Input data too long."); } if (channels == 0) { channels = inputLength + 1; } if (channels == 2) { channels = 3; } for (int i = 0; i < inputLength; i++) { targetValue *= 10; targetValue += barcodeData[i] - '0'; } switch (channels) { case 3: if (targetValue > 26) { outOfRange = true; } break; case 4: if (targetValue > 292) { outOfRange = true; } break; case 5: if (targetValue > 3493) { outOfRange = true; } break; case 6: if (targetValue > 44072) { outOfRange = true; } break; case 7: if (targetValue > 576688) { outOfRange = true; } break; case 8: if (targetValue > 7742862) { outOfRange = true; } break; } if (outOfRange) { throw new InvalidDataException("Channel Code: Input data out of range."); } B[0] = S[1] = B[1] = S[2] = B[2] = 1; index = 0; NextS(channels, 3, channels, channels); string zeros = new String('0', channels - 1 - inputLength); barcodeData = ArrayExtensions.Insert(barcodeData, 0, zeros); inputLength = barcodeData.Length; barcodeText = new string(barcodeData); // Expand row into the symbol data. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f); }
private void TelepenNumeric() { int checkDigit, glyph; int count = 0; StringBuilder rowPattern = new StringBuilder(); int inputLength = barcodeData.Length; barcodeData = ArrayEx.ArrayExtensions.ToUpper(barcodeData); if (inputLength > 60) { throw new InvalidDataLengthException("Telepen Numeric: Input data too long."); } for (int i = 0; i < inputLength; i++) { if (CharacterSets.TelepenNumeric.IndexOf(barcodeData[i]) == -1) { throw new InvalidDataException("Telepen Numeric: Invalid characters in input data."); } } // Length must even, add a leading zero if required. if ((inputLength & 1) == 1) { barcodeData = ArrayEx.ArrayExtensions.Insert(barcodeData, 0, '0'); inputLength = barcodeData.Length; } // Start character. rowPattern.Append(TeleTable['_']); for (int i = 0; i < inputLength; i += 2) { if (barcodeData[i] == 'X') { throw new InvalidDataFormatException("Telepen Numeric: Invalid position of X in Telepen data."); } if (barcodeData[i + 1] == 'X') { glyph = (barcodeData[i] - '0') + 17; count += glyph; } else { glyph = ((10 * (barcodeData[i] - '0')) + (barcodeData[i + 1] - '0')); glyph += 27; count += glyph; } rowPattern.Append(TeleTable[glyph]); } checkDigit = 127 - (count % 127); if (checkDigit == 127) { checkDigit = 0; } rowPattern.Append(TeleTable[checkDigit]); // Stop character. rowPattern.Append(TeleTable['z']); // Expand row into the symbol data. SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f); }