Added rendering fix from beyonddeath
[zxing.git] / csharp / oned / MultiFormatOneDReader.cs
1 /*\r
2 * Licensed under the Apache License, Version 2.0 (the "License");\r
3 * you may not use this file except in compliance with the License.\r
4 * You may obtain a copy of the License at\r
5 *\r
6 *      http://www.apache.org/licenses/LICENSE-2.0\r
7 *\r
8 * Unless required by applicable law or agreed to in writing, software\r
9 * distributed under the License is distributed on an "AS IS" BASIS,\r
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
11 * See the License for the specific language governing permissions and\r
12 * limitations under the License.\r
13 */\r
14 namespace com.google.zxing.oned\r
15 {\r
16     /**\r
17      * @author dswitkin@google.com (Daniel Switkin)\r
18      * @author Sean Owen\r
19      */\r
20     using System.Text;\r
21     using com.google.zxing.common;\r
22 \r
23     public sealed class MultiFormatOneDReader : AbstractOneDReader\r
24     { \r
25           private System.Collections.ArrayList readers;\r
26 \r
27           public MultiFormatOneDReader(System.Collections.Hashtable hints)\r
28           {\r
29             System.Collections.ArrayList possibleFormats = hints == null ? null : (System.Collections.ArrayList) hints[DecodeHintType.POSSIBLE_FORMATS];\r
30             readers = new System.Collections.ArrayList();\r
31             if (possibleFormats != null) {\r
32               if (possibleFormats.Contains(BarcodeFormat.EAN_13) ||\r
33                   possibleFormats.Contains(BarcodeFormat.UPC_A) ||\r
34                   possibleFormats.Contains(BarcodeFormat.EAN_8) ||\r
35                   possibleFormats.Contains(BarcodeFormat.UPC_E))\r
36               {\r
37                 readers.Add(new MultiFormatUPCEANReader(hints));\r
38               }\r
39               if (possibleFormats.Contains(BarcodeFormat.CODE_39)) {\r
40                   readers.Add(new Code39Reader());\r
41               }\r
42               if (possibleFormats.Contains(BarcodeFormat.CODE_128))\r
43               {\r
44                   readers.Add(new Code128Reader());\r
45               }\r
46               if (possibleFormats.Contains(BarcodeFormat.ITF))\r
47               {\r
48                   readers.Add(new ITFReader());\r
49               }\r
50             }\r
51             if (readers.Count==0) {\r
52                 readers.Contains(new MultiFormatUPCEANReader(hints));\r
53                 readers.Contains(new Code39Reader());\r
54                 readers.Contains(new Code128Reader());\r
55               // TODO: Add ITFReader once it is validated as production ready, and tested for performance.\r
56               //readers.addElement(new ITFReader());\r
57             }\r
58           }\r
59 \r
60           public override Result decodeRow(int rowNumber, BitArray row, System.Collections.Hashtable hints)\r
61           {\r
62             int size = readers.Count;\r
63             for (int i = 0; i < size; i++) {\r
64               OneDReader reader = (OneDReader) readers[i];\r
65               try {\r
66                 return reader.decodeRow(rowNumber, row, hints);\r
67               } catch (ReaderException re) {\r
68                 // continue\r
69               }\r
70             }\r
71 \r
72             throw new ReaderException();\r
73           }\r
74     \r
75     }\r
76 }