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;
27 import com.google.zxing.oned.rss.expanded.RSSExpandedReader;
29 import java.util.Hashtable;
30 import java.util.Vector;
33 * @author dswitkin@google.com (Daniel Switkin)
36 public final class MultiFormatOneDReader extends OneDReader {
38 private final Vector readers;
40 public MultiFormatOneDReader(Hashtable hints) {
41 Vector possibleFormats = hints == null ? null :
42 (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
43 boolean useCode39CheckDigit = hints != null &&
44 hints.get(DecodeHintType.ASSUME_CODE_39_CHECK_DIGIT) != null;
45 readers = new Vector();
46 if (possibleFormats != null) {
47 if (possibleFormats.contains(BarcodeFormat.EAN_13) ||
48 possibleFormats.contains(BarcodeFormat.UPC_A) ||
49 possibleFormats.contains(BarcodeFormat.EAN_8) ||
50 possibleFormats.contains(BarcodeFormat.UPC_E)) {
51 readers.addElement(new MultiFormatUPCEANReader(hints));
53 if (possibleFormats.contains(BarcodeFormat.CODE_39)) {
54 readers.addElement(new Code39Reader(useCode39CheckDigit));
56 if (possibleFormats.contains(BarcodeFormat.CODE_128)) {
57 readers.addElement(new Code128Reader());
59 if (possibleFormats.contains(BarcodeFormat.ITF)) {
60 readers.addElement(new ITFReader());
62 if (possibleFormats.contains(BarcodeFormat.RSS14)) {
63 readers.addElement(new RSS14Reader());
65 if (possibleFormats.contains(BarcodeFormat.RSS_EXPANDED)){
66 readers.addElement(new RSSExpandedReader());
69 if (readers.isEmpty()) {
70 readers.addElement(new MultiFormatUPCEANReader(hints));
71 readers.addElement(new Code39Reader());
72 readers.addElement(new Code128Reader());
73 readers.addElement(new ITFReader());
74 readers.addElement(new RSS14Reader());
75 readers.addElement(new RSSExpandedReader());
79 public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws NotFoundException {
80 int size = readers.size();
81 for (int i = 0; i < size; i++) {
82 OneDReader reader = (OneDReader) readers.elementAt(i);
84 return reader.decodeRow(rowNumber, row, hints);
85 } catch (ReaderException re) {
90 throw NotFoundException.getNotFoundInstance();
94 int size = readers.size();
95 for (int i = 0; i < size; i++) {
96 Reader reader = (Reader) readers.elementAt(i);