public void testLookup()
 {
    EANManufacturerOrgSupport support = new EANManufacturerOrgSupport();
    Assert.IsNull(support.lookupCountryIdentifier("472000"));
    Assert.AreEqual("US/CA", support.lookupCountryIdentifier("000000"));
    Assert.AreEqual("MO", support.lookupCountryIdentifier("958000"));
    Assert.AreEqual("GB", support.lookupCountryIdentifier("500000"));
    Assert.AreEqual("GB", support.lookupCountryIdentifier("509000"));
 }
        public void testLookup()
        {
            EANManufacturerOrgSupport support = new EANManufacturerOrgSupport();

            Assert.IsNull(support.lookupCountryIdentifier("472000"));
            Assert.AreEqual("US/CA", support.lookupCountryIdentifier("000000"));
            Assert.AreEqual("MO", support.lookupCountryIdentifier("958000"));
            Assert.AreEqual("GB", support.lookupCountryIdentifier("500000"));
            Assert.AreEqual("GB", support.lookupCountryIdentifier("509000"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// <p>Like <seealso cref="#decodeRow(int, BitArray, java.util.Map)"/>, but
        /// allows caller to inform method about where the UPC/EAN start pattern is
        /// found. This allows this to be computed once and reused across many implementations.</p>
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public com.google.zxing.Result decodeRow(int rowNumber, com.google.zxing.common.BitArray row, int[] startGuardRange, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.NotFoundException, com.google.zxing.ChecksumException, com.google.zxing.FormatException
        public virtual Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, IDictionary <DecodeHintType, object> hints)
        {
            //ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK];
            ResultPointCallback resultPointCallback = null;

            if (hints != null && hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK))
            {
                resultPointCallback = (ResultPointCallback)hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK];
            }

            if (resultPointCallback != null)
            {
                resultPointCallback.foundPossibleResultPoint(new ResultPoint((startGuardRange[0] + startGuardRange[1]) / 2.0f, rowNumber));
            }

            StringBuilder result = decodeRowStringBuffer;

            result.Length = 0;
            int endStart = decodeMiddle(row, startGuardRange, result);

            if (resultPointCallback != null)
            {
                resultPointCallback.foundPossibleResultPoint(new ResultPoint(endStart, rowNumber));
            }

            int[] endRange = decodeEnd(row, endStart);

            if (resultPointCallback != null)
            {
                resultPointCallback.foundPossibleResultPoint(new ResultPoint((endRange[0] + endRange[1]) / 2.0f, rowNumber));
            }


            // Make sure there is a quiet zone at least as big as the end pattern after the barcode. The
            // spec might want more whitespace, but in practice this is the maximum we can count on.
            int end      = endRange[1];
            int quietEnd = end + (end - endRange[0]);

            if (quietEnd >= row.Size || !row.isRange(end, quietEnd, false))
            {
                throw NotFoundException.NotFoundInstance;
            }

            string resultString = result.ToString();

            if (!checkChecksum(resultString))
            {
                throw ChecksumException.ChecksumInstance;
            }

            float         left         = (float)(startGuardRange[1] + startGuardRange[0]) / 2.0f;
            float         right        = (float)(endRange[1] + endRange[0]) / 2.0f;
            BarcodeFormat format       = BarcodeFormat;
            Result        decodeResult = new Result(resultString, null, new ResultPoint[] { new ResultPoint(left, (float)rowNumber), new ResultPoint(right, (float)rowNumber) }, format); // no natural byte representation for these barcodes

            try
            {
                Result extensionResult = extensionReader.decodeRow(rowNumber, row, endRange[1]);
                decodeResult.putMetadata(ResultMetadataType.UPC_EAN_EXTENSION, extensionResult.Text);
                decodeResult.putAllMetadata(extensionResult.ResultMetadata);
                decodeResult.addResultPoints(extensionResult.ResultPoints);
            }
            catch (ReaderException re)
            {
                // continue
            }

            if (format == BarcodeFormat.EAN_13 || format == BarcodeFormat.UPC_A)
            {
                string countryID = eanManSupport.lookupCountryIdentifier(resultString);
                if (countryID != null)
                {
                    decodeResult.putMetadata(ResultMetadataType.POSSIBLE_COUNTRY, countryID);
                }
            }

            return(decodeResult);
        }