2 * Copyright 2009 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 using BarcodeFormat = com.google.zxing.BarcodeFormat;
\r
18 using WriterException = com.google.zxing.WriterException;
\r
19 using ByteMatrix = com.google.zxing.common.ByteMatrix;
\r
20 namespace com.google.zxing.oned
\r
23 /// <summary> This object renders an EAN8 code as a ByteMatrix 2D array of greyscale
\r
27 /// <author> aripollak@gmail.com (Ari Pollak)
\r
29 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
31 public sealed class EAN8Writer:UPCEANWriter
\r
34 private const int codeWidth = 3 + (7 * 4) + 5 + (7 * 4) + 3; // end guard
\r
36 public override ByteMatrix encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Hashtable hints)
\r
38 if (format != BarcodeFormat.EAN_8)
\r
40 throw new System.ArgumentException("Can only encode EAN_8, but got " + format);
\r
43 return base.encode(contents, format, width, height, hints);
\r
46 /// <returns> a byte array of horizontal pixels (0 = white, 1 = black)
\r
48 public override sbyte[] encode(System.String contents)
\r
50 if (contents.Length != 8)
\r
52 throw new System.ArgumentException("Requested contents should be 8 digits long, but got " + contents.Length);
\r
55 sbyte[] result = new sbyte[codeWidth];
\r
58 pos += appendPattern(result, pos, UPCEANReader.START_END_PATTERN, 1);
\r
60 for (int i = 0; i <= 3; i++)
\r
62 int digit = System.Int32.Parse(contents.Substring(i, (i + 1) - (i)));
\r
63 pos += appendPattern(result, pos, UPCEANReader.L_PATTERNS[digit], 0);
\r
66 pos += appendPattern(result, pos, UPCEANReader.MIDDLE_PATTERN, 0);
\r
68 for (int i = 4; i <= 7; i++)
\r
70 int digit = System.Int32.Parse(contents.Substring(i, (i + 1) - (i)));
\r
71 pos += appendPattern(result, pos, UPCEANReader.L_PATTERNS[digit], 1);
\r
73 pos += appendPattern(result, pos, UPCEANReader.START_END_PATTERN, 1);
\r