2 * Copyright 2008 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.oned;
19 import com.google.zxing.BarcodeFormat;
20 import com.google.zxing.DecodeHintType;
21 import com.google.zxing.NotFoundException;
22 import com.google.zxing.Reader;
23 import com.google.zxing.ReaderException;
24 import com.google.zxing.Result;
25 import com.google.zxing.common.BitArray;
26 import com.google.zxing.oned.rss.RSS14Reader;
28 import java.util.Hashtable;
29 import java.util.Vector;
32 * @author dswitkin@google.com (Daniel Switkin)
35 public final class MultiFormatOneDReader extends OneDReader {
37 private final Vector readers;
39 public MultiFormatOneDReader(Hashtable hints) {
40 Vector possibleFormats = hints == null ? null :
41 (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
42 boolean useCode39CheckDigit = hints != null &&
43 hints.get(DecodeHintType.ASSUME_CODE_39_CHECK_DIGIT) != null;
44 readers = new Vector();
45 if (possibleFormats != null) {
46 if (possibleFormats.contains(BarcodeFormat.EAN_13) ||
47 possibleFormats.contains(BarcodeFormat.UPC_A) ||
48 possibleFormats.contains(BarcodeFormat.EAN_8) ||
49 possibleFormats.contains(BarcodeFormat.UPC_E)) {
50 readers.addElement(new MultiFormatUPCEANReader(hints));
52 if (possibleFormats.contains(BarcodeFormat.CODE_39)) {
53 readers.addElement(new Code39Reader(useCode39CheckDigit));
55 if (possibleFormats.contains(BarcodeFormat.CODE_128)) {
56 readers.addElement(new Code128Reader());
58 if (possibleFormats.contains(BarcodeFormat.ITF)) {
59 readers.addElement(new ITFReader());
61 if (possibleFormats.contains(BarcodeFormat.RSS14)) {
62 readers.addElement(new RSS14Reader());
65 if (readers.isEmpty()) {
66 readers.addElement(new MultiFormatUPCEANReader(hints));
67 readers.addElement(new Code39Reader());
68 readers.addElement(new Code128Reader());
69 readers.addElement(new ITFReader());
70 readers.addElement(new RSS14Reader());
74 public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws NotFoundException {
75 int size = readers.size();
76 for (int i = 0; i < size; i++) {
77 OneDReader reader = (OneDReader) readers.elementAt(i);
79 return reader.decodeRow(rowNumber, row, hints);
80 } catch (ReaderException re) {
85 throw NotFoundException.getNotFoundInstance();
89 int size = readers.size();
90 for (int i = 0; i < size; i++) {
91 Reader reader = (Reader) readers.elementAt(i);