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
24 /// <summary> This object renders an EAN13 code as a ByteMatrix 2D array of greyscale
\r
28 /// <author> aripollak@gmail.com (Ari Pollak)
\r
30 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
32 public sealed class EAN13Writer:UPCEANWriter
\r
35 private const int codeWidth = 3 + (7 * 6) + 5 + (7 * 6) + 3; // end guard
\r
37 public override ByteMatrix encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Hashtable hints)
\r
39 if (format != BarcodeFormat.EAN_13)
\r
41 throw new System.ArgumentException("Can only encode EAN_13, but got " + format);
\r
44 return base.encode(contents, format, width, height, hints);
\r
47 public override sbyte[] encode(System.String contents)
\r
49 if (contents.Length != 13)
\r
51 throw new System.ArgumentException("Requested contents should be 13 digits long, but got " + contents.Length);
\r
54 int firstDigit = System.Int32.Parse(contents.Substring(0, (1) - (0)));
\r
55 int parities = EAN13Reader.FIRST_DIGIT_ENCODINGS[firstDigit];
\r
56 sbyte[] result = new sbyte[codeWidth];
\r
59 pos += appendPattern(result, pos, UPCEANReader.START_END_PATTERN, 1);
\r
61 // See {@link #EAN13Reader} for a description of how the first digit & left bars are encoded
\r
62 for (int i = 1; i <= 6; i++)
\r
64 int digit = System.Int32.Parse(contents.Substring(i, (i + 1) - (i)));
\r
65 if ((parities >> (6 - i) & 1) == 1)
\r
69 pos += appendPattern(result, pos, UPCEANReader.L_AND_G_PATTERNS[digit], 0);
\r
72 pos += appendPattern(result, pos, UPCEANReader.MIDDLE_PATTERN, 0);
\r
74 for (int i = 7; i <= 12; i++)
\r
76 int digit = System.Int32.Parse(contents.Substring(i, (i + 1) - (i)));
\r
77 pos += appendPattern(result, pos, UPCEANReader.L_PATTERNS[digit], 1);
\r
79 pos += appendPattern(result, pos, UPCEANReader.START_END_PATTERN, 1);
\r