mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Issue 1738 Add support for margin hint in PDF417
git-svn-id: https://zxing.googlecode.com/svn/trunk@2846 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
29eeee8ccd
commit
ef96893525
|
@ -33,6 +33,11 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public final class PDF417Writer implements Writer {
|
public final class PDF417Writer implements Writer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default white space (margin) around the code
|
||||||
|
*/
|
||||||
|
static final int WHITE_SPACE = 30;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BitMatrix encode(String contents,
|
public BitMatrix encode(String contents,
|
||||||
BarcodeFormat format,
|
BarcodeFormat format,
|
||||||
|
@ -44,6 +49,7 @@ public final class PDF417Writer implements Writer {
|
||||||
}
|
}
|
||||||
|
|
||||||
PDF417 encoder = new PDF417();
|
PDF417 encoder = new PDF417();
|
||||||
|
int margin = WHITE_SPACE;
|
||||||
|
|
||||||
if (hints != null) {
|
if (hints != null) {
|
||||||
if (hints.containsKey(EncodeHintType.PDF417_COMPACT)) {
|
if (hints.containsKey(EncodeHintType.PDF417_COMPACT)) {
|
||||||
|
@ -59,9 +65,12 @@ public final class PDF417Writer implements Writer {
|
||||||
dimensions.getMaxRows(),
|
dimensions.getMaxRows(),
|
||||||
dimensions.getMinRows());
|
dimensions.getMinRows());
|
||||||
}
|
}
|
||||||
|
if (hints.containsKey(EncodeHintType.MARGIN)) {
|
||||||
|
margin = ((Number) hints.get(EncodeHintType.MARGIN)).intValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitMatrixFromEncoder(encoder, contents, width, height);
|
return bitMatrixFromEncoder(encoder, contents, width, height, margin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -78,7 +87,8 @@ public final class PDF417Writer implements Writer {
|
||||||
private static BitMatrix bitMatrixFromEncoder(PDF417 encoder,
|
private static BitMatrix bitMatrixFromEncoder(PDF417 encoder,
|
||||||
String contents,
|
String contents,
|
||||||
int width,
|
int width,
|
||||||
int height) throws WriterException {
|
int height,
|
||||||
|
int margin) throws WriterException {
|
||||||
int errorCorrectionLevel = 2;
|
int errorCorrectionLevel = 2;
|
||||||
encoder.generateBarcodeLogic(contents, errorCorrectionLevel);
|
encoder.generateBarcodeLogic(contents, errorCorrectionLevel);
|
||||||
|
|
||||||
|
@ -107,29 +117,27 @@ public final class PDF417Writer implements Writer {
|
||||||
if (rotated) {
|
if (rotated) {
|
||||||
scaledMatrix = rotateArray(scaledMatrix);
|
scaledMatrix = rotateArray(scaledMatrix);
|
||||||
}
|
}
|
||||||
return bitMatrixFrombitArray(scaledMatrix);
|
return bitMatrixFrombitArray(scaledMatrix, margin);
|
||||||
}
|
}
|
||||||
return bitMatrixFrombitArray(originalScale);
|
return bitMatrixFrombitArray(originalScale, margin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This takes an array holding the values of the PDF 417
|
* This takes an array holding the values of the PDF 417
|
||||||
*
|
*
|
||||||
* @param input a byte array of information with 0 is black, and 1 is white
|
* @param input a byte array of information with 0 is black, and 1 is white
|
||||||
|
* @param margin border around the barcode
|
||||||
* @return BitMatrix of the input
|
* @return BitMatrix of the input
|
||||||
*/
|
*/
|
||||||
private static BitMatrix bitMatrixFrombitArray(byte[][] input) {
|
private static BitMatrix bitMatrixFrombitArray(byte[][] input, int margin) {
|
||||||
// Creates a small whitespace border around the barcode
|
|
||||||
int whiteSpace = 30;
|
|
||||||
|
|
||||||
// Creates the bitmatrix with extra space for whitespace
|
// Creates the bitmatrix with extra space for whitespace
|
||||||
BitMatrix output = new BitMatrix(input[0].length + 2 * whiteSpace, input.length + 2 * whiteSpace);
|
BitMatrix output = new BitMatrix(input[0].length + 2 * margin, input.length + 2 * margin);
|
||||||
output.clear();
|
output.clear();
|
||||||
for (int y = 0, yOutput = output.getHeight() - whiteSpace; y < input.length; y++, yOutput--) {
|
for (int y = 0, yOutput = output.getHeight() - margin - 1; y < input.length; y++, yOutput--) {
|
||||||
for (int x = 0; x < input[0].length; x++) {
|
for (int x = 0; x < input[0].length; x++) {
|
||||||
// Zero is white in the bytematrix
|
// Zero is white in the bytematrix
|
||||||
if (input[y][x] == 1) {
|
if (input[y][x] == 1) {
|
||||||
output.set(x + whiteSpace, yOutput);
|
output.set(x + margin, yOutput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,14 +33,14 @@ public final class BarcodeMatrix {
|
||||||
* @param width the width of the matrix (Cols)
|
* @param width the width of the matrix (Cols)
|
||||||
*/
|
*/
|
||||||
BarcodeMatrix(int height, int width) {
|
BarcodeMatrix(int height, int width) {
|
||||||
matrix = new BarcodeRow[height + 2];
|
matrix = new BarcodeRow[height];
|
||||||
//Initializes the array to the correct width
|
//Initializes the array to the correct width
|
||||||
for (int i = 0, matrixLength = matrix.length; i < matrixLength; i++) {
|
for (int i = 0, matrixLength = matrix.length; i < matrixLength; i++) {
|
||||||
matrix[i] = new BarcodeRow((width + 4) * 17 + 1);
|
matrix[i] = new BarcodeRow((width + 4) * 17 + 1);
|
||||||
}
|
}
|
||||||
this.width = width * 17;
|
this.width = width * 17;
|
||||||
this.height = height + 2;
|
this.height = height;
|
||||||
this.currentRow = 0;
|
this.currentRow = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set(int x, int y, byte value) {
|
void set(int x, int y, byte value) {
|
||||||
|
|
Loading…
Reference in a new issue