2 * Copyright 2008 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 using BarcodeFormat = com.google.zxing.BarcodeFormat;
\r
18 using DecodeHintType = com.google.zxing.DecodeHintType;
\r
19 using ReaderException = com.google.zxing.ReaderException;
\r
20 using Result = com.google.zxing.Result;
\r
21 using BitArray = com.google.zxing.common.BitArray;
\r
22 namespace com.google.zxing.oned
\r
25 /// <summary> <p>A reader that can read all available UPC/EAN formats. If a caller wants to try to
\r
26 /// read all such formats, it is most efficient to use this implementation rather than invoke
\r
27 /// individual readers.</p>
\r
30 /// <author> Sean Owen
\r
32 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
34 public sealed class MultiFormatUPCEANReader:OneDReader
\r
37 //UPGRADE_NOTE: Final was removed from the declaration of 'readers '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
38 private System.Collections.ArrayList readers;
\r
40 public MultiFormatUPCEANReader(System.Collections.Hashtable hints)
\r
42 System.Collections.ArrayList possibleFormats = hints == null?null:(System.Collections.ArrayList) hints[DecodeHintType.POSSIBLE_FORMATS];
\r
43 readers = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
\r
44 if (possibleFormats != null)
\r
46 if (possibleFormats.Contains(BarcodeFormat.EAN_13))
\r
48 readers.Add(new EAN13Reader());
\r
50 else if (possibleFormats.Contains(BarcodeFormat.UPC_A))
\r
52 readers.Add(new UPCAReader());
\r
54 if (possibleFormats.Contains(BarcodeFormat.EAN_8))
\r
56 readers.Add(new EAN8Reader());
\r
58 if (possibleFormats.Contains(BarcodeFormat.UPC_E))
\r
60 readers.Add(new UPCEReader());
\r
63 if ((readers.Count == 0))
\r
65 readers.Add(new EAN13Reader());
\r
66 // UPC-A is covered by EAN-13
\r
67 readers.Add(new EAN8Reader());
\r
68 readers.Add(new UPCEReader());
\r
72 public override Result decodeRow(int rowNumber, BitArray row, System.Collections.Hashtable hints)
\r
74 // Compute this location once and reuse it on multiple implementations
\r
75 int[] startGuardPattern = UPCEANReader.findStartGuardPattern(row);
\r
76 int size = readers.Count;
\r
77 for (int i = 0; i < size; i++)
\r
79 UPCEANReader reader = (UPCEANReader) readers[i];
\r
83 result = reader.decodeRow(rowNumber, row, startGuardPattern, hints);
\r
85 catch (ReaderException re)
\r
89 // Special case: a 12-digit code encoded in UPC-A is identical to a "0"
\r
90 // followed by those 12 digits encoded as EAN-13. Each will recognize such a code,
\r
91 // UPC-A as a 12-digit string and EAN-13 as a 13-digit string starting with "0".
\r
92 // Individually these are correct and their readers will both read such a code
\r
93 // and correctly call it EAN-13, or UPC-A, respectively.
\r
95 // In this case, if we've been looking for both types, we'd like to call it
\r
96 // a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read
\r
97 // UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A
\r
98 // result if appropriate.
\r
99 if (result.BarcodeFormat.Equals(BarcodeFormat.EAN_13) && result.Text[0] == '0')
\r
101 return new Result(result.Text.Substring(1), null, result.ResultPoints, BarcodeFormat.UPC_A);
\r
106 throw ReaderException.Instance;
\r