New C# port from Suraj Supekar
[zxing.git] / csharp / oned / UPCAReader.cs
diff --git a/csharp/oned/UPCAReader.cs b/csharp/oned/UPCAReader.cs
new file mode 100755 (executable)
index 0000000..660e011
--- /dev/null
@@ -0,0 +1,86 @@
+/*\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
+*\r
+*      http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\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 ReaderException = com.google.zxing.ReaderException;\r
+using Result = com.google.zxing.Result;\r
+using BinaryBitmap = com.google.zxing.BinaryBitmap;\r
+using BitArray = com.google.zxing.common.BitArray;\r
+namespace com.google.zxing.oned\r
+{\r
+       \r
+       /// <summary> <p>Implements decoding of the UPC-A format.</p>\r
+       /// \r
+       /// </summary>\r
+       /// <author>  dswitkin@google.com (Daniel Switkin)\r
+       /// </author>\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 UPCAReader:UPCEANReader\r
+       {\r
+               override internal BarcodeFormat BarcodeFormat\r
+               {\r
+                       get\r
+                       {\r
+                               return BarcodeFormat.UPC_A;\r
+                       }\r
+                       \r
+               }\r
+               \r
+               //UPGRADE_NOTE: Final was removed from the declaration of 'ean13Reader '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+               private UPCEANReader ean13Reader = new EAN13Reader();\r
+               \r
+               public override Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, System.Collections.Hashtable hints)\r
+               {\r
+                       return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange, hints));\r
+               }\r
+               \r
+               public override Result decodeRow(int rowNumber, BitArray row, System.Collections.Hashtable hints)\r
+               {\r
+                       return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, hints));\r
+               }\r
+               \r
+               public override Result decode(BinaryBitmap image)\r
+               {\r
+                       return maybeReturnResult(ean13Reader.decode(image));\r
+               }\r
+               \r
+               public override Result decode(BinaryBitmap image, System.Collections.Hashtable hints)\r
+               {\r
+                       return maybeReturnResult(ean13Reader.decode(image, hints));\r
+               }\r
+               \r
+               protected internal override int decodeMiddle(BitArray row, int[] startRange, System.Text.StringBuilder resultString)\r
+               {\r
+                       return ean13Reader.decodeMiddle(row, startRange, resultString);\r
+               }\r
+               \r
+               private static Result maybeReturnResult(Result result)\r
+               {\r
+                       System.String text = result.Text;\r
+                       if (text[0] == '0')\r
+                       {\r
+                               return new Result(text.Substring(1), null, result.ResultPoints, BarcodeFormat.UPC_A);\r
+                       }\r
+                       else\r
+                       {\r
+                               throw ReaderException.Instance;\r
+                       }\r
+               }\r
+       }\r
+}
\ No newline at end of file