public byte[] encode(String contents) { int length = contents.length(); if (length > 80) { throw new IllegalArgumentException( "Requested contents should be less than 80 digits long, but got " + length); } byte[] result = new byte[9 + 9 * length]; int[] start = {1, 1, 1, 1}; int pos = appendPattern(result, 0, start, 1); for (int i = 0; i < length; i += 2) { int one = Character.digit(contents.charAt(i), 10); int two = Character.digit(contents.charAt(i+1), 10); int[] encoding = new int[18]; for (int j = 0; j < 10; j += 2) { encoding[j] = ITFReader.PATTERNS[one][j]; encoding[j + 1] = ITFReader.PATTERNS[two][j]; } pos += appendPattern(result, pos, encoding, 1); } int[] end = {3, 1, 1}; pos += appendPattern(result, pos, end, 1); return result; }
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Hashtable hints) throws WriterException { Writer writer; if (format == BarcodeFormat.EAN_8) { writer = new EAN8Writer(); } else if (format == BarcodeFormat.EAN_13) { writer = new EAN13Writer(); } else if (format == BarcodeFormat.QR_CODE) { writer = new QRCodeWriter(); } else if (format == BarcodeFormat.CODE_39) { writer = new Code39Writer(); } else if (format == BarcodeFormat.CODE_128) { writer = new Code128Writer(); } else if (format == BarcodeFormat.ITF) { writer = new ITFWriter(); } else { throw new IllegalArgumentException("No encoder available for format " + format); } return writer.encode(contents, format, width, height, hints); }
@Override public boolean[] encode(String contents) { int length = contents.length(); if (length % 2 != 0) { throw new IllegalArgumentException("The length of the input should be even"); } if (length > 80) { throw new IllegalArgumentException( "Requested contents should be less than 80 digits long, but got " + length); } boolean[] result = new boolean[9 + 9 * length]; int pos = appendPattern(result, 0, START_PATTERN, true); for (int i = 0; i < length; i += 2) { int one = Character.digit(contents.charAt(i), 10); int two = Character.digit(contents.charAt(i + 1), 10); int[] encoding = new int[10]; for (int j = 0; j < 5; j++) { encoding[2 * j] = ITFReader.PATTERNS[one][j]; encoding[2 * j + 1] = ITFReader.PATTERNS[two][j]; } pos += appendPattern(result, pos, encoding, true); } appendPattern(result, pos, END_PATTERN, true); return result; }
@Override public boolean[] encode(String contents) { int length = contents.length(); if (length % 2 != 0) { throw new IllegalArgumentException("The length of the input should be even"); } if (length > 80) { throw new IllegalArgumentException( "Requested contents should be less than 80 digits long, but got " + length); } boolean[] result = new boolean[9 + 9 * length]; int pos = appendPattern(result, 0, START_PATTERN, true); for (int i = 0; i < length; i += 2) { int one = Character.digit(contents.charAt(i), 10); int two = Character.digit(contents.charAt(i + 1), 10); int[] encoding = new int[10]; for (int j = 0; j < 5; j++) { encoding[2 * j] = ITFReader.PATTERNS[one][j]; encoding[2 * j + 1] = ITFReader.PATTERNS[two][j]; } pos += appendPattern(result, pos, encoding, true); } appendPattern(result, pos, END_PATTERN, true); return result; }