Exemplo n.º 1
0
        private void encodeLowLevel(String fullCodewords,
                                    int c,
                                    int r,
                                    int errorCorrectionLevel,
                                    BarcodeMatrix logic)
        {
            int idx = 0;

            for (int y = 0; y < r; y++)
            {
                int cluster = y % 3;
                logic.startRow();
                encodeChar(START_PATTERN, 17, logic.getCurrentRow());

                int left;
                int right;
                if (cluster == 0)
                {
                    left  = (30 * (y / 3)) + ((r - 1) / 3);
                    right = (30 * (y / 3)) + (c - 1);
                }
                else if (cluster == 1)
                {
                    left  = (30 * (y / 3)) + (errorCorrectionLevel * 3) + ((r - 1) % 3);
                    right = (30 * (y / 3)) + ((r - 1) / 3);
                }
                else
                {
                    left  = (30 * (y / 3)) + (c - 1);
                    right = (30 * (y / 3)) + (errorCorrectionLevel * 3) + ((r - 1) % 3);
                }

                int pattern = CODEWORD_TABLE[cluster][left];
                encodeChar(pattern, 17, logic.getCurrentRow());

                for (int x = 0; x < c; x++)
                {
                    pattern = CODEWORD_TABLE[cluster][fullCodewords[idx]];
                    encodeChar(pattern, 17, logic.getCurrentRow());
                    idx++;
                }

                if (compact)
                {
                    encodeChar(STOP_PATTERN, 1, logic.getCurrentRow()); // encodes stop line for compact pdf417
                }
                else
                {
                    pattern = CODEWORD_TABLE[cluster][right];
                    encodeChar(pattern, 17, logic.getCurrentRow());

                    encodeChar(STOP_PATTERN, 18, logic.getCurrentRow());
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates the barcode logic.
        /// </summary>
        /// <param name="msg">the message to encode</param>
        /// <param name="errorCorrectionLevel">PDF417 error correction level to use</param>
        internal void generateBarcodeLogic(String msg, int errorCorrectionLevel, int longDimension, int shortDimension, ref int aspectRatio)
        {
            //1. step: High-level encoding
            String highLevel       = PDF417HighLevelEncoder.encodeHighLevel(msg, compaction, encoding, disableEci);
            int    sourceCodeWords = highLevel.Length;

            errorCorrectionLevel = PDF417ErrorCorrection.getErrorCorrectionLevel(errorCorrectionLevel, sourceCodeWords);
            int errorCorrectionCodeWords = PDF417ErrorCorrection.getErrorCorrectionCodewordCount(errorCorrectionLevel);

            int[] dimension = determineDimensions(sourceCodeWords, errorCorrectionCodeWords, longDimension, shortDimension, ref aspectRatio);

            int cols = dimension[0];
            int rows = dimension[1];

            int pad = getNumberOfPadCodewords(sourceCodeWords, errorCorrectionCodeWords, cols, rows);

            //2. step: construct data codewords
            if (sourceCodeWords + errorCorrectionCodeWords + 1 > 929)
            {
                // +1 for symbol length CW
                throw new WriterException(
                          "Encoded message contains too many code words, message too big (" + msg.Length + " bytes)");
            }
            int           n  = sourceCodeWords + pad + 1;
            StringBuilder sb = new StringBuilder(n);

            sb.Append((char)n);
            sb.Append(highLevel);
            for (int i = 0; i < pad; i++)
            {
                sb.Append((char)900); //PAD characters
            }
            String dataCodewords = sb.ToString();

            //3. step: Error correction
            String ec            = PDF417ErrorCorrection.generateErrorCorrection(dataCodewords, errorCorrectionLevel);
            String fullCodewords = dataCodewords + ec;

            //4. step: low-level encoding
            barcodeMatrix = new BarcodeMatrix(rows, cols, compact);
            encodeLowLevel(fullCodewords, cols, rows, errorCorrectionLevel, barcodeMatrix);
        }
Exemplo n.º 3
0
      /// <summary>
      /// Generates the barcode logic.
      ///
      /// <param name="msg">the message to encode</param>
      /// </summary>
      internal void generateBarcodeLogic(String msg, int errorCorrectionLevel)
      {

         //1. step: High-level encoding
         int errorCorrectionCodeWords = PDF417ErrorCorrection.getErrorCorrectionCodewordCount(errorCorrectionLevel);
         String highLevel = PDF417HighLevelEncoder.encodeHighLevel(msg, compaction);
         int sourceCodeWords = highLevel.Length;

         int[] dimension = determineDimensions(sourceCodeWords, errorCorrectionCodeWords);

         int cols = dimension[0];
         int rows = dimension[1];

         int pad = getNumberOfPadCodewords(sourceCodeWords, errorCorrectionCodeWords, cols, rows);

         //2. step: construct data codewords
         if (sourceCodeWords + errorCorrectionCodeWords + 1 > 929)
         { // +1 for symbol length CW
            throw new WriterException(
                "Encoded message contains to many code words, message to big (" + msg.Length + " bytes)");
         }
         int n = sourceCodeWords + pad + 1;
         StringBuilder sb = new StringBuilder(n);
         sb.Append((char)n);
         sb.Append(highLevel);
         for (int i = 0; i < pad; i++)
         {
            sb.Append((char)900); //PAD characters
         }
         String dataCodewords = sb.ToString();

         //3. step: Error correction
         String ec = PDF417ErrorCorrection.generateErrorCorrection(dataCodewords, errorCorrectionLevel);
         String fullCodewords = dataCodewords + ec;

         //4. step: low-level encoding
         barcodeMatrix = new BarcodeMatrix(rows, cols);
         encodeLowLevel(fullCodewords, cols, rows, errorCorrectionLevel, barcodeMatrix);
      }
Exemplo n.º 4
0
      private void encodeLowLevel(String fullCodewords,
                                  int c,
                                  int r,
                                  int errorCorrectionLevel,
                                  BarcodeMatrix logic)
      {

         int idx = 0;
         for (int y = 0; y < r; y++)
         {
            int cluster = y % 3;
            logic.startRow();
            encodeChar(START_PATTERN, 17, logic.getCurrentRow());

            int left;
            int right;
            if (cluster == 0)
            {
               left = (30 * (y / 3)) + ((r - 1) / 3);
               right = (30 * (y / 3)) + (c - 1);
            }
            else if (cluster == 1)
            {
               left = (30 * (y / 3)) + (errorCorrectionLevel * 3) + ((r - 1) % 3);
               right = (30 * (y / 3)) + ((r - 1) / 3);
            }
            else
            {
               left = (30 * (y / 3)) + (c - 1);
               right = (30 * (y / 3)) + (errorCorrectionLevel * 3) + ((r - 1) % 3);
            }

            int pattern = CODEWORD_TABLE[cluster][left];
            encodeChar(pattern, 17, logic.getCurrentRow());

            for (int x = 0; x < c; x++)
            {
               pattern = CODEWORD_TABLE[cluster][fullCodewords[idx]];
               encodeChar(pattern, 17, logic.getCurrentRow());
               idx++;
            }

            if (compact)
            {
               encodeChar(STOP_PATTERN, 1, logic.getCurrentRow()); // encodes stop line for compact pdf417
            }
            else
            {
               pattern = CODEWORD_TABLE[cluster][right];
               encodeChar(pattern, 17, logic.getCurrentRow());

               encodeChar(STOP_PATTERN, 18, logic.getCurrentRow());
            }
         }
      }