mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Issue 1263 refactor PDF417 Writer interface
git-svn-id: https://zxing.googlecode.com/svn/trunk@2289 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
9fa7d9aba4
commit
6ea8a2e6b0
|
@ -24,13 +24,32 @@ package com.google.zxing;
|
||||||
public enum EncodeHintType {
|
public enum EncodeHintType {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies what degree of error correction to use, for example in QR Codes (type Integer).
|
* Specifies what degree of error correction to use, for example in QR Codes.
|
||||||
|
* Type depends on the encoder. For example for QR codes it's type
|
||||||
|
* {@link com.google.zxing.qrcode.decoder.ErrorCorrectionLevel ErrorCorrectionLevel}.
|
||||||
*/
|
*/
|
||||||
ERROR_CORRECTION,
|
ERROR_CORRECTION,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies what character encoding to use where applicable (type String)
|
* Specifies what character encoding to use where applicable (type {@link String})
|
||||||
*/
|
*/
|
||||||
CHARACTER_SET,
|
CHARACTER_SET,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies whether to use compact mode for PDF417 (type {@link Boolean}).
|
||||||
|
*/
|
||||||
|
PDF417_COMPACT,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies what compaction mode to use for PDF417 (type
|
||||||
|
* {@link com.google.zxing.pdf417.encoder.Compaction Compaction}).
|
||||||
|
*/
|
||||||
|
PDF417_COMPACTION,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the minimum and maximum number of rows and columns for PDF417 (type
|
||||||
|
* {@link com.google.zxing.pdf417.encoder.Dimensions Dimensions}).
|
||||||
|
*/
|
||||||
|
PDF417_DIMENSIONS,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
54
core/src/com/google/zxing/pdf417/encoder/Dimensions.java
Normal file
54
core/src/com/google/zxing/pdf417/encoder/Dimensions.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012 ZXing authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.zxing.pdf417.encoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data object to specify the minimum and maximum number of rows and columns for a PDF417 barcode.
|
||||||
|
*
|
||||||
|
* @author qwandor@google.com (Andrew Walbran)
|
||||||
|
*/
|
||||||
|
public final class Dimensions {
|
||||||
|
|
||||||
|
private final int minCols;
|
||||||
|
private final int maxCols;
|
||||||
|
private final int minRows;
|
||||||
|
private final int maxRows;
|
||||||
|
|
||||||
|
public Dimensions(int minCols, int maxCols, int minRows, int maxRows) {
|
||||||
|
this.minCols = minCols;
|
||||||
|
this.maxCols = maxCols;
|
||||||
|
this.minRows = minRows;
|
||||||
|
this.maxRows = maxRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinCols() {
|
||||||
|
return minCols;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxCols() {
|
||||||
|
return maxCols;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinRows() {
|
||||||
|
return minRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxRows() {
|
||||||
|
return maxRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 ZXing authors
|
* Copyright 2012 ZXing authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -22,10 +22,12 @@ import com.google.zxing.Writer;
|
||||||
import com.google.zxing.WriterException;
|
import com.google.zxing.WriterException;
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
|
|
||||||
|
import java.util.EnumMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jacob Haynes
|
* @author Jacob Haynes
|
||||||
|
* @author qwandor@google.com (Andrew Walbran)
|
||||||
*/
|
*/
|
||||||
public final class PDF417Writer implements Writer {
|
public final class PDF417Writer implements Writer {
|
||||||
|
|
||||||
|
@ -35,7 +37,29 @@ public final class PDF417Writer implements Writer {
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
Map<EncodeHintType,?> hints) throws WriterException {
|
Map<EncodeHintType,?> hints) throws WriterException {
|
||||||
return encode(contents, format, width, height);
|
if (format != BarcodeFormat.PDF_417) {
|
||||||
|
throw new IllegalArgumentException("Can only encode PDF_417, but got " + format);
|
||||||
|
}
|
||||||
|
|
||||||
|
PDF417 encoder = new PDF417();
|
||||||
|
|
||||||
|
if (hints != null) {
|
||||||
|
if (hints.containsKey(EncodeHintType.PDF417_COMPACT)) {
|
||||||
|
encoder.setCompact((Boolean) hints.get(EncodeHintType.PDF417_COMPACT));
|
||||||
|
}
|
||||||
|
if (hints.containsKey(EncodeHintType.PDF417_COMPACTION)) {
|
||||||
|
encoder.setCompaction((Compaction) hints.get(EncodeHintType.PDF417_COMPACTION));
|
||||||
|
}
|
||||||
|
if (hints.containsKey(EncodeHintType.PDF417_DIMENSIONS)) {
|
||||||
|
Dimensions dimensions = (Dimensions) hints.get(EncodeHintType.PDF417_DIMENSIONS);
|
||||||
|
encoder.setDimensions(dimensions.getMaxCols(),
|
||||||
|
dimensions.getMinCols(),
|
||||||
|
dimensions.getMaxRows(),
|
||||||
|
dimensions.getMinRows());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitMatrixFromEncoder(encoder, contents, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,10 +67,14 @@ public final class PDF417Writer implements Writer {
|
||||||
BarcodeFormat format,
|
BarcodeFormat format,
|
||||||
int width,
|
int width,
|
||||||
int height) throws WriterException {
|
int height) throws WriterException {
|
||||||
PDF417 encoder = initializeEncoder(format, false);
|
return encode(contents, format, width, height, null);
|
||||||
return bitMatrixFromEncoder(encoder, contents, width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #encode(String, BarcodeFormat, int, int, Map)} instead, with hints to
|
||||||
|
* specify the encoding options.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public BitMatrix encode(String contents,
|
public BitMatrix encode(String contents,
|
||||||
BarcodeFormat format,
|
BarcodeFormat format,
|
||||||
boolean compact,
|
boolean compact,
|
||||||
|
@ -57,26 +85,11 @@ public final class PDF417Writer implements Writer {
|
||||||
int minRows,
|
int minRows,
|
||||||
int maxRows,
|
int maxRows,
|
||||||
Compaction compaction) throws WriterException {
|
Compaction compaction) throws WriterException {
|
||||||
PDF417 encoder = initializeEncoder(format, compact);
|
Map<EncodeHintType, Object> hints = new EnumMap<EncodeHintType,Object>(EncodeHintType.class);
|
||||||
|
hints.put(EncodeHintType.PDF417_COMPACT, compact);
|
||||||
// Set options: dimensions and byte compaction
|
hints.put(EncodeHintType.PDF417_COMPACTION, compaction);
|
||||||
encoder.setDimensions(maxCols, minCols, maxRows, minRows);
|
hints.put(EncodeHintType.PDF417_DIMENSIONS, new Dimensions(maxCols, minCols, maxRows, minRows));
|
||||||
encoder.setCompaction(compaction);
|
return encode(contents, format, width, height, hints);
|
||||||
|
|
||||||
return bitMatrixFromEncoder(encoder, contents, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the encoder based on the format (whether it's compact or not)
|
|
||||||
*/
|
|
||||||
private static PDF417 initializeEncoder(BarcodeFormat format, boolean compact) {
|
|
||||||
if (format != BarcodeFormat.PDF_417) {
|
|
||||||
throw new IllegalArgumentException("Can only encode PDF_417, but got " + format);
|
|
||||||
}
|
|
||||||
|
|
||||||
PDF417 encoder = new PDF417();
|
|
||||||
encoder.setCompact(compact);
|
|
||||||
return encoder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,10 +139,10 @@ public final class PDF417Writer implements Writer {
|
||||||
* @return BitMatrix of the input
|
* @return BitMatrix of the input
|
||||||
*/
|
*/
|
||||||
private static BitMatrix bitMatrixFrombitArray(byte[][] input) {
|
private static BitMatrix bitMatrixFrombitArray(byte[][] input) {
|
||||||
//Creates a small whitespace boarder around the barcode
|
// Creates a small whitespace border around the barcode
|
||||||
int whiteSpace = 30;
|
int whiteSpace = 30;
|
||||||
|
|
||||||
//Creates the bitmatrix with extra space for whtespace
|
// Creates the bitmatrix with extra space for whitespace
|
||||||
BitMatrix output = new BitMatrix(input.length + 2 * whiteSpace, input[0].length + 2 * whiteSpace);
|
BitMatrix output = new BitMatrix(input.length + 2 * whiteSpace, input[0].length + 2 * whiteSpace);
|
||||||
output.clear();
|
output.clear();
|
||||||
for (int ii = 0; ii < input.length; ii++) {
|
for (int ii = 0; ii < input.length; ii++) {
|
||||||
|
|
Loading…
Reference in a new issue