Houjie
2025-07-24 52a3ff1bce1417b39f6872d8e8cb378e9c2ccc6f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright 2008 ZXing authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*namespace com.google.zxing.oned {*/
import BarcodeFormat from '../BarcodeFormat';
import DecodeHintType from '../DecodeHintType';
import NotFoundException from '../NotFoundException';
import Code128Reader from './Code128Reader';
import Code39Reader from './Code39Reader';
import Code93Reader from './Code93Reader';
import ITFReader from './ITFReader';
import MultiFormatUPCEANReader from './MultiFormatUPCEANReader';
import OneDReader from './OneDReader';
import CodaBarReader from './CodaBarReader';
import RSSExpandedReader from './rss/expanded/RSSExpandedReader';
import RSS14Reader from './rss/RSS14Reader';
/**
 * @author Daniel Switkin <dswitkin@google.com>
 * @author Sean Owen
 */
export default class MultiFormatOneDReader extends OneDReader {
    constructor(hints) {
        super();
        this.readers = [];
        const possibleFormats = !hints ? null : hints.get(DecodeHintType.POSSIBLE_FORMATS);
        const useCode39CheckDigit = hints && hints.get(DecodeHintType.ASSUME_CODE_39_CHECK_DIGIT) !== undefined;
        const useCode39ExtendedMode = hints && hints.get(DecodeHintType.ENABLE_CODE_39_EXTENDED_MODE) !== undefined;
        if (possibleFormats) {
            if (possibleFormats.includes(BarcodeFormat.EAN_13) ||
                possibleFormats.includes(BarcodeFormat.UPC_A) ||
                possibleFormats.includes(BarcodeFormat.EAN_8) ||
                possibleFormats.includes(BarcodeFormat.UPC_E)) {
                this.readers.push(new MultiFormatUPCEANReader(hints));
            }
            if (possibleFormats.includes(BarcodeFormat.CODE_39)) {
                this.readers.push(new Code39Reader(useCode39CheckDigit, useCode39ExtendedMode));
            }
            if (possibleFormats.includes(BarcodeFormat.CODE_93)) {
                this.readers.push(new Code93Reader());
            }
            if (possibleFormats.includes(BarcodeFormat.CODE_128)) {
                this.readers.push(new Code128Reader());
            }
            if (possibleFormats.includes(BarcodeFormat.ITF)) {
                this.readers.push(new ITFReader());
            }
            if (possibleFormats.includes(BarcodeFormat.CODABAR)) {
                this.readers.push(new CodaBarReader());
            }
            if (possibleFormats.includes(BarcodeFormat.RSS_14)) {
                this.readers.push(new RSS14Reader());
            }
            if (possibleFormats.includes(BarcodeFormat.RSS_EXPANDED)) {
                console.warn('RSS Expanded reader IS NOT ready for production yet! use at your own risk.');
                this.readers.push(new RSSExpandedReader());
            }
        }
        if (this.readers.length === 0) {
            this.readers.push(new MultiFormatUPCEANReader(hints));
            this.readers.push(new Code39Reader());
            // this.readers.push(new CodaBarReader());
            this.readers.push(new Code93Reader());
            this.readers.push(new MultiFormatUPCEANReader(hints));
            this.readers.push(new Code128Reader());
            this.readers.push(new ITFReader());
            this.readers.push(new RSS14Reader());
            // this.readers.push(new RSSExpandedReader());
        }
    }
    // @Override
    decodeRow(rowNumber, row, hints) {
        for (let i = 0; i < this.readers.length; i++) {
            try {
                return this.readers[i].decodeRow(rowNumber, row, hints);
            }
            catch (re) {
                // continue
            }
        }
        throw new NotFoundException();
    }
    // @Override
    reset() {
        this.readers.forEach(reader => reader.reset());
    }
}