Example #1
0
        /// <summary>
        /// Gets the barcode metadata.
        /// </summary>
        /// <returns>The barcode metadata.</returns>
        public BarcodeMetadata GetBarcodeMetadata()
        {
            BarcodeValue barcodeColumnCount       = new BarcodeValue();
            BarcodeValue barcodeRowCountUpperPart = new BarcodeValue();
            BarcodeValue barcodeRowCountLowerPart = new BarcodeValue();
            BarcodeValue barcodeECLevel           = new BarcodeValue();

            foreach (Codeword codeword in Codewords)
            {
                if (codeword == null)
                {
                    continue;
                }
                codeword.SetRowNumberAsRowIndicatorColumn();
                int rowIndicatorValue = codeword.Value % 30;
                int codewordRowNumber = codeword.RowNumber;
                if (!IsLeft)
                {
                    codewordRowNumber += 2;
                }
                switch (codewordRowNumber % 3)
                {
                case 0:
                    barcodeRowCountUpperPart.SetValue(rowIndicatorValue * 3 + 1);
                    break;

                case 1:
                    barcodeECLevel.SetValue(rowIndicatorValue / 3);
                    barcodeRowCountLowerPart.SetValue(rowIndicatorValue % 3);
                    break;

                case 2:
                    barcodeColumnCount.SetValue(rowIndicatorValue + 1);
                    break;
                }
            }
            // Maybe we should check if we have ambiguous values?
            if ((barcodeColumnCount.GetValue().Length == 0) ||
                (barcodeRowCountUpperPart.GetValue().Length == 0) ||
                (barcodeRowCountLowerPart.GetValue().Length == 0) ||
                (barcodeECLevel.GetValue().Length == 0) ||
                barcodeColumnCount.GetValue()[0] < 1 ||
                barcodeRowCountUpperPart.GetValue()[0] + barcodeRowCountLowerPart.GetValue()[0] < PDF417Common.MIN_ROWS_IN_BARCODE ||
                barcodeRowCountUpperPart.GetValue()[0] + barcodeRowCountLowerPart.GetValue()[0] > PDF417Common.MAX_ROWS_IN_BARCODE)
            {
                return(null);
            }
            BarcodeMetadata barcodeMetadata = new BarcodeMetadata(barcodeColumnCount.GetValue()[0],
                                                                  barcodeRowCountUpperPart.GetValue()[0],
                                                                  barcodeRowCountLowerPart.GetValue()[0],
                                                                  barcodeECLevel.GetValue()[0]);

            RemoveIncorrectCodewords(barcodeMetadata);
            return(barcodeMetadata);
        }
        /// <summary>
        /// Returns a <see cref="System.String"/> that represents the <see cref="ZXing.PDF417.Internal.BarcodeValue"/> jagged array.
        /// </summary>
        /// <returns>A <see cref="System.String"/> that represents the <see cref="ZXing.PDF417.Internal.BarcodeValue"/> jagged array.</returns>
        /// <param name="barcodeMatrix">Barcode matrix as a jagged array.</param>
        public static String ToString(BarcodeValue[][] barcodeMatrix)
        {
            StringBuilder formatter = new StringBuilder();

            for (int row = 0; row < barcodeMatrix.Length; row++)
            {
                formatter.AppendFormat("Row {0,2}: ", row);
                for (int column = 0; column < barcodeMatrix[row].Length; column++)
                {
                    BarcodeValue barcodeValue = barcodeMatrix[row][column];
                    if (barcodeValue.GetValue().Length == 0)
                    {
                        formatter.Append("        ");
                    }
                    else
                    {
                        formatter.AppendFormat("{0,4}({0,3})", barcodeValue.GetValue()[0], barcodeValue.GetConfidence(barcodeValue.GetValue()[0]));
                    }
                }
                formatter.Append("\n");
            }
            return(formatter.ToString());
        }
 /// <summary>
 /// Gets the barcode metadata.
 /// </summary>
 /// <returns>The barcode metadata.</returns>
 public BarcodeMetadata GetBarcodeMetadata()
 {
     BarcodeValue barcodeColumnCount = new BarcodeValue();
     BarcodeValue barcodeRowCountUpperPart = new BarcodeValue();
     BarcodeValue barcodeRowCountLowerPart = new BarcodeValue();
     BarcodeValue barcodeECLevel = new BarcodeValue();
     foreach (Codeword codeword in Codewords)
     {
         if (codeword == null)
         {
             continue;
         }
         codeword.SetRowNumberAsRowIndicatorColumn();
         int rowIndicatorValue = codeword.Value % 30;
         int codewordRowNumber = codeword.RowNumber;
         if (!IsLeft)
         {
             codewordRowNumber += 2;
         }
         switch (codewordRowNumber % 3)
         {
             case 0:
                 barcodeRowCountUpperPart.SetValue(rowIndicatorValue * 3 + 1);
                 break;
             case 1:
                 barcodeECLevel.SetValue(rowIndicatorValue / 3);
                 barcodeRowCountLowerPart.SetValue(rowIndicatorValue % 3);
                 break;
             case 2:
                 barcodeColumnCount.SetValue(rowIndicatorValue + 1);
                 break;
         }
     }
     // Maybe we should check if we have ambiguous values?
     if ((barcodeColumnCount.GetValue().Length == 0) ||
         (barcodeRowCountUpperPart.GetValue().Length == 0) ||
         (barcodeRowCountLowerPart.GetValue().Length == 0) ||
         (barcodeECLevel.GetValue().Length == 0) ||
         barcodeColumnCount.GetValue()[0] < 1 ||
         barcodeRowCountUpperPart.GetValue()[0] + barcodeRowCountLowerPart.GetValue()[0] < PDF417Common.MIN_ROWS_IN_BARCODE ||
         barcodeRowCountUpperPart.GetValue()[0] + barcodeRowCountLowerPart.GetValue()[0] > PDF417Common.MAX_ROWS_IN_BARCODE)
     {
         return null;
     }
     BarcodeMetadata barcodeMetadata = new BarcodeMetadata(barcodeColumnCount.GetValue()[0],
                                                           barcodeRowCountUpperPart.GetValue()[0],
                                                           barcodeRowCountLowerPart.GetValue()[0],
                                                           barcodeECLevel.GetValue()[0]);
     RemoveIncorrectCodewords(barcodeMetadata);
     return barcodeMetadata;
 }