private void USPostWriter(StringBuilder symbolPattern) { int patternLength; int index = 0; SymbolData symbolData; byte[] rowData1; byte[] rowData2; patternLength = symbolPattern.Length; rowData1 = new byte[patternLength * 3]; rowData2 = new byte[patternLength * 3]; for (int p = 0; p < patternLength; p++) { if (symbolPattern[p] == 'L') { rowData1[index] = 1; } rowData2[index] = 1; index += 3; } symbolData = new SymbolData(rowData1, 6.0f); Symbol.Add(symbolData); symbolData = new SymbolData(rowData2, 6.0f); Symbol.Add(symbolData); }
private void BuildSymbol(StringBuilder barPattern) { // Turn the symbol into a bar pattern. int index = 0; int patternLength = barPattern.Length; byte[] rowData1 = new byte[patternLength * 2]; byte[] rowData2 = new byte[patternLength * 2]; byte[] rowData3 = new byte[patternLength * 2]; SymbolData symbolData; for (int i = 0; i < patternLength; i++) { if ((barPattern[i] == '1') || (barPattern[i] == '0')) { rowData1[index] = 1; } rowData2[index] = 1; if ((barPattern[i] == '2') || (barPattern[i] == '0')) { rowData3[index] = 1; } index += 2; } symbolData = new SymbolData(rowData1, 4.0f); Symbol.Add(symbolData); symbolData = new SymbolData(rowData2, 2.5f); Symbol.Add(symbolData); symbolData = new SymbolData(rowData3, 4.0f); Symbol.Add(symbolData); }
/// <summary> /// Generates a Column Symbol (Used everywhere else) /// </summary> /// <param name="xoCurrentToken"></param> /// <param name="xoList"></param> /// <returns></returns> private static SyntaxNode FactoryCreateColumn(ParsingContext xoContext, Boolean xbIsAliasNeeded = false) { ISyntax xoCurrentToken = xoContext.List.Peek(); // A Symbol consists of multiple parts Symbol oTable; Symbol oColumn; // If this is a literal Column if (SyntaxKindFacts.IsLiteral(xoCurrentToken.ExpectedType)) { oColumn = new Symbol(xoContext.List.Pop(), NodeStrategyFactory.NULL_STRATEGY); // Assign the alias if (xbIsAliasNeeded) { oColumn.Alias = SyntaxNodeFactory.ScanAheadForAlias(xoContext.List); } return(oColumn); } // Trailing item is . (table.column) if (xoContext.List.Peek(1).ExpectedType == SyntaxKind.DotToken) { oTable = new Symbol(xoCurrentToken, NodeStrategyFactory.NULL_STRATEGY); oColumn = new Symbol(xoContext.List.Peek(2)); // Grab the Column oTable.Add(oColumn); xoContext.List.Pop(3); // Skip over the next 2 } // Standalone Column else { oTable = new Symbol(new SyntaxToken(SyntaxKind.IdentifierTableSymbol, String.Empty)); oColumn = new Symbol(xoCurrentToken, NodeStrategyFactory.NULL_STRATEGY); // Grab the Column oTable.Add(oColumn); xoContext.List.Pop(); // Skip over the next 1 } // Assign the alias if (xbIsAliasNeeded) { oColumn.Alias = SyntaxNodeFactory.ScanAheadForAlias(xoContext.List); } oColumn.ExpectedType = SyntaxKind.IdentifierColumnSymbol; oTable.ExpectedType = SyntaxKind.IdentifierTableSymbol; // Return the top level node return(oTable); }
private void PharmaTwo() { char[] symbolPattern; int patternLength; int index = 0; int length = barcodeData.Length; SymbolData symbolData; byte[] rowData1; byte[] rowData2; if (length > 8) { throw new InvalidDataLengthException("Pharmacode 2-Track: Input data too long."); } symbolPattern = PharmaTwoCalculator(); patternLength = symbolPattern.Length; rowData1 = new byte[patternLength * 2]; rowData2 = new byte[patternLength * 2]; for (int l = 0; l < patternLength; l++) { if ((symbolPattern[l] == '2') || (symbolPattern[l] == '3')) { rowData1[index] = 1; } if ((symbolPattern[l] == '1') || (symbolPattern[l] == '3')) { rowData2[index] = 1; } index += 2; } symbolData = new SymbolData(rowData1); Symbol.Add(symbolData); symbolData = new SymbolData(rowData2); Symbol.Add(symbolData); }
// Translate 4-state data pattern to symbol. private void BuildSymbol(StringBuilder barPattern) { int index = 0; SymbolData symbolData; byte[] rowData1; byte[] rowData2; byte[] rowData3; int patternLength = barPattern.Length; rowData1 = new byte[patternLength * 2]; rowData2 = new byte[patternLength * 2]; rowData3 = new byte[patternLength * 2]; for (int p = 0; p < patternLength; p++) { if ((barPattern[p] == '1') || (barPattern[p] == '0')) { rowData1[index] = 1; } rowData2[index] = 1; if ((barPattern[p] == '2') || (barPattern[p] == '0')) { rowData3[index] = 1; } index += 2; } symbolData = new SymbolData(rowData1, 4.0f); Symbol.Add(symbolData); symbolData = new SymbolData(rowData2, 2.5f); Symbol.Add(symbolData); symbolData = new SymbolData(rowData3, 4.0f); Symbol.Add(symbolData); }
private void MaxiCode() { int inputLength = barcodeData.Length; int eccLength; int[] bitPattern = new int[7]; int countryCode = 0; int serviceClass = 0; char[] postcode; char[] primaryData; char[] secondaryData = new char[inputLength]; int[] maxiCodewords = new int[144]; int[,] symbolGrid = new int[33, 30]; char[] scmHeader = { '[', ')', '>', (char)(0x1e), '0', '1', (char)(0x1d) }; if (mode == MaxicodeMode.Mode2 || mode == MaxicodeMode.Mode3) { // Process the primary data. // Check for valid structured carrier message header. for (int i = 0; i < scmHeader.Length; i++ ) { if(barcodeData[i] != scmHeader[i]) throw new InvalidDataFormatException("Maxicode: Invalid Mode 2 / Mode 3 structured carrier message header."); } // Check for mandatory UPS data requirements. // Header + Postcode + Country Code + Service Type + Tracking Code + SCAC + EOM (44 characters mode 2, 41 for mode 3). int minimumDataLength = (mode == MaxicodeMode.Mode2) ? 44 : 41; if (inputLength < minimumDataLength) throw new InvalidDataException("Maxicode: Input data is less than mandatory UPS requirements."); // Check for the EOM. if (Array.IndexOf(barcodeData, (char)(0x04)) == -1) throw new InvalidDataFormatException("Maxicode: EOM (0x04 Hex) marker missing in input data."); // Extract the postcode, country code and service class and save in the primary data buffer. // Note: Group separators (GS = decimal 029) are removed. int primaryDataLength = (mode == MaxicodeMode.Mode2) ? 15 : 12; primaryData = new char[primaryDataLength]; int offset = 9; // Start of postcode. int idx = 9; int postcodeLength = 0; do { postcodeLength++; idx++; } while (barcodeData[idx] != (char)(0x1d) && idx < inputLength); if (idx == inputLength) throw new InvalidDataFormatException("Maxicode: Input data missing GS."); if ((mode == MaxicodeMode.Mode2 && postcodeLength != 9) || (mode == MaxicodeMode.Mode3 && postcodeLength != 6)) throw new InvalidDataException("Maxicode: Invalid postcode in input data."); Array.Copy(barcodeData, offset, primaryData, 0, postcodeLength); idx++; offset = idx; int countryCodeLength = 0; do { countryCodeLength++; idx++; } while (barcodeData[idx] != (char)(0x1d) && idx < inputLength); if (idx == inputLength) throw new InvalidDataFormatException("Input data missing GS."); if (countryCodeLength != 3) throw new InvalidDataLengthException("Maxicode: Invalid length for Country Code"); Array.Copy(barcodeData, offset, primaryData, postcodeLength, countryCodeLength); idx++; offset = idx; int serviceClassLength = 0; do { serviceClassLength++; idx++; } while (barcodeData[idx] != (char)(0x1d) && idx < inputLength); if (idx == inputLength) throw new InvalidDataFormatException("Maxicode: Input data missing GS."); if (serviceClassLength != 3) throw new InvalidDataLengthException("Maxicode: Invalid length for Service Class"); Array.Copy(barcodeData, offset, primaryData, postcodeLength + countryCodeLength, serviceClassLength); idx++; offset = idx; if (mode == MaxicodeMode.Mode2) { for (int i = 0; i < primaryData.Length; i++ ) { if(!Char.IsDigit(primaryData[i])) throw new InvalidDataException("Maxicode: Primary data must be numeric."); } postcode = new char[9]; Array.Copy(primaryData, postcode, 9); countryCode = int.Parse(new string(primaryData, 9, 3), CultureInfo.CurrentCulture); if (countryCode != 840) throw new InvalidDataException("Maxicode: Mode 2 requires US Country Code 840."); serviceClass = int.Parse(new string(primaryData, 12, 3), CultureInfo.CurrentCulture); PrimaryMode2(postcode, countryCode, serviceClass, maxiCodewords); } else { postcode = new char[6]; Array.Copy(primaryData, postcode, 6); ArrayEx.ArrayExtensions.ToUpper(primaryData); if (!IsNumeric(primaryData, 6, 6)) throw new InvalidDataException("Maxicode: Primary data must be numeric."); countryCode = int.Parse(new string(primaryData, 6, 3), CultureInfo.CurrentCulture); serviceClass = int.Parse(new string(primaryData, 9, 3), CultureInfo.CurrentCulture); PrimaryMode3(postcode, countryCode, serviceClass, maxiCodewords); } // Copy the header and the 2 digit year into the secondary data buffer. Array.Copy(barcodeData, 0, secondaryData, 0, 9); // Copy the rest of the data into the secondary data buffer. Array.Copy(barcodeData, offset, secondaryData, 9, inputLength - offset); int secondaryLength = Array.IndexOf(secondaryData, (char)(0x04)); Array.Resize(ref secondaryData, secondaryLength + 1); } else { // Not using a primary, just copy all the data into the secondary data buffer. maxiCodewords[0] = (int)mode; Array.Copy(barcodeData, secondaryData, inputLength); } if (!ProcessText(secondaryData, maxiCodewords)) throw new InvalidDataLengthException("Maxicode: Input data too long."); // All the data is sorted - now do error correction. PrimaryDataCheck(maxiCodewords); // Always EEC. if (mode == MaxicodeMode.Mode5) eccLength = 56; // 68 data codewords, 56 error corrections else eccLength = 40; // 84 data codewords, 40 error corrections SecondaryDataCheckEven(eccLength / 2, maxiCodewords); // Do error correction of even. SecondaryDataCheckOdd(eccLength / 2, maxiCodewords); // Do error correction of odd. // Copy data into symbol grid. for (int row = 0; row < 33; row++) { for (int column = 0; column < 30; column++) { int block = (MaxiGrid[(row * 30) + column] + 5) / 6; int bit = (MaxiGrid[(row * 30) + column] + 5) % 6; if (block != 0) { bitPattern[0] = (maxiCodewords[block - 1] & 0x20) >> 5; bitPattern[1] = (maxiCodewords[block - 1] & 0x10) >> 4; bitPattern[2] = (maxiCodewords[block - 1] & 0x8) >> 3; bitPattern[3] = (maxiCodewords[block - 1] & 0x4) >> 2; bitPattern[4] = (maxiCodewords[block - 1] & 0x2) >> 1; bitPattern[5] = (maxiCodewords[block - 1] & 0x1); if (bitPattern[bit] != 0) SetModule(row, column, symbolGrid); } } } // Add orientation markings. SetModule(0, 28, symbolGrid); // Top right filler SetModule(0, 29, symbolGrid); SetModule(9, 10, symbolGrid); // Top left marker SetModule(9, 11, symbolGrid); SetModule(10, 11, symbolGrid); SetModule(15, 7, symbolGrid); // Left hand marker SetModule(16, 8, symbolGrid); SetModule(16, 20, symbolGrid); // Right hand marker SetModule(17, 20, symbolGrid); SetModule(22, 10, symbolGrid); // Bottom left marker SetModule(23, 10, symbolGrid); SetModule(22, 17, symbolGrid); // Bottom right marker SetModule(23, 17, symbolGrid); // Expand the row pattern into the symbol data. byte[] rowData; for (int y = 0; y < 33; y++) { rowData = new byte[30]; for (int x = 0; x < 30; x++) rowData[x] = GetModule(y, x, symbolGrid); SymbolData symbolData = new SymbolData(rowData, 1.0f); Symbol.Add(symbolData); } }
private void PDF417() { int inputLength = barcodeData.Length; int modeListCount = 0; int offset; int eccLevel; int[,] modeList = new int[2, inputLength]; List <int> dataStream = new List <int>(); int[] eccStream; for (int i = 0; i < inputLength; i++) { int mode = GetMode(barcodeData[i]); if (i == 0) { modeList[1, modeListCount] = mode; modeList[0, modeListCount]++; } else { if (mode == modeList[1, modeListCount]) { modeList[0, modeListCount]++; } else { modeListCount++; modeList[1, modeListCount] = mode; modeList[0, modeListCount]++; } } } modeListCount++; SmoothPDF(ref modeListCount, modeList); // Compress the data. int dataIndex = 0; int dataStreamLength; for (int i = 0; i < modeListCount; i++) { switch (modeList[1, i]) { case TEXT: ProcessText(dataStream, dataIndex, modeList[0, i]); break; case BYTE: ProcessByte(dataStream, dataIndex, modeList[0, i]); break; case NUMBER: ProcessNumber(dataStream, dataIndex, modeList[0, i]); break; } dataIndex += modeList[0, i]; } // Now take care of the number of CWs per row. dataStreamLength = dataStream.Count; if (optionErrorCorrection < 0) { optionErrorCorrection = 6; if (dataStreamLength < 864) { optionErrorCorrection = 5; } if (dataStreamLength < 321) { optionErrorCorrection = 4; } if (dataStreamLength < 161) { optionErrorCorrection = 3; } if (dataStreamLength < 41) { optionErrorCorrection = 2; } } eccLevel = 1; for (int i = 1; i <= (optionErrorCorrection + 1); i++) { eccLevel *= 2; } if (optionDataColumns < 1) { optionDataColumns = (int)(0.5 + Math.Sqrt((dataStreamLength + eccLevel) / 3.0)); } if (((dataStreamLength + eccLevel) / optionDataColumns) > 90) { // Stop the symbol from becoming too high by increasing the columns. optionDataColumns = optionDataColumns + 1; } if ((dataStreamLength + eccLevel) > 928) { throw new InvalidDataLengthException("PDF417: Input data too long."); } if (((dataStreamLength + eccLevel) / optionDataColumns) > 90) { throw new InvalidDataLengthException("PDF417: Input data too long for specified number of columns."); } // Padding calculation. int totalLength = dataStreamLength + eccLevel + 1; int padding = 0; if ((totalLength / optionDataColumns) < 3) // A bar code must have at least three rows. { padding = (optionDataColumns * 3) - totalLength; } else { if ((totalLength % optionDataColumns) > 0) { padding = optionDataColumns - (totalLength % optionDataColumns); } } // Add the padding. while (padding > 0) { dataStream.Add(900); padding--; } // Insert the length descriptor. dataStream.Insert(0, dataStream.Count + 1); // We now take care of the Reed Solomon codes. if (optionErrorCorrection == 0) { offset = 0; } else { offset = eccLevel - 2; } dataStreamLength = dataStream.Count; eccStream = new int[eccLevel]; for (int i = 0; i < dataStreamLength; i++) { int total = (dataStream[i] + eccStream[eccLevel - 1]) % 929; for (int j = eccLevel - 1; j > 0; j--) { eccStream[j] = ((eccStream[j - 1] + 929) - (total * PDF417Tables.Coefficients[offset + j]) % 929) % 929; } eccStream[0] = (929 - (total * PDF417Tables.Coefficients[offset]) % 929) % 929; } // Add the code words to the data stream. for (int i = eccLevel - 1; i >= 0; i--) { dataStream.Add((eccStream[i] != 0) ? 929 - eccStream[i] : 0); } dataStreamLength = dataStream.Count; int rowCount = dataStreamLength / optionDataColumns; if (dataStreamLength % optionDataColumns != 0) { rowCount++; } int c1 = (rowCount - 1) / 3; int c2 = (optionErrorCorrection * 3) + ((rowCount - 1) % 3); int c3 = optionDataColumns - 1; // Encode each row. StringBuilder codeString = new StringBuilder(); BitVector bitPattern = new BitVector(); int[] buffer = new int[optionDataColumns + 2]; for (int row = 0; row < rowCount; row++) { for (int i = 0; i < buffer.Length; i++) { buffer[i] = 0; } for (int i = 0; i < optionDataColumns; i++) { buffer[i + 1] = dataStream[row * optionDataColumns + i]; } int errorCorrection = (row / 3) * 30; switch (row % 3) { /* Follows this codePattern from US Patent 5,243,655: * Row 0: L0 (row #, # of rows) R0 (row #, # of columns) * Row 1: L1 (row #, security level) R1 (row #, # of rows) * Row 2: L2 (row #, # of columns) R2 (row #, security level) * Row 3: L3 (row #, # of rows) R3 (row #, # of columns) * etc. */ case 0: buffer[0] = errorCorrection + c1; buffer[optionDataColumns + 1] = errorCorrection + c3; break; case 1: buffer[0] = errorCorrection + c2; buffer[optionDataColumns + 1] = errorCorrection + c1; break; case 2: buffer[0] = errorCorrection + c3; buffer[optionDataColumns + 1] = errorCorrection + c2; break; } codeString.Append("+*"); if (isTruncated) { // Truncated PDF - remove the last 5 characters. for (int j = 0; j <= optionDataColumns; j++) { switch (row % 3) { case 1: offset = 929; break; case 2: offset = 1858; break; default: offset = 0; break; } codeString.Append(PDF417Tables.EncodingPatterns[offset + buffer[j]]); codeString.Append("*"); } } else { // Normal PDF417 symbol. for (int j = 0; j <= optionDataColumns + 1; j++) { switch (row % 3) { case 1: offset = 929; break; case 2: offset = 1858; break; default: offset = 0; break; } codeString.Append(PDF417Tables.EncodingPatterns[offset + buffer[j]]); codeString.Append("*"); } codeString.Append("-"); } for (int i = 0; i < codeString.Length; i++) { int position = PDF417Tables.PDFSet.IndexOf(codeString[i]); if (position >= 0 && position < 32) { bitPattern.AppendBits(position, 5); } else if (position == 32) { bitPattern.AppendBits(1, 2); } else if (position == 33) { bitPattern.AppendBits(0xff54, 16); } else { bitPattern.AppendBits(0x1fa29, 17); } } int size = bitPattern.SizeInBits; byte[] rowData = new byte[size]; for (int i = 0; i < size; i++) { rowData[i] = bitPattern[i]; } SymbolData symbolData = new SymbolData(rowData, optionElementHeight); Symbol.Add(symbolData); // Clear data ready for next row. codeString.Clear(); bitPattern.Clear(); } }
/// <summary> /// Generate a Micro PDF barcode. /// </summary> private void MicroPDF417() { int inputLength = barcodeData.Length; int offset; int modeListCount = 0; List <int> dataStream = new List <int>(); int[] eccStream; // Encoding starts out the same as PDF417, so use the same code. int[,] modeList = new int[2, inputLength]; for (int i = 0; i < inputLength; i++) { int mode = GetMode(barcodeData[i]); if (i == 0) // First character. { modeList[1, modeListCount] = mode; modeList[0, modeListCount]++; } else { // Next character same mode. if (mode == modeList[1, modeListCount]) { modeList[0, modeListCount]++; } else { // Next character a different mode. modeListCount++; modeList[1, modeListCount] = mode; modeList[0, modeListCount]++; } } } modeListCount++; SmoothPDF(ref modeListCount, modeList); // Compress the data. int dataIndex = 0; int dataStreamLength; for (int i = 0; i < modeListCount; i++) { switch (modeList[1, i]) { case TEXT: ProcessText(dataStream, dataIndex, modeList[0, i]); break; case BYTE: ProcessByte(dataStream, dataIndex, modeList[0, i]); break; case NUMBER: ProcessNumber(dataStream, dataIndex, modeList[0, i]); break; } dataIndex += modeList[0, i]; } // // This is where it all changes! // dataStreamLength = dataStream.Count; if (dataStreamLength > 126) { throw new InvalidDataLengthException(); } if (optionDataColumns > 4) { optionDataColumns = 0; } // Now figure out which variant of the symbol to use and load values accordingly. int variant = 0; if ((optionDataColumns == 1) && (dataStreamLength > 20)) { // The user specified 1 column but the data doesn't fit - go to automatic optionDataColumns = 0; } if ((optionDataColumns == 2) && (dataStreamLength > 37)) { // The user specified 2 columns but the data doesn't fit - go to automatic optionDataColumns = 0; } if ((optionDataColumns == 3) && (dataStreamLength > 82)) { // The user specified 3 columns but the data doesn't fit - go to automatic optionDataColumns = 0; } if (optionDataColumns == 1) { variant = 6; if (dataStreamLength <= 16) { variant = 5; } if (dataStreamLength <= 12) { variant = 4; } if (dataStreamLength <= 10) { variant = 3; } if (dataStreamLength <= 7) { variant = 2; } if (dataStreamLength <= 4) { variant = 1; } } if (optionDataColumns == 2) { variant = 13; if (dataStreamLength <= 33) { variant = 12; } if (dataStreamLength <= 29) { variant = 11; } if (dataStreamLength <= 24) { variant = 10; } if (dataStreamLength <= 19) { variant = 9; } if (dataStreamLength <= 13) { variant = 8; } if (dataStreamLength <= 8) { variant = 7; } } if (optionDataColumns == 3) { // The user specified 3 columns and the data does fit variant = 23; if (dataStreamLength <= 70) { variant = 22; } if (dataStreamLength <= 58) { variant = 21; } if (dataStreamLength <= 46) { variant = 20; } if (dataStreamLength <= 34) { variant = 19; } if (dataStreamLength <= 24) { variant = 18; } if (dataStreamLength <= 18) { variant = 17; } if (dataStreamLength <= 14) { variant = 16; } if (dataStreamLength <= 10) { variant = 15; } if (dataStreamLength <= 6) { variant = 14; } } if (optionDataColumns == 4) { // The user specified 4 columns and the data does fit. variant = 34; if (dataStreamLength <= 108) { variant = 33; } if (dataStreamLength <= 90) { variant = 32; } if (dataStreamLength <= 72) { variant = 31; } if (dataStreamLength <= 54) { variant = 30; } if (dataStreamLength <= 39) { variant = 29; } if (dataStreamLength <= 30) { variant = 28; } if (dataStreamLength <= 24) { variant = 27; } if (dataStreamLength <= 18) { variant = 26; } if (dataStreamLength <= 12) { variant = 25; } if (dataStreamLength <= 8) { variant = 24; } } if (variant == 0) { // Let ZintNET choose automatically from all available variations. for (int i = 27; i >= 0; i--) { if (PDF417Tables.MicroAutoSize[i] >= dataStreamLength) { variant = PDF417Tables.MicroAutoSize[i + 28]; } } } // Now we have the variant we can load the data. variant--; optionDataColumns = PDF417Tables.MicroVariants[variant]; // columns int rowCount = PDF417Tables.MicroVariants[variant + 34]; // row Count int eccCodewords = PDF417Tables.MicroVariants[variant + 68]; // number of error correction CWs int dataCodewords = (optionDataColumns * rowCount) - eccCodewords; // number of data CWs int padding = dataCodewords - dataStreamLength; // amount of padding required offset = PDF417Tables.MicroVariants[variant + 102]; // coefficient offset // Add the padding while (padding > 0) { dataStream.Add(900); padding--; } // Reed-Solomon error correction dataStreamLength = dataStream.Count; eccStream = new int[eccCodewords]; for (int i = 0; i < dataStreamLength; i++) { int total = (dataStream[i] + eccStream[eccCodewords - 1]) % 929; for (int j = eccCodewords - 1; j > 0; j--) { eccStream[j] = ((eccStream[j - 1] + 929) - (total * PDF417Tables.MicroCoefficients[offset + j]) % 929) % 929; } eccStream[0] = (929 - (total * PDF417Tables.MicroCoefficients[offset]) % 929) % 929; } for (int j = 0; j < eccCodewords; j++) { if (eccStream[j] != 0) { eccStream[j] = 929 - eccStream[j]; } } // Add the reed-solomon codewords to the data stream. for (int i = eccCodewords - 1; i >= 0; i--) { dataStream.Add(eccStream[i]); } // RAP (Row Address Pattern) start values int leftRAPStart = PDF417Tables.RowAddressTable[variant]; int centreRAPStart = PDF417Tables.RowAddressTable[variant + 34]; int rightRAPStart = PDF417Tables.RowAddressTable[variant + 68]; int startCluster = PDF417Tables.RowAddressTable[variant + 102] / 3; // Start encoding. int leftRAP = leftRAPStart; int centreRAP = centreRAPStart; int rightRAP = rightRAPStart; int cluster = startCluster; // Cluster can be 0, 1 or 2 for Cluster(0), Cluster(3) and Cluster(6). StringBuilder codeString = new StringBuilder(); BitVector bitPattern = new BitVector(); int[] buffer = new int[optionDataColumns + 1]; for (int row = 0; row < rowCount; row++) { for (int i = 0; i < buffer.Length; i++) { buffer[i] = 0; } for (int i = 0; i < optionDataColumns; i++) { buffer[i + 1] = dataStream[row * optionDataColumns + i]; } // Copy the data into code string. offset = 929 * cluster; codeString.Append(PDF417Tables.RowAddressPattern[leftRAP]); codeString.Append("1"); codeString.Append(PDF417Tables.EncodingPatterns[offset + buffer[1]]); codeString.Append("1"); if (optionDataColumns == 3) { codeString.Append(PDF417Tables.CentreRowAddressPattern[centreRAP]); } if (optionDataColumns >= 2) { codeString.Append("1"); codeString.Append(PDF417Tables.EncodingPatterns[offset + buffer[2]]); codeString.Append("1"); } if (optionDataColumns == 4) { codeString.Append(PDF417Tables.CentreRowAddressPattern[centreRAP]); } if (optionDataColumns >= 3) { codeString.Append("1"); codeString.Append(PDF417Tables.EncodingPatterns[offset + buffer[3]]); codeString.Append("1"); } if (optionDataColumns == 4) { codeString.Append("1"); codeString.Append(PDF417Tables.EncodingPatterns[offset + buffer[4]]); codeString.Append("1"); } codeString.Append(PDF417Tables.RowAddressPattern[rightRAP]); codeString.Append("1"); // Stop. // Now codeString is a mixture of letters and numbers bool latch = true; int value; for (int i = 0; i < codeString.Length; i++) { if ((codeString[i] >= '0') && (codeString[i] <= '9')) { value = (int)(codeString[i] - '0'); bitPattern.AppendBits((latch) ? 0xfff : 0, value); latch = !latch; } else { int position = PDF417Tables.PDFSet.IndexOf(codeString[i]); if (position >= 0 && position < 32) { bitPattern.AppendBits(position, 5); } } } int size = bitPattern.SizeInBits; byte[] rowData = new byte[size]; for (int i = 0; i < size; i++) { rowData[i] = bitPattern[i]; } SymbolData symbolData = new SymbolData(rowData, 2); Symbol.Add(symbolData); codeString.Clear(); bitPattern.Clear(); // Set up RAPs and Cluster for next row. leftRAP++; centreRAP++; rightRAP++; cluster++; if (leftRAP == 53) { leftRAP = 1; } if (centreRAP == 53) { centreRAP = 1; } if (rightRAP == 53) { rightRAP = 1; } if (cluster == 3) { cluster = 0; } } }
private void JapanPost() { int sourceIndex = 0; int intermediateIndex = 0; int rowIndex = 0; int sum, checkValue; char checkDigit = '\0'; int patternLength; SymbolData symbolData; byte[] rowData1; byte[] rowData2; byte[] rowData3; StringBuilder intermediate = new StringBuilder(); StringBuilder symbolPattern = new StringBuilder(); int inputLength = barcodeData.Length; if (inputLength > 20) { throw new InvalidDataLengthException("Flattermarken: Input data too long."); } //inter_posn = 0; for (int i = 0; i < inputLength; i++) { barcodeData[i] = Char.ToUpper(barcodeData[i], CultureInfo.CurrentCulture); if (CharacterSets.SHKASUTSET.IndexOf(barcodeData[i]) == -1) { throw new InvalidDataException("Japan Post: Invalid characters in input data."); } } intermediate.Append('d', 20); // Pad character CC4. //index = 0; //intermediateIndex = 0; do { if (((barcodeData[sourceIndex] >= '0') && (barcodeData[sourceIndex] <= '9')) || (barcodeData[sourceIndex] == '-')) { intermediate[intermediateIndex] = barcodeData[sourceIndex]; intermediateIndex++; } else { if ((barcodeData[sourceIndex] >= 'A') && (barcodeData[sourceIndex] <= 'J')) { intermediate[intermediateIndex] = 'a'; intermediate[intermediateIndex + 1] = (char)(barcodeData[sourceIndex] - 'A' + '0'); intermediateIndex += 2; } if ((barcodeData[sourceIndex] >= 'K') && (barcodeData[sourceIndex] <= 'T')) { intermediate[intermediateIndex] = 'b'; intermediate[intermediateIndex + 1] = (char)(barcodeData[sourceIndex] - 'K' + '0'); intermediateIndex += 2; } if ((barcodeData[sourceIndex] >= 'U') && (barcodeData[sourceIndex] <= 'Z')) { intermediate[intermediateIndex] = 'c'; intermediate[intermediateIndex + 1] = (char)(barcodeData[sourceIndex] - 'U' + '0'); intermediateIndex += 2; } } sourceIndex++; } while ((sourceIndex < inputLength) && (intermediateIndex < 20)); symbolPattern.Append("13"); // Start. sum = 0; for (int i = 0; i < 20; i++) { int position = CharacterSets.KASUTSET.IndexOf(intermediate[i]); symbolPattern.Append(JapanTable[position]); sum += CharacterSets.CHKASUTSET.IndexOf(intermediate[i]); } // Calculate check digit. checkValue = 19 - (sum % 19); if (checkValue == 19) { checkValue = 0; } if (checkValue <= 9) { checkDigit = (char)(checkValue + '0'); } if (checkValue == 10) { checkDigit = '-'; } if (checkValue >= 11) { checkDigit = (char)((checkValue - 11) + 'a'); } symbolPattern.Append(JapanTable[CharacterSets.KASUTSET.IndexOf(checkDigit)]); symbolPattern.Append("31"); // Stop. patternLength = symbolPattern.Length; rowData1 = new byte[patternLength * 2]; rowData2 = new byte[patternLength * 2]; rowData3 = new byte[patternLength * 2]; for (int l = 0; l < patternLength; l++) { if ((symbolPattern[l] == '2') || (symbolPattern[l] == '1')) { rowData1[rowIndex] = 1; } rowData2[rowIndex] = 1; if ((symbolPattern[l] == '3') || (symbolPattern[l] == '1')) { rowData3[rowIndex] = 1; } rowIndex += 2; } symbolData = new SymbolData(rowData1, 3.0f); Symbol.Add(symbolData); symbolData = new SymbolData(rowData2, 2.0f); Symbol.Add(symbolData); symbolData = new SymbolData(rowData3, 3.0f); Symbol.Add(symbolData); }
/// <summary> /// Generates a simple Table Symbol /// </summary> /// <param name="xoList"></param> /// <returns></returns> public static SyntaxNode FactoryCreateTable(ParsingContext xoContext) { ISyntax xoCurrentToken = xoContext.List.Peek(); if (xoCurrentToken.ExpectedType == SyntaxKind.OpenParenthesisToken) { // Subquery start ISyntax oNextToken = xoContext.List.Pop(); oNextToken.ExpectedType = SyntaxKind.IdentifierSubQuerySymbol; // give it a better type // Create a table symbol Symbol oSubquery = new Symbol(oNextToken); return(oSubquery); } SyntaxNode oDatabase; SyntaxNode oSchema; // A Symbol consists of multiple parts SyntaxNode oTable; int iSchemaLocation = 0; int iTableLocation = 0; // Trailing item is a .. (Database) if (xoContext.List.Peek(1).ExpectedType == SyntaxKind.DotDotToken) { iSchemaLocation = -1; iTableLocation = 2; } else if (xoContext.List.Peek(1).ExpectedType == SyntaxKind.DotToken) { iSchemaLocation = 2; iTableLocation = 4; } // Standalone Table else { iSchemaLocation = -1; iTableLocation = 0; } oDatabase = new Symbol(new SyntaxToken(SyntaxKind.IdentifierDatabaseSymbol, iTableLocation != 0 ? xoCurrentToken.RawSQLText : String.Empty)); // Generate the Schema Node oSchema = new Symbol(new SyntaxToken(SyntaxKind.IdentifierSchemaSymbol, iSchemaLocation != -1 ? xoContext.List.Peek(iSchemaLocation).RawSQLText : String.Empty)); oTable = new Symbol(new SyntaxToken(SyntaxKind.IdentifierTableSymbol, xoContext.List.Peek(iTableLocation).RawSQLText)); // create the decorator obj oSchema.Add(oTable); oDatabase.Add(oSchema); // Pop the tokens xoContext.List.Pop(Math.Max(iSchemaLocation, iTableLocation) + 1); // Assign the alias ((Symbol)oTable).Alias = SyntaxNodeFactory.ScanAheadForAlias(xoContext.List); return(oDatabase); }