Preserve line breaks into XHTML
[zxing.git] / csharp / oned / MultiFormatUPCEANReader.cs
index 98dbf79..a801fa6 100755 (executable)
@@ -1,4 +1,6 @@
-/*\r
+/*\r
+* Copyright 2008 ZXing authors\r
+*\r
 * Licensed under the Apache License, Version 2.0 (the "License");\r
 * you may not use this file except in compliance with the License.\r
 * You may obtain a copy of the License at\r
 * See the License for the specific language governing permissions and\r
 * limitations under the License.\r
 */\r
+using System;\r
+using BarcodeFormat = com.google.zxing.BarcodeFormat;\r
+using DecodeHintType = com.google.zxing.DecodeHintType;\r
+using ReaderException = com.google.zxing.ReaderException;\r
+using Result = com.google.zxing.Result;\r
+using BitArray = com.google.zxing.common.BitArray;\r
 namespace com.google.zxing.oned\r
 {\r
-    /**\r
-     * @author dswitkin@google.com (Daniel Switkin)\r
-     * @author Sean Owen\r
-     */\r
-    using System.Text;\r
-    using com.google.zxing.common;\r
-\r
-    public sealed class MultiFormatUPCEANReader : AbstractOneDReader\r
-    { \r
-          private  System.Collections.ArrayList readers;\r
-          public MultiFormatUPCEANReader(System.Collections.Hashtable hints) {\r
-            System.Collections.ArrayList possibleFormats = hints == null ? null : (System.Collections.ArrayList) hints[DecodeHintType.POSSIBLE_FORMATS];\r
-            readers = new System.Collections.ArrayList();\r
-            if (possibleFormats != null) {\r
-              if (possibleFormats.Contains(BarcodeFormat.EAN_13)) {\r
-                readers.Add(new EAN13Reader());\r
-              } else if (possibleFormats.Contains(BarcodeFormat.UPC_A)) {\r
-                readers.Add(new UPCAReader());\r
-              }\r
-              if (possibleFormats.Contains(BarcodeFormat.EAN_8)) {\r
-                readers.Add(new EAN8Reader());\r
-              }\r
-              if (possibleFormats.Contains(BarcodeFormat.UPC_E)) {\r
-                readers.Add(new UPCEReader());\r
-              }\r
-            }\r
-            if (readers.Count==0) {\r
-              readers.Add(new EAN13Reader());\r
-              // UPC-A is covered by EAN-13\r
-              readers.Add(new EAN8Reader());\r
-              readers.Add(new UPCEReader());\r
-            }\r
-          }\r
-\r
-          public override Result decodeRow(int rowNumber, BitArray row, System.Collections.Hashtable hints) {\r
-            // Compute this location once and reuse it on multiple implementations\r
-            int[] startGuardPattern = AbstractUPCEANReader.findStartGuardPattern(row);\r
-            int size = readers.Count;\r
-            for (int i = 0; i < size; i++) {\r
-              UPCEANReader reader = (UPCEANReader) readers[i];\r
-              Result result;\r
-              try {\r
-                result = reader.decodeRow(rowNumber, row, startGuardPattern);\r
-              } catch (ReaderException re) {\r
-                continue;\r
-              }\r
-              // Special case: a 12-digit code encoded in UPC-A is identical to a "0"\r
-              // followed by those 12 digits encoded as EAN-13. Each will recognize such a code,\r
-              // UPC-A as a 12-digit string and EAN-13 as a 13-digit string starting with "0".\r
-              // Individually these are correct and their readers will both read such a code\r
-              // and correctly call it EAN-13, or UPC-A, respectively.\r
-              //\r
-              // In this case, if we've been looking for both types, we'd like to call it\r
-              // a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read\r
-              // UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A\r
-              // result if appropriate.\r
-              if (result.getBarcodeFormat().Equals(BarcodeFormat.EAN_13) && result.getText()[0] == '0') {\r
-                return new Result(result.getText().Substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A);\r
-              }\r
-              return result;\r
-            }\r
-\r
-            throw new ReaderException();\r
-          }\r
-    \r
-    }\r
+       \r
+       /// <summary> <p>A reader that can read all available UPC/EAN formats. If a caller wants to try to\r
+       /// read all such formats, it is most efficient to use this implementation rather than invoke\r
+       /// individual readers.</p>\r
+       /// \r
+       /// </summary>\r
+       /// <author>  Sean Owen\r
+       /// </author>\r
+       /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
+       /// </author>\r
+       public sealed class MultiFormatUPCEANReader:OneDReader\r
+       {\r
+               \r
+               //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
+               private System.Collections.ArrayList readers;\r
+               \r
+               public MultiFormatUPCEANReader(System.Collections.Hashtable hints)\r
+               {\r
+                       System.Collections.ArrayList possibleFormats = hints == null?null:(System.Collections.ArrayList) hints[DecodeHintType.POSSIBLE_FORMATS];\r
+                       readers = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));\r
+                       if (possibleFormats != null)\r
+                       {\r
+                               if (possibleFormats.Contains(BarcodeFormat.EAN_13))\r
+                               {\r
+                                       readers.Add(new EAN13Reader());\r
+                               }\r
+                               else if (possibleFormats.Contains(BarcodeFormat.UPC_A))\r
+                               {\r
+                                       readers.Add(new UPCAReader());\r
+                               }\r
+                               if (possibleFormats.Contains(BarcodeFormat.EAN_8))\r
+                               {\r
+                                       readers.Add(new EAN8Reader());\r
+                               }\r
+                               if (possibleFormats.Contains(BarcodeFormat.UPC_E))\r
+                               {\r
+                                       readers.Add(new UPCEReader());\r
+                               }\r
+                       }\r
+                       if ((readers.Count == 0))\r
+                       {\r
+                               readers.Add(new EAN13Reader());\r
+                               // UPC-A is covered by EAN-13\r
+                               readers.Add(new EAN8Reader());\r
+                               readers.Add(new UPCEReader());\r
+                       }\r
+               }\r
+               \r
+               public override Result decodeRow(int rowNumber, BitArray row, System.Collections.Hashtable hints)\r
+               {\r
+                       // Compute this location once and reuse it on multiple implementations\r
+                       int[] startGuardPattern = UPCEANReader.findStartGuardPattern(row);\r
+                       int size = readers.Count;\r
+                       for (int i = 0; i < size; i++)\r
+                       {\r
+                               UPCEANReader reader = (UPCEANReader) readers[i];\r
+                               Result result;\r
+                               try\r
+                               {\r
+                                       result = reader.decodeRow(rowNumber, row, startGuardPattern, hints);\r
+                               }\r
+                               catch (ReaderException re)\r
+                               {\r
+                                       continue;\r
+                               }\r
+                               // Special case: a 12-digit code encoded in UPC-A is identical to a "0"\r
+                               // followed by those 12 digits encoded as EAN-13. Each will recognize such a code,\r
+                               // UPC-A as a 12-digit string and EAN-13 as a 13-digit string starting with "0".\r
+                               // Individually these are correct and their readers will both read such a code\r
+                               // and correctly call it EAN-13, or UPC-A, respectively.\r
+                               //\r
+                               // In this case, if we've been looking for both types, we'd like to call it\r
+                               // a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read\r
+                               // UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A\r
+                               // result if appropriate.\r
+                               if (result.BarcodeFormat.Equals(BarcodeFormat.EAN_13) && result.Text[0] == '0')\r
+                               {\r
+                                       return new Result(result.Text.Substring(1), null, result.ResultPoints, BarcodeFormat.UPC_A);\r
+                               }\r
+                               return result;\r
+                       }\r
+                       \r
+                       throw ReaderException.Instance;\r
+               }\r
+       }\r
 }
\ No newline at end of file